d5cae4c28d511e903773f11010145fba36983d25
[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 <thomas.faber@reactos.org>
6 */
7
8 #define KMT_EMULATE_KERNEL
9 #include <kmt_test.h>
10
11 START_TEST(RtlException)
12 {
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 KmtStartSeh()
44 ExRaiseStatus(STATUS_ACCESS_VIOLATION);
45 KmtEndSeh(STATUS_ACCESS_VIOLATION);
46
47 KmtStartSeh()
48 ExRaiseStatus(STATUS_TIMEOUT);
49 KmtEndSeh(STATUS_TIMEOUT);
50
51 KmtStartSeh()
52 ExRaiseStatus(STATUS_STACK_OVERFLOW);
53 KmtEndSeh(STATUS_STACK_OVERFLOW);
54
55 KmtStartSeh()
56 ExRaiseStatus(STATUS_GUARD_PAGE_VIOLATION);
57 KmtEndSeh(STATUS_GUARD_PAGE_VIOLATION);
58
59 /* We cannot test this in kernel mode easily - the stack is just "somewhere"
60 * in system space, and there's no guard page below it */
61 #if CORE_6640_IS_FIXED
62 #ifdef KMT_USER_MODE
63 /* Overflow the stack - must cause a special exception */
64 KmtStartSeh()
65 volatile CHAR *Pointer;
66
67 while (1)
68 {
69 Pointer = _alloca(1024);
70 *Pointer = 5;
71 }
72 KmtEndSeh(STATUS_STACK_OVERFLOW);
73 #endif
74 #endif /* CORE_6640_IS_FIXED */
75 }