[KMTESTS:RTL]
[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
15 /* Access a valid pointer - must not trigger SEH */
16 KmtStartSeh()
17 RtlFillMemory(Buffer, sizeof(Buffer), 0x12);
18 KmtEndSeh(STATUS_SUCCESS);
19
20 /* Read from a NULL pointer - must cause an access violation */
21 KmtStartSeh()
22 (void)*(volatile CHAR *)NULL;
23 KmtEndSeh(STATUS_ACCESS_VIOLATION);
24
25 /* Write to a NULL pointer - must cause an access violation */
26 KmtStartSeh()
27 *(volatile CHAR *)NULL = 5;
28 KmtEndSeh(STATUS_ACCESS_VIOLATION);
29
30 /* TODO: Find where MmBadPointer is defined - gives an unresolved external */
31 #if 0 //def KMT_KERNEL_MODE
32 /* Read from MmBadPointer - must cause an access violation */
33 KmtStartSeh()
34 (void)*(volatile CHAR *)MmBadPointer;
35 KmtEndSeh(STATUS_ACCESS_VIOLATION);
36
37 /* Write to MmBadPointer - must cause an access violation */
38 KmtStartSeh()
39 *(volatile CHAR *)MmBadPointer = 5;
40 KmtEndSeh(STATUS_ACCESS_VIOLATION);
41 #endif
42
43 /* We cannot test this in kernel mode easily - the stack is just "somewhere"
44 * in system space, and there's no guard page below it */
45 #if CORE_6640_IS_FIXED
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 #endif /* CORE_6640_IS_FIXED */
59 }