1b38098ebed71db6c22843428199073a5250ef2f
[reactos.git] / rostests / kmtests / rtl / RtlException.c
1 /*
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 <thfabba@gmx.de>
6 */
7
8 #include <kmt_test.h>
9
10 #define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY {
11 #define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok_eq_hex(ExceptionStatus, ExpectedStatus)
12
13 START_TEST(RtlException)
14 {
15 NTSTATUS ExceptionStatus;
16 PCHAR Buffer[128];
17 CHAR Value;
18
19 /* Access a valid pointer - must not trigger SEH */
20 StartSeh()
21 RtlFillMemory(Buffer, sizeof(Buffer), 0x12);
22 EndSeh(STATUS_SUCCESS);
23
24 /* Read from a NULL pointer - must cause an access violation */
25 StartSeh()
26 Value = *(volatile CHAR *)NULL;
27 EndSeh(STATUS_ACCESS_VIOLATION);
28
29 /* Write to a NULL pointer - must cause an access violation */
30 StartSeh()
31 *(volatile CHAR *)NULL = 5;
32 EndSeh(STATUS_ACCESS_VIOLATION);
33
34 /* TODO: Find where MmBadPointer is defined - gives an unresolved external */
35 #if 0 //def KMT_KERNEL_MODE
36 /* Read from MmBadPointer - must cause an access violation */
37 StartSeh()
38 Value = *(volatile CHAR *)MmBadPointer;
39 EndSeh(STATUS_ACCESS_VIOLATION);
40
41 /* Write to MmBadPointer - must cause an access violation */
42 StartSeh()
43 *(volatile CHAR *)MmBadPointer = 5;
44 EndSeh(STATUS_ACCESS_VIOLATION);
45 #endif
46
47 /* We cannot test this in kernel mode easily - the stack is just "somewhere"
48 * in system space, and there's no guard page below it */
49 #ifdef KMT_USER_MODE
50 /* Overflow the stack - must cause a special exception */
51 StartSeh()
52 PCHAR Pointer;
53
54 while (1)
55 {
56 Pointer = _alloca(1024);
57 *Pointer = 5;
58 }
59 EndSeh(STATUS_STACK_OVERFLOW);
60 #endif
61 }