From d1eed619a7d258588d35e0e7efa823dfe1b3b6ff Mon Sep 17 00:00:00 2001 From: Aiken Harris Date: Thu, 30 Apr 2026 13:00:59 +0200 Subject: [PATCH] Extend KSD with InterruptTime --- sdk/xtdk/ketypes.h | 1 + xtoskrnl/includes/ke/shdata.hh | 2 ++ xtoskrnl/ke/shdata.cc | 49 ++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/sdk/xtdk/ketypes.h b/sdk/xtdk/ketypes.h index 3837d6b..607e8a6 100644 --- a/sdk/xtdk/ketypes.h +++ b/sdk/xtdk/ketypes.h @@ -460,6 +460,7 @@ typedef struct _KSYSTEM_TIME /* Kernel Shared Data (KSD) structure definition */ typedef struct _KSHARED_DATA { + VOLATILE KSYSTEM_TIME InterruptTime; VOLATILE KSYSTEM_TIME SystemTime; ULONG XtMajorVersion; ULONG XtMinorVersion; diff --git a/xtoskrnl/includes/ke/shdata.hh b/xtoskrnl/includes/ke/shdata.hh index cc00b4a..a6a01c0 100644 --- a/xtoskrnl/includes/ke/shdata.hh +++ b/xtoskrnl/includes/ke/shdata.hh @@ -21,9 +21,11 @@ namespace KE STATIC PKSHARED_DATA KernelSharedData; public: + STATIC XTAPI LARGE_INTEGER GetInterruptTime(VOID); STATIC XTAPI PKSHARED_DATA GetKernelSharedData(VOID); STATIC XTAPI LARGE_INTEGER GetSystemTime(VOID); 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 2d08dc6..713d6ad 100644 --- a/xtoskrnl/ke/shdata.cc +++ b/xtoskrnl/ke/shdata.cc @@ -9,6 +9,35 @@ #include +/** + * Retrieves the current interrupt time using a lock-free read mechanism. + * + * @return This routine returns a LARGE_INTEGER containing the interrupt time. + * + * @since XT 1.0 + */ +XTAPI +LARGE_INTEGER +KE::SharedData::GetInterruptTime(VOID) +{ + LARGE_INTEGER InterruptTime; + + /* Initialize to zero */ + InterruptTime.QuadPart = 0; + + /* Perform a lock-free read sequence */ + do + { + /* Read the primary high part and low part */ + InterruptTime.HighPart = KernelSharedData->SystemTime.High1Part; + InterruptTime.LowPart = KernelSharedData->SystemTime.LowPart; + } + while(InterruptTime.HighPart != KernelSharedData->SystemTime.High2Part); + + /* Return the 64-bit time */ + return InterruptTime; +} + /** * Retrieves a pointer to the memory-mapped Kernel Shared Data. * @@ -108,6 +137,26 @@ KE::SharedData::InitializeKernelSharedData(VOID) (sizeof(KernelSharedData->XtFullDate) / sizeof(WCHAR)) - 1); } +/** + * Updates the global interrupt time using a strict lock-free write mechanism. + * + * @param Time + * Supplies the new interrupt time as a 64-bit LARGE_INTEGER value. + * + * @return This routine does not return any value. + * + * @since XT 1.0 + */ +XTAPI +VOID +KE::SharedData::SetInterruptTime(IN LARGE_INTEGER Time) +{ + /* Set the new interrupt time */ + KernelSharedData->InterruptTime.High2Part = Time.HighPart; + KernelSharedData->InterruptTime.LowPart = Time.LowPart; + KernelSharedData->InterruptTime.High1Part = Time.HighPart; +} + /** * Updates the global system time using a strict lock-free write mechanism. *