diff --git a/sdk/xtdk/ketypes.h b/sdk/xtdk/ketypes.h index 607e8a6..11eaf4c 100644 --- a/sdk/xtdk/ketypes.h +++ b/sdk/xtdk/ketypes.h @@ -462,6 +462,7 @@ typedef struct _KSHARED_DATA { VOLATILE KSYSTEM_TIME InterruptTime; VOLATILE KSYSTEM_TIME SystemTime; + VOLATILE KSYSTEM_TIME TickCount; ULONG XtMajorVersion; ULONG XtMinorVersion; WCHAR XtBuild[8]; diff --git a/xtoskrnl/includes/ke/shdata.hh b/xtoskrnl/includes/ke/shdata.hh index a6a01c0..ec5a00a 100644 --- a/xtoskrnl/includes/ke/shdata.hh +++ b/xtoskrnl/includes/ke/shdata.hh @@ -24,6 +24,8 @@ namespace KE STATIC XTAPI LARGE_INTEGER GetInterruptTime(VOID); STATIC XTAPI PKSHARED_DATA GetKernelSharedData(VOID); STATIC XTAPI LARGE_INTEGER GetSystemTime(VOID); + STATIC XTAPI LARGE_INTEGER GetTickCount(VOID); + STATIC XTAPI VOID IncrementTickCount(); STATIC XTAPI VOID InitializeKernelSharedData(VOID); STATIC XTAPI VOID SetInterruptTime(IN LARGE_INTEGER Time); STATIC XTAPI VOID SetSystemTime(IN LARGE_INTEGER Time); diff --git a/xtoskrnl/ke/shdata.cc b/xtoskrnl/ke/shdata.cc index 1e8b98d..9f6b047 100644 --- a/xtoskrnl/ke/shdata.cc +++ b/xtoskrnl/ke/shdata.cc @@ -82,6 +82,48 @@ KE::SharedData::GetSystemTime(VOID) return CurrentTime; } +/** + * Retrieves the global system tick count. + * + * @return This routine returns the current tick count. + * + * @since XT 1.0 + */ +XTAPI +LARGE_INTEGER +KE::SharedData::GetTickCount(VOID) +{ + LARGE_INTEGER Ticks; + + /* Read the 64-bit tick count */ + Ticks.QuadPart = (*(ULONGLONG*)&KernelSharedData->TickCount); + + /* Return the retrieved tick count */ + return Ticks; +} + +/** + * Increments the global system tick count by one using a strict lock-free write mechanism. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::SharedData::IncrementTickCount() +{ + LARGE_INTEGER Ticks; + + /* Increment tick count */ + Ticks.QuadPart = (*(ULONGLONG*)&KernelSharedData->TickCount) + 1; + + /* Set the new tick count */ + KernelSharedData->TickCount.High2Part = Ticks.HighPart; + KernelSharedData->TickCount.LowPart = Ticks.LowPart; + KernelSharedData->TickCount.High1Part = Ticks.HighPart; +} + /** * Maps and initializes the Kernel Shared Data (KSD) structure. *