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