ReactOS  0.4.15-dev-489-g75a0787
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 
11 static
12 VOID
14  _In_ BOOLEAN Raise)
15 {
16  if (Raise)
17  {
19  }
20 }
21 
22 static
23 VOID
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);
33  _SEH2_TRY
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  }
50  _SEH2_END;
51 
52  ok_eq_int(Var, 123);
53  ok_eq_pointer(&Var, AddressOfVar);
54  ok_eq_ulong(*State, 4);
55  *State = 5;
56 }
57 
58 static
59 VOID
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);
69  _SEH2_TRY
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  }
83  _SEH2_END;
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 
94 static
95 VOID
97 {
98  ULONG State;
99 
100  State = 0;
102  ok_eq_ulong(State, 8);
103 
104  State = 0;
106  ok_eq_ulong(State, 8);
107 }
108 
109 START_TEST(RtlException)
110 {
111  PCHAR Buffer[128];
112 
113  /* Access a valid pointer - must not trigger SEH */
114  KmtStartSeh()
115  RtlFillMemory(Buffer, sizeof(Buffer), 0x12);
117 
118  /* Read from a NULL pointer - must cause an access violation */
119  KmtStartSeh()
120  (void)*(volatile CHAR *)NULL;
122 
123  /* Write to a NULL pointer - must cause an access violation */
124  KmtStartSeh()
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 */
131  KmtStartSeh()
132  (void)*(volatile CHAR *)MmBadPointer;
134 
135  /* Write to MmBadPointer - must cause an access violation */
136  KmtStartSeh()
137  *(volatile CHAR *)MmBadPointer = 5;
139 #endif
140 
141  KmtStartSeh()
144 
145  KmtStartSeh()
148 
149  KmtStartSeh()
152 
153  KmtStartSeh()
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 */
163  KmtStartSeh()
164  volatile CHAR *Pointer;
165 
166  while (1)
167  {
168  Pointer = _alloca(1024);
169  *Pointer = 5;
170  }
172 #endif
173 }
signed char * PCHAR
Definition: retypes.h:7
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define ok_eq_int(value, expected)
Definition: kmt_test.h:238
#define ok_eq_pointer(value, expected)
char CHAR
Definition: xmlstorage.h:175
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
#define STATUS_GUARD_PAGE_VIOLATION
Definition: ntstatus.h:170
#define ExRaiseStatus
Definition: ntoskrnl.h:96
int32_t INT
Definition: typedefs.h:57
_SEH2_TRY
Definition: create.c:4226
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
static VOID PossiblyRaise(_In_ BOOLEAN Raise)
Definition: RtlException.c:13
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define STATUS_ASSERTION_FAILURE
Definition: ntstatus.h:946
static VOID InnerFunction(_Inout_ PULONG State, _In_ BOOLEAN Raise)
Definition: RtlException.c:24
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static VOID OuterFunction(_Inout_ PULONG State, _In_ BOOLEAN Raise)
Definition: RtlException.c:60
#define _Inout_
Definition: no_sal2.h:244
static VOID TestNestedExceptionHandler(VOID)
Definition: RtlException.c:96
#define KmtStartSeh()
Definition: kmt_test.h:277
#define _In_
Definition: no_sal2.h:204
enum State_ State
Definition: pofuncs.h:54
_SEH2_END
Definition: create.c:4400
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
_SEH2_FINALLY
Definition: create.c:4371
unsigned int * PULONG
Definition: retypes.h:1
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:475
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
NTKERNELAPI PVOID MmBadPointer
START_TEST(RtlException)
Definition: RtlException.c:109
return STATUS_SUCCESS
Definition: btrfs.c:3014