2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Kernel-Mode Test Suite Exception test
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
8 #define KMT_EMULATE_KERNEL
18 ExRaiseStatus(STATUS_ASSERTION_FAILURE
);
28 _SEH2_VOLATILE INT Var
= 123;
29 static _SEH2_VOLATILE INT
*AddressOfVar
;
32 ok_eq_ulong(*State
, 1);
37 ok_eq_ulong(*State
, 2);
43 ok_eq_pointer(&Var
, AddressOfVar
);
45 ok_eq_ulong(*State
, 2);
47 ok_eq_ulong(*State
, 3);
53 ok_eq_pointer(&Var
, AddressOfVar
);
54 ok_eq_ulong(*State
, 4);
64 _SEH2_VOLATILE INT Var
= 456;
65 static _SEH2_VOLATILE INT
*AddressOfVar
;
68 ok_eq_ulong(*State
, 0);
72 InnerFunction(State
, Raise
);
73 ok_eq_ulong(*State
, 5);
76 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
79 ok_eq_pointer(&Var
, AddressOfVar
);
80 ok_eq_ulong(*State
, 4);
86 ok_eq_pointer(&Var
, AddressOfVar
);
88 ok_eq_ulong(*State
, 7);
90 ok_eq_ulong(*State
, 6);
96 TestNestedExceptionHandler(VOID
)
101 OuterFunction(&State
, FALSE
);
102 ok_eq_ulong(State
, 8);
105 OuterFunction(&State
, TRUE
);
106 ok_eq_ulong(State
, 8);
109 START_TEST(RtlException
)
113 /* Access a valid pointer - must not trigger SEH */
115 RtlFillMemory(Buffer
, sizeof(Buffer
), 0x12);
116 KmtEndSeh(STATUS_SUCCESS
);
118 /* Read from a NULL pointer - must cause an access violation */
120 (void)*(volatile CHAR
*)NULL
;
121 KmtEndSeh(STATUS_ACCESS_VIOLATION
);
123 /* Write to a NULL pointer - must cause an access violation */
125 *(volatile CHAR
*)NULL
= 5;
126 KmtEndSeh(STATUS_ACCESS_VIOLATION
);
128 /* TODO: Find where MmBadPointer is defined - gives an unresolved external */
129 #if 0 //def KMT_KERNEL_MODE
130 /* Read from MmBadPointer - must cause an access violation */
132 (void)*(volatile CHAR
*)MmBadPointer
;
133 KmtEndSeh(STATUS_ACCESS_VIOLATION
);
135 /* Write to MmBadPointer - must cause an access violation */
137 *(volatile CHAR
*)MmBadPointer
= 5;
138 KmtEndSeh(STATUS_ACCESS_VIOLATION
);
142 ExRaiseStatus(STATUS_ACCESS_VIOLATION
);
143 KmtEndSeh(STATUS_ACCESS_VIOLATION
);
146 ExRaiseStatus(STATUS_TIMEOUT
);
147 KmtEndSeh(STATUS_TIMEOUT
);
150 ExRaiseStatus(STATUS_STACK_OVERFLOW
);
151 KmtEndSeh(STATUS_STACK_OVERFLOW
);
154 ExRaiseStatus(STATUS_GUARD_PAGE_VIOLATION
);
155 KmtEndSeh(STATUS_GUARD_PAGE_VIOLATION
);
157 TestNestedExceptionHandler();
159 /* We cannot test this in kernel mode easily - the stack is just "somewhere"
160 * in system space, and there's no guard page below it */
161 #if CORE_6640_IS_FIXED
163 /* Overflow the stack - must cause a special exception */
165 volatile CHAR
*Pointer
;
169 Pointer
= _alloca(1024);
172 KmtEndSeh(STATUS_STACK_OVERFLOW
);
174 #endif /* CORE_6640_IS_FIXED */