Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.8 KiB

  1. //--------------------------------------------------------------------
  2. // AccurateSysCalls - implementation
  3. // Copyright (C) Microsoft Corporation, 1999
  4. //
  5. // Created by: Louis Thomas (louisth), 9-24-99
  6. //
  7. // More accurate time functions calling the NT api directly
  8. //
  9. #include <pch.h>
  10. //--------------------------------------------------------------------
  11. void __fastcall AccurateGetSystemTime(unsigned __int64 * pqwTime) {
  12. FILETIME ft;
  13. // GetSystemTimeAsFileTime is more efficient than NtQuerySystemTime.
  14. GetSystemTimeAsFileTime(&ft);
  15. *pqwTime = ft.dwLowDateTime+(((unsigned __int64)ft.dwHighDateTime)<<32);
  16. }
  17. //--------------------------------------------------------------------
  18. void __fastcall AccurateSetSystemTime(unsigned __int64 * pqwTime) {
  19. NtSetSystemTime((LARGE_INTEGER *)pqwTime, NULL);
  20. }
  21. //--------------------------------------------------------------------
  22. void __fastcall AccurateGetTickCount(unsigned __int64 * pqwTick) {
  23. // HACKHACK: this is not thread safe and assumes that it will
  24. // always be called more often than every 47 days.
  25. static unsigned __int32 dwLastTickCount=0;
  26. static unsigned __int32 dwHighTickCount=0;
  27. unsigned __int64 qwTickCount;
  28. qwTickCount = NtGetTickCount();
  29. if (static_cast<DWORD>(qwTickCount)<dwLastTickCount) {
  30. dwHighTickCount++;
  31. }
  32. dwLastTickCount=static_cast<DWORD>(qwTickCount);
  33. *pqwTick=dwLastTickCount+(((unsigned __int64)dwHighTickCount)<<32);
  34. };
  35. //--------------------------------------------------------------------
  36. void __fastcall AccurateGetTickCount2(unsigned __int64 * pqwTick) {
  37. // HACKHACK: this is not thread safe and assumes that it will
  38. // always be called more often than every 47 days.
  39. static unsigned __int32 dwLastTickCount=0;
  40. static unsigned __int32 dwHighTickCount=0;
  41. unsigned __int64 qwTickCount;
  42. qwTickCount = NtGetTickCount();
  43. if (static_cast<DWORD>(qwTickCount)<dwLastTickCount) {
  44. dwHighTickCount++;
  45. }
  46. dwLastTickCount=static_cast<DWORD>(qwTickCount);
  47. *pqwTick=dwLastTickCount+(((unsigned __int64)dwHighTickCount)<<32);
  48. };
  49. //--------------------------------------------------------------------
  50. void __fastcall AccurateGetInterruptCount(unsigned __int64 * pqwTick) {
  51. // HACKHACK: this is not thread safe and assumes that it will
  52. // always be called more often than every 47 days.
  53. static unsigned __int32 dwLastTickCount=0;
  54. static unsigned __int32 dwHighTickCount=0;
  55. if (USER_SHARED_DATA->TickCount.LowPart<dwLastTickCount) {
  56. dwHighTickCount++;
  57. }
  58. dwLastTickCount=USER_SHARED_DATA->TickCount.LowPart;
  59. *pqwTick=USER_SHARED_DATA->TickCount.LowPart+(((unsigned __int64)dwHighTickCount)<<32);
  60. };
  61. //--------------------------------------------------------------------
  62. void __fastcall AccurateGetInterruptCount2(unsigned __int64 * pqwTick) {
  63. // HACKHACK: this is not thread safe and assumes that it will
  64. // always be called more often than every 47 days
  65. static unsigned __int32 dwLastTickCount=0;
  66. static unsigned __int32 dwHighTickCount=0;
  67. if (USER_SHARED_DATA->TickCount.LowPart<dwLastTickCount) {
  68. dwHighTickCount++;
  69. }
  70. dwLastTickCount=USER_SHARED_DATA->TickCount.LowPart;
  71. *pqwTick=USER_SHARED_DATA->TickCount.LowPart+(((unsigned __int64)dwHighTickCount)<<32);
  72. };
  73. //--------------------------------------------------------------------
  74. unsigned __int32 SetTimeSlipEvent(HANDLE hTimeSlipEvent) {
  75. return NtSetSystemInformation(SystemTimeSlipNotification, &hTimeSlipEvent, sizeof(HANDLE));
  76. }
  77. //--------------------------------------------------------------------
  78. void GetSysExpirationDate(unsigned __int64 * pqwTime) {
  79. *(LARGE_INTEGER *)pqwTime=USER_SHARED_DATA->SystemExpirationDate;
  80. }