ReactOS 0.4.15-dev-7924-g5949c20
RtlException.c
Go to the documentation of this file.
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
11static
12VOID
14 _In_ BOOLEAN Raise)
15{
16 if (Raise)
17 {
19 }
20}
21
22static
23VOID
26 _In_ BOOLEAN Raise)
27{
28 _SEH2_VOLATILE INT Var = 123;
29 static _SEH2_VOLATILE INT *AddressOfVar;
30
31 AddressOfVar = &Var;
32 ok_eq_ulong(*State, 1);
34 {
35 *State = 2;
36 PossiblyRaise(Raise);
37 ok_eq_ulong(*State, 2);
38 *State = 3;
39 }
41 {
42 ok_eq_int(Var, 123);
43 ok_eq_pointer(&Var, AddressOfVar);
44 if (Raise)
45 ok_eq_ulong(*State, 2);
46 else
47 ok_eq_ulong(*State, 3);
48 *State = 4;
49 }
51
52 ok_eq_int(Var, 123);
53 ok_eq_pointer(&Var, AddressOfVar);
54 ok_eq_ulong(*State, 4);
55 *State = 5;
56}
57
58static
59VOID
62 _In_ BOOLEAN Raise)
63{
64 _SEH2_VOLATILE INT Var = 456;
65 static _SEH2_VOLATILE INT *AddressOfVar;
66
67 AddressOfVar = &Var;
68 ok_eq_ulong(*State, 0);
70 {
71 *State = 1;
72 InnerFunction(State, Raise);
73 ok_eq_ulong(*State, 5);
74 *State = 6;
75 }
77 {
78 ok_eq_int(Var, 456);
79 ok_eq_pointer(&Var, AddressOfVar);
80 ok_eq_ulong(*State, 4);
81 *State = 7;
82 }
84
85 ok_eq_int(Var, 456);
86 ok_eq_pointer(&Var, AddressOfVar);
87 if (Raise)
88 ok_eq_ulong(*State, 7);
89 else
90 ok_eq_ulong(*State, 6);
91 *State = 8;
92}
93
94static
95VOID
97{
99
100 State = 0;
102 ok_eq_ulong(State, 8);
103
104 State = 0;
106 ok_eq_ulong(State, 8);
107}
108
109START_TEST(RtlException)
110{
111 PCHAR Buffer[128];
112
113 /* Access a valid pointer - must not trigger SEH */
115 RtlFillMemory(Buffer, sizeof(Buffer), 0x12);
117
118 /* Read from a NULL pointer - must cause an access violation */
120 (void)*(volatile CHAR *)NULL;
122
123 /* Write to a NULL pointer - must cause an access violation */
125 *(volatile CHAR *)NULL = 5;
127
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;
134
135 /* Write to MmBadPointer - must cause an access violation */
137 *(volatile CHAR *)MmBadPointer = 5;
139#endif
140
144
148
152
156
158
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#ifdef KMT_USER_MODE
162 /* Overflow the stack - must cause a special exception */
164 volatile CHAR *Pointer;
165
166 while (1)
167 {
168 Pointer = _alloca(1024);
169 *Pointer = 5;
170 }
172#endif
173}
unsigned char BOOLEAN
static VOID InnerFunction(_Inout_ PULONG State, _In_ BOOLEAN Raise)
Definition: RtlException.c:24
static VOID OuterFunction(_Inout_ PULONG State, _In_ BOOLEAN Raise)
Definition: RtlException.c:60
static VOID TestNestedExceptionHandler(VOID)
Definition: RtlException.c:96
static VOID PossiblyRaise(_In_ BOOLEAN Raise)
Definition: RtlException.c:13
#define ok_eq_pointer(value, expected)
Definition: apitest.h:59
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define START_TEST(x)
Definition: atltest.h:75
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
#define KmtStartSeh()
Definition: kmt_test.h:282
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:288
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define ExRaiseStatus
Definition: ntoskrnl.h:114
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
#define STATUS_ASSERTION_FAILURE
Definition: ntstatus.h:960
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:489
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_GUARD_PAGE_VIOLATION
Definition: ntstatus.h:182
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define _SEH2_VOLATILE
Definition: pseh2_64.h:163
#define STATUS_SUCCESS
Definition: shellext.h:65
uint32_t * PULONG
Definition: typedefs.h:59
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
NTKERNELAPI PVOID MmBadPointer
char CHAR
Definition: xmlstorage.h:175