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
25 #define _WIN32_WINNT 0x500 /* For NTSTATUS */
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #define WIN32_NO_STATUS
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
*pRtlUnwind
)(PVOID
, PVOID
, PEXCEPTION_RECORD
, PVOID
);
47 static PVOID (WINAPI
*pRtlAddVectoredExceptionHandler
)(ULONG first
, PVECTORED_EXCEPTION_HANDLER func
);
48 static ULONG (WINAPI
*pRtlRemoveVectoredExceptionHandler
)(PVOID handler
);
49 static PVOID (WINAPI
*pRtlAddVectoredContinueHandler
)(ULONG first
, PVECTORED_EXCEPTION_HANDLER func
);
50 static ULONG (WINAPI
*pRtlRemoveVectoredContinueHandler
)(PVOID handler
);
51 static NTSTATUS (WINAPI
*pNtReadVirtualMemory
)(HANDLE
, const void*, void*, SIZE_T
, SIZE_T
*);
52 static NTSTATUS (WINAPI
*pNtTerminateProcess
)(HANDLE handle
, LONG exit_code
);
53 static NTSTATUS (WINAPI
*pNtQueryInformationProcess
)(HANDLE
, PROCESSINFOCLASS
, PVOID
, ULONG
, PULONG
);
54 static NTSTATUS (WINAPI
*pNtSetInformationProcess
)(HANDLE
, PROCESSINFOCLASS
, PVOID
, ULONG
);
55 static BOOL (WINAPI
*pIsWow64Process
)(HANDLE
, PBOOL
);
57 #if defined(__x86_64__)
58 static BOOLEAN (CDECL
*pRtlAddFunctionTable
)(RUNTIME_FUNCTION
*, DWORD
, DWORD64
);
59 static BOOLEAN (CDECL
*pRtlDeleteFunctionTable
)(RUNTIME_FUNCTION
*);
60 static BOOLEAN (CDECL
*pRtlInstallFunctionTableCallback
)(DWORD64
, DWORD64
, DWORD
, PGET_RUNTIME_FUNCTION_CALLBACK
, PVOID
, PCWSTR
);
61 static PRUNTIME_FUNCTION (WINAPI
*pRtlLookupFunctionEntry
)(ULONG64
, ULONG64
*, UNWIND_HISTORY_TABLE
*);
66 #ifndef __WINE_WINTRNL_H
67 #define ProcessExecuteFlags 0x22
68 #define MEM_EXECUTE_OPTION_DISABLE 0x01
69 #define MEM_EXECUTE_OPTION_ENABLE 0x02
70 #define MEM_EXECUTE_OPTION_PERMANENT 0x08
74 static char** my_argv
;
75 static int test_stage
;
79 /* Test various instruction combinations that cause a protection fault on the i386,
80 * and check what the resulting exception looks like.
83 static const struct exception
85 BYTE code
[18]; /* asm code */
86 BYTE offset
; /* offset of faulting instruction */
87 BYTE length
; /* length of faulting instruction */
88 BOOL wow64_broken
; /* broken on Wow64, should be skipped */
89 NTSTATUS status
; /* expected status code */
90 DWORD nb_params
; /* expected number of parameters */
91 DWORD params
[4]; /* expected parameters */
92 NTSTATUS alt_status
; /* alternative status code */
93 DWORD alt_nb_params
; /* alternative number of parameters */
94 DWORD alt_params
[4]; /* alternative parameters */
98 /* test some privileged instructions */
99 { { 0xfb, 0xc3 }, /* 0: sti; ret */
100 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
101 { { 0x6c, 0xc3 }, /* 1: insb (%dx); ret */
102 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
103 { { 0x6d, 0xc3 }, /* 2: insl (%dx); ret */
104 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
105 { { 0x6e, 0xc3 }, /* 3: outsb (%dx); ret */
106 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
107 { { 0x6f, 0xc3 }, /* 4: outsl (%dx); ret */
108 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
110 { { 0xe4, 0x11, 0xc3 }, /* 5: inb $0x11,%al; ret */
111 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
112 { { 0xe5, 0x11, 0xc3 }, /* 6: inl $0x11,%eax; ret */
113 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
114 { { 0xe6, 0x11, 0xc3 }, /* 7: outb %al,$0x11; ret */
115 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
116 { { 0xe7, 0x11, 0xc3 }, /* 8: outl %eax,$0x11; ret */
117 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
118 { { 0xed, 0xc3 }, /* 9: inl (%dx),%eax; ret */
119 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
121 { { 0xee, 0xc3 }, /* 10: outb %al,(%dx); ret */
122 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
123 { { 0xef, 0xc3 }, /* 11: outl %eax,(%dx); ret */
124 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
125 { { 0xf4, 0xc3 }, /* 12: hlt; ret */
126 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
127 { { 0xfa, 0xc3 }, /* 13: cli; ret */
128 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
130 /* test long jump to invalid selector */
131 { { 0xea, 0, 0, 0, 0, 0, 0, 0xc3 }, /* 14: ljmp $0,$0; ret */
132 0, 7, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
135 /* test iret to invalid selector */
136 { { 0x6a, 0x00, 0x6a, 0x00, 0x6a, 0x00, 0xcf, 0x83, 0xc4, 0x0c, 0xc3 },
137 /* 15: pushl $0; pushl $0; pushl $0; iret; addl $12,%esp; ret */
138 6, 1, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
140 /* test loading an invalid selector */
141 { { 0xb8, 0xef, 0xbe, 0x00, 0x00, 0x8e, 0xe8, 0xc3 }, /* 16: mov $beef,%ax; mov %ax,%gs; ret */
142 5, 2, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xbee8 } }, /* 0xbee8 or 0xffffffff */
144 /* test accessing a zero selector (%es broken on Wow64) */
145 { { 0x06, 0x31, 0xc0, 0x8e, 0xc0, 0x26, 0xa1, 0, 0, 0, 0, 0x07, 0xc3 },
146 /* push %es; xor %eax,%eax; mov %ax,%es; mov %es:(0),%ax; pop %es; ret */
147 5, 6, TRUE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
148 { { 0x0f, 0xa8, 0x31, 0xc0, 0x8e, 0xe8, 0x65, 0xa1, 0, 0, 0, 0, 0x0f, 0xa9, 0xc3 },
149 /* push %gs; xor %eax,%eax; mov %ax,%gs; mov %gs:(0),%ax; pop %gs; ret */
150 6, 6, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
152 /* test moving %cs -> %ss */
153 { { 0x0e, 0x17, 0x58, 0xc3 }, /* pushl %cs; popl %ss; popl %eax; ret */
154 1, 1, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
157 /* test overlong instruction (limit is 15 bytes, 5 on Win7) */
158 { { 0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xfa,0xc3 },
159 0, 16, TRUE
, STATUS_ILLEGAL_INSTRUCTION
, 0, { 0 },
160 STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
161 { { 0x64,0x64,0x64,0x64,0xfa,0xc3 },
162 0, 5, TRUE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
164 /* test invalid interrupt */
165 { { 0xcd, 0xff, 0xc3 }, /* int $0xff; ret */
166 0, 2, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
168 /* test moves to/from Crx */
169 { { 0x0f, 0x20, 0xc0, 0xc3 }, /* movl %cr0,%eax; ret */
170 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
171 { { 0x0f, 0x20, 0xe0, 0xc3 }, /* movl %cr4,%eax; ret */
172 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
174 { { 0x0f, 0x22, 0xc0, 0xc3 }, /* movl %eax,%cr0; ret */
175 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
176 { { 0x0f, 0x22, 0xe0, 0xc3 }, /* movl %eax,%cr4; ret */
177 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
179 /* test moves to/from Drx */
180 { { 0x0f, 0x21, 0xc0, 0xc3 }, /* movl %dr0,%eax; ret */
181 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
182 { { 0x0f, 0x21, 0xc8, 0xc3 }, /* movl %dr1,%eax; ret */
183 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
184 { { 0x0f, 0x21, 0xf8, 0xc3 }, /* movl %dr7,%eax; ret */
185 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
187 { { 0x0f, 0x23, 0xc0, 0xc3 }, /* movl %eax,%dr0; ret */
188 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
189 { { 0x0f, 0x23, 0xc8, 0xc3 }, /* movl %eax,%dr1; ret */
190 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
191 { { 0x0f, 0x23, 0xf8, 0xc3 }, /* movl %eax,%dr7; ret */
192 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
194 /* test memory reads */
195 { { 0xa1, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffc,%eax; ret */
196 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffc } },
197 { { 0xa1, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffd,%eax; ret */
198 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffd } },
200 { { 0xa1, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffe,%eax; ret */
201 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffe } },
202 { { 0xa1, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xffffffff,%eax; ret */
203 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
205 /* test memory writes */
206 { { 0xa3, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffc; ret */
207 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffc } },
208 { { 0xa3, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffd; ret */
209 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffd } },
210 { { 0xa3, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffe; ret */
211 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffe } },
213 { { 0xa3, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xffffffff; ret */
214 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xffffffff } },
216 /* test exception with cleared %ds and %es (broken on Wow64) */
217 { { 0x1e, 0x06, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0xfa, 0x07, 0x1f, 0xc3 },
218 /* push %ds; push %es; xorl %eax,%eax; mov %ax,%ds; mov %ax,%es; cli; pop %es; pop %ds; ret */
219 8, 1, TRUE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
221 { { 0xf1, 0x90, 0xc3 }, /* icebp; nop; ret */
222 1, 1, FALSE
, STATUS_SINGLE_STEP
, 0 },
225 static int got_exception
;
226 static BOOL have_vectored_api
;
228 static void run_exception_test(void *handler
, const void* context
,
229 const void *code
, unsigned int code_size
,
233 EXCEPTION_REGISTRATION_RECORD frame
;
236 void (*func
)(void) = code_mem
;
237 DWORD oldaccess
, oldaccess2
;
239 exc_frame
.frame
.Handler
= handler
;
240 exc_frame
.frame
.Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
241 exc_frame
.context
= context
;
243 memcpy(code_mem
, code
, code_size
);
245 VirtualProtect(code_mem
, code_size
, access
, &oldaccess
);
247 pNtCurrentTeb()->Tib
.ExceptionList
= &exc_frame
.frame
;
249 pNtCurrentTeb()->Tib
.ExceptionList
= exc_frame
.frame
.Prev
;
252 VirtualProtect(code_mem
, code_size
, oldaccess
, &oldaccess2
);
255 static LONG CALLBACK
rtlraiseexception_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
257 PCONTEXT context
= ExceptionInfo
->ContextRecord
;
258 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
259 trace("vect. handler %08x addr:%p context.Eip:%x\n", rec
->ExceptionCode
,
260 rec
->ExceptionAddress
, context
->Eip
);
262 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0xb, "ExceptionAddress at %p instead of %p\n",
263 rec
->ExceptionAddress
, (char *)code_mem
+ 0xb);
265 if (pNtCurrentTeb()->Peb
->BeingDebugged
)
266 ok((void *)context
->Eax
== pRtlRaiseException
||
267 broken( is_wow64
&& context
->Eax
== 0xf00f00f1 ), /* broken on vista */
268 "debugger managed to modify Eax to %x should be %p\n",
269 context
->Eax
, pRtlRaiseException
);
271 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
272 * even if raised by RtlRaiseException
274 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
)
276 ok(context
->Eip
== (DWORD
)code_mem
+ 0xa ||
277 broken(context
->Eip
== (DWORD
)code_mem
+ 0xb), /* win2k3 */
278 "Eip at %x instead of %x or %x\n", context
->Eip
,
279 (DWORD
)code_mem
+ 0xa, (DWORD
)code_mem
+ 0xb);
283 ok(context
->Eip
== (DWORD
)code_mem
+ 0xb, "Eip at %x instead of %x\n",
284 context
->Eip
, (DWORD
)code_mem
+ 0xb);
287 /* test if context change is preserved from vectored handler to stack handlers */
288 context
->Eax
= 0xf00f00f0;
289 return EXCEPTION_CONTINUE_SEARCH
;
292 static DWORD
rtlraiseexception_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
293 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
295 trace( "exception: %08x flags:%x addr:%p context: Eip:%x\n",
296 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
, context
->Eip
);
298 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0xb, "ExceptionAddress at %p instead of %p\n",
299 rec
->ExceptionAddress
, (char *)code_mem
+ 0xb);
301 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
302 * even if raised by RtlRaiseException
304 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
)
306 ok(context
->Eip
== (DWORD
)code_mem
+ 0xa ||
307 broken(context
->Eip
== (DWORD
)code_mem
+ 0xb), /* win2k3 */
308 "Eip at %x instead of %x or %x\n", context
->Eip
,
309 (DWORD
)code_mem
+ 0xa, (DWORD
)code_mem
+ 0xb);
313 ok(context
->Eip
== (DWORD
)code_mem
+ 0xb, "Eip at %x instead of %x\n",
314 context
->Eip
, (DWORD
)code_mem
+ 0xb);
317 if(have_vectored_api
)
318 ok(context
->Eax
== 0xf00f00f0, "Eax is %x, should have been set to 0xf00f00f0 in vectored handler\n",
321 /* give the debugger a chance to examine the state a second time */
322 /* without the exception handler changing Eip */
324 return ExceptionContinueSearch
;
326 /* Eip in context is decreased by 1
327 * Increase it again, else execution will continue in the middle of an instruction */
328 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
&& (context
->Eip
== (DWORD
)code_mem
+ 0xa))
330 return ExceptionContinueExecution
;
334 static const BYTE call_one_arg_code
[] = {
335 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
336 0x50, /* push %eax */
337 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
338 0xff, 0xd0, /* call *%eax */
347 static void run_rtlraiseexception_test(DWORD exceptioncode
)
349 EXCEPTION_REGISTRATION_RECORD frame
;
350 EXCEPTION_RECORD record
;
351 PVOID vectored_handler
= NULL
;
353 void (*func
)(void* function
, EXCEPTION_RECORD
* record
) = code_mem
;
355 record
.ExceptionCode
= exceptioncode
;
356 record
.ExceptionFlags
= 0;
357 record
.ExceptionRecord
= NULL
;
358 record
.ExceptionAddress
= NULL
; /* does not matter, copied return address */
359 record
.NumberParameters
= 0;
361 frame
.Handler
= rtlraiseexception_handler
;
362 frame
.Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
364 memcpy(code_mem
, call_one_arg_code
, sizeof(call_one_arg_code
));
366 pNtCurrentTeb()->Tib
.ExceptionList
= &frame
;
367 if (have_vectored_api
)
369 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &rtlraiseexception_vectored_handler
);
370 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
373 func(pRtlRaiseException
, &record
);
374 ok( record
.ExceptionAddress
== (char *)code_mem
+ 0x0b,
375 "address set to %p instead of %p\n", record
.ExceptionAddress
, (char *)code_mem
+ 0x0b );
377 if (have_vectored_api
)
378 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
379 pNtCurrentTeb()->Tib
.ExceptionList
= frame
.Prev
;
382 static void test_rtlraiseexception(void)
384 if (!pRtlRaiseException
)
386 skip("RtlRaiseException not found\n");
390 /* test without debugger */
391 run_rtlraiseexception_test(0x12345);
392 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
393 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
396 static DWORD unwind_expected_eax
;
398 static DWORD
unwind_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
399 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
401 trace("exception: %08x flags:%x addr:%p context: Eip:%x\n",
402 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
, context
->Eip
);
404 ok(rec
->ExceptionCode
== STATUS_UNWIND
, "ExceptionCode is %08x instead of %08x\n",
405 rec
->ExceptionCode
, STATUS_UNWIND
);
406 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0x22, "ExceptionAddress at %p instead of %p\n",
407 rec
->ExceptionAddress
, (char *)code_mem
+ 0x22);
408 ok(context
->Eax
== unwind_expected_eax
, "context->Eax is %08x instead of %08x\n",
409 context
->Eax
, unwind_expected_eax
);
412 return ExceptionContinueSearch
;
415 static const BYTE call_unwind_code
[] = {
416 0x55, /* push %ebp */
417 0x53, /* push %ebx */
418 0x56, /* push %esi */
419 0x57, /* push %edi */
420 0xe8, 0x00, 0x00, 0x00, 0x00, /* call 0 */
421 0x58, /* 0: pop %eax */
422 0x05, 0x1e, 0x00, 0x00, 0x00, /* add $0x1e,%eax */
423 0xff, 0x74, 0x24, 0x20, /* push 0x20(%esp) */
424 0xff, 0x74, 0x24, 0x20, /* push 0x20(%esp) */
425 0x50, /* push %eax */
426 0xff, 0x74, 0x24, 0x24, /* push 0x24(%esp) */
427 0x8B, 0x44, 0x24, 0x24, /* mov 0x24(%esp),%eax */
428 0xff, 0xd0, /* call *%eax */
437 static void test_unwind(void)
439 EXCEPTION_REGISTRATION_RECORD frames
[2], *frame2
= &frames
[0], *frame1
= &frames
[1];
440 DWORD (*func
)(void* function
, EXCEPTION_REGISTRATION_RECORD
*pEndFrame
, EXCEPTION_RECORD
* record
, DWORD retval
) = code_mem
;
443 memcpy(code_mem
, call_unwind_code
, sizeof(call_unwind_code
));
445 /* add first unwind handler */
446 frame1
->Handler
= unwind_handler
;
447 frame1
->Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
448 pNtCurrentTeb()->Tib
.ExceptionList
= frame1
;
450 /* add second unwind handler */
451 frame2
->Handler
= unwind_handler
;
452 frame2
->Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
453 pNtCurrentTeb()->Tib
.ExceptionList
= frame2
;
455 /* test unwind to current frame */
456 unwind_expected_eax
= 0xDEAD0000;
457 retval
= func(pRtlUnwind
, frame2
, NULL
, 0xDEAD0000);
458 ok(retval
== 0xDEAD0000, "RtlUnwind returned eax %08x instead of %08x\n", retval
, 0xDEAD0000);
459 ok(pNtCurrentTeb()->Tib
.ExceptionList
== frame2
, "Exception record points to %p instead of %p\n",
460 pNtCurrentTeb()->Tib
.ExceptionList
, frame2
);
462 /* unwind to frame1 */
463 unwind_expected_eax
= 0xDEAD0000;
464 retval
= func(pRtlUnwind
, frame1
, NULL
, 0xDEAD0000);
465 ok(retval
== 0xDEAD0001, "RtlUnwind returned eax %08x instead of %08x\n", retval
, 0xDEAD0001);
466 ok(pNtCurrentTeb()->Tib
.ExceptionList
== frame1
, "Exception record points to %p instead of %p\n",
467 pNtCurrentTeb()->Tib
.ExceptionList
, frame1
);
469 /* restore original handler */
470 pNtCurrentTeb()->Tib
.ExceptionList
= frame1
->Prev
;
473 static DWORD
handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
474 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
476 const struct exception
*except
= *(const struct exception
**)(frame
+ 1);
477 unsigned int i
, entry
= except
- exceptions
;
480 trace( "exception %u: %x flags:%x addr:%p\n",
481 entry
, rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
);
483 ok( rec
->ExceptionCode
== except
->status
||
484 (except
->alt_status
!= 0 && rec
->ExceptionCode
== except
->alt_status
),
485 "%u: Wrong exception code %x/%x\n", entry
, rec
->ExceptionCode
, except
->status
);
486 ok( rec
->ExceptionAddress
== (char*)code_mem
+ except
->offset
,
487 "%u: Wrong exception address %p/%p\n", entry
,
488 rec
->ExceptionAddress
, (char*)code_mem
+ except
->offset
);
490 if (except
->alt_status
== 0 || rec
->ExceptionCode
!= except
->alt_status
)
492 ok( rec
->NumberParameters
== except
->nb_params
,
493 "%u: Wrong number of parameters %u/%u\n", entry
, rec
->NumberParameters
, except
->nb_params
);
497 ok( rec
->NumberParameters
== except
->alt_nb_params
,
498 "%u: Wrong number of parameters %u/%u\n", entry
, rec
->NumberParameters
, except
->nb_params
);
501 /* Most CPUs (except Intel Core apparently) report a segment limit violation */
502 /* instead of page faults for accesses beyond 0xffffffff */
503 if (except
->nb_params
== 2 && except
->params
[1] >= 0xfffffffd)
505 if (rec
->ExceptionInformation
[0] == 0 && rec
->ExceptionInformation
[1] == 0xffffffff)
509 /* Seems that both 0xbee8 and 0xfffffffff can be returned in windows */
510 if (except
->nb_params
== 2 && rec
->NumberParameters
== 2
511 && except
->params
[1] == 0xbee8 && rec
->ExceptionInformation
[1] == 0xffffffff
512 && except
->params
[0] == rec
->ExceptionInformation
[0])
517 if (except
->alt_status
== 0 || rec
->ExceptionCode
!= except
->alt_status
)
519 for (i
= 0; i
< rec
->NumberParameters
; i
++)
520 ok( rec
->ExceptionInformation
[i
] == except
->params
[i
],
521 "%u: Wrong parameter %d: %lx/%x\n",
522 entry
, i
, rec
->ExceptionInformation
[i
], except
->params
[i
] );
526 for (i
= 0; i
< rec
->NumberParameters
; i
++)
527 ok( rec
->ExceptionInformation
[i
] == except
->alt_params
[i
],
528 "%u: Wrong parameter %d: %lx/%x\n",
529 entry
, i
, rec
->ExceptionInformation
[i
], except
->alt_params
[i
] );
533 /* don't handle exception if it's not the address we expected */
534 if (rec
->ExceptionAddress
!= (char*)code_mem
+ except
->offset
) return ExceptionContinueSearch
;
536 context
->Eip
+= except
->length
;
537 return ExceptionContinueExecution
;
540 static void test_prot_fault(void)
544 for (i
= 0; i
< sizeof(exceptions
)/sizeof(exceptions
[0]); i
++)
546 if (is_wow64
&& exceptions
[i
].wow64_broken
&& !strcmp( winetest_platform
, "windows" ))
548 skip( "Exception %u broken on Wow64\n", i
);
552 run_exception_test(handler
, &exceptions
[i
], &exceptions
[i
].code
,
553 sizeof(exceptions
[i
].code
), 0);
554 if (!i
&& !got_exception
)
556 trace( "No exception, assuming win9x, no point in testing further\n" );
559 ok( got_exception
== (exceptions
[i
].status
!= 0),
560 "%u: bad exception count %d\n", i
, got_exception
);
565 DWORD dr0
, dr1
, dr2
, dr3
, dr6
, dr7
;
568 /* test handling of debug registers */
569 static DWORD
dreg_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
570 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
572 const struct dbgreg_test
*test
= *(const struct dbgreg_test
**)(frame
+ 1);
574 context
->Eip
+= 2; /* Skips the popl (%eax) */
575 context
->Dr0
= test
->dr0
;
576 context
->Dr1
= test
->dr1
;
577 context
->Dr2
= test
->dr2
;
578 context
->Dr3
= test
->dr3
;
579 context
->Dr6
= test
->dr6
;
580 context
->Dr7
= test
->dr7
;
581 return ExceptionContinueExecution
;
584 #define CHECK_DEBUG_REG(n, m) \
585 ok((ctx.Dr##n & m) == test->dr##n, "(%d) failed to set debug register " #n " to %x, got %x\n", \
586 test_num, test->dr##n, ctx.Dr##n)
588 static void check_debug_registers(int test_num
, const struct dbgreg_test
*test
)
593 ctx
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
594 status
= pNtGetContextThread(GetCurrentThread(), &ctx
);
595 ok(status
== STATUS_SUCCESS
, "NtGetContextThread failed with %x\n", status
);
597 CHECK_DEBUG_REG(0, ~0);
598 CHECK_DEBUG_REG(1, ~0);
599 CHECK_DEBUG_REG(2, ~0);
600 CHECK_DEBUG_REG(3, ~0);
601 CHECK_DEBUG_REG(6, 0x0f);
602 CHECK_DEBUG_REG(7, ~0xdc00);
605 static const BYTE segfault_code
[5] = {
606 0x31, 0xc0, /* xor %eax,%eax */
607 0x8f, 0x00, /* popl (%eax) - cause exception */
611 /* test the single step exception behaviour */
612 static DWORD
single_step_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
613 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
616 ok (!(context
->EFlags
& 0x100), "eflags has single stepping bit set\n");
618 if( got_exception
< 3)
619 context
->EFlags
|= 0x100; /* single step until popf instruction */
621 /* show that the last single step exception on the popf instruction
622 * (which removed the TF bit), still is a EXCEPTION_SINGLE_STEP exception */
623 ok( rec
->ExceptionCode
== EXCEPTION_SINGLE_STEP
,
624 "exception is not EXCEPTION_SINGLE_STEP: %x\n", rec
->ExceptionCode
);
627 return ExceptionContinueExecution
;
630 static const BYTE single_stepcode
[] = {
633 0x0d,0,1,0,0, /* or $0x100,%eax */
634 0x50, /* push %eax */
636 0x35,0,1,0,0, /* xor $0x100,%eax */
637 0x50, /* push %eax */
642 /* Test the alignment check (AC) flag handling. */
643 static const BYTE align_check_code
[] = {
644 0x55, /* push %ebp */
645 0x89,0xe5, /* mov %esp,%ebp */
648 0x0d,0,0,4,0, /* or $0x40000,%eax */
649 0x50, /* push %eax */
651 0x89,0xe0, /* mov %esp, %eax */
652 0x8b,0x40,0x1, /* mov 0x1(%eax), %eax - cause exception */
655 0x35,0,0,4,0, /* xor $0x40000,%eax */
656 0x50, /* push %eax */
662 static DWORD
align_check_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
663 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
665 ok (!(context
->EFlags
& 0x40000), "eflags has AC bit set\n");
667 return ExceptionContinueExecution
;
670 /* Test the direction flag handling. */
671 static const BYTE direction_flag_code
[] = {
672 0x55, /* push %ebp */
673 0x89,0xe5, /* mov %esp,%ebp */
675 0xfa, /* cli - cause exception */
680 static DWORD
direction_flag_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
681 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
685 __asm__("pushfl; popl %0; cld" : "=r" (flags
) );
686 /* older windows versions don't clear DF properly so don't test */
687 if (flags
& 0x400) trace( "eflags has DF bit set\n" );
689 ok( context
->EFlags
& 0x400, "context eflags has DF bit cleared\n" );
691 context
->Eip
++; /* skip cli */
692 context
->EFlags
&= ~0x400; /* make sure it is cleared on return */
693 return ExceptionContinueExecution
;
696 /* test single stepping over hardware breakpoint */
697 static DWORD
bpx_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
698 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
701 ok( rec
->ExceptionCode
== EXCEPTION_SINGLE_STEP
,
702 "wrong exception code: %x\n", rec
->ExceptionCode
);
704 if(got_exception
== 1) {
705 /* hw bp exception on first nop */
706 ok( context
->Eip
== (DWORD
)code_mem
, "eip is wrong: %x instead of %x\n",
707 context
->Eip
, (DWORD
)code_mem
);
708 ok( (context
->Dr6
& 0xf) == 1, "B0 flag is not set in Dr6\n");
709 ok( !(context
->Dr6
& 0x4000), "BS flag is set in Dr6\n");
710 context
->Dr0
= context
->Dr0
+ 1; /* set hw bp again on next instruction */
711 context
->EFlags
|= 0x100; /* enable single stepping */
712 } else if( got_exception
== 2) {
713 /* single step exception on second nop */
714 ok( context
->Eip
== (DWORD
)code_mem
+ 1, "eip is wrong: %x instead of %x\n",
715 context
->Eip
, (DWORD
)code_mem
+ 1);
716 ok( (context
->Dr6
& 0x4000), "BS flag is not set in Dr6\n");
717 /* depending on the win version the B0 bit is already set here as well
718 ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n"); */
719 context
->EFlags
|= 0x100;
720 } else if( got_exception
== 3) {
721 /* hw bp exception on second nop */
722 ok( context
->Eip
== (DWORD
)code_mem
+ 1, "eip is wrong: %x instead of %x\n",
723 context
->Eip
, (DWORD
)code_mem
+ 1);
724 ok( (context
->Dr6
& 0xf) == 1, "B0 flag is not set in Dr6\n");
725 ok( !(context
->Dr6
& 0x4000), "BS flag is set in Dr6\n");
726 context
->Dr0
= 0; /* clear breakpoint */
727 context
->EFlags
|= 0x100;
729 /* single step exception on ret */
730 ok( context
->Eip
== (DWORD
)code_mem
+ 2, "eip is wrong: %x instead of %x\n",
731 context
->Eip
, (DWORD
)code_mem
+ 2);
732 ok( (context
->Dr6
& 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n");
733 ok( (context
->Dr6
& 0x4000), "BS flag is not set in Dr6\n");
736 context
->Dr6
= 0; /* clear status register */
737 return ExceptionContinueExecution
;
740 static const BYTE dummy_code
[] = { 0x90, 0x90, 0xc3 }; /* nop, nop, ret */
742 /* test int3 handling */
743 static DWORD
int3_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
744 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
746 ok( rec
->ExceptionAddress
== code_mem
, "exception address not at: %p, but at %p\n",
747 code_mem
, rec
->ExceptionAddress
);
748 ok( context
->Eip
== (DWORD
)code_mem
, "eip not at: %p, but at %#x\n", code_mem
, context
->Eip
);
749 if(context
->Eip
== (DWORD
)code_mem
) context
->Eip
++; /* skip breakpoint */
751 return ExceptionContinueExecution
;
754 static const BYTE int3_code
[] = { 0xCC, 0xc3 }; /* int 3, ret */
757 static void test_exceptions(void)
761 struct dbgreg_test dreg_test
;
763 if (!pNtGetContextThread
|| !pNtSetContextThread
)
765 skip( "NtGetContextThread/NtSetContextThread not found\n" );
769 /* test handling of debug registers */
770 memset(&dreg_test
, 0, sizeof(dreg_test
));
772 dreg_test
.dr0
= 0x42424240;
773 dreg_test
.dr2
= 0x126bb070;
774 dreg_test
.dr3
= 0x0badbad0;
775 dreg_test
.dr7
= 0xffff0115;
776 run_exception_test(dreg_handler
, &dreg_test
, &segfault_code
, sizeof(segfault_code
), 0);
777 check_debug_registers(1, &dreg_test
);
779 dreg_test
.dr0
= 0x42424242;
780 dreg_test
.dr2
= 0x100f0fe7;
781 dreg_test
.dr3
= 0x0abebabe;
782 dreg_test
.dr7
= 0x115;
783 run_exception_test(dreg_handler
, &dreg_test
, &segfault_code
, sizeof(segfault_code
), 0);
784 check_debug_registers(2, &dreg_test
);
786 /* test single stepping behavior */
788 run_exception_test(single_step_handler
, NULL
, &single_stepcode
, sizeof(single_stepcode
), 0);
789 ok(got_exception
== 3, "expected 3 single step exceptions, got %d\n", got_exception
);
791 /* test alignment exceptions */
793 run_exception_test(align_check_handler
, NULL
, align_check_code
, sizeof(align_check_code
), 0);
794 ok(got_exception
== 0, "got %d alignment faults, expected 0\n", got_exception
);
796 /* test direction flag */
798 run_exception_test(direction_flag_handler
, NULL
, direction_flag_code
, sizeof(direction_flag_code
), 0);
799 ok(got_exception
== 1, "got %d exceptions, expected 1\n", got_exception
);
801 /* test single stepping over hardware breakpoint */
802 memset(&ctx
, 0, sizeof(ctx
));
803 ctx
.Dr0
= (DWORD
) code_mem
; /* set hw bp on first nop */
805 ctx
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
806 res
= pNtSetContextThread( GetCurrentThread(), &ctx
);
807 ok( res
== STATUS_SUCCESS
, "NtSetContextThread failed with %x\n", res
);
810 run_exception_test(bpx_handler
, NULL
, dummy_code
, sizeof(dummy_code
), 0);
811 ok( got_exception
== 4,"expected 4 exceptions, got %d\n", got_exception
);
813 /* test int3 handling */
814 run_exception_test(int3_handler
, NULL
, int3_code
, sizeof(int3_code
), 0);
817 static void test_debugger(void)
819 char cmdline
[MAX_PATH
];
820 PROCESS_INFORMATION pi
;
821 STARTUPINFOA si
= { 0 };
823 DWORD continuestatus
;
824 PVOID code_mem_address
= NULL
;
831 if(!pNtGetContextThread
|| !pNtSetContextThread
|| !pNtReadVirtualMemory
|| !pNtTerminateProcess
)
833 skip("NtGetContextThread, NtSetContextThread, NtReadVirtualMemory or NtTerminateProcess not found\n");
837 sprintf(cmdline
, "%s %s %s %p", my_argv
[0], my_argv
[1], "debuggee", &test_stage
);
838 ret
= CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &si
, &pi
);
839 ok(ret
, "could not create child process error: %u\n", GetLastError());
845 continuestatus
= DBG_CONTINUE
;
846 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
848 if (de
.dwThreadId
!= pi
.dwThreadId
)
850 trace("event %d not coming from main thread, ignoring\n", de
.dwDebugEventCode
);
851 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
855 if (de
.dwDebugEventCode
== CREATE_PROCESS_DEBUG_EVENT
)
857 if(de
.u
.CreateProcessInfo
.lpBaseOfImage
!= pNtCurrentTeb()->Peb
->ImageBaseAddress
)
859 skip("child process loaded at different address, terminating it\n");
860 pNtTerminateProcess(pi
.hProcess
, 0);
863 else if (de
.dwDebugEventCode
== EXCEPTION_DEBUG_EVENT
)
869 status
= pNtReadVirtualMemory(pi
.hProcess
, &code_mem
, &code_mem_address
,
870 sizeof(code_mem_address
), &size_read
);
871 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
872 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
873 sizeof(stage
), &size_read
);
874 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
876 ctx
.ContextFlags
= CONTEXT_FULL
;
877 status
= pNtGetContextThread(pi
.hThread
, &ctx
);
878 ok(!status
, "NtGetContextThread failed with 0x%x\n", status
);
880 trace("exception 0x%x at %p firstchance=%d Eip=0x%x, Eax=0x%x\n",
881 de
.u
.Exception
.ExceptionRecord
.ExceptionCode
,
882 de
.u
.Exception
.ExceptionRecord
.ExceptionAddress
, de
.u
.Exception
.dwFirstChance
, ctx
.Eip
, ctx
.Eax
);
886 ok(FALSE
, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
887 pNtTerminateProcess(pi
.hProcess
, 1);
889 else if (counter
>= 2) /* skip startup breakpoint */
893 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at %x instead of %p\n",
894 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
895 /* setting the context from debugger does not affect the context, the exception handlers gets */
896 /* uncomment once wine is fixed */
897 /* ctx.Eip = 0x12345; */
898 ctx
.Eax
= 0xf00f00f1;
900 /* let the debuggee handle the exception */
901 continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
905 if (de
.u
.Exception
.dwFirstChance
)
907 /* debugger gets first chance exception with unmodified ctx.Eip */
908 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at 0x%x instead of %p\n",
909 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
911 /* setting the context from debugger does not affect the context, the exception handlers gets */
912 /* uncomment once wine is fixed */
913 /* ctx.Eip = 0x12345; */
914 ctx
.Eax
= 0xf00f00f1;
916 /* pass exception to debuggee
917 * exception will not be handled and
918 * a second chance exception will be raised */
919 continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
923 /* debugger gets context after exception handler has played with it */
924 /* ctx.Eip is the same value the exception handler got */
925 if (de
.u
.Exception
.ExceptionRecord
.ExceptionCode
== EXCEPTION_BREAKPOINT
)
927 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xa ||
928 broken(is_wow64
&& (char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb),
929 "Eip at 0x%x instead of %p\n",
930 ctx
.Eip
, (char *)code_mem_address
+ 0xa);
931 /* need to fixup Eip for debuggee */
932 if ((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xa)
936 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at 0x%x instead of %p\n",
937 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
938 /* here we handle exception */
942 ok(FALSE
, "unexpected stage %x\n", stage
);
944 status
= pNtSetContextThread(pi
.hThread
, &ctx
);
945 ok(!status
, "NtSetContextThread failed with 0x%x\n", status
);
948 else if (de
.dwDebugEventCode
== OUTPUT_DEBUG_STRING_EVENT
)
953 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
954 sizeof(stage
), &size_read
);
955 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
957 ok(!de
.u
.DebugString
.fUnicode
, "unepxected unicode debug string event\n");
958 ok(de
.u
.DebugString
.nDebugStringLength
< sizeof(buffer
) - 1, "buffer not large enough to hold %d bytes\n",
959 de
.u
.DebugString
.nDebugStringLength
);
961 memset(buffer
, 0, sizeof(buffer
));
962 status
= pNtReadVirtualMemory(pi
.hProcess
, de
.u
.DebugString
.lpDebugStringData
, buffer
,
963 de
.u
.DebugString
.nDebugStringLength
, &size_read
);
964 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
966 if (stage
== 3 || stage
== 4)
967 ok(!strcmp(buffer
, "Hello World"), "got unexpected debug string '%s'\n", buffer
);
968 else /* ignore unrelated debug strings like 'SHIMVIEW: ShimInfo(Complete)' */
969 ok(strstr(buffer
, "SHIMVIEW") != NULL
, "unexpected stage %x, got debug string event '%s'\n", stage
, buffer
);
971 if (stage
== 4) continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
973 else if (de
.dwDebugEventCode
== RIP_EVENT
)
977 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
978 sizeof(stage
), &size_read
);
979 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
981 if (stage
== 5 || stage
== 6)
983 ok(de
.u
.RipInfo
.dwError
== 0x11223344, "got unexpected rip error code %08x, expected %08x\n",
984 de
.u
.RipInfo
.dwError
, 0x11223344);
985 ok(de
.u
.RipInfo
.dwType
== 0x55667788, "got unexpected rip type %08x, expected %08x\n",
986 de
.u
.RipInfo
.dwType
, 0x55667788);
989 ok(FALSE
, "unexpected stage %x\n", stage
);
991 if (stage
== 6) continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
994 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, continuestatus
);
996 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
998 winetest_wait_child_process( pi
.hProcess
);
999 ret
= CloseHandle(pi
.hThread
);
1000 ok(ret
, "error %u\n", GetLastError());
1001 ret
= CloseHandle(pi
.hProcess
);
1002 ok(ret
, "error %u\n", GetLastError());
1007 static DWORD
simd_fault_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1008 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1010 int *stage
= *(int **)(frame
+ 1);
1015 /* fault while executing sse instruction */
1016 context
->Eip
+= 3; /* skip addps */
1017 return ExceptionContinueExecution
;
1020 /* stage 2 - divide by zero fault */
1021 if( rec
->ExceptionCode
== EXCEPTION_ILLEGAL_INSTRUCTION
)
1022 skip("system doesn't support SIMD exceptions\n");
1024 ok( rec
->ExceptionCode
== STATUS_FLOAT_MULTIPLE_TRAPS
,
1025 "exception code: %#x, should be %#x\n",
1026 rec
->ExceptionCode
, STATUS_FLOAT_MULTIPLE_TRAPS
);
1027 ok( rec
->NumberParameters
== 1 || broken(is_wow64
&& rec
->NumberParameters
== 2),
1028 "# of params: %i, should be 1\n",
1029 rec
->NumberParameters
);
1030 if( rec
->NumberParameters
== 1 )
1031 ok( rec
->ExceptionInformation
[0] == 0, "param #1: %lx, should be 0\n", rec
->ExceptionInformation
[0]);
1034 context
->Eip
+= 3; /* skip divps */
1036 return ExceptionContinueExecution
;
1039 static const BYTE simd_exception_test
[] = {
1040 0x83, 0xec, 0x4, /* sub $0x4, %esp */
1041 0x0f, 0xae, 0x1c, 0x24, /* stmxcsr (%esp) */
1042 0x66, 0x81, 0x24, 0x24, 0xff, 0xfd, /* andw $0xfdff,(%esp) * enable divide by */
1043 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) * zero exceptions */
1044 0x6a, 0x01, /* push $0x1 */
1045 0x6a, 0x01, /* push $0x1 */
1046 0x6a, 0x01, /* push $0x1 */
1047 0x6a, 0x01, /* push $0x1 */
1048 0x0f, 0x10, 0x0c, 0x24, /* movups (%esp),%xmm1 * fill dividend */
1049 0x0f, 0x57, 0xc0, /* xorps %xmm0,%xmm0 * clear divisor */
1050 0x0f, 0x5e, 0xc8, /* divps %xmm0,%xmm1 * generate fault */
1051 0x83, 0xc4, 0x10, /* add $0x10,%esp */
1052 0x66, 0x81, 0x0c, 0x24, 0x00, 0x02, /* orw $0x200,(%esp) * disable exceptions */
1053 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) */
1054 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1058 static const BYTE sse_check
[] = {
1059 0x0f, 0x58, 0xc8, /* addps %xmm0,%xmm1 */
1063 static void test_simd_exceptions(void)
1067 /* test if CPU & OS can do sse */
1070 run_exception_test(simd_fault_handler
, &stage
, sse_check
, sizeof(sse_check
), 0);
1072 skip("system doesn't support SSE\n");
1076 /* generate a SIMD exception */
1079 run_exception_test(simd_fault_handler
, &stage
, simd_exception_test
,
1080 sizeof(simd_exception_test
), 0);
1081 ok( got_exception
== 1, "got exception: %i, should be 1\n", got_exception
);
1084 struct fpu_exception_info
1086 DWORD exception_code
;
1087 DWORD exception_offset
;
1091 static DWORD
fpu_exception_handler(EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1092 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1094 struct fpu_exception_info
*info
= *(struct fpu_exception_info
**)(frame
+ 1);
1096 info
->exception_code
= rec
->ExceptionCode
;
1097 info
->exception_offset
= (BYTE
*)rec
->ExceptionAddress
- (BYTE
*)code_mem
;
1098 info
->eip_offset
= context
->Eip
- (DWORD
)code_mem
;
1101 return ExceptionContinueExecution
;
1104 static void test_fpu_exceptions(void)
1106 static const BYTE fpu_exception_test_ie
[] =
1108 0x83, 0xec, 0x04, /* sub $0x4,%esp */
1109 0x66, 0xc7, 0x04, 0x24, 0xfe, 0x03, /* movw $0x3fe,(%esp) */
1110 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
1111 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
1112 0xd9, 0xee, /* fldz */
1113 0xd9, 0xe8, /* fld1 */
1114 0xde, 0xf1, /* fdivp */
1115 0xdd, 0xd8, /* fstp %st(0) */
1116 0xdd, 0xd8, /* fstp %st(0) */
1118 0xdb, 0xe2, /* fnclex */
1119 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
1120 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1124 static const BYTE fpu_exception_test_de
[] =
1126 0x83, 0xec, 0x04, /* sub $0x4,%esp */
1127 0x66, 0xc7, 0x04, 0x24, 0xfb, 0x03, /* movw $0x3fb,(%esp) */
1128 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
1129 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
1130 0xdd, 0xd8, /* fstp %st(0) */
1131 0xd9, 0xee, /* fldz */
1132 0xd9, 0xe8, /* fld1 */
1133 0xde, 0xf1, /* fdivp */
1135 0xdb, 0xe2, /* fnclex */
1136 0xdd, 0xd8, /* fstp %st(0) */
1137 0xdd, 0xd8, /* fstp %st(0) */
1138 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
1139 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1143 struct fpu_exception_info info
;
1145 memset(&info
, 0, sizeof(info
));
1146 run_exception_test(fpu_exception_handler
, &info
, fpu_exception_test_ie
, sizeof(fpu_exception_test_ie
), 0);
1147 ok(info
.exception_code
== EXCEPTION_FLT_STACK_CHECK
,
1148 "Got exception code %#x, expected EXCEPTION_FLT_STACK_CHECK\n", info
.exception_code
);
1149 ok(info
.exception_offset
== 0x19 ||
1150 broken( is_wow64
&& info
.exception_offset
== info
.eip_offset
),
1151 "Got exception offset %#x, expected 0x19\n", info
.exception_offset
);
1152 ok(info
.eip_offset
== 0x1b, "Got EIP offset %#x, expected 0x1b\n", info
.eip_offset
);
1154 memset(&info
, 0, sizeof(info
));
1155 run_exception_test(fpu_exception_handler
, &info
, fpu_exception_test_de
, sizeof(fpu_exception_test_de
), 0);
1156 ok(info
.exception_code
== EXCEPTION_FLT_DIVIDE_BY_ZERO
,
1157 "Got exception code %#x, expected EXCEPTION_FLT_DIVIDE_BY_ZERO\n", info
.exception_code
);
1158 ok(info
.exception_offset
== 0x17 ||
1159 broken( is_wow64
&& info
.exception_offset
== info
.eip_offset
),
1160 "Got exception offset %#x, expected 0x17\n", info
.exception_offset
);
1161 ok(info
.eip_offset
== 0x19, "Got EIP offset %#x, expected 0x19\n", info
.eip_offset
);
1164 struct dpe_exception_info
{
1165 BOOL exception_caught
;
1166 DWORD exception_info
;
1169 static DWORD
dpe_exception_handler(EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1170 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1173 struct dpe_exception_info
*info
= *(struct dpe_exception_info
**)(frame
+ 1);
1175 ok(rec
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
,
1176 "Exception code %08x\n", rec
->ExceptionCode
);
1177 ok(rec
->NumberParameters
== 2,
1178 "Parameter count: %d\n", rec
->NumberParameters
);
1179 ok((LPVOID
)rec
->ExceptionInformation
[1] == code_mem
,
1180 "Exception address: %p, expected %p\n",
1181 (LPVOID
)rec
->ExceptionInformation
[1], code_mem
);
1183 info
->exception_info
= rec
->ExceptionInformation
[0];
1184 info
->exception_caught
= TRUE
;
1186 VirtualProtect(code_mem
, 1, PAGE_EXECUTE_READWRITE
, &old_prot
);
1187 return ExceptionContinueExecution
;
1190 static void test_dpe_exceptions(void)
1192 static const BYTE single_ret
[] = {0xC3};
1193 struct dpe_exception_info info
;
1195 BOOL has_hw_support
;
1196 BOOL is_permanent
= FALSE
, can_test_without
= TRUE
, can_test_with
= TRUE
;
1200 /* Query DEP with len too small */
1201 stat
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
- 1, &len
);
1202 if(stat
== STATUS_INVALID_INFO_CLASS
)
1204 skip("This software platform does not support DEP\n");
1207 ok(stat
== STATUS_INFO_LENGTH_MISMATCH
, "buffer too small: %08x\n", stat
);
1210 stat
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
, &len
);
1211 ok(stat
== STATUS_SUCCESS
, "querying DEP: status %08x\n", stat
);
1212 if(stat
== STATUS_SUCCESS
)
1214 ok(len
== sizeof val
, "returned length: %d\n", len
);
1215 if(val
& MEM_EXECUTE_OPTION_PERMANENT
)
1217 skip("toggling DEP impossible - status locked\n");
1218 is_permanent
= TRUE
;
1219 if(val
& MEM_EXECUTE_OPTION_DISABLE
)
1220 can_test_without
= FALSE
;
1222 can_test_with
= FALSE
;
1229 val
= MEM_EXECUTE_OPTION_DISABLE
;
1230 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1231 ok(stat
== STATUS_SUCCESS
, "enabling DEP: status %08x\n", stat
);
1236 /* Try access to locked page with DEP on*/
1237 info
.exception_caught
= FALSE
;
1238 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_NOACCESS
);
1239 ok(info
.exception_caught
== TRUE
, "Execution of disabled memory succeeded\n");
1240 ok(info
.exception_info
== EXCEPTION_READ_FAULT
||
1241 info
.exception_info
== EXCEPTION_EXECUTE_FAULT
,
1242 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1243 has_hw_support
= info
.exception_info
== EXCEPTION_EXECUTE_FAULT
;
1244 trace("DEP hardware support: %s\n", has_hw_support
?"Yes":"No");
1246 /* Try execution of data with DEP on*/
1247 info
.exception_caught
= FALSE
;
1248 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_READWRITE
);
1251 ok(info
.exception_caught
== TRUE
, "Execution of data memory succeeded\n");
1252 ok(info
.exception_info
== EXCEPTION_EXECUTE_FAULT
,
1253 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1256 ok(info
.exception_caught
== FALSE
, "Execution trapped without hardware support\n");
1259 skip("DEP is in AlwaysOff state\n");
1264 val
= MEM_EXECUTE_OPTION_ENABLE
;
1265 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1266 ok(stat
== STATUS_SUCCESS
, "disabling DEP: status %08x\n", stat
);
1269 /* page is read without exec here */
1270 if(can_test_without
)
1272 /* Try execution of data with DEP off */
1273 info
.exception_caught
= FALSE
;
1274 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_READWRITE
);
1275 ok(info
.exception_caught
== FALSE
, "Execution trapped with DEP turned off\n");
1277 /* Try access to locked page with DEP off - error code is different than
1278 with hardware DEP on */
1279 info
.exception_caught
= FALSE
;
1280 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_NOACCESS
);
1281 ok(info
.exception_caught
== TRUE
, "Execution of disabled memory succeeded\n");
1282 ok(info
.exception_info
== EXCEPTION_READ_FAULT
,
1283 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1286 skip("DEP is in AlwaysOn state\n");
1290 /* Turn off DEP permanently */
1291 val
= MEM_EXECUTE_OPTION_ENABLE
| MEM_EXECUTE_OPTION_PERMANENT
;
1292 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1293 ok(stat
== STATUS_SUCCESS
, "disabling DEP permanently: status %08x\n", stat
);
1296 /* Try to turn off DEP */
1297 val
= MEM_EXECUTE_OPTION_ENABLE
;
1298 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1299 ok(stat
== STATUS_ACCESS_DENIED
, "disabling DEP while permanent: status %08x\n", stat
);
1301 /* Try to turn on DEP */
1302 val
= MEM_EXECUTE_OPTION_DISABLE
;
1303 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1304 ok(stat
== STATUS_ACCESS_DENIED
, "enabling DEP while permanent: status %08x\n", stat
);
1307 #elif defined(__x86_64__)
1309 #define UNW_FLAG_NHANDLER 0
1310 #define UNW_FLAG_EHANDLER 1
1311 #define UNW_FLAG_UHANDLER 2
1312 #define UNW_FLAG_CHAININFO 4
1314 #define UWOP_PUSH_NONVOL 0
1315 #define UWOP_ALLOC_LARGE 1
1316 #define UWOP_ALLOC_SMALL 2
1317 #define UWOP_SET_FPREG 3
1318 #define UWOP_SAVE_NONVOL 4
1319 #define UWOP_SAVE_NONVOL_FAR 5
1320 #define UWOP_SAVE_XMM128 8
1321 #define UWOP_SAVE_XMM128_FAR 9
1322 #define UWOP_PUSH_MACHFRAME 10
1326 int rip_offset
; /* rip offset from code start */
1327 int rbp_offset
; /* rbp offset from stack pointer */
1328 int handler
; /* expect handler to be set? */
1329 int rip
; /* expected final rip value */
1330 int frame
; /* expected frame return value */
1331 int regs
[8][2]; /* expected values for registers */
1336 const BYTE
*function
;
1337 size_t function_size
;
1338 const BYTE
*unwind_info
;
1339 const struct results
*results
;
1340 unsigned int nb_results
;
1345 rax
, rcx
, rdx
, rbx
, rsp
, rbp
, rsi
, rdi
,
1346 r8
, r9
, r10
, r11
, r12
, r13
, r14
, r15
1349 static const char * const reg_names
[16] =
1351 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
1352 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1355 #define UWOP(code,info) (UWOP_##code | ((info) << 4))
1357 static void call_virtual_unwind( int testnum
, const struct unwind_test
*test
)
1359 static const int code_offset
= 1024;
1360 static const int unwind_offset
= 2048;
1361 void *handler
, *data
;
1363 RUNTIME_FUNCTION runtime_func
;
1364 KNONVOLATILE_CONTEXT_POINTERS ctx_ptr
;
1366 ULONG64 fake_stack
[256];
1367 ULONG64 frame
, orig_rip
, orig_rbp
, unset_reg
;
1368 UINT unwind_size
= 4 + 2 * test
->unwind_info
[2] + 8;
1370 memcpy( (char *)code_mem
+ code_offset
, test
->function
, test
->function_size
);
1371 memcpy( (char *)code_mem
+ unwind_offset
, test
->unwind_info
, unwind_size
);
1373 runtime_func
.BeginAddress
= code_offset
;
1374 runtime_func
.EndAddress
= code_offset
+ test
->function_size
;
1375 runtime_func
.UnwindData
= unwind_offset
;
1377 trace( "code: %p stack: %p\n", code_mem
, fake_stack
);
1379 for (i
= 0; i
< test
->nb_results
; i
++)
1381 memset( &ctx_ptr
, 0, sizeof(ctx_ptr
) );
1382 memset( &context
, 0x55, sizeof(context
) );
1383 memset( &unset_reg
, 0x55, sizeof(unset_reg
) );
1384 for (j
= 0; j
< 256; j
++) fake_stack
[j
] = j
* 8;
1386 context
.Rsp
= (ULONG_PTR
)fake_stack
;
1387 context
.Rbp
= (ULONG_PTR
)fake_stack
+ test
->results
[i
].rbp_offset
;
1388 orig_rbp
= context
.Rbp
;
1389 orig_rip
= (ULONG64
)code_mem
+ code_offset
+ test
->results
[i
].rip_offset
;
1391 trace( "%u/%u: rip=%p (%02x) rbp=%p rsp=%p\n", testnum
, i
,
1392 (void *)orig_rip
, *(BYTE
*)orig_rip
, (void *)orig_rbp
, (void *)context
.Rsp
);
1394 data
= (void *)0xdeadbeef;
1395 handler
= RtlVirtualUnwind( UNW_FLAG_EHANDLER
, (ULONG64
)code_mem
, orig_rip
,
1396 &runtime_func
, &context
, &data
, &frame
, &ctx_ptr
);
1397 if (test
->results
[i
].handler
)
1399 ok( (char *)handler
== (char *)code_mem
+ 0x200,
1400 "%u/%u: wrong handler %p/%p\n", testnum
, i
, handler
, (char *)code_mem
+ 0x200 );
1401 if (handler
) ok( *(DWORD
*)data
== 0x08070605,
1402 "%u/%u: wrong handler data %p\n", testnum
, i
, data
);
1406 ok( handler
== NULL
, "%u/%u: handler %p instead of NULL\n", testnum
, i
, handler
);
1407 ok( data
== (void *)0xdeadbeef, "%u/%u: handler data set to %p\n", testnum
, i
, data
);
1410 ok( context
.Rip
== test
->results
[i
].rip
, "%u/%u: wrong rip %p/%x\n",
1411 testnum
, i
, (void *)context
.Rip
, test
->results
[i
].rip
);
1412 ok( frame
== (ULONG64
)fake_stack
+ test
->results
[i
].frame
, "%u/%u: wrong frame %p/%p\n",
1413 testnum
, i
, (void *)frame
, (char *)fake_stack
+ test
->results
[i
].frame
);
1415 for (j
= 0; j
< 16; j
++)
1417 static const UINT nb_regs
= sizeof(test
->results
[i
].regs
) / sizeof(test
->results
[i
].regs
[0]);
1419 for (k
= 0; k
< nb_regs
; k
++)
1421 if (test
->results
[i
].regs
[k
][0] == -1)
1426 if (test
->results
[i
].regs
[k
][0] == j
) break;
1429 if (j
== rsp
) /* rsp is special */
1431 ok( !ctx_ptr
.u2
.IntegerContext
[j
],
1432 "%u/%u: rsp should not be set in ctx_ptr\n", testnum
, i
);
1433 ok( context
.Rsp
== (ULONG64
)fake_stack
+ test
->results
[i
].regs
[k
][1],
1434 "%u/%u: register rsp wrong %p/%p\n",
1435 testnum
, i
, (void *)context
.Rsp
, (char *)fake_stack
+ test
->results
[i
].regs
[k
][1] );
1439 if (ctx_ptr
.u2
.IntegerContext
[j
])
1441 ok( k
< nb_regs
, "%u/%u: register %s should not be set to %lx\n",
1442 testnum
, i
, reg_names
[j
], *(&context
.Rax
+ j
) );
1444 ok( *(&context
.Rax
+ j
) == test
->results
[i
].regs
[k
][1],
1445 "%u/%u: register %s wrong %p/%x\n",
1446 testnum
, i
, reg_names
[j
], (void *)*(&context
.Rax
+ j
), test
->results
[i
].regs
[k
][1] );
1450 ok( k
== nb_regs
, "%u/%u: register %s should be set\n", testnum
, i
, reg_names
[j
] );
1452 ok( context
.Rbp
== orig_rbp
, "%u/%u: register rbp wrong %p/unset\n",
1453 testnum
, i
, (void *)context
.Rbp
);
1455 ok( *(&context
.Rax
+ j
) == unset_reg
,
1456 "%u/%u: register %s wrong %p/unset\n",
1457 testnum
, i
, reg_names
[j
], (void *)*(&context
.Rax
+ j
));
1463 static void test_virtual_unwind(void)
1465 static const BYTE function_0
[] =
1467 0xff, 0xf5, /* 00: push %rbp */
1468 0x48, 0x81, 0xec, 0x10, 0x01, 0x00, 0x00, /* 02: sub $0x110,%rsp */
1469 0x48, 0x8d, 0x6c, 0x24, 0x30, /* 09: lea 0x30(%rsp),%rbp */
1470 0x48, 0x89, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 0e: mov %rbx,0xf0(%rbp) */
1471 0x48, 0x89, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 15: mov %rsi,0xf8(%rbp) */
1473 0x48, 0x8b, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 1d: mov 0xf0(%rbp),%rbx */
1474 0x48, 0x8b, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 24: mov 0xf8(%rbp),%rsi */
1475 0x48, 0x8d, 0xa5, 0xe0, 0x00, 0x00, 0x00, /* 2b: lea 0xe0(%rbp),%rsp */
1476 0x5d, /* 32: pop %rbp */
1480 static const BYTE unwind_info_0
[] =
1482 1 | (UNW_FLAG_EHANDLER
<< 3), /* version + flags */
1483 0x1c, /* prolog size */
1484 8, /* opcode count */
1485 (0x03 << 4) | rbp
, /* frame reg rbp offset 0x30 */
1487 0x1c, UWOP(SAVE_NONVOL
, rsi
), 0x25, 0, /* 1c: mov %rsi,0x128(%rsp) */
1488 0x15, UWOP(SAVE_NONVOL
, rbx
), 0x24, 0, /* 15: mov %rbx,0x120(%rsp) */
1489 0x0e, UWOP(SET_FPREG
, rbp
), /* 0e: lea 0x30(%rsp),rbp */
1490 0x09, UWOP(ALLOC_LARGE
, 0), 0x22, 0, /* 09: sub $0x110,%rsp */
1491 0x02, UWOP(PUSH_NONVOL
, rbp
), /* 02: push %rbp */
1493 0x00, 0x02, 0x00, 0x00, /* handler */
1494 0x05, 0x06, 0x07, 0x08, /* data */
1497 static const struct results results_0
[] =
1499 /* offset rbp handler rip frame registers */
1500 { 0x00, 0x40, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1501 { 0x02, 0x40, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbp
,0x000}, {-1,-1} }},
1502 { 0x09, 0x40, FALSE
, 0x118, 0x000, { {rsp
,0x120}, {rbp
,0x110}, {-1,-1} }},
1503 { 0x0e, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {-1,-1} }},
1504 { 0x15, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {-1,-1} }},
1505 { 0x1c, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1506 { 0x1d, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1507 { 0x24, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1508 { 0x2b, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {-1,-1}}},
1509 { 0x32, 0x40, FALSE
, 0x008, 0x010, { {rsp
,0x010}, {rbp
,0x000}, {-1,-1}}},
1510 { 0x33, 0x40, FALSE
, 0x000, 0x010, { {rsp
,0x008}, {-1,-1}}},
1514 static const BYTE function_1
[] =
1516 0x53, /* 00: push %rbx */
1517 0x55, /* 01: push %rbp */
1518 0x56, /* 02: push %rsi */
1519 0x57, /* 03: push %rdi */
1520 0x41, 0x54, /* 04: push %r12 */
1521 0x48, 0x83, 0xec, 0x30, /* 06: sub $0x30,%rsp */
1522 0x90, 0x90, /* 0a: nop; nop */
1523 0x48, 0x83, 0xc4, 0x30, /* 0c: add $0x30,%rsp */
1524 0x41, 0x5c, /* 10: pop %r12 */
1525 0x5f, /* 12: pop %rdi */
1526 0x5e, /* 13: pop %rsi */
1527 0x5d, /* 14: pop %rbp */
1528 0x5b, /* 15: pop %rbx */
1532 static const BYTE unwind_info_1
[] =
1534 1 | (UNW_FLAG_EHANDLER
<< 3), /* version + flags */
1535 0x0a, /* prolog size */
1536 6, /* opcode count */
1539 0x0a, UWOP(ALLOC_SMALL
, 5), /* 0a: sub $0x30,%rsp */
1540 0x06, UWOP(PUSH_NONVOL
, r12
), /* 06: push %r12 */
1541 0x04, UWOP(PUSH_NONVOL
, rdi
), /* 04: push %rdi */
1542 0x03, UWOP(PUSH_NONVOL
, rsi
), /* 03: push %rsi */
1543 0x02, UWOP(PUSH_NONVOL
, rbp
), /* 02: push %rbp */
1544 0x01, UWOP(PUSH_NONVOL
, rbx
), /* 01: push %rbx */
1546 0x00, 0x02, 0x00, 0x00, /* handler */
1547 0x05, 0x06, 0x07, 0x08, /* data */
1550 static const struct results results_1
[] =
1552 /* offset rbp handler rip frame registers */
1553 { 0x00, 0x50, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1554 { 0x01, 0x50, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbx
,0x000}, {-1,-1} }},
1555 { 0x02, 0x50, FALSE
, 0x010, 0x000, { {rsp
,0x018}, {rbx
,0x008}, {rbp
,0x000}, {-1,-1} }},
1556 { 0x03, 0x50, FALSE
, 0x018, 0x000, { {rsp
,0x020}, {rbx
,0x010}, {rbp
,0x008}, {rsi
,0x000}, {-1,-1} }},
1557 { 0x04, 0x50, FALSE
, 0x020, 0x000, { {rsp
,0x028}, {rbx
,0x018}, {rbp
,0x010}, {rsi
,0x008}, {rdi
,0x000}, {-1,-1} }},
1558 { 0x06, 0x50, FALSE
, 0x028, 0x000, { {rsp
,0x030}, {rbx
,0x020}, {rbp
,0x018}, {rsi
,0x010}, {rdi
,0x008}, {r12
,0x000}, {-1,-1} }},
1559 { 0x0a, 0x50, TRUE
, 0x058, 0x000, { {rsp
,0x060}, {rbx
,0x050}, {rbp
,0x048}, {rsi
,0x040}, {rdi
,0x038}, {r12
,0x030}, {-1,-1} }},
1560 { 0x0c, 0x50, FALSE
, 0x058, 0x000, { {rsp
,0x060}, {rbx
,0x050}, {rbp
,0x048}, {rsi
,0x040}, {rdi
,0x038}, {r12
,0x030}, {-1,-1} }},
1561 { 0x10, 0x50, FALSE
, 0x028, 0x000, { {rsp
,0x030}, {rbx
,0x020}, {rbp
,0x018}, {rsi
,0x010}, {rdi
,0x008}, {r12
,0x000}, {-1,-1} }},
1562 { 0x12, 0x50, FALSE
, 0x020, 0x000, { {rsp
,0x028}, {rbx
,0x018}, {rbp
,0x010}, {rsi
,0x008}, {rdi
,0x000}, {-1,-1} }},
1563 { 0x13, 0x50, FALSE
, 0x018, 0x000, { {rsp
,0x020}, {rbx
,0x010}, {rbp
,0x008}, {rsi
,0x000}, {-1,-1} }},
1564 { 0x14, 0x50, FALSE
, 0x010, 0x000, { {rsp
,0x018}, {rbx
,0x008}, {rbp
,0x000}, {-1,-1} }},
1565 { 0x15, 0x50, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbx
,0x000}, {-1,-1} }},
1566 { 0x16, 0x50, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1569 static const struct unwind_test tests
[] =
1571 { function_0
, sizeof(function_0
), unwind_info_0
,
1572 results_0
, sizeof(results_0
)/sizeof(results_0
[0]) },
1573 { function_1
, sizeof(function_1
), unwind_info_1
,
1574 results_1
, sizeof(results_1
)/sizeof(results_1
[0]) }
1578 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
1579 call_virtual_unwind( i
, &tests
[i
] );
1582 static RUNTIME_FUNCTION
* CALLBACK
dynamic_unwind_callback( DWORD64 pc
, PVOID context
)
1584 static const int code_offset
= 1024;
1585 static RUNTIME_FUNCTION runtime_func
;
1586 (*(DWORD
*)context
)++;
1588 runtime_func
.BeginAddress
= code_offset
+ 16;
1589 runtime_func
.EndAddress
= code_offset
+ 32;
1590 runtime_func
.UnwindData
= 0;
1591 return &runtime_func
;
1594 static void test_dynamic_unwind(void)
1596 static const int code_offset
= 1024;
1597 char buf
[sizeof(RUNTIME_FUNCTION
) + 4];
1598 RUNTIME_FUNCTION
*runtime_func
, *func
;
1599 ULONG_PTR table
, base
;
1602 /* Test RtlAddFunctionTable with aligned RUNTIME_FUNCTION pointer */
1603 runtime_func
= (RUNTIME_FUNCTION
*)buf
;
1604 runtime_func
->BeginAddress
= code_offset
;
1605 runtime_func
->EndAddress
= code_offset
+ 16;
1606 runtime_func
->UnwindData
= 0;
1607 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1608 "RtlAddFunctionTable failed for runtime_func = %p (aligned)\n", runtime_func
);
1610 /* Lookup function outside of any function table */
1612 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 16, &base
, NULL
);
1614 "RtlLookupFunctionEntry returned unexpected function, expected: NULL, got: %p\n", func
);
1615 ok( !base
|| broken(base
== 0xdeadbeef),
1616 "RtlLookupFunctionEntry modified base address, expected: 0, got: %lx\n", base
);
1618 /* Test with pointer inside of our function */
1620 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 8, &base
, NULL
);
1621 ok( func
== runtime_func
,
1622 "RtlLookupFunctionEntry didn't return expected function, expected: %p, got: %p\n", runtime_func
, func
);
1623 ok( base
== (ULONG_PTR
)code_mem
,
1624 "RtlLookupFunctionEntry returned invalid base, expected: %lx, got: %lx\n", (ULONG_PTR
)code_mem
, base
);
1626 /* Test RtlDeleteFunctionTable */
1627 ok( pRtlDeleteFunctionTable( runtime_func
),
1628 "RtlDeleteFunctionTable failed for runtime_func = %p (aligned)\n", runtime_func
);
1629 ok( !pRtlDeleteFunctionTable( runtime_func
),
1630 "RtlDeleteFunctionTable returned success for nonexistent table runtime_func = %p\n", runtime_func
);
1632 /* Unaligned RUNTIME_FUNCTION pointer */
1633 runtime_func
= (RUNTIME_FUNCTION
*)((ULONG_PTR
)buf
| 0x3);
1634 runtime_func
->BeginAddress
= code_offset
;
1635 runtime_func
->EndAddress
= code_offset
+ 16;
1636 runtime_func
->UnwindData
= 0;
1637 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1638 "RtlAddFunctionTable failed for runtime_func = %p (unaligned)\n", runtime_func
);
1639 ok( pRtlDeleteFunctionTable( runtime_func
),
1640 "RtlDeleteFunctionTable failed for runtime_func = %p (unaligned)\n", runtime_func
);
1642 /* Attempt to insert the same entry twice */
1643 runtime_func
= (RUNTIME_FUNCTION
*)buf
;
1644 runtime_func
->BeginAddress
= code_offset
;
1645 runtime_func
->EndAddress
= code_offset
+ 16;
1646 runtime_func
->UnwindData
= 0;
1647 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1648 "RtlAddFunctionTable failed for runtime_func = %p (first attempt)\n", runtime_func
);
1649 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1650 "RtlAddFunctionTable failed for runtime_func = %p (second attempt)\n", runtime_func
);
1651 ok( pRtlDeleteFunctionTable( runtime_func
),
1652 "RtlDeleteFunctionTable failed for runtime_func = %p (first attempt)\n", runtime_func
);
1653 ok( pRtlDeleteFunctionTable( runtime_func
),
1654 "RtlDeleteFunctionTable failed for runtime_func = %p (second attempt)\n", runtime_func
);
1655 ok( !pRtlDeleteFunctionTable( runtime_func
),
1656 "RtlDeleteFunctionTable returned success for nonexistent table runtime_func = %p\n", runtime_func
);
1658 /* Test RtlInstallFunctionTableCallback with both low bits unset */
1659 table
= (ULONG_PTR
)code_mem
;
1660 ok( !pRtlInstallFunctionTableCallback( table
, (ULONG_PTR
)code_mem
, code_offset
+ 32, &dynamic_unwind_callback
, (PVOID
*)&count
, NULL
),
1661 "RtlInstallFunctionTableCallback returned success for table = %lx\n", table
);
1663 /* Test RtlInstallFunctionTableCallback with both low bits set */
1664 table
= (ULONG_PTR
)code_mem
| 0x3;
1665 ok( pRtlInstallFunctionTableCallback( table
, (ULONG_PTR
)code_mem
, code_offset
+ 32, &dynamic_unwind_callback
, (PVOID
*)&count
, NULL
),
1666 "RtlInstallFunctionTableCallback failed for table = %lx\n", table
);
1668 /* Lookup function outside of any function table */
1671 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 32, &base
, NULL
);
1673 "RtlLookupFunctionEntry returned unexpected function, expected: NULL, got: %p\n", func
);
1674 ok( !base
|| broken(base
== 0xdeadbeef),
1675 "RtlLookupFunctionEntry modified base address, expected: 0, got: %lx\n", base
);
1677 "RtlLookupFunctionEntry issued %d unexpected calls to dynamic_unwind_callback\n", count
);
1679 /* Test with pointer inside of our function */
1682 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 24, &base
, NULL
);
1683 ok( func
!= NULL
&& func
->BeginAddress
== code_offset
+ 16 && func
->EndAddress
== code_offset
+ 32,
1684 "RtlLookupFunctionEntry didn't return expected function, got: %p\n", func
);
1685 ok( base
== (ULONG_PTR
)code_mem
,
1686 "RtlLookupFunctionEntry returned invalid base, expected: %lx, got: %lx\n", (ULONG_PTR
)code_mem
, base
);
1688 "RtlLookupFunctionEntry issued %d calls to dynamic_unwind_callback, expected: 1\n", count
);
1690 /* Clean up again */
1691 ok( pRtlDeleteFunctionTable( (PRUNTIME_FUNCTION
)table
),
1692 "RtlDeleteFunctionTable failed for table = %p\n", (PVOID
)table
);
1693 ok( !pRtlDeleteFunctionTable( (PRUNTIME_FUNCTION
)table
),
1694 "RtlDeleteFunctionTable returned success for nonexistent table = %p\n", (PVOID
)table
);
1698 #endif /* __x86_64__ */
1700 #if defined(__i386__) || defined(__x86_64__)
1701 static DWORD outputdebugstring_exceptions
;
1703 static LONG CALLBACK
outputdebugstring_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
1705 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
1706 trace("vect. handler %08x addr:%p\n", rec
->ExceptionCode
, rec
->ExceptionAddress
);
1708 ok(rec
->ExceptionCode
== DBG_PRINTEXCEPTION_C
, "ExceptionCode is %08x instead of %08x\n",
1709 rec
->ExceptionCode
, DBG_PRINTEXCEPTION_C
);
1710 ok(rec
->NumberParameters
== 2, "ExceptionParameters is %d instead of 2\n", rec
->NumberParameters
);
1711 ok(rec
->ExceptionInformation
[0] == 12, "ExceptionInformation[0] = %d instead of 12\n", (DWORD
)rec
->ExceptionInformation
[0]);
1712 ok(!strcmp((char *)rec
->ExceptionInformation
[1], "Hello World"),
1713 "ExceptionInformation[1] = '%s' instead of 'Hello World'\n", (char *)rec
->ExceptionInformation
[1]);
1715 outputdebugstring_exceptions
++;
1716 return EXCEPTION_CONTINUE_SEARCH
;
1719 static void test_outputdebugstring(DWORD numexc
, BOOL todo
)
1721 PVOID vectored_handler
;
1723 if (!pRtlAddVectoredExceptionHandler
|| !pRtlRemoveVectoredExceptionHandler
)
1725 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n");
1729 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &outputdebugstring_vectored_handler
);
1730 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
1732 outputdebugstring_exceptions
= 0;
1733 OutputDebugStringA("Hello World");
1736 ok(outputdebugstring_exceptions
== numexc
, "OutputDebugStringA generated %d exceptions, expected %d\n",
1737 outputdebugstring_exceptions
, numexc
);
1739 ok(outputdebugstring_exceptions
== numexc
, "OutputDebugStringA generated %d exceptions, expected %d\n",
1740 outputdebugstring_exceptions
, numexc
);
1742 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
1745 static DWORD ripevent_exceptions
;
1747 static LONG CALLBACK
ripevent_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
1749 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
1750 trace("vect. handler %08x addr:%p\n", rec
->ExceptionCode
, rec
->ExceptionAddress
);
1752 ok(rec
->ExceptionCode
== DBG_RIPEXCEPTION
, "ExceptionCode is %08x instead of %08x\n",
1753 rec
->ExceptionCode
, DBG_RIPEXCEPTION
);
1754 ok(rec
->NumberParameters
== 2, "ExceptionParameters is %d instead of 2\n", rec
->NumberParameters
);
1755 ok(rec
->ExceptionInformation
[0] == 0x11223344, "ExceptionInformation[0] = %08x instead of %08x\n",
1756 (NTSTATUS
)rec
->ExceptionInformation
[0], 0x11223344);
1757 ok(rec
->ExceptionInformation
[1] == 0x55667788, "ExceptionInformation[1] = %08x instead of %08x\n",
1758 (NTSTATUS
)rec
->ExceptionInformation
[1], 0x55667788);
1760 ripevent_exceptions
++;
1761 return (rec
->ExceptionCode
== DBG_RIPEXCEPTION
) ? EXCEPTION_CONTINUE_EXECUTION
: EXCEPTION_CONTINUE_SEARCH
;
1764 static void test_ripevent(DWORD numexc
)
1766 EXCEPTION_RECORD record
;
1767 PVOID vectored_handler
;
1769 if (!pRtlAddVectoredExceptionHandler
|| !pRtlRemoveVectoredExceptionHandler
|| !pRtlRaiseException
)
1771 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler or RtlRaiseException not found\n");
1775 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &ripevent_vectored_handler
);
1776 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
1778 record
.ExceptionCode
= DBG_RIPEXCEPTION
;
1779 record
.ExceptionFlags
= 0;
1780 record
.ExceptionRecord
= NULL
;
1781 record
.ExceptionAddress
= NULL
;
1782 record
.NumberParameters
= 2;
1783 record
.ExceptionInformation
[0] = 0x11223344;
1784 record
.ExceptionInformation
[1] = 0x55667788;
1786 ripevent_exceptions
= 0;
1787 pRtlRaiseException(&record
);
1788 ok(ripevent_exceptions
== numexc
, "RtlRaiseException generated %d exceptions, expected %d\n",
1789 ripevent_exceptions
, numexc
);
1791 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
1794 static void test_vectored_continue_handler(void)
1796 PVOID handler1
, handler2
;
1799 if (!pRtlAddVectoredContinueHandler
|| !pRtlRemoveVectoredContinueHandler
)
1801 skip("RtlAddVectoredContinueHandler or RtlRemoveVectoredContinueHandler not found\n");
1805 handler1
= pRtlAddVectoredContinueHandler(TRUE
, (void *)0xdeadbeef);
1806 ok(handler1
!= 0, "RtlAddVectoredContinueHandler failed\n");
1808 handler2
= pRtlAddVectoredContinueHandler(TRUE
, (void *)0xdeadbeef);
1809 ok(handler2
!= 0, "RtlAddVectoredContinueHandler failed\n");
1810 ok(handler1
!= handler2
, "RtlAddVectoredContinueHandler returned same handler\n");
1812 if (pRtlRemoveVectoredExceptionHandler
)
1814 ret
= pRtlRemoveVectoredExceptionHandler(handler1
);
1815 ok(!ret
, "RtlRemoveVectoredExceptionHandler succeeded\n");
1818 ret
= pRtlRemoveVectoredContinueHandler(handler1
);
1819 ok(ret
, "RtlRemoveVectoredContinueHandler failed\n");
1821 ret
= pRtlRemoveVectoredContinueHandler(handler2
);
1822 ok(ret
, "RtlRemoveVectoredContinueHandler failed\n");
1824 ret
= pRtlRemoveVectoredContinueHandler(handler1
);
1825 ok(!ret
, "RtlRemoveVectoredContinueHandler succeeded\n");
1827 ret
= pRtlRemoveVectoredContinueHandler((void *)0x11223344);
1828 ok(!ret
, "RtlRemoveVectoredContinueHandler succeeded\n");
1830 #endif /* defined(__i386__) || defined(__x86_64__) */
1832 START_TEST(exception
)
1834 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1836 code_mem
= VirtualAlloc(NULL
, 65536, MEM_RESERVE
| MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1838 trace("VirtualAlloc failed\n");
1842 pNtCurrentTeb
= (void *)GetProcAddress( hntdll
, "NtCurrentTeb" );
1843 pNtGetContextThread
= (void *)GetProcAddress( hntdll
, "NtGetContextThread" );
1844 pNtSetContextThread
= (void *)GetProcAddress( hntdll
, "NtSetContextThread" );
1845 pNtReadVirtualMemory
= (void *)GetProcAddress( hntdll
, "NtReadVirtualMemory" );
1846 pRtlUnwind
= (void *)GetProcAddress( hntdll
, "RtlUnwind" );
1847 pRtlRaiseException
= (void *)GetProcAddress( hntdll
, "RtlRaiseException" );
1848 pNtTerminateProcess
= (void *)GetProcAddress( hntdll
, "NtTerminateProcess" );
1849 pRtlAddVectoredExceptionHandler
= (void *)GetProcAddress( hntdll
,
1850 "RtlAddVectoredExceptionHandler" );
1851 pRtlRemoveVectoredExceptionHandler
= (void *)GetProcAddress( hntdll
,
1852 "RtlRemoveVectoredExceptionHandler" );
1853 pRtlAddVectoredContinueHandler
= (void *)GetProcAddress( hntdll
,
1854 "RtlAddVectoredContinueHandler" );
1855 pRtlRemoveVectoredContinueHandler
= (void *)GetProcAddress( hntdll
,
1856 "RtlRemoveVectoredContinueHandler" );
1857 pNtQueryInformationProcess
= (void*)GetProcAddress( hntdll
,
1858 "NtQueryInformationProcess" );
1859 pNtSetInformationProcess
= (void*)GetProcAddress( hntdll
,
1860 "NtSetInformationProcess" );
1861 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
1866 skip( "NtCurrentTeb not found\n" );
1869 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1871 if (pRtlAddVectoredExceptionHandler
&& pRtlRemoveVectoredExceptionHandler
)
1872 have_vectored_api
= TRUE
;
1874 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n");
1876 my_argc
= winetest_get_mainargs( &my_argv
);
1880 sscanf( my_argv
[3], "%p", &addr
);
1882 if (addr
!= &test_stage
)
1884 skip( "child process not mapped at same address (%p/%p)\n", &test_stage
, addr
);
1888 /* child must be run under a debugger */
1889 if (!pNtCurrentTeb()->Peb
->BeingDebugged
)
1891 ok(FALSE
, "child process not being debugged?\n");
1895 if (pRtlRaiseException
)
1898 run_rtlraiseexception_test(0x12345);
1899 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
1900 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
1902 run_rtlraiseexception_test(0x12345);
1903 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
1904 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
1906 test_outputdebugstring(0, FALSE
);
1908 test_outputdebugstring(2, TRUE
); /* is this a Windows bug? */
1915 skip( "RtlRaiseException not found\n" );
1917 /* rest of tests only run in parent */
1923 test_rtlraiseexception();
1924 test_outputdebugstring(1, FALSE
);
1926 test_vectored_continue_handler();
1928 test_simd_exceptions();
1929 test_fpu_exceptions();
1930 test_dpe_exceptions();
1933 #elif defined(__x86_64__)
1934 pRtlAddFunctionTable
= (void *)GetProcAddress( hntdll
,
1935 "RtlAddFunctionTable" );
1936 pRtlDeleteFunctionTable
= (void *)GetProcAddress( hntdll
,
1937 "RtlDeleteFunctionTable" );
1938 pRtlInstallFunctionTableCallback
= (void *)GetProcAddress( hntdll
,
1939 "RtlInstallFunctionTableCallback" );
1940 pRtlLookupFunctionEntry
= (void *)GetProcAddress( hntdll
,
1941 "RtlLookupFunctionEntry" );
1943 test_outputdebugstring(1, FALSE
);
1945 test_vectored_continue_handler();
1946 test_virtual_unwind();
1948 if (pRtlAddFunctionTable
&& pRtlDeleteFunctionTable
&& pRtlInstallFunctionTableCallback
&& pRtlLookupFunctionEntry
)
1949 test_dynamic_unwind();
1951 skip( "Dynamic unwind functions not found\n" );
1955 VirtualFree(code_mem
, 0, MEM_FREE
);