From 03f4387231047624dd708e71469dcdcf89395b10 Mon Sep 17 00:00:00 2001 From: Mohammed al-Ramadany Date: Sat, 18 Oct 2025 17:28:59 +0300 Subject: [PATCH] [KMTEST] ExHardError and RtlCaptureContextKM fixes (#8342) - Adjust expected values according to NT version and architecture --- .../apitests/rtl/amd64/RtlCaptureContext.c | 23 ++++++++++--- .../rostests/kmtests/ntos_ex/ExHardError.c | 34 +++++++++++++++---- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/modules/rostests/apitests/rtl/amd64/RtlCaptureContext.c b/modules/rostests/apitests/rtl/amd64/RtlCaptureContext.c index 286d6bfd5d8..417dca54e67 100644 --- a/modules/rostests/apitests/rtl/amd64/RtlCaptureContext.c +++ b/modules/rostests/apitests/rtl/amd64/RtlCaptureContext.c @@ -154,10 +154,20 @@ START_TEST(RtlCaptureContext) ok_eq_hex64(CapturedContext.Legacy[7].Low, OriginalContext.Legacy[7].Low); ok_eq_hex64(CapturedContext.Legacy[7].High, OriginalContext.Legacy[7].High & 0xFF); #else - ok_eq_hex(CapturedContext.FltSave.ControlWord, 0xcccc); - ok_eq_hex(CapturedContext.FltSave.StatusWord, 0xcccc); - ok_eq_hex(CapturedContext.FltSave.TagWord, 0xcc); - ok_eq_hex(CapturedContext.FltSave.Reserved1, 0xcc); + if (GetNTVersion() >= _WIN32_WINNT_WIN8) + { + ok_eq_hex(CapturedContext.FltSave.ControlWord, 0x27f); + ok_eq_hex(CapturedContext.FltSave.StatusWord, 0x00); + ok_eq_hex(CapturedContext.FltSave.TagWord, 0x00); + ok_eq_hex(CapturedContext.FltSave.Reserved1, 0x00); + } + else + { + ok_eq_hex(CapturedContext.FltSave.ControlWord, 0xcccc); + ok_eq_hex(CapturedContext.FltSave.StatusWord, 0xcccc); + ok_eq_hex(CapturedContext.FltSave.TagWord, 0xcc); + ok_eq_hex(CapturedContext.FltSave.Reserved1, 0xcc); + } ok_eq_hex(CapturedContext.FltSave.MxCsr_Mask, 0xcccccccc); ok_eq_hex(CapturedContext.FltSave.ErrorOpcode, 0xcccc); ok_eq_hex(CapturedContext.FltSave.ErrorOffset, 0xcccccccc); @@ -168,7 +178,10 @@ START_TEST(RtlCaptureContext) ok_eq_hex(CapturedContext.FltSave.Reserved3, 0xcccc); /* We get the value from OriginalContext.MxCsr, since we set that later in the wrapper */ - ok_eq_hex(CapturedContext.FltSave.MxCsr, 0xcccccccc); + if (GetNTVersion() >= _WIN32_WINNT_WIN8) + ok_eq_hex(CapturedContext.FltSave.MxCsr, 0xffff); + else + ok_eq_hex(CapturedContext.FltSave.MxCsr, 0xcccccccc); /* Legacy floating point registers are truncated to 10 bytes */ ok_eq_hex64(CapturedContext.Legacy[0].Low, 0xcccccccccccccccc); diff --git a/modules/rostests/kmtests/ntos_ex/ExHardError.c b/modules/rostests/kmtests/ntos_ex/ExHardError.c index 1d0662a2c21..e858063d34a 100644 --- a/modules/rostests/kmtests/ntos_ex/ExHardError.c +++ b/modules/rostests/kmtests/ntos_ex/ExHardError.c @@ -94,7 +94,27 @@ TestHardError( CheckHardError(0x40000003, 0, OptionOk, STATUS_SUCCESS, ResponseNotHandled, 6, 1, 2, 3, 4, 5, 6); // TODO: interactive on ROS } - CheckHardError(0x40000004, 0, OptionShutdownSystem, STATUS_PRIVILEGE_NOT_HELD, ResponseNotHandled, 0, 0); + // The return value is a random large value on Windows Server 2003 + if (GetNTVersion() > _WIN32_WINNT_WS03) + { +#if _WIN64 + if (GetNTVersion() == _WIN32_WINNT_VISTA) + { + CheckHardError(0x40000004, 0, OptionShutdownSystem, STATUS_PRIVILEGE_NOT_HELD, 64, 0, 0); + } + else + { + CheckHardError(0x40000004, 0, OptionShutdownSystem, STATUS_PRIVILEGE_NOT_HELD, ResponseReturnToCaller, 0, 0); + } +#else + // Return value is also a random large value on 32-bit 8+ + if (GetNTVersion() < _WIN32_WINNT_WIN8) + { + CheckHardError(0x40000004, 0, OptionShutdownSystem, STATUS_PRIVILEGE_NOT_HELD, ResponseReturnToCaller, 0, 0); + } +#endif + } + if (InteractivePart1) { // TODO: these 2 are interactive on ROS @@ -116,12 +136,12 @@ TestHardError( CheckHardError(0x40000013, 0, OptionYesNoCancel, STATUS_SUCCESS, ResponseNo, 0, 0); // outputs a box :| CheckHardError(0x40000013, 0, OptionYesNoCancel, STATUS_SUCCESS, ResponseCancel, 0, 0); // outputs a box :| } - CheckHardError(0x40000009, 0, 9, STATUS_SUCCESS, ResponseNotHandled, 0, 0); - CheckHardError(0x4000000a, 0, 10, STATUS_SUCCESS, ResponseNotHandled, 0, 0); - CheckHardError(0x4000000b, 0, 11, STATUS_SUCCESS, ResponseNotHandled, 0, 0); - CheckHardError(0x4000000c, 0, 12, STATUS_SUCCESS, ResponseNotHandled, 0, 0); - CheckHardError(0x4000000d, 0, MAXULONG / 2 + 1, STATUS_SUCCESS, ResponseNotHandled, 0, 0); - CheckHardError(0x4000000d, 0, MAXULONG, STATUS_SUCCESS, ResponseNotHandled, 0, 0); + CheckHardError(0x40000009, 0, 9, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); + CheckHardError(0x4000000a, 0, 10, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); + CheckHardError(0x4000000b, 0, 11, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); + CheckHardError(0x4000000c, 0, 12, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); + CheckHardError(0x4000000d, 0, MAXULONG / 2 + 1, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); + CheckHardError(0x4000000d, 0, MAXULONG, STATUS_SUCCESS, ResponseReturnToCaller, 0, 0); if (InteractivePart2) {