ntdll/tests: Skip a couple of exception tests that crash on Wow64.
[wine/multimedia.git] / dlls / ntdll / tests / exception.c
blob154a7c7cb2b8701ed33c24d1dd580b75f1cd2f30
1 /*
2 * Unit test suite for ntdll exceptions
4 * Copyright 2005 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #ifndef _WIN32_WINNT
25 #define _WIN32_WINNT 0x500 /* For NTSTATUS */
26 #endif
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winnt.h"
35 #include "winreg.h"
36 #include "winternl.h"
37 #include "excpt.h"
38 #include "wine/test.h"
40 static void *code_mem;
42 static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
43 static NTSTATUS (WINAPI *pNtGetContextThread)(HANDLE,CONTEXT*);
44 static NTSTATUS (WINAPI *pNtSetContextThread)(HANDLE,CONTEXT*);
45 static NTSTATUS (WINAPI *pRtlRaiseException)(EXCEPTION_RECORD *rec);
46 static PVOID (WINAPI *pRtlAddVectoredExceptionHandler)(ULONG first, PVECTORED_EXCEPTION_HANDLER func);
47 static ULONG (WINAPI *pRtlRemoveVectoredExceptionHandler)(PVOID handler);
48 static NTSTATUS (WINAPI *pNtReadVirtualMemory)(HANDLE, const void*, void*, SIZE_T, SIZE_T*);
49 static NTSTATUS (WINAPI *pNtTerminateProcess)(HANDLE handle, LONG exit_code);
50 static NTSTATUS (WINAPI *pNtQueryInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG);
51 static NTSTATUS (WINAPI *pNtSetInformationProcess)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG);
52 static BOOL (WINAPI *pIsWow64Process)(HANDLE, PBOOL);
54 #ifdef __i386__
56 #ifndef __WINE_WINTRNL_H
57 #define ProcessExecuteFlags 0x22
58 #define MEM_EXECUTE_OPTION_DISABLE 0x01
59 #define MEM_EXECUTE_OPTION_ENABLE 0x02
60 #define MEM_EXECUTE_OPTION_PERMANENT 0x08
61 #endif
63 static int my_argc;
64 static char** my_argv;
65 static int test_stage;
67 static BOOL is_wow64;
69 /* Test various instruction combinations that cause a protection fault on the i386,
70 * and check what the resulting exception looks like.
73 static const struct exception
75 BYTE code[18]; /* asm code */
76 BYTE offset; /* offset of faulting instruction */
77 BYTE length; /* length of faulting instruction */
78 BOOL wow64_broken; /* broken on Wow64, should be skipped */
79 NTSTATUS status; /* expected status code */
80 DWORD nb_params; /* expected number of parameters */
81 DWORD params[4]; /* expected parameters */
82 } exceptions[] =
84 /* 0 */
85 /* test some privileged instructions */
86 { { 0xfb, 0xc3 }, /* 0: sti; ret */
87 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
88 { { 0x6c, 0xc3 }, /* 1: insb (%dx); ret */
89 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
90 { { 0x6d, 0xc3 }, /* 2: insl (%dx); ret */
91 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
92 { { 0x6e, 0xc3 }, /* 3: outsb (%dx); ret */
93 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
94 { { 0x6f, 0xc3 }, /* 4: outsl (%dx); ret */
95 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
96 /* 5 */
97 { { 0xe4, 0x11, 0xc3 }, /* 5: inb $0x11,%al; ret */
98 0, 2, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
99 { { 0xe5, 0x11, 0xc3 }, /* 6: inl $0x11,%eax; ret */
100 0, 2, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
101 { { 0xe6, 0x11, 0xc3 }, /* 7: outb %al,$0x11; ret */
102 0, 2, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
103 { { 0xe7, 0x11, 0xc3 }, /* 8: outl %eax,$0x11; ret */
104 0, 2, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
105 { { 0xed, 0xc3 }, /* 9: inl (%dx),%eax; ret */
106 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
107 /* 10 */
108 { { 0xee, 0xc3 }, /* 10: outb %al,(%dx); ret */
109 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
110 { { 0xef, 0xc3 }, /* 11: outl %eax,(%dx); ret */
111 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
112 { { 0xf4, 0xc3 }, /* 12: hlt; ret */
113 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
114 { { 0xfa, 0xc3 }, /* 13: cli; ret */
115 0, 1, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
117 /* test long jump to invalid selector */
118 { { 0xea, 0, 0, 0, 0, 0, 0, 0xc3 }, /* 14: ljmp $0,$0; ret */
119 0, 7, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
121 /* 15 */
122 /* test iret to invalid selector */
123 { { 0x6a, 0x00, 0x6a, 0x00, 0x6a, 0x00, 0xcf, 0x83, 0xc4, 0x0c, 0xc3 },
124 /* 15: pushl $0; pushl $0; pushl $0; iret; addl $12,%esp; ret */
125 6, 1, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
127 /* test loading an invalid selector */
128 { { 0xb8, 0xef, 0xbe, 0x00, 0x00, 0x8e, 0xe8, 0xc3 }, /* 16: mov $beef,%ax; mov %ax,%gs; ret */
129 5, 2, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xbee8 } }, /* 0xbee8 or 0xffffffff */
131 /* test accessing a zero selector (%es broken on Wow64) */
132 { { 0x06, 0x31, 0xc0, 0x8e, 0xc0, 0x26, 0xa1, 0, 0, 0, 0, 0x07, 0xc3 },
133 /* push %es; xor %eax,%eax; mov %ax,%es; mov %es:(0),%ax; pop %es; ret */
134 5, 6, TRUE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
135 { { 0x0f, 0xa8, 0x31, 0xc0, 0x8e, 0xe8, 0x65, 0xa1, 0, 0, 0, 0, 0x0f, 0xa9, 0xc3 },
136 /* push %gs; xor %eax,%eax; mov %ax,%gs; mov %gs:(0),%ax; pop %gs; ret */
137 6, 6, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
139 /* test moving %cs -> %ss */
140 { { 0x0e, 0x17, 0x58, 0xc3 }, /* 18: pushl %cs; popl %ss; popl %eax; ret */
141 1, 1, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
143 /* 20 */
144 /* test overlong instruction (limit is 15 bytes, 5 on Win7) */
145 { { 0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xfa,0xc3 },
146 0, 16, FALSE, STATUS_ILLEGAL_INSTRUCTION, 0 },
147 { { 0x64,0x64,0x64,0x64,0xfa,0xc3 },
148 0, 5, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
150 /* test invalid interrupt */
151 { { 0xcd, 0xff, 0xc3 }, /* 21: int $0xff; ret */
152 0, 2, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
154 /* test moves to/from Crx */
155 { { 0x0f, 0x20, 0xc0, 0xc3 }, /* 22: movl %cr0,%eax; ret */
156 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
157 { { 0x0f, 0x20, 0xe0, 0xc3 }, /* 23: movl %cr4,%eax; ret */
158 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
159 /* 25 */
160 { { 0x0f, 0x22, 0xc0, 0xc3 }, /* 24: movl %eax,%cr0; ret */
161 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
162 { { 0x0f, 0x22, 0xe0, 0xc3 }, /* 25: movl %eax,%cr4; ret */
163 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
165 /* test moves to/from Drx */
166 { { 0x0f, 0x21, 0xc0, 0xc3 }, /* 26: movl %dr0,%eax; ret */
167 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
168 { { 0x0f, 0x21, 0xc8, 0xc3 }, /* 27: movl %dr1,%eax; ret */
169 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
170 { { 0x0f, 0x21, 0xf8, 0xc3 }, /* 28: movl %dr7,%eax; ret */
171 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
172 /* 30 */
173 { { 0x0f, 0x23, 0xc0, 0xc3 }, /* 29: movl %eax,%dr0; ret */
174 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
175 { { 0x0f, 0x23, 0xc8, 0xc3 }, /* 30: movl %eax,%dr1; ret */
176 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
177 { { 0x0f, 0x23, 0xf8, 0xc3 }, /* 31: movl %eax,%dr7; ret */
178 0, 3, FALSE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
180 /* test memory reads */
181 { { 0xa1, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* 32: movl 0xfffffffc,%eax; ret */
182 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffc } },
183 { { 0xa1, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* 33: movl 0xfffffffd,%eax; ret */
184 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffd } },
185 /* 35 */
186 { { 0xa1, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* 34: movl 0xfffffffe,%eax; ret */
187 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffe } },
188 { { 0xa1, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* 35: movl 0xffffffff,%eax; ret */
189 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
191 /* test memory writes */
192 { { 0xa3, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* 36: movl %eax,0xfffffffc; ret */
193 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffc } },
194 { { 0xa3, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* 37: movl %eax,0xfffffffd; ret */
195 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffd } },
196 { { 0xa3, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* 38: movl %eax,0xfffffffe; ret */
197 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffe } },
198 /* 40 */
199 { { 0xa3, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* 39: movl %eax,0xffffffff; ret */
200 0, 5, FALSE, STATUS_ACCESS_VIOLATION, 2, { 1, 0xffffffff } },
202 /* test exception with cleared %ds and %es (broken on Wow64) */
203 { { 0x1e, 0x06, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0xfa, 0x07, 0x1f, 0xc3 },
204 /* push %ds; push %es; xorl %eax,%eax; mov %ax,%ds; mov %ax,%es; cli; pop %es; pop %ds; ret */
205 8, 1, TRUE, STATUS_PRIVILEGED_INSTRUCTION, 0 },
208 static int got_exception;
209 static BOOL have_vectored_api;
211 static void run_exception_test(void *handler, const void* context,
212 const void *code, unsigned int code_size,
213 DWORD access)
215 struct {
216 EXCEPTION_REGISTRATION_RECORD frame;
217 const void *context;
218 } exc_frame;
219 void (*func)(void) = code_mem;
220 DWORD oldaccess, oldaccess2;
222 exc_frame.frame.Handler = handler;
223 exc_frame.frame.Prev = pNtCurrentTeb()->Tib.ExceptionList;
224 exc_frame.context = context;
226 memcpy(code_mem, code, code_size);
227 if(access)
228 VirtualProtect(code_mem, code_size, access, &oldaccess);
230 pNtCurrentTeb()->Tib.ExceptionList = &exc_frame.frame;
231 func();
232 pNtCurrentTeb()->Tib.ExceptionList = exc_frame.frame.Prev;
234 if(access)
235 VirtualProtect(code_mem, code_size, oldaccess, &oldaccess2);
238 static LONG CALLBACK rtlraiseexception_vectored_handler(EXCEPTION_POINTERS *ExceptionInfo)
240 PCONTEXT context = ExceptionInfo->ContextRecord;
241 PEXCEPTION_RECORD rec = ExceptionInfo->ExceptionRecord;
242 trace("vect. handler %08x addr:%p context.Eip:%x\n", rec->ExceptionCode,
243 rec->ExceptionAddress, context->Eip);
245 ok(rec->ExceptionAddress == (char *)code_mem + 0xb, "ExceptionAddress at %p instead of %p\n",
246 rec->ExceptionAddress, (char *)code_mem + 0xb);
248 if (pNtCurrentTeb()->Peb->BeingDebugged)
249 ok((void *)context->Eax == pRtlRaiseException, "debugger managed to modify Eax to %x should be %p\n",
250 context->Eax, pRtlRaiseException);
252 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
253 * even if raised by RtlRaiseException
255 if(rec->ExceptionCode == EXCEPTION_BREAKPOINT)
257 ok(context->Eip == (DWORD)code_mem + 0xa ||
258 broken(context->Eip == (DWORD)code_mem + 0xb), /* win2k3 */
259 "Eip at %x instead of %x or %x\n", context->Eip,
260 (DWORD)code_mem + 0xa, (DWORD)code_mem + 0xb);
262 else
264 ok(context->Eip == (DWORD)code_mem + 0xb, "Eip at %x instead of %x\n",
265 context->Eip, (DWORD)code_mem + 0xb);
268 /* test if context change is preserved from vectored handler to stack handlers */
269 context->Eax = 0xf00f00f0;
270 return EXCEPTION_CONTINUE_SEARCH;
273 static DWORD rtlraiseexception_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
274 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
276 trace( "exception: %08x flags:%x addr:%p context: Eip:%x\n",
277 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress, context->Eip );
279 ok(rec->ExceptionAddress == (char *)code_mem + 0xb, "ExceptionAddress at %p instead of %p\n",
280 rec->ExceptionAddress, (char *)code_mem + 0xb);
282 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
283 * even if raised by RtlRaiseException
285 if(rec->ExceptionCode == EXCEPTION_BREAKPOINT)
287 ok(context->Eip == (DWORD)code_mem + 0xa ||
288 broken(context->Eip == (DWORD)code_mem + 0xb), /* win2k3 */
289 "Eip at %x instead of %x or %x\n", context->Eip,
290 (DWORD)code_mem + 0xa, (DWORD)code_mem + 0xb);
292 else
294 ok(context->Eip == (DWORD)code_mem + 0xb, "Eip at %x instead of %x\n",
295 context->Eip, (DWORD)code_mem + 0xb);
298 if(have_vectored_api)
299 ok(context->Eax == 0xf00f00f0, "Eax is %x, should have been set to 0xf00f00f0 in vectored handler\n",
300 context->Eax);
302 /* give the debugger a chance to examine the state a second time */
303 /* without the exception handler changing Eip */
304 if (test_stage == 2)
305 return ExceptionContinueSearch;
307 /* Eip in context is decreased by 1
308 * Increase it again, else execution will continue in the middle of a instruction */
309 if(rec->ExceptionCode == EXCEPTION_BREAKPOINT && (context->Eip == (DWORD)code_mem + 0xa))
310 context->Eip += 1;
311 return ExceptionContinueExecution;
315 static const BYTE call_one_arg_code[] = {
316 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
317 0x50, /* push %eax */
318 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
319 0xff, 0xd0, /* call *%eax */
320 0x90, /* nop */
321 0x90, /* nop */
322 0x90, /* nop */
323 0x90, /* nop */
324 0xc3, /* ret */
328 static void run_rtlraiseexception_test(DWORD exceptioncode)
330 EXCEPTION_REGISTRATION_RECORD frame;
331 EXCEPTION_RECORD record;
332 PVOID vectored_handler = NULL;
334 void (*func)(void* function, EXCEPTION_RECORD* record) = code_mem;
336 record.ExceptionCode = exceptioncode;
337 record.ExceptionFlags = 0;
338 record.ExceptionRecord = NULL;
339 record.ExceptionAddress = NULL; /* does not matter, copied return address */
340 record.NumberParameters = 0;
342 frame.Handler = rtlraiseexception_handler;
343 frame.Prev = pNtCurrentTeb()->Tib.ExceptionList;
345 memcpy(code_mem, call_one_arg_code, sizeof(call_one_arg_code));
347 pNtCurrentTeb()->Tib.ExceptionList = &frame;
348 if (have_vectored_api)
350 vectored_handler = pRtlAddVectoredExceptionHandler(TRUE, &rtlraiseexception_vectored_handler);
351 ok(vectored_handler != 0, "RtlAddVectoredExceptionHandler failed\n");
354 func(pRtlRaiseException, &record);
355 ok( record.ExceptionAddress == (char *)code_mem + 0x0b,
356 "address set to %p instead of %p\n", record.ExceptionAddress, (char *)code_mem + 0x0b );
358 if (have_vectored_api)
359 pRtlRemoveVectoredExceptionHandler(vectored_handler);
360 pNtCurrentTeb()->Tib.ExceptionList = frame.Prev;
363 static void test_rtlraiseexception(void)
365 if (!pRtlRaiseException)
367 skip("RtlRaiseException not found\n");
368 return;
371 /* test without debugger */
372 run_rtlraiseexception_test(0x12345);
373 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT);
374 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE);
377 static DWORD handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
378 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
380 const struct exception *except = *(const struct exception **)(frame + 1);
381 unsigned int i, entry = except - exceptions;
383 got_exception++;
384 trace( "exception %u: %x flags:%x addr:%p\n",
385 entry, rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
387 ok( rec->ExceptionCode == except->status,
388 "%u: Wrong exception code %x/%x\n", entry, rec->ExceptionCode, except->status );
389 ok( rec->ExceptionAddress == (char*)code_mem + except->offset,
390 "%u: Wrong exception address %p/%p\n", entry,
391 rec->ExceptionAddress, (char*)code_mem + except->offset );
393 ok( rec->NumberParameters == except->nb_params,
394 "%u: Wrong number of parameters %u/%u\n", entry, rec->NumberParameters, except->nb_params );
396 /* Most CPUs (except Intel Core apparently) report a segment limit violation */
397 /* instead of page faults for accesses beyond 0xffffffff */
398 if (except->nb_params == 2 && except->params[1] >= 0xfffffffd)
400 if (rec->ExceptionInformation[0] == 0 && rec->ExceptionInformation[1] == 0xffffffff)
401 goto skip_params;
404 /* Seems that both 0xbee8 and 0xfffffffff can be returned in windows */
405 if (except->nb_params == 2 && rec->NumberParameters == 2
406 && except->params[1] == 0xbee8 && rec->ExceptionInformation[1] == 0xffffffff
407 && except->params[0] == rec->ExceptionInformation[0])
409 goto skip_params;
412 for (i = 0; i < rec->NumberParameters; i++)
413 ok( rec->ExceptionInformation[i] == except->params[i],
414 "%u: Wrong parameter %d: %lx/%x\n",
415 entry, i, rec->ExceptionInformation[i], except->params[i] );
417 skip_params:
418 /* don't handle exception if it's not the address we expected */
419 if (rec->ExceptionAddress != (char*)code_mem + except->offset) return ExceptionContinueSearch;
421 context->Eip += except->length;
422 return ExceptionContinueExecution;
425 static void test_prot_fault(void)
427 unsigned int i;
429 for (i = 0; i < sizeof(exceptions)/sizeof(exceptions[0]); i++)
431 if (is_wow64 && exceptions[i].wow64_broken && !strcmp( winetest_platform, "windows" ))
433 skip( "Exception %u broken on Wow64\n", i );
434 continue;
436 got_exception = 0;
437 run_exception_test(handler, &exceptions[i], &exceptions[i].code,
438 sizeof(exceptions[i].code), 0);
439 if (!i && !got_exception)
441 trace( "No exception, assuming win9x, no point in testing further\n" );
442 break;
444 ok( got_exception == (exceptions[i].status != 0),
445 "%u: bad exception count %d\n", i, got_exception );
449 /* test handling of debug registers */
450 static DWORD dreg_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
451 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
453 context->Eip += 2; /* Skips the popl (%eax) */
454 context->Dr0 = 0x42424242;
455 context->Dr1 = 0;
456 context->Dr2 = 0;
457 context->Dr3 = 0;
458 context->Dr6 = 0;
459 context->Dr7 = 0x155;
460 return ExceptionContinueExecution;
463 static const BYTE segfault_code[5] = {
464 0x31, 0xc0, /* xor %eax,%eax */
465 0x8f, 0x00, /* popl (%eax) - cause exception */
466 0xc3 /* ret */
469 /* test the single step exception behaviour */
470 static DWORD single_step_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
471 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
473 got_exception++;
474 ok (!(context->EFlags & 0x100), "eflags has single stepping bit set\n");
476 if( got_exception < 3)
477 context->EFlags |= 0x100; /* single step until popf instruction */
478 else {
479 /* show that the last single step exception on the popf instruction
480 * (which removed the TF bit), still is a EXCEPTION_SINGLE_STEP exception */
481 ok( rec->ExceptionCode == EXCEPTION_SINGLE_STEP,
482 "exception is not EXCEPTION_SINGLE_STEP: %x\n", rec->ExceptionCode);
485 return ExceptionContinueExecution;
488 static const BYTE single_stepcode[] = {
489 0x9c, /* pushf */
490 0x58, /* pop %eax */
491 0x0d,0,1,0,0, /* or $0x100,%eax */
492 0x50, /* push %eax */
493 0x9d, /* popf */
494 0x35,0,1,0,0, /* xor $0x100,%eax */
495 0x50, /* push %eax */
496 0x9d, /* popf */
497 0xc3
500 /* Test the alignment check (AC) flag handling. */
501 static const BYTE align_check_code[] = {
502 0x55, /* push %ebp */
503 0x89,0xe5, /* mov %esp,%ebp */
504 0x9c, /* pushf */
505 0x58, /* pop %eax */
506 0x0d,0,0,4,0, /* or $0x40000,%eax */
507 0x50, /* push %eax */
508 0x9d, /* popf */
509 0x89,0xe0, /* mov %esp, %eax */
510 0x8b,0x40,0x1, /* mov 0x1(%eax), %eax - cause exception */
511 0x9c, /* pushf */
512 0x58, /* pop %eax */
513 0x35,0,0,4,0, /* xor $0x40000,%eax */
514 0x50, /* push %eax */
515 0x9d, /* popf */
516 0x5d, /* pop %ebp */
517 0xc3, /* ret */
520 static DWORD align_check_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
521 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
523 ok (!(context->EFlags & 0x40000), "eflags has AC bit set\n");
524 got_exception++;
525 return ExceptionContinueExecution;
528 /* Test the direction flag handling. */
529 static const BYTE direction_flag_code[] = {
530 0x55, /* push %ebp */
531 0x89,0xe5, /* mov %esp,%ebp */
532 0xfd, /* std */
533 0xfa, /* cli - cause exception */
534 0x5d, /* pop %ebp */
535 0xc3, /* ret */
538 static DWORD direction_flag_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
539 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
541 #ifdef __GNUC__
542 unsigned int flags;
543 __asm__("pushfl; popl %0; cld" : "=r" (flags) );
544 /* older windows versions don't clear DF properly so don't test */
545 if (flags & 0x400) trace( "eflags has DF bit set\n" );
546 #endif
547 ok( context->EFlags & 0x400, "context eflags has DF bit cleared\n" );
548 got_exception++;
549 context->Eip++; /* skip cli */
550 context->EFlags &= ~0x400; /* make sure it is cleared on return */
551 return ExceptionContinueExecution;
554 /* test single stepping over hardware breakpoint */
555 static DWORD bpx_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
556 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
558 got_exception++;
559 ok( rec->ExceptionCode == EXCEPTION_SINGLE_STEP,
560 "wrong exception code: %x\n", rec->ExceptionCode);
562 if(got_exception == 1) {
563 /* hw bp exception on first nop */
564 ok( context->Eip == (DWORD)code_mem, "eip is wrong: %x instead of %x\n",
565 context->Eip, (DWORD)code_mem);
566 ok( (context->Dr6 & 0xf) == 1, "B0 flag is not set in Dr6\n");
567 ok( !(context->Dr6 & 0x4000), "BS flag is set in Dr6\n");
568 context->Dr0 = context->Dr0 + 1; /* set hw bp again on next instruction */
569 context->EFlags |= 0x100; /* enable single stepping */
570 } else if( got_exception == 2) {
571 /* single step exception on second nop */
572 ok( context->Eip == (DWORD)code_mem + 1, "eip is wrong: %x instead of %x\n",
573 context->Eip, (DWORD)code_mem + 1);
574 ok( (context->Dr6 & 0x4000), "BS flag is not set in Dr6\n");
575 /* depending on the win version the B0 bit is already set here as well
576 ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n"); */
577 context->EFlags |= 0x100;
578 } else if( got_exception == 3) {
579 /* hw bp exception on second nop */
580 ok( context->Eip == (DWORD)code_mem + 1, "eip is wrong: %x instead of %x\n",
581 context->Eip, (DWORD)code_mem + 1);
582 ok( (context->Dr6 & 0xf) == 1, "B0 flag is not set in Dr6\n");
583 ok( !(context->Dr6 & 0x4000), "BS flag is set in Dr6\n");
584 context->Dr0 = 0; /* clear breakpoint */
585 context->EFlags |= 0x100;
586 } else {
587 /* single step exception on ret */
588 ok( context->Eip == (DWORD)code_mem + 2, "eip is wrong: %x instead of %x\n",
589 context->Eip, (DWORD)code_mem + 2);
590 ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n");
591 ok( (context->Dr6 & 0x4000), "BS flag is not set in Dr6\n");
594 context->Dr6 = 0; /* clear status register */
595 return ExceptionContinueExecution;
598 static const BYTE dummy_code[] = { 0x90, 0x90, 0xc3 }; /* nop, nop, ret */
600 /* test int3 handling */
601 static DWORD int3_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
602 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
604 ok( rec->ExceptionAddress == code_mem, "exception address not at: %p, but at %p\n",
605 code_mem, rec->ExceptionAddress);
606 ok( context->Eip == (DWORD)code_mem, "eip not at: %p, but at %#x\n", code_mem, context->Eip);
607 if(context->Eip == (DWORD)code_mem) context->Eip++; /* skip breakpoint */
609 return ExceptionContinueExecution;
612 static const BYTE int3_code[] = { 0xCC, 0xc3 }; /* int 3, ret */
615 static void test_exceptions(void)
617 CONTEXT ctx;
618 NTSTATUS res;
620 if (!pNtGetContextThread || !pNtSetContextThread)
622 skip( "NtGetContextThread/NtSetContextThread not found\n" );
623 return;
626 /* test handling of debug registers */
627 run_exception_test(dreg_handler, NULL, &segfault_code, sizeof(segfault_code), 0);
629 ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
630 res = pNtGetContextThread(GetCurrentThread(), &ctx);
631 ok (res == STATUS_SUCCESS,"NtGetContextThread failed with %x\n", res);
632 ok(ctx.Dr0 == 0x42424242,"failed to set debugregister 0 to 0x42424242, got %x\n", ctx.Dr0);
633 ok((ctx.Dr7 & ~0xdc00) == 0x155,"failed to set debugregister 7 to 0x155, got %x\n", ctx.Dr7);
635 /* test single stepping behavior */
636 got_exception = 0;
637 run_exception_test(single_step_handler, NULL, &single_stepcode, sizeof(single_stepcode), 0);
638 ok(got_exception == 3, "expected 3 single step exceptions, got %d\n", got_exception);
640 /* test alignment exceptions */
641 got_exception = 0;
642 run_exception_test(align_check_handler, NULL, align_check_code, sizeof(align_check_code), 0);
643 ok(got_exception == 0, "got %d alignment faults, expected 0\n", got_exception);
645 /* test direction flag */
646 got_exception = 0;
647 run_exception_test(direction_flag_handler, NULL, direction_flag_code, sizeof(direction_flag_code), 0);
648 ok(got_exception == 1, "got %d exceptions, expected 1\n", got_exception);
650 /* test single stepping over hardware breakpoint */
651 memset(&ctx, 0, sizeof(ctx));
652 ctx.Dr0 = (DWORD) code_mem; /* set hw bp on first nop */
653 ctx.Dr7 = 3;
654 ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
655 res = pNtSetContextThread( GetCurrentThread(), &ctx);
656 ok( res == STATUS_SUCCESS, "NtSetContextThread faild with %x\n", res);
658 got_exception = 0;
659 run_exception_test(bpx_handler, NULL, dummy_code, sizeof(dummy_code), 0);
660 ok( got_exception == 4,"expected 4 exceptions, got %d\n", got_exception);
662 /* test int3 handling */
663 run_exception_test(int3_handler, NULL, int3_code, sizeof(int3_code), 0);
666 static void test_debugger(void)
668 char cmdline[MAX_PATH];
669 PROCESS_INFORMATION pi;
670 STARTUPINFO si = { 0 };
671 DEBUG_EVENT de;
672 DWORD continuestatus;
673 PVOID code_mem_address = NULL;
674 NTSTATUS status;
675 SIZE_T size_read;
676 BOOL ret;
677 int counter = 0;
678 si.cb = sizeof(si);
680 if(!pNtGetContextThread || !pNtSetContextThread || !pNtReadVirtualMemory || !pNtTerminateProcess)
682 skip("NtGetContextThread, NtSetContextThread, NtReadVirtualMemory or NtTerminateProcess not found\n");
683 return;
686 sprintf(cmdline, "%s %s %s %p", my_argv[0], my_argv[1], "debuggee", &test_stage);
687 ret = CreateProcess(NULL, cmdline, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, &si, &pi);
688 ok(ret, "could not create child process error: %u\n", GetLastError());
689 if (!ret)
690 return;
694 continuestatus = DBG_CONTINUE;
695 ok(WaitForDebugEvent(&de, INFINITE), "reading debug event\n");
697 if (de.dwThreadId != pi.dwThreadId)
699 trace("event %d not coming from main thread, ignoring\n", de.dwDebugEventCode);
700 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, DBG_CONTINUE);
701 continue;
704 if (de.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT)
706 if(de.u.CreateProcessInfo.lpBaseOfImage != pNtCurrentTeb()->Peb->ImageBaseAddress)
708 skip("child process loaded at different address, terminating it\n");
709 pNtTerminateProcess(pi.hProcess, 0);
712 else if (de.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
714 CONTEXT ctx;
715 int stage;
717 counter++;
718 status = pNtReadVirtualMemory(pi.hProcess, &code_mem, &code_mem_address,
719 sizeof(code_mem_address), &size_read);
720 ok(!status,"NtReadVirtualMemory failed with 0x%x\n", status);
721 status = pNtReadVirtualMemory(pi.hProcess, &test_stage, &stage,
722 sizeof(stage), &size_read);
723 ok(!status,"NtReadVirtualMemory failed with 0x%x\n", status);
725 ctx.ContextFlags = CONTEXT_FULL;
726 status = pNtGetContextThread(pi.hThread, &ctx);
727 ok(!status, "NtGetContextThread failed with 0x%x\n", status);
729 trace("exception 0x%x at %p firstchance=%d Eip=0x%x, Eax=0x%x\n",
730 de.u.Exception.ExceptionRecord.ExceptionCode,
731 de.u.Exception.ExceptionRecord.ExceptionAddress, de.u.Exception.dwFirstChance, ctx.Eip, ctx.Eax);
733 if (counter > 100)
735 ok(FALSE, "got way too many exceptions, probaby caught in a infinite loop, terminating child\n");
736 pNtTerminateProcess(pi.hProcess, 1);
738 else if (counter >= 2) /* skip startup breakpoint */
740 if (stage == 1)
742 ok((char *)ctx.Eip == (char *)code_mem_address + 0xb, "Eip at %x instead of %p\n",
743 ctx.Eip, (char *)code_mem_address + 0xb);
744 /* setting the context from debugger does not affect the context, the exception handlers gets */
745 /* uncomment once wine is fixed */
746 /* ctx.Eip = 0x12345; */
747 ctx.Eax = 0xf00f00f1;
749 /* let the debuggee handle the exception */
750 continuestatus = DBG_EXCEPTION_NOT_HANDLED;
752 else if (stage == 2)
754 if (de.u.Exception.dwFirstChance)
756 /* debugger gets first chance exception with unmodified ctx.Eip */
757 ok((char *)ctx.Eip == (char *)code_mem_address + 0xb, "Eip at 0x%x instead of %p\n",
758 ctx.Eip, (char *)code_mem_address + 0xb);
760 /* setting the context from debugger does not affect the context, the exception handlers gets */
761 /* uncomment once wine is fixed */
762 /* ctx.Eip = 0x12345; */
763 ctx.Eax = 0xf00f00f1;
765 /* pass exception to debuggee
766 * exception will not be handled and
767 * a second chance exception will be raised */
768 continuestatus = DBG_EXCEPTION_NOT_HANDLED;
770 else
772 /* debugger gets context after exception handler has played with it */
773 /* ctx.Eip is the same value the exception handler got */
774 if (de.u.Exception.ExceptionRecord.ExceptionCode == EXCEPTION_BREAKPOINT)
776 ok((char *)ctx.Eip == (char *)code_mem_address + 0xa, "Eip at 0x%x instead of %p\n",
777 ctx.Eip, (char *)code_mem_address + 0xa);
778 /* need to fixup Eip for debuggee */
779 if ((char *)ctx.Eip == (char *)code_mem_address + 0xa)
780 ctx.Eip += 1;
782 else
783 ok((char *)ctx.Eip == (char *)code_mem_address + 0xb, "Eip at 0x%x instead of %p\n",
784 ctx.Eip, (char *)code_mem_address + 0xb);
785 /* here we handle exception */
788 else
789 ok(FALSE, "unexpected stage %x\n", stage);
791 status = pNtSetContextThread(pi.hThread, &ctx);
792 ok(!status, "NtSetContextThread failed with 0x%x\n", status);
796 ContinueDebugEvent(de.dwProcessId, de.dwThreadId, continuestatus);
798 } while (de.dwDebugEventCode != EXIT_PROCESS_DEBUG_EVENT);
800 winetest_wait_child_process( pi.hProcess );
801 ok(CloseHandle(pi.hThread) != 0, "error %u\n", GetLastError());
802 ok(CloseHandle(pi.hProcess) != 0, "error %u\n", GetLastError());
804 return;
807 static DWORD simd_fault_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
808 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
810 int *stage = *(int **)(frame + 1);
812 got_exception++;
814 if( *stage == 1) {
815 /* fault while executing sse instruction */
816 context->Eip += 3; /* skip addps */
817 return ExceptionContinueExecution;
820 /* stage 2 - divide by zero fault */
821 if( rec->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION)
822 skip("system doesn't support SIMD exceptions\n");
823 else {
824 ok( rec->ExceptionCode == STATUS_FLOAT_MULTIPLE_TRAPS,
825 "exception code: %#x, should be %#x\n",
826 rec->ExceptionCode, STATUS_FLOAT_MULTIPLE_TRAPS);
827 ok( rec->NumberParameters == 1, "# of params: %i, should be 1\n",
828 rec->NumberParameters);
829 if( rec->NumberParameters == 1 )
830 ok( rec->ExceptionInformation[0] == 0, "param #1: %lx, should be 0\n", rec->ExceptionInformation[0]);
833 context->Eip += 3; /* skip divps */
835 return ExceptionContinueExecution;
838 static const BYTE simd_exception_test[] = {
839 0x83, 0xec, 0x4, /* sub $0x4, %esp */
840 0x0f, 0xae, 0x1c, 0x24, /* stmxcsr (%esp) */
841 0x66, 0x81, 0x24, 0x24, 0xff, 0xfd, /* andw $0xfdff,(%esp) * enable divide by */
842 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) * zero exceptions */
843 0x6a, 0x01, /* push $0x1 */
844 0x6a, 0x01, /* push $0x1 */
845 0x6a, 0x01, /* push $0x1 */
846 0x6a, 0x01, /* push $0x1 */
847 0x0f, 0x10, 0x0c, 0x24, /* movups (%esp),%xmm1 * fill dividend */
848 0x0f, 0x57, 0xc0, /* xorps %xmm0,%xmm0 * clear divisor */
849 0x0f, 0x5e, 0xc8, /* divps %xmm0,%xmm1 * generate fault */
850 0x83, 0xc4, 0x10, /* add $0x10,%esp */
851 0x66, 0x81, 0x0c, 0x24, 0x00, 0x02, /* orw $0x200,(%esp) * disable exceptions */
852 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) */
853 0x83, 0xc4, 0x04, /* add $0x4,%esp */
854 0xc3, /* ret */
857 static const BYTE sse_check[] = {
858 0x0f, 0x58, 0xc8, /* addps %xmm0,%xmm1 */
859 0xc3, /* ret */
862 static void test_simd_exceptions(void)
864 int stage;
866 /* test if CPU & OS can do sse */
867 stage = 1;
868 got_exception = 0;
869 run_exception_test(simd_fault_handler, &stage, sse_check, sizeof(sse_check), 0);
870 if(got_exception) {
871 skip("system doesn't support SSE\n");
872 return;
875 /* generate a SIMD exception */
876 stage = 2;
877 got_exception = 0;
878 run_exception_test(simd_fault_handler, &stage, simd_exception_test,
879 sizeof(simd_exception_test), 0);
880 ok( got_exception == 1, "got exception: %i, should be 1\n", got_exception);
883 struct fpu_exception_info
885 DWORD exception_code;
886 DWORD exception_offset;
887 DWORD eip_offset;
890 static DWORD fpu_exception_handler(EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
891 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher)
893 struct fpu_exception_info *info = *(struct fpu_exception_info **)(frame + 1);
895 info->exception_code = rec->ExceptionCode;
896 info->exception_offset = (BYTE *)rec->ExceptionAddress - (BYTE *)code_mem;
897 info->eip_offset = context->Eip - (DWORD)code_mem;
899 ++context->Eip;
900 return ExceptionContinueExecution;
903 static void test_fpu_exceptions(void)
905 static const BYTE fpu_exception_test_ie[] =
907 0x83, 0xec, 0x04, /* sub $0x4,%esp */
908 0x66, 0xc7, 0x04, 0x24, 0xfe, 0x03, /* movw $0x3fe,(%esp) */
909 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
910 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
911 0xd9, 0xee, /* fldz */
912 0xd9, 0xe8, /* fld1 */
913 0xde, 0xf1, /* fdivp */
914 0xdd, 0xd8, /* fstp %st(0) */
915 0xdd, 0xd8, /* fstp %st(0) */
916 0x9b, /* fwait */
917 0xdb, 0xe2, /* fnclex */
918 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
919 0x83, 0xc4, 0x04, /* add $0x4,%esp */
920 0xc3, /* ret */
923 static const BYTE fpu_exception_test_de[] =
925 0x83, 0xec, 0x04, /* sub $0x4,%esp */
926 0x66, 0xc7, 0x04, 0x24, 0xfb, 0x03, /* movw $0x3fb,(%esp) */
927 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
928 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
929 0xdd, 0xd8, /* fstp %st(0) */
930 0xd9, 0xee, /* fldz */
931 0xd9, 0xe8, /* fld1 */
932 0xde, 0xf1, /* fdivp */
933 0x9b, /* fwait */
934 0xdb, 0xe2, /* fnclex */
935 0xdd, 0xd8, /* fstp %st(0) */
936 0xdd, 0xd8, /* fstp %st(0) */
937 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
938 0x83, 0xc4, 0x04, /* add $0x4,%esp */
939 0xc3, /* ret */
942 struct fpu_exception_info info;
944 memset(&info, 0, sizeof(info));
945 run_exception_test(fpu_exception_handler, &info, fpu_exception_test_ie, sizeof(fpu_exception_test_ie), 0);
946 ok(info.exception_code == EXCEPTION_FLT_STACK_CHECK,
947 "Got exception code %#x, expected EXCEPTION_FLT_STACK_CHECK\n", info.exception_code);
948 ok(info.exception_offset == 0x19 ||
949 broken( is_wow64 && info.exception_offset == info.eip_offset ),
950 "Got exception offset %#x, expected 0x19\n", info.exception_offset);
951 ok(info.eip_offset == 0x1b, "Got EIP offset %#x, expected 0x1b\n", info.eip_offset);
953 memset(&info, 0, sizeof(info));
954 run_exception_test(fpu_exception_handler, &info, fpu_exception_test_de, sizeof(fpu_exception_test_de), 0);
955 ok(info.exception_code == EXCEPTION_FLT_DIVIDE_BY_ZERO,
956 "Got exception code %#x, expected EXCEPTION_FLT_DIVIDE_BY_ZERO\n", info.exception_code);
957 ok(info.exception_offset == 0x17 ||
958 broken( is_wow64 && info.exception_offset == info.eip_offset ),
959 "Got exception offset %#x, expected 0x17\n", info.exception_offset);
960 ok(info.eip_offset == 0x19, "Got EIP offset %#x, expected 0x19\n", info.eip_offset);
963 struct dpe_exception_info {
964 BOOL exception_caught;
965 DWORD exception_info;
968 static DWORD dpe_exception_handler(EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
969 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher)
971 DWORD old_prot;
972 struct dpe_exception_info *info = *(struct dpe_exception_info **)(frame + 1);
974 ok(rec->ExceptionCode == EXCEPTION_ACCESS_VIOLATION,
975 "Exception code %08x\n", rec->ExceptionCode);
976 ok(rec->NumberParameters == 2,
977 "Parameter count: %d\n", rec->NumberParameters);
978 ok((LPVOID)rec->ExceptionInformation[1] == code_mem,
979 "Exception address: %p, expected %p\n",
980 (LPVOID)rec->ExceptionInformation[1], code_mem);
982 info->exception_info = rec->ExceptionInformation[0];
983 info->exception_caught = TRUE;
985 VirtualProtect(code_mem, 1, PAGE_EXECUTE_READWRITE, &old_prot);
986 return ExceptionContinueExecution;
989 static void test_dpe_exceptions(void)
991 static char single_ret[] = {0xC3};
992 struct dpe_exception_info info;
993 NTSTATUS stat;
994 BOOL has_hw_support;
995 BOOL is_permanent = FALSE, can_test_without = TRUE, can_test_with = TRUE;
996 DWORD val;
997 ULONG len;
999 /* Query DEP with len to small */
1000 stat = pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val - 1, &len);
1001 if(stat == STATUS_INVALID_INFO_CLASS)
1003 skip("This software platform does not support DEP\n");
1004 return;
1006 ok(stat == STATUS_INFO_LENGTH_MISMATCH, "buffer too small: %08x\n", stat);
1008 /* Query DEP */
1009 stat = pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val, &len);
1010 ok(stat == STATUS_SUCCESS, "querying DEP: status %08x\n", stat);
1011 if(stat == STATUS_SUCCESS)
1013 ok(len == sizeof val, "returned length: %d\n", len);
1014 if(val & MEM_EXECUTE_OPTION_PERMANENT)
1016 skip("toggling DEP impossible - status locked\n");
1017 is_permanent = TRUE;
1018 if(val & MEM_EXECUTE_OPTION_DISABLE)
1019 can_test_without = FALSE;
1020 else
1021 can_test_with = FALSE;
1025 if(!is_permanent)
1027 /* Enable DEP */
1028 val = MEM_EXECUTE_OPTION_DISABLE;
1029 stat = pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val);
1030 ok(stat == STATUS_SUCCESS, "enabling DEP: status %08x\n", stat);
1033 if(can_test_with)
1035 /* Try access to locked page with DEP on*/
1036 info.exception_caught = FALSE;
1037 run_exception_test(dpe_exception_handler, &info, single_ret, sizeof(single_ret), PAGE_NOACCESS);
1038 ok(info.exception_caught == TRUE, "Execution of disabled memory succeeded\n");
1039 ok(info.exception_info == EXCEPTION_READ_FAULT ||
1040 info.exception_info == EXCEPTION_EXECUTE_FAULT,
1041 "Access violation type: %08x\n", (unsigned)info.exception_info);
1042 has_hw_support = info.exception_info == EXCEPTION_EXECUTE_FAULT;
1043 trace("DEP hardware support: %s\n", has_hw_support?"Yes":"No");
1045 /* Try execution of data with DEP on*/
1046 info.exception_caught = FALSE;
1047 run_exception_test(dpe_exception_handler, &info, single_ret, sizeof(single_ret), PAGE_READWRITE);
1048 if(has_hw_support)
1050 ok(info.exception_caught == TRUE, "Execution of data memory succeeded\n");
1051 ok(info.exception_info == EXCEPTION_EXECUTE_FAULT,
1052 "Access violation type: %08x\n", (unsigned)info.exception_info);
1054 else
1055 ok(info.exception_caught == FALSE, "Execution trapped without hardware support\n");
1057 else
1058 skip("DEP is in AlwaysOff state\n");
1060 if(!is_permanent)
1062 /* Disable DEP */
1063 val = MEM_EXECUTE_OPTION_ENABLE;
1064 stat = pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val);
1065 ok(stat == STATUS_SUCCESS, "disabling DEP: status %08x\n", stat);
1068 /* page is read without exec here */
1069 if(can_test_without)
1071 /* Try execution of data with DEP off */
1072 info.exception_caught = FALSE;
1073 run_exception_test(dpe_exception_handler, &info, single_ret, sizeof(single_ret), PAGE_READWRITE);
1074 ok(info.exception_caught == FALSE, "Execution trapped with DEP turned off\n");
1076 /* Try access to locked page with DEP off - error code is different than
1077 with hardware DEP on */
1078 info.exception_caught = FALSE;
1079 run_exception_test(dpe_exception_handler, &info, single_ret, sizeof(single_ret), PAGE_NOACCESS);
1080 ok(info.exception_caught == TRUE, "Execution of disabled memory succeeded\n");
1081 ok(info.exception_info == EXCEPTION_READ_FAULT,
1082 "Access violation type: %08x\n", (unsigned)info.exception_info);
1084 else
1085 skip("DEP is in AlwaysOn state\n");
1087 if(!is_permanent)
1089 /* Turn off DEP permanently */
1090 val = MEM_EXECUTE_OPTION_ENABLE | MEM_EXECUTE_OPTION_PERMANENT;
1091 stat = pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val);
1092 ok(stat == STATUS_SUCCESS, "disabling DEP permanently: status %08x\n", stat);
1095 /* Try to turn off DEP */
1096 val = MEM_EXECUTE_OPTION_ENABLE;
1097 stat = pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val);
1098 ok(stat == STATUS_ACCESS_DENIED, "disabling DEP while permanent: status %08x\n", stat);
1100 /* Try to turn on DEP */
1101 val = MEM_EXECUTE_OPTION_DISABLE;
1102 stat = pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &val, sizeof val);
1103 ok(stat == STATUS_ACCESS_DENIED, "enabling DEP while permanent: status %08x\n", stat);
1106 #elif defined(__x86_64__)
1108 #define UNW_FLAG_NHANDLER 0
1109 #define UNW_FLAG_EHANDLER 1
1110 #define UNW_FLAG_UHANDLER 2
1111 #define UNW_FLAG_CHAININFO 4
1113 #define UWOP_PUSH_NONVOL 0
1114 #define UWOP_ALLOC_LARGE 1
1115 #define UWOP_ALLOC_SMALL 2
1116 #define UWOP_SET_FPREG 3
1117 #define UWOP_SAVE_NONVOL 4
1118 #define UWOP_SAVE_NONVOL_FAR 5
1119 #define UWOP_SAVE_XMM128 8
1120 #define UWOP_SAVE_XMM128_FAR 9
1121 #define UWOP_PUSH_MACHFRAME 10
1123 struct results
1125 int rip_offset; /* rip offset from code start */
1126 int rbp_offset; /* rbp offset from stack pointer */
1127 int handler; /* expect handler to be set? */
1128 int rip; /* expected final rip value */
1129 int frame; /* expected frame return value */
1130 int regs[8][2]; /* expected values for registers */
1133 struct unwind_test
1135 const BYTE *function;
1136 size_t function_size;
1137 const BYTE *unwind_info;
1138 const struct results *results;
1139 unsigned int nb_results;
1142 enum regs
1144 rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi,
1145 r8, r9, r10, r11, r12, r13, r14, r15
1148 static const char * const reg_names[16] =
1150 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
1151 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1154 #define UWOP(code,info) (UWOP_##code | ((info) << 4))
1156 static void call_virtual_unwind( int testnum, const struct unwind_test *test )
1158 static const int code_offset = 1024;
1159 static const int unwind_offset = 2048;
1160 void *handler, *data;
1161 CONTEXT context;
1162 RUNTIME_FUNCTION runtime_func;
1163 KNONVOLATILE_CONTEXT_POINTERS ctx_ptr;
1164 UINT i, j, k;
1165 ULONG64 fake_stack[256];
1166 ULONG64 frame, orig_rip, orig_rbp, unset_reg;
1167 UINT unwind_size = 4 + 2 * test->unwind_info[2] + 8;
1169 memcpy( (char *)code_mem + code_offset, test->function, test->function_size );
1170 memcpy( (char *)code_mem + unwind_offset, test->unwind_info, unwind_size );
1172 runtime_func.BeginAddress = code_offset;
1173 runtime_func.EndAddress = code_offset + test->function_size;
1174 runtime_func.UnwindData = unwind_offset;
1176 trace( "code: %p stack: %p\n", code_mem, fake_stack );
1178 for (i = 0; i < test->nb_results; i++)
1180 memset( &ctx_ptr, 0, sizeof(ctx_ptr) );
1181 memset( &context, 0x55, sizeof(context) );
1182 memset( &unset_reg, 0x55, sizeof(unset_reg) );
1183 for (j = 0; j < 256; j++) fake_stack[j] = j * 8;
1185 context.Rsp = (ULONG_PTR)fake_stack;
1186 context.Rbp = (ULONG_PTR)fake_stack + test->results[i].rbp_offset;
1187 orig_rbp = context.Rbp;
1188 orig_rip = (ULONG64)code_mem + code_offset + test->results[i].rip_offset;
1190 trace( "%u/%u: rip=%p (%02x) rbp=%p rsp=%p\n", testnum, i,
1191 (void *)orig_rip, *(BYTE *)orig_rip, (void *)orig_rbp, (void *)context.Rsp );
1193 data = (void *)0xdeadbeef;
1194 handler = RtlVirtualUnwind( UNW_FLAG_EHANDLER, (ULONG64)code_mem, orig_rip,
1195 &runtime_func, &context, &data, &frame, &ctx_ptr );
1196 if (test->results[i].handler)
1198 ok( (char *)handler == (char *)code_mem + 0x200,
1199 "%u/%u: wrong handler %p/%p\n", testnum, i, handler, (char *)code_mem + 0x200 );
1200 if (handler) ok( *(DWORD *)data == 0x08070605,
1201 "%u/%u: wrong handler data %p\n", testnum, i, data );
1203 else
1205 ok( handler == NULL, "%u/%u: handler %p instead of NULL\n", testnum, i, handler );
1206 ok( data == (void *)0xdeadbeef, "%u/%u: handler data set to %p\n", testnum, i, data );
1209 ok( context.Rip == test->results[i].rip, "%u/%u: wrong rip %p/%x\n",
1210 testnum, i, (void *)context.Rip, test->results[i].rip );
1211 ok( frame == (ULONG64)fake_stack + test->results[i].frame, "%u/%u: wrong frame %p/%p\n",
1212 testnum, i, (void *)frame, (char *)fake_stack + test->results[i].frame );
1214 for (j = 0; j < 16; j++)
1216 static const UINT nb_regs = sizeof(test->results[i].regs) / sizeof(test->results[i].regs[0]);
1218 for (k = 0; k < nb_regs; k++)
1220 if (test->results[i].regs[k][0] == -1)
1222 k = nb_regs;
1223 break;
1225 if (test->results[i].regs[k][0] == j) break;
1228 if (j == rsp) /* rsp is special */
1230 ok( !ctx_ptr.u2.IntegerContext[j],
1231 "%u/%u: rsp should not be set in ctx_ptr\n", testnum, i );
1232 ok( context.Rsp == (ULONG64)fake_stack + test->results[i].regs[k][1],
1233 "%u/%u: register rsp wrong %p/%p\n",
1234 testnum, i, (void *)context.Rsp, (char *)fake_stack + test->results[i].regs[k][1] );
1235 continue;
1238 if (ctx_ptr.u2.IntegerContext[j])
1240 ok( k < nb_regs, "%u/%u: register %s should not be set to %lx\n",
1241 testnum, i, reg_names[j], *(&context.Rax + j) );
1242 if (k < nb_regs)
1243 ok( *(&context.Rax + j) == test->results[i].regs[k][1],
1244 "%u/%u: register %s wrong %p/%x\n",
1245 testnum, i, reg_names[j], (void *)*(&context.Rax + j), test->results[i].regs[k][1] );
1247 else
1249 ok( k == nb_regs, "%u/%u: register %s should be set\n", testnum, i, reg_names[j] );
1250 if (j == rbp)
1251 ok( context.Rbp == orig_rbp, "%u/%u: register rbp wrong %p/unset\n",
1252 testnum, i, (void *)context.Rbp );
1253 else
1254 ok( *(&context.Rax + j) == unset_reg,
1255 "%u/%u: register %s wrong %p/unset\n",
1256 testnum, i, reg_names[j], (void *)*(&context.Rax + j));
1262 static void test_virtual_unwind(void)
1264 static const BYTE function_0[] =
1266 0xff, 0xf5, /* 00: push %rbp */
1267 0x48, 0x81, 0xec, 0x10, 0x01, 0x00, 0x00, /* 02: sub $0x110,%rsp */
1268 0x48, 0x8d, 0x6c, 0x24, 0x30, /* 09: lea 0x30(%rsp),%rbp */
1269 0x48, 0x89, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 0e: mov %rbx,0xf0(%rbp) */
1270 0x48, 0x89, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 15: mov %rsi,0xf8(%rbp) */
1271 0x90, /* 1c: nop */
1272 0x48, 0x8b, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 1d: mov 0xf0(%rbp),%rbx */
1273 0x48, 0x8b, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 24: mov 0xf8(%rbp),%rsi */
1274 0x48, 0x8d, 0xa5, 0xe0, 0x00, 0x00, 0x00, /* 2b: lea 0xe0(%rbp),%rsp */
1275 0x5d, /* 32: pop %rbp */
1276 0xc3 /* 33: ret */
1279 static const BYTE unwind_info_0[] =
1281 1 | (UNW_FLAG_EHANDLER << 3), /* version + flags */
1282 0x1c, /* prolog size */
1283 8, /* opcode count */
1284 (0x03 << 4) | rbp, /* frame reg rbp offset 0x30 */
1286 0x1c, UWOP(SAVE_NONVOL, rsi), 0x25, 0, /* 1c: mov %rsi,0x128(%rsp) */
1287 0x15, UWOP(SAVE_NONVOL, rbx), 0x24, 0, /* 15: mov %rbx,0x120(%rsp) */
1288 0x0e, UWOP(SET_FPREG, rbp), /* 0e: lea 0x30(%rsp),rbp */
1289 0x09, UWOP(ALLOC_LARGE, 0), 0x22, 0, /* 09: sub $0x110,%rsp */
1290 0x02, UWOP(PUSH_NONVOL, rbp), /* 02: push %rbp */
1292 0x00, 0x02, 0x00, 0x00, /* handler */
1293 0x05, 0x06, 0x07, 0x08, /* data */
1296 static const struct results results_0[] =
1298 /* offset rbp handler rip frame registers */
1299 { 0x00, 0x40, FALSE, 0x000, 0x000, { {rsp,0x008}, {-1,-1} }},
1300 { 0x02, 0x40, FALSE, 0x008, 0x000, { {rsp,0x010}, {rbp,0x000}, {-1,-1} }},
1301 { 0x09, 0x40, FALSE, 0x118, 0x000, { {rsp,0x120}, {rbp,0x110}, {-1,-1} }},
1302 { 0x0e, 0x40, FALSE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {-1,-1} }},
1303 { 0x15, 0x40, FALSE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {rbx,0x130}, {-1,-1} }},
1304 { 0x1c, 0x40, TRUE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {rbx,0x130}, {rsi,0x138}, {-1,-1}}},
1305 { 0x1d, 0x40, TRUE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {rbx,0x130}, {rsi,0x138}, {-1,-1}}},
1306 { 0x24, 0x40, TRUE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {rbx,0x130}, {rsi,0x138}, {-1,-1}}},
1307 { 0x2b, 0x40, FALSE, 0x128, 0x010, { {rsp,0x130}, {rbp,0x120}, {-1,-1}}},
1308 { 0x32, 0x40, FALSE, 0x008, 0x010, { {rsp,0x010}, {rbp,0x000}, {-1,-1}}},
1309 { 0x33, 0x40, FALSE, 0x000, 0x010, { {rsp,0x008}, {-1,-1}}},
1313 static const BYTE function_1[] =
1315 0x53, /* 00: push %rbx */
1316 0x55, /* 01: push %rbp */
1317 0x56, /* 02: push %rsi */
1318 0x57, /* 03: push %rdi */
1319 0x41, 0x54, /* 04: push %r12 */
1320 0x48, 0x83, 0xec, 0x30, /* 06: sub $0x30,%rsp */
1321 0x90, 0x90, /* 0a: nop; nop */
1322 0x48, 0x83, 0xc4, 0x30, /* 0c: add $0x30,%rsp */
1323 0x41, 0x5c, /* 10: pop %r12 */
1324 0x5f, /* 12: pop %rdi */
1325 0x5e, /* 13: pop %rsi */
1326 0x5d, /* 14: pop %rbp */
1327 0x5b, /* 15: pop %rbx */
1328 0xc3 /* 16: ret */
1331 static const BYTE unwind_info_1[] =
1333 1 | (UNW_FLAG_EHANDLER << 3), /* version + flags */
1334 0x0a, /* prolog size */
1335 6, /* opcode count */
1336 0, /* frame reg */
1338 0x0a, UWOP(ALLOC_SMALL, 5), /* 0a: sub $0x30,%rsp */
1339 0x06, UWOP(PUSH_NONVOL, r12), /* 06: push %r12 */
1340 0x04, UWOP(PUSH_NONVOL, rdi), /* 04: push %rdi */
1341 0x03, UWOP(PUSH_NONVOL, rsi), /* 03: push %rsi */
1342 0x02, UWOP(PUSH_NONVOL, rbp), /* 02: push %rbp */
1343 0x01, UWOP(PUSH_NONVOL, rbx), /* 01: push %rbx */
1345 0x00, 0x02, 0x00, 0x00, /* handler */
1346 0x05, 0x06, 0x07, 0x08, /* data */
1349 static const struct results results_1[] =
1351 /* offset rbp handler rip frame registers */
1352 { 0x00, 0x50, FALSE, 0x000, 0x000, { {rsp,0x008}, {-1,-1} }},
1353 { 0x01, 0x50, FALSE, 0x008, 0x000, { {rsp,0x010}, {rbx,0x000}, {-1,-1} }},
1354 { 0x02, 0x50, FALSE, 0x010, 0x000, { {rsp,0x018}, {rbx,0x008}, {rbp,0x000}, {-1,-1} }},
1355 { 0x03, 0x50, FALSE, 0x018, 0x000, { {rsp,0x020}, {rbx,0x010}, {rbp,0x008}, {rsi,0x000}, {-1,-1} }},
1356 { 0x04, 0x50, FALSE, 0x020, 0x000, { {rsp,0x028}, {rbx,0x018}, {rbp,0x010}, {rsi,0x008}, {rdi,0x000}, {-1,-1} }},
1357 { 0x06, 0x50, FALSE, 0x028, 0x000, { {rsp,0x030}, {rbx,0x020}, {rbp,0x018}, {rsi,0x010}, {rdi,0x008}, {r12,0x000}, {-1,-1} }},
1358 { 0x0a, 0x50, TRUE, 0x058, 0x000, { {rsp,0x060}, {rbx,0x050}, {rbp,0x048}, {rsi,0x040}, {rdi,0x038}, {r12,0x030}, {-1,-1} }},
1359 { 0x0c, 0x50, FALSE, 0x058, 0x000, { {rsp,0x060}, {rbx,0x050}, {rbp,0x048}, {rsi,0x040}, {rdi,0x038}, {r12,0x030}, {-1,-1} }},
1360 { 0x10, 0x50, FALSE, 0x028, 0x000, { {rsp,0x030}, {rbx,0x020}, {rbp,0x018}, {rsi,0x010}, {rdi,0x008}, {r12,0x000}, {-1,-1} }},
1361 { 0x12, 0x50, FALSE, 0x020, 0x000, { {rsp,0x028}, {rbx,0x018}, {rbp,0x010}, {rsi,0x008}, {rdi,0x000}, {-1,-1} }},
1362 { 0x13, 0x50, FALSE, 0x018, 0x000, { {rsp,0x020}, {rbx,0x010}, {rbp,0x008}, {rsi,0x000}, {-1,-1} }},
1363 { 0x14, 0x50, FALSE, 0x010, 0x000, { {rsp,0x018}, {rbx,0x008}, {rbp,0x000}, {-1,-1} }},
1364 { 0x15, 0x50, FALSE, 0x008, 0x000, { {rsp,0x010}, {rbx,0x000}, {-1,-1} }},
1365 { 0x16, 0x50, FALSE, 0x000, 0x000, { {rsp,0x008}, {-1,-1} }},
1368 static const struct unwind_test tests[] =
1370 { function_0, sizeof(function_0), unwind_info_0,
1371 results_0, sizeof(results_0)/sizeof(results_0[0]) },
1372 { function_1, sizeof(function_1), unwind_info_1,
1373 results_1, sizeof(results_1)/sizeof(results_1[0]) }
1375 unsigned int i;
1377 for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
1378 call_virtual_unwind( i, &tests[i] );
1381 #endif /* __x86_64__ */
1383 START_TEST(exception)
1385 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1387 code_mem = VirtualAlloc(NULL, 65536, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
1388 if(!code_mem) {
1389 trace("VirtualAlloc failed\n");
1390 return;
1393 pNtCurrentTeb = (void *)GetProcAddress( hntdll, "NtCurrentTeb" );
1394 pNtGetContextThread = (void *)GetProcAddress( hntdll, "NtGetContextThread" );
1395 pNtSetContextThread = (void *)GetProcAddress( hntdll, "NtSetContextThread" );
1396 pNtReadVirtualMemory = (void *)GetProcAddress( hntdll, "NtReadVirtualMemory" );
1397 pRtlRaiseException = (void *)GetProcAddress( hntdll, "RtlRaiseException" );
1398 pNtTerminateProcess = (void *)GetProcAddress( hntdll, "NtTerminateProcess" );
1399 pRtlAddVectoredExceptionHandler = (void *)GetProcAddress( hntdll,
1400 "RtlAddVectoredExceptionHandler" );
1401 pRtlRemoveVectoredExceptionHandler = (void *)GetProcAddress( hntdll,
1402 "RtlRemoveVectoredExceptionHandler" );
1403 pNtQueryInformationProcess = (void*)GetProcAddress( hntdll,
1404 "NtQueryInformationProcess" );
1405 pNtSetInformationProcess = (void*)GetProcAddress( hntdll,
1406 "NtSetInformationProcess" );
1407 pIsWow64Process = (void *)GetProcAddress(GetModuleHandle("kernel32.dll"), "IsWow64Process");
1409 #ifdef __i386__
1410 if (!pNtCurrentTeb)
1412 skip( "NtCurrentTeb not found\n" );
1413 return;
1415 if (!pIsWow64Process || !pIsWow64Process( GetCurrentProcess(), &is_wow64 )) is_wow64 = FALSE;
1417 if (pRtlAddVectoredExceptionHandler && pRtlRemoveVectoredExceptionHandler)
1418 have_vectored_api = TRUE;
1419 else
1420 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n");
1422 my_argc = winetest_get_mainargs( &my_argv );
1423 if (my_argc >= 4)
1425 void *addr;
1426 sscanf( my_argv[3], "%p", &addr );
1428 if (addr != &test_stage)
1430 skip( "child process not mapped at same address (%p/%p)\n", &test_stage, addr);
1431 return;
1434 /* child must be run under a debugger */
1435 if (!pNtCurrentTeb()->Peb->BeingDebugged)
1437 ok(FALSE, "child process not being debugged?\n");
1438 return;
1441 if (pRtlRaiseException)
1443 test_stage = 1;
1444 run_rtlraiseexception_test(0x12345);
1445 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT);
1446 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE);
1447 test_stage = 2;
1448 run_rtlraiseexception_test(0x12345);
1449 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT);
1450 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE);
1452 else
1453 skip( "RtlRaiseException not found\n" );
1455 /* rest of tests only run in parent */
1456 return;
1459 test_prot_fault();
1460 test_exceptions();
1461 test_rtlraiseexception();
1462 test_debugger();
1463 test_simd_exceptions();
1464 test_fpu_exceptions();
1465 test_dpe_exceptions();
1467 #elif defined(__x86_64__)
1469 test_virtual_unwind();
1471 #endif
1473 VirtualFree(code_mem, 0, MEM_FREE);