From 52adca06a98dce5b14009d56bf81aa09256a45a6 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 6 Nov 2016 09:31:09 +0000 Subject: [PATCH] [KMTESTS:RTL] - Add a test checking stack frame correctness in a nested __finally handler CORE-12283 svn path=/trunk/; revision=73148 --- rostests/kmtests/rtl/RtlException.c | 100 ++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/rostests/kmtests/rtl/RtlException.c b/rostests/kmtests/rtl/RtlException.c index d5cae4c28d5..a8b76a3b1ea 100644 --- a/rostests/kmtests/rtl/RtlException.c +++ b/rostests/kmtests/rtl/RtlException.c @@ -8,6 +8,104 @@ #define KMT_EMULATE_KERNEL #include +static +VOID +PossiblyRaise( + _In_ BOOLEAN Raise) +{ + if (Raise) + { + ExRaiseStatus(STATUS_ASSERTION_FAILURE); + } +} + +static +VOID +InnerFunction( + _Inout_ PULONG State, + _In_ BOOLEAN Raise) +{ + _SEH2_VOLATILE INT Var = 123; + static _SEH2_VOLATILE INT *AddressOfVar; + + AddressOfVar = &Var; + ok_eq_ulong(*State, 1); + _SEH2_TRY + { + *State = 2; + PossiblyRaise(Raise); + ok_eq_ulong(*State, 2); + *State = 3; + } + _SEH2_FINALLY + { + ok_eq_int(Var, 123); + ok_eq_pointer(&Var, AddressOfVar); + if (Raise) + ok_eq_ulong(*State, 2); + else + ok_eq_ulong(*State, 3); + *State = 4; + } + _SEH2_END; + + ok_eq_int(Var, 123); + ok_eq_pointer(&Var, AddressOfVar); + ok_eq_ulong(*State, 4); + *State = 5; +} + +static +VOID +OuterFunction( + _Inout_ PULONG State, + _In_ BOOLEAN Raise) +{ + _SEH2_VOLATILE INT Var = 456; + static _SEH2_VOLATILE INT *AddressOfVar; + + AddressOfVar = &Var; + ok_eq_ulong(*State, 0); + _SEH2_TRY + { + *State = 1; + InnerFunction(State, Raise); + ok_eq_ulong(*State, 5); + *State = 6; + } + _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) + { + ok_eq_int(Var, 456); + ok_eq_pointer(&Var, AddressOfVar); + ok_eq_ulong(*State, 4); + *State = 7; + } + _SEH2_END; + + ok_eq_int(Var, 456); + ok_eq_pointer(&Var, AddressOfVar); + if (Raise) + ok_eq_ulong(*State, 7); + else + ok_eq_ulong(*State, 6); + *State = 8; +} + +static +VOID +TestNestedExceptionHandler(VOID) +{ + ULONG State; + + State = 0; + OuterFunction(&State, FALSE); + ok_eq_ulong(State, 8); + + State = 0; + OuterFunction(&State, TRUE); + ok_eq_ulong(State, 8); +} + START_TEST(RtlException) { PCHAR Buffer[128]; @@ -56,6 +154,8 @@ START_TEST(RtlException) ExRaiseStatus(STATUS_GUARD_PAGE_VIOLATION); KmtEndSeh(STATUS_GUARD_PAGE_VIOLATION); + TestNestedExceptionHandler(); + /* We cannot test this in kernel mode easily - the stack is just "somewhere" * in system space, and there's no guard page below it */ #if CORE_6640_IS_FIXED -- 2.17.1