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
36 #include "wine/winternl.h"
37 #include "wine/exception.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
*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
);
56 static NTSTATUS (WINAPI
*pNtClose
)(HANDLE
);
58 #if defined(__x86_64__)
59 static BOOLEAN (CDECL
*pRtlAddFunctionTable
)(RUNTIME_FUNCTION
*, DWORD
, DWORD64
);
60 static BOOLEAN (CDECL
*pRtlDeleteFunctionTable
)(RUNTIME_FUNCTION
*);
61 static BOOLEAN (CDECL
*pRtlInstallFunctionTableCallback
)(DWORD64
, DWORD64
, DWORD
, PGET_RUNTIME_FUNCTION_CALLBACK
, PVOID
, PCWSTR
);
62 static PRUNTIME_FUNCTION (WINAPI
*pRtlLookupFunctionEntry
)(ULONG64
, ULONG64
*, UNWIND_HISTORY_TABLE
*);
67 #ifndef __WINE_WINTRNL_H
68 #define ProcessExecuteFlags 0x22
69 #define MEM_EXECUTE_OPTION_DISABLE 0x01
70 #define MEM_EXECUTE_OPTION_ENABLE 0x02
71 #define MEM_EXECUTE_OPTION_PERMANENT 0x08
75 static char** my_argv
;
76 static int test_stage
;
80 /* Test various instruction combinations that cause a protection fault on the i386,
81 * and check what the resulting exception looks like.
84 static const struct exception
86 BYTE code
[18]; /* asm code */
87 BYTE offset
; /* offset of faulting instruction */
88 BYTE length
; /* length of faulting instruction */
89 BOOL wow64_broken
; /* broken on Wow64, should be skipped */
90 NTSTATUS status
; /* expected status code */
91 DWORD nb_params
; /* expected number of parameters */
92 DWORD params
[4]; /* expected parameters */
93 NTSTATUS alt_status
; /* alternative status code */
94 DWORD alt_nb_params
; /* alternative number of parameters */
95 DWORD alt_params
[4]; /* alternative parameters */
99 /* test some privileged instructions */
100 { { 0xfb, 0xc3 }, /* 0: sti; ret */
101 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
102 { { 0x6c, 0xc3 }, /* 1: insb (%dx); ret */
103 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
104 { { 0x6d, 0xc3 }, /* 2: insl (%dx); ret */
105 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
106 { { 0x6e, 0xc3 }, /* 3: outsb (%dx); ret */
107 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
108 { { 0x6f, 0xc3 }, /* 4: outsl (%dx); ret */
109 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
111 { { 0xe4, 0x11, 0xc3 }, /* 5: inb $0x11,%al; ret */
112 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
113 { { 0xe5, 0x11, 0xc3 }, /* 6: inl $0x11,%eax; ret */
114 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
115 { { 0xe6, 0x11, 0xc3 }, /* 7: outb %al,$0x11; ret */
116 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
117 { { 0xe7, 0x11, 0xc3 }, /* 8: outl %eax,$0x11; ret */
118 0, 2, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
119 { { 0xed, 0xc3 }, /* 9: inl (%dx),%eax; ret */
120 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
122 { { 0xee, 0xc3 }, /* 10: outb %al,(%dx); ret */
123 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
124 { { 0xef, 0xc3 }, /* 11: outl %eax,(%dx); ret */
125 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
126 { { 0xf4, 0xc3 }, /* 12: hlt; ret */
127 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
128 { { 0xfa, 0xc3 }, /* 13: cli; ret */
129 0, 1, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
131 /* test long jump to invalid selector */
132 { { 0xea, 0, 0, 0, 0, 0, 0, 0xc3 }, /* 14: ljmp $0,$0; ret */
133 0, 7, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
136 /* test iret to invalid selector */
137 { { 0x6a, 0x00, 0x6a, 0x00, 0x6a, 0x00, 0xcf, 0x83, 0xc4, 0x0c, 0xc3 },
138 /* 15: pushl $0; pushl $0; pushl $0; iret; addl $12,%esp; ret */
139 6, 1, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
141 /* test loading an invalid selector */
142 { { 0xb8, 0xef, 0xbe, 0x00, 0x00, 0x8e, 0xe8, 0xc3 }, /* 16: mov $beef,%ax; mov %ax,%gs; ret */
143 5, 2, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xbee8 } }, /* 0xbee8 or 0xffffffff */
145 /* test accessing a zero selector (%es broken on Wow64) */
146 { { 0x06, 0x31, 0xc0, 0x8e, 0xc0, 0x26, 0xa1, 0, 0, 0, 0, 0x07, 0xc3 },
147 /* push %es; xor %eax,%eax; mov %ax,%es; mov %es:(0),%ax; pop %es; ret */
148 5, 6, TRUE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
149 { { 0x0f, 0xa8, 0x31, 0xc0, 0x8e, 0xe8, 0x65, 0xa1, 0, 0, 0, 0, 0x0f, 0xa9, 0xc3 },
150 /* push %gs; xor %eax,%eax; mov %ax,%gs; mov %gs:(0),%ax; pop %gs; ret */
151 6, 6, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
153 /* test moving %cs -> %ss */
154 { { 0x0e, 0x17, 0x58, 0xc3 }, /* pushl %cs; popl %ss; popl %eax; ret */
155 1, 1, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
158 /* test overlong instruction (limit is 15 bytes, 5 on Win7) */
159 { { 0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xfa,0xc3 },
160 0, 16, TRUE
, STATUS_ILLEGAL_INSTRUCTION
, 0, { 0 },
161 STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
162 { { 0x64,0x64,0x64,0x64,0xfa,0xc3 },
163 0, 5, TRUE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
165 /* test invalid interrupt */
166 { { 0xcd, 0xff, 0xc3 }, /* int $0xff; ret */
167 0, 2, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
169 /* test moves to/from Crx */
170 { { 0x0f, 0x20, 0xc0, 0xc3 }, /* movl %cr0,%eax; ret */
171 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
172 { { 0x0f, 0x20, 0xe0, 0xc3 }, /* movl %cr4,%eax; ret */
173 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
175 { { 0x0f, 0x22, 0xc0, 0xc3 }, /* movl %eax,%cr0; ret */
176 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
177 { { 0x0f, 0x22, 0xe0, 0xc3 }, /* movl %eax,%cr4; ret */
178 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
180 /* test moves to/from Drx */
181 { { 0x0f, 0x21, 0xc0, 0xc3 }, /* movl %dr0,%eax; ret */
182 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
183 { { 0x0f, 0x21, 0xc8, 0xc3 }, /* movl %dr1,%eax; ret */
184 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
185 { { 0x0f, 0x21, 0xf8, 0xc3 }, /* movl %dr7,%eax; ret */
186 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
188 { { 0x0f, 0x23, 0xc0, 0xc3 }, /* movl %eax,%dr0; ret */
189 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
190 { { 0x0f, 0x23, 0xc8, 0xc3 }, /* movl %eax,%dr1; ret */
191 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
192 { { 0x0f, 0x23, 0xf8, 0xc3 }, /* movl %eax,%dr7; ret */
193 0, 3, FALSE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
195 /* test memory reads */
196 { { 0xa1, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffc,%eax; ret */
197 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffc } },
198 { { 0xa1, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffd,%eax; ret */
199 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffd } },
201 { { 0xa1, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xfffffffe,%eax; ret */
202 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xfffffffe } },
203 { { 0xa1, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* movl 0xffffffff,%eax; ret */
204 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 0, 0xffffffff } },
206 /* test memory writes */
207 { { 0xa3, 0xfc, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffc; ret */
208 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffc } },
209 { { 0xa3, 0xfd, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffd; ret */
210 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffd } },
211 { { 0xa3, 0xfe, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xfffffffe; ret */
212 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xfffffffe } },
214 { { 0xa3, 0xff, 0xff, 0xff, 0xff, 0xc3 }, /* movl %eax,0xffffffff; ret */
215 0, 5, FALSE
, STATUS_ACCESS_VIOLATION
, 2, { 1, 0xffffffff } },
217 /* test exception with cleared %ds and %es (broken on Wow64) */
218 { { 0x1e, 0x06, 0x31, 0xc0, 0x8e, 0xd8, 0x8e, 0xc0, 0xfa, 0x07, 0x1f, 0xc3 },
219 /* push %ds; push %es; xorl %eax,%eax; mov %ax,%ds; mov %ax,%es; cli; pop %es; pop %ds; ret */
220 8, 1, TRUE
, STATUS_PRIVILEGED_INSTRUCTION
, 0 },
222 { { 0xf1, 0x90, 0xc3 }, /* icebp; nop; ret */
223 1, 1, FALSE
, STATUS_SINGLE_STEP
, 0 },
226 static int got_exception
;
227 static BOOL have_vectored_api
;
229 static void run_exception_test(void *handler
, const void* context
,
230 const void *code
, unsigned int code_size
,
234 EXCEPTION_REGISTRATION_RECORD frame
;
237 void (*func
)(void) = code_mem
;
238 DWORD oldaccess
, oldaccess2
;
240 exc_frame
.frame
.Handler
= handler
;
241 exc_frame
.frame
.Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
242 exc_frame
.context
= context
;
244 memcpy(code_mem
, code
, code_size
);
246 VirtualProtect(code_mem
, code_size
, access
, &oldaccess
);
248 pNtCurrentTeb()->Tib
.ExceptionList
= &exc_frame
.frame
;
250 pNtCurrentTeb()->Tib
.ExceptionList
= exc_frame
.frame
.Prev
;
253 VirtualProtect(code_mem
, code_size
, oldaccess
, &oldaccess2
);
256 static LONG CALLBACK
rtlraiseexception_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
258 PCONTEXT context
= ExceptionInfo
->ContextRecord
;
259 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
260 trace("vect. handler %08x addr:%p context.Eip:%x\n", rec
->ExceptionCode
,
261 rec
->ExceptionAddress
, context
->Eip
);
263 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0xb, "ExceptionAddress at %p instead of %p\n",
264 rec
->ExceptionAddress
, (char *)code_mem
+ 0xb);
266 if (pNtCurrentTeb()->Peb
->BeingDebugged
)
267 ok((void *)context
->Eax
== pRtlRaiseException
||
268 broken( is_wow64
&& context
->Eax
== 0xf00f00f1 ), /* broken on vista */
269 "debugger managed to modify Eax to %x should be %p\n",
270 context
->Eax
, pRtlRaiseException
);
272 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
273 * even if raised by RtlRaiseException
275 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
)
277 ok(context
->Eip
== (DWORD
)code_mem
+ 0xa ||
278 broken(context
->Eip
== (DWORD
)code_mem
+ 0xb), /* win2k3 */
279 "Eip at %x instead of %x or %x\n", context
->Eip
,
280 (DWORD
)code_mem
+ 0xa, (DWORD
)code_mem
+ 0xb);
284 ok(context
->Eip
== (DWORD
)code_mem
+ 0xb, "Eip at %x instead of %x\n",
285 context
->Eip
, (DWORD
)code_mem
+ 0xb);
288 /* test if context change is preserved from vectored handler to stack handlers */
289 context
->Eax
= 0xf00f00f0;
290 return EXCEPTION_CONTINUE_SEARCH
;
293 static DWORD
rtlraiseexception_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
294 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
296 trace( "exception: %08x flags:%x addr:%p context: Eip:%x\n",
297 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
, context
->Eip
);
299 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0xb, "ExceptionAddress at %p instead of %p\n",
300 rec
->ExceptionAddress
, (char *)code_mem
+ 0xb);
302 /* check that context.Eip is fixed up only for EXCEPTION_BREAKPOINT
303 * even if raised by RtlRaiseException
305 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
)
307 ok(context
->Eip
== (DWORD
)code_mem
+ 0xa ||
308 broken(context
->Eip
== (DWORD
)code_mem
+ 0xb), /* win2k3 */
309 "Eip at %x instead of %x or %x\n", context
->Eip
,
310 (DWORD
)code_mem
+ 0xa, (DWORD
)code_mem
+ 0xb);
314 ok(context
->Eip
== (DWORD
)code_mem
+ 0xb, "Eip at %x instead of %x\n",
315 context
->Eip
, (DWORD
)code_mem
+ 0xb);
318 if(have_vectored_api
)
319 ok(context
->Eax
== 0xf00f00f0, "Eax is %x, should have been set to 0xf00f00f0 in vectored handler\n",
322 /* give the debugger a chance to examine the state a second time */
323 /* without the exception handler changing Eip */
325 return ExceptionContinueSearch
;
327 /* Eip in context is decreased by 1
328 * Increase it again, else execution will continue in the middle of an instruction */
329 if(rec
->ExceptionCode
== EXCEPTION_BREAKPOINT
&& (context
->Eip
== (DWORD
)code_mem
+ 0xa))
331 return ExceptionContinueExecution
;
335 static const BYTE call_one_arg_code
[] = {
336 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
337 0x50, /* push %eax */
338 0x8b, 0x44, 0x24, 0x08, /* mov 0x8(%esp),%eax */
339 0xff, 0xd0, /* call *%eax */
348 static void run_rtlraiseexception_test(DWORD exceptioncode
)
350 EXCEPTION_REGISTRATION_RECORD frame
;
351 EXCEPTION_RECORD record
;
352 PVOID vectored_handler
= NULL
;
354 void (*func
)(void* function
, EXCEPTION_RECORD
* record
) = code_mem
;
356 record
.ExceptionCode
= exceptioncode
;
357 record
.ExceptionFlags
= 0;
358 record
.ExceptionRecord
= NULL
;
359 record
.ExceptionAddress
= NULL
; /* does not matter, copied return address */
360 record
.NumberParameters
= 0;
362 frame
.Handler
= rtlraiseexception_handler
;
363 frame
.Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
365 memcpy(code_mem
, call_one_arg_code
, sizeof(call_one_arg_code
));
367 pNtCurrentTeb()->Tib
.ExceptionList
= &frame
;
368 if (have_vectored_api
)
370 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &rtlraiseexception_vectored_handler
);
371 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
374 func(pRtlRaiseException
, &record
);
375 ok( record
.ExceptionAddress
== (char *)code_mem
+ 0x0b,
376 "address set to %p instead of %p\n", record
.ExceptionAddress
, (char *)code_mem
+ 0x0b );
378 if (have_vectored_api
)
379 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
380 pNtCurrentTeb()->Tib
.ExceptionList
= frame
.Prev
;
383 static void test_rtlraiseexception(void)
385 if (!pRtlRaiseException
)
387 skip("RtlRaiseException not found\n");
391 /* test without debugger */
392 run_rtlraiseexception_test(0x12345);
393 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
394 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
397 static DWORD unwind_expected_eax
;
399 static DWORD
unwind_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
400 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
402 trace("exception: %08x flags:%x addr:%p context: Eip:%x\n",
403 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
, context
->Eip
);
405 ok(rec
->ExceptionCode
== STATUS_UNWIND
, "ExceptionCode is %08x instead of %08x\n",
406 rec
->ExceptionCode
, STATUS_UNWIND
);
407 ok(rec
->ExceptionAddress
== (char *)code_mem
+ 0x22, "ExceptionAddress at %p instead of %p\n",
408 rec
->ExceptionAddress
, (char *)code_mem
+ 0x22);
409 ok(context
->Eax
== unwind_expected_eax
, "context->Eax is %08x instead of %08x\n",
410 context
->Eax
, unwind_expected_eax
);
413 return ExceptionContinueSearch
;
416 static const BYTE call_unwind_code
[] = {
417 0x55, /* push %ebp */
418 0x53, /* push %ebx */
419 0x56, /* push %esi */
420 0x57, /* push %edi */
421 0xe8, 0x00, 0x00, 0x00, 0x00, /* call 0 */
422 0x58, /* 0: pop %eax */
423 0x05, 0x1e, 0x00, 0x00, 0x00, /* add $0x1e,%eax */
424 0xff, 0x74, 0x24, 0x20, /* push 0x20(%esp) */
425 0xff, 0x74, 0x24, 0x20, /* push 0x20(%esp) */
426 0x50, /* push %eax */
427 0xff, 0x74, 0x24, 0x24, /* push 0x24(%esp) */
428 0x8B, 0x44, 0x24, 0x24, /* mov 0x24(%esp),%eax */
429 0xff, 0xd0, /* call *%eax */
438 static void test_unwind(void)
440 EXCEPTION_REGISTRATION_RECORD frames
[2], *frame2
= &frames
[0], *frame1
= &frames
[1];
441 DWORD (*func
)(void* function
, EXCEPTION_REGISTRATION_RECORD
*pEndFrame
, EXCEPTION_RECORD
* record
, DWORD retval
) = code_mem
;
444 memcpy(code_mem
, call_unwind_code
, sizeof(call_unwind_code
));
446 /* add first unwind handler */
447 frame1
->Handler
= unwind_handler
;
448 frame1
->Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
449 pNtCurrentTeb()->Tib
.ExceptionList
= frame1
;
451 /* add second unwind handler */
452 frame2
->Handler
= unwind_handler
;
453 frame2
->Prev
= pNtCurrentTeb()->Tib
.ExceptionList
;
454 pNtCurrentTeb()->Tib
.ExceptionList
= frame2
;
456 /* test unwind to current frame */
457 unwind_expected_eax
= 0xDEAD0000;
458 retval
= func(pRtlUnwind
, frame2
, NULL
, 0xDEAD0000);
459 ok(retval
== 0xDEAD0000, "RtlUnwind returned eax %08x instead of %08x\n", retval
, 0xDEAD0000);
460 ok(pNtCurrentTeb()->Tib
.ExceptionList
== frame2
, "Exception record points to %p instead of %p\n",
461 pNtCurrentTeb()->Tib
.ExceptionList
, frame2
);
463 /* unwind to frame1 */
464 unwind_expected_eax
= 0xDEAD0000;
465 retval
= func(pRtlUnwind
, frame1
, NULL
, 0xDEAD0000);
466 ok(retval
== 0xDEAD0001, "RtlUnwind returned eax %08x instead of %08x\n", retval
, 0xDEAD0001);
467 ok(pNtCurrentTeb()->Tib
.ExceptionList
== frame1
, "Exception record points to %p instead of %p\n",
468 pNtCurrentTeb()->Tib
.ExceptionList
, frame1
);
470 /* restore original handler */
471 pNtCurrentTeb()->Tib
.ExceptionList
= frame1
->Prev
;
474 static DWORD
handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
475 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
477 const struct exception
*except
= *(const struct exception
**)(frame
+ 1);
478 unsigned int i
, entry
= except
- exceptions
;
481 trace( "exception %u: %x flags:%x addr:%p\n",
482 entry
, rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
);
484 ok( rec
->ExceptionCode
== except
->status
||
485 (except
->alt_status
!= 0 && rec
->ExceptionCode
== except
->alt_status
),
486 "%u: Wrong exception code %x/%x\n", entry
, rec
->ExceptionCode
, except
->status
);
487 ok( rec
->ExceptionAddress
== (char*)code_mem
+ except
->offset
,
488 "%u: Wrong exception address %p/%p\n", entry
,
489 rec
->ExceptionAddress
, (char*)code_mem
+ except
->offset
);
491 if (except
->alt_status
== 0 || rec
->ExceptionCode
!= except
->alt_status
)
493 ok( rec
->NumberParameters
== except
->nb_params
,
494 "%u: Wrong number of parameters %u/%u\n", entry
, rec
->NumberParameters
, except
->nb_params
);
498 ok( rec
->NumberParameters
== except
->alt_nb_params
,
499 "%u: Wrong number of parameters %u/%u\n", entry
, rec
->NumberParameters
, except
->nb_params
);
502 /* Most CPUs (except Intel Core apparently) report a segment limit violation */
503 /* instead of page faults for accesses beyond 0xffffffff */
504 if (except
->nb_params
== 2 && except
->params
[1] >= 0xfffffffd)
506 if (rec
->ExceptionInformation
[0] == 0 && rec
->ExceptionInformation
[1] == 0xffffffff)
510 /* Seems that both 0xbee8 and 0xfffffffff can be returned in windows */
511 if (except
->nb_params
== 2 && rec
->NumberParameters
== 2
512 && except
->params
[1] == 0xbee8 && rec
->ExceptionInformation
[1] == 0xffffffff
513 && except
->params
[0] == rec
->ExceptionInformation
[0])
518 if (except
->alt_status
== 0 || rec
->ExceptionCode
!= except
->alt_status
)
520 for (i
= 0; i
< rec
->NumberParameters
; i
++)
521 ok( rec
->ExceptionInformation
[i
] == except
->params
[i
],
522 "%u: Wrong parameter %d: %lx/%x\n",
523 entry
, i
, rec
->ExceptionInformation
[i
], except
->params
[i
] );
527 for (i
= 0; i
< rec
->NumberParameters
; i
++)
528 ok( rec
->ExceptionInformation
[i
] == except
->alt_params
[i
],
529 "%u: Wrong parameter %d: %lx/%x\n",
530 entry
, i
, rec
->ExceptionInformation
[i
], except
->alt_params
[i
] );
534 /* don't handle exception if it's not the address we expected */
535 if (rec
->ExceptionAddress
!= (char*)code_mem
+ except
->offset
) return ExceptionContinueSearch
;
537 context
->Eip
+= except
->length
;
538 return ExceptionContinueExecution
;
541 static void test_prot_fault(void)
545 for (i
= 0; i
< sizeof(exceptions
)/sizeof(exceptions
[0]); i
++)
547 if (is_wow64
&& exceptions
[i
].wow64_broken
&& !strcmp( winetest_platform
, "windows" ))
549 skip( "Exception %u broken on Wow64\n", i
);
553 run_exception_test(handler
, &exceptions
[i
], &exceptions
[i
].code
,
554 sizeof(exceptions
[i
].code
), 0);
555 if (!i
&& !got_exception
)
557 trace( "No exception, assuming win9x, no point in testing further\n" );
560 ok( got_exception
== (exceptions
[i
].status
!= 0),
561 "%u: bad exception count %d\n", i
, got_exception
);
566 DWORD dr0
, dr1
, dr2
, dr3
, dr6
, dr7
;
569 /* test handling of debug registers */
570 static DWORD
dreg_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
571 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
573 const struct dbgreg_test
*test
= *(const struct dbgreg_test
**)(frame
+ 1);
575 context
->Eip
+= 2; /* Skips the popl (%eax) */
576 context
->Dr0
= test
->dr0
;
577 context
->Dr1
= test
->dr1
;
578 context
->Dr2
= test
->dr2
;
579 context
->Dr3
= test
->dr3
;
580 context
->Dr6
= test
->dr6
;
581 context
->Dr7
= test
->dr7
;
582 return ExceptionContinueExecution
;
585 #define CHECK_DEBUG_REG(n, m) \
586 ok((ctx.Dr##n & m) == test->dr##n, "(%d) failed to set debug register " #n " to %x, got %x\n", \
587 test_num, test->dr##n, ctx.Dr##n)
589 static void check_debug_registers(int test_num
, const struct dbgreg_test
*test
)
594 ctx
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
595 status
= pNtGetContextThread(GetCurrentThread(), &ctx
);
596 ok(status
== STATUS_SUCCESS
, "NtGetContextThread failed with %x\n", status
);
598 CHECK_DEBUG_REG(0, ~0);
599 CHECK_DEBUG_REG(1, ~0);
600 CHECK_DEBUG_REG(2, ~0);
601 CHECK_DEBUG_REG(3, ~0);
602 CHECK_DEBUG_REG(6, 0x0f);
603 CHECK_DEBUG_REG(7, ~0xdc00);
606 static const BYTE segfault_code
[5] = {
607 0x31, 0xc0, /* xor %eax,%eax */
608 0x8f, 0x00, /* popl (%eax) - cause exception */
612 /* test the single step exception behaviour */
613 static DWORD
single_step_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
614 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
617 ok (!(context
->EFlags
& 0x100), "eflags has single stepping bit set\n");
619 if( got_exception
< 3)
620 context
->EFlags
|= 0x100; /* single step until popf instruction */
622 /* show that the last single step exception on the popf instruction
623 * (which removed the TF bit), still is a EXCEPTION_SINGLE_STEP exception */
624 ok( rec
->ExceptionCode
== EXCEPTION_SINGLE_STEP
,
625 "exception is not EXCEPTION_SINGLE_STEP: %x\n", rec
->ExceptionCode
);
628 return ExceptionContinueExecution
;
631 static const BYTE single_stepcode
[] = {
634 0x0d,0,1,0,0, /* or $0x100,%eax */
635 0x50, /* push %eax */
637 0x35,0,1,0,0, /* xor $0x100,%eax */
638 0x50, /* push %eax */
643 /* Test the alignment check (AC) flag handling. */
644 static const BYTE align_check_code
[] = {
645 0x55, /* push %ebp */
646 0x89,0xe5, /* mov %esp,%ebp */
649 0x0d,0,0,4,0, /* or $0x40000,%eax */
650 0x50, /* push %eax */
652 0x89,0xe0, /* mov %esp, %eax */
653 0x8b,0x40,0x1, /* mov 0x1(%eax), %eax - cause exception */
656 0x35,0,0,4,0, /* xor $0x40000,%eax */
657 0x50, /* push %eax */
663 static DWORD
align_check_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
664 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
666 ok (!(context
->EFlags
& 0x40000), "eflags has AC bit set\n");
668 return ExceptionContinueExecution
;
671 /* Test the direction flag handling. */
672 static const BYTE direction_flag_code
[] = {
673 0x55, /* push %ebp */
674 0x89,0xe5, /* mov %esp,%ebp */
676 0xfa, /* cli - cause exception */
681 static DWORD
direction_flag_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
682 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
686 __asm__("pushfl; popl %0; cld" : "=r" (flags
) );
687 /* older windows versions don't clear DF properly so don't test */
688 if (flags
& 0x400) trace( "eflags has DF bit set\n" );
690 ok( context
->EFlags
& 0x400, "context eflags has DF bit cleared\n" );
692 context
->Eip
++; /* skip cli */
693 context
->EFlags
&= ~0x400; /* make sure it is cleared on return */
694 return ExceptionContinueExecution
;
697 /* test single stepping over hardware breakpoint */
698 static DWORD
bpx_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
699 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
702 ok( rec
->ExceptionCode
== EXCEPTION_SINGLE_STEP
,
703 "wrong exception code: %x\n", rec
->ExceptionCode
);
705 if(got_exception
== 1) {
706 /* hw bp exception on first nop */
707 ok( context
->Eip
== (DWORD
)code_mem
, "eip is wrong: %x instead of %x\n",
708 context
->Eip
, (DWORD
)code_mem
);
709 ok( (context
->Dr6
& 0xf) == 1, "B0 flag is not set in Dr6\n");
710 ok( !(context
->Dr6
& 0x4000), "BS flag is set in Dr6\n");
711 context
->Dr0
= context
->Dr0
+ 1; /* set hw bp again on next instruction */
712 context
->EFlags
|= 0x100; /* enable single stepping */
713 } else if( got_exception
== 2) {
714 /* single step exception on second nop */
715 ok( context
->Eip
== (DWORD
)code_mem
+ 1, "eip is wrong: %x instead of %x\n",
716 context
->Eip
, (DWORD
)code_mem
+ 1);
717 ok( (context
->Dr6
& 0x4000), "BS flag is not set in Dr6\n");
718 /* depending on the win version the B0 bit is already set here as well
719 ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n"); */
720 context
->EFlags
|= 0x100;
721 } else if( got_exception
== 3) {
722 /* hw bp exception on second nop */
723 ok( context
->Eip
== (DWORD
)code_mem
+ 1, "eip is wrong: %x instead of %x\n",
724 context
->Eip
, (DWORD
)code_mem
+ 1);
725 ok( (context
->Dr6
& 0xf) == 1, "B0 flag is not set in Dr6\n");
726 ok( !(context
->Dr6
& 0x4000), "BS flag is set in Dr6\n");
727 context
->Dr0
= 0; /* clear breakpoint */
728 context
->EFlags
|= 0x100;
730 /* single step exception on ret */
731 ok( context
->Eip
== (DWORD
)code_mem
+ 2, "eip is wrong: %x instead of %x\n",
732 context
->Eip
, (DWORD
)code_mem
+ 2);
733 ok( (context
->Dr6
& 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n");
734 ok( (context
->Dr6
& 0x4000), "BS flag is not set in Dr6\n");
737 context
->Dr6
= 0; /* clear status register */
738 return ExceptionContinueExecution
;
741 static const BYTE dummy_code
[] = { 0x90, 0x90, 0xc3 }; /* nop, nop, ret */
743 /* test int3 handling */
744 static DWORD
int3_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
745 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
747 ok( rec
->ExceptionAddress
== code_mem
, "exception address not at: %p, but at %p\n",
748 code_mem
, rec
->ExceptionAddress
);
749 ok( context
->Eip
== (DWORD
)code_mem
, "eip not at: %p, but at %#x\n", code_mem
, context
->Eip
);
750 if(context
->Eip
== (DWORD
)code_mem
) context
->Eip
++; /* skip breakpoint */
752 return ExceptionContinueExecution
;
755 static const BYTE int3_code
[] = { 0xCC, 0xc3 }; /* int 3, ret */
758 static void test_exceptions(void)
762 struct dbgreg_test dreg_test
;
764 if (!pNtGetContextThread
|| !pNtSetContextThread
)
766 skip( "NtGetContextThread/NtSetContextThread not found\n" );
770 /* test handling of debug registers */
771 memset(&dreg_test
, 0, sizeof(dreg_test
));
773 dreg_test
.dr0
= 0x42424240;
774 dreg_test
.dr2
= 0x126bb070;
775 dreg_test
.dr3
= 0x0badbad0;
776 dreg_test
.dr7
= 0xffff0115;
777 run_exception_test(dreg_handler
, &dreg_test
, &segfault_code
, sizeof(segfault_code
), 0);
778 check_debug_registers(1, &dreg_test
);
780 dreg_test
.dr0
= 0x42424242;
781 dreg_test
.dr2
= 0x100f0fe7;
782 dreg_test
.dr3
= 0x0abebabe;
783 dreg_test
.dr7
= 0x115;
784 run_exception_test(dreg_handler
, &dreg_test
, &segfault_code
, sizeof(segfault_code
), 0);
785 check_debug_registers(2, &dreg_test
);
787 /* test single stepping behavior */
789 run_exception_test(single_step_handler
, NULL
, &single_stepcode
, sizeof(single_stepcode
), 0);
790 ok(got_exception
== 3, "expected 3 single step exceptions, got %d\n", got_exception
);
792 /* test alignment exceptions */
794 run_exception_test(align_check_handler
, NULL
, align_check_code
, sizeof(align_check_code
), 0);
795 ok(got_exception
== 0, "got %d alignment faults, expected 0\n", got_exception
);
797 /* test direction flag */
799 run_exception_test(direction_flag_handler
, NULL
, direction_flag_code
, sizeof(direction_flag_code
), 0);
800 ok(got_exception
== 1, "got %d exceptions, expected 1\n", got_exception
);
802 /* test single stepping over hardware breakpoint */
803 memset(&ctx
, 0, sizeof(ctx
));
804 ctx
.Dr0
= (DWORD
) code_mem
; /* set hw bp on first nop */
806 ctx
.ContextFlags
= CONTEXT_DEBUG_REGISTERS
;
807 res
= pNtSetContextThread( GetCurrentThread(), &ctx
);
808 ok( res
== STATUS_SUCCESS
, "NtSetContextThread failed with %x\n", res
);
811 run_exception_test(bpx_handler
, NULL
, dummy_code
, sizeof(dummy_code
), 0);
812 ok( got_exception
== 4,"expected 4 exceptions, got %d\n", got_exception
);
814 /* test int3 handling */
815 run_exception_test(int3_handler
, NULL
, int3_code
, sizeof(int3_code
), 0);
818 static void test_debugger(void)
820 char cmdline
[MAX_PATH
];
821 PROCESS_INFORMATION pi
;
822 STARTUPINFOA si
= { 0 };
824 DWORD continuestatus
;
825 PVOID code_mem_address
= NULL
;
832 if(!pNtGetContextThread
|| !pNtSetContextThread
|| !pNtReadVirtualMemory
|| !pNtTerminateProcess
)
834 skip("NtGetContextThread, NtSetContextThread, NtReadVirtualMemory or NtTerminateProcess not found\n");
838 sprintf(cmdline
, "%s %s %s %p", my_argv
[0], my_argv
[1], "debuggee", &test_stage
);
839 ret
= CreateProcessA(NULL
, cmdline
, NULL
, NULL
, FALSE
, DEBUG_PROCESS
, NULL
, NULL
, &si
, &pi
);
840 ok(ret
, "could not create child process error: %u\n", GetLastError());
846 continuestatus
= DBG_CONTINUE
;
847 ok(WaitForDebugEvent(&de
, INFINITE
), "reading debug event\n");
849 if (de
.dwThreadId
!= pi
.dwThreadId
)
851 trace("event %d not coming from main thread, ignoring\n", de
.dwDebugEventCode
);
852 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, DBG_CONTINUE
);
856 if (de
.dwDebugEventCode
== CREATE_PROCESS_DEBUG_EVENT
)
858 if(de
.u
.CreateProcessInfo
.lpBaseOfImage
!= pNtCurrentTeb()->Peb
->ImageBaseAddress
)
860 skip("child process loaded at different address, terminating it\n");
861 pNtTerminateProcess(pi
.hProcess
, 0);
864 else if (de
.dwDebugEventCode
== EXCEPTION_DEBUG_EVENT
)
870 status
= pNtReadVirtualMemory(pi
.hProcess
, &code_mem
, &code_mem_address
,
871 sizeof(code_mem_address
), &size_read
);
872 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
873 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
874 sizeof(stage
), &size_read
);
875 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
877 ctx
.ContextFlags
= CONTEXT_FULL
;
878 status
= pNtGetContextThread(pi
.hThread
, &ctx
);
879 ok(!status
, "NtGetContextThread failed with 0x%x\n", status
);
881 trace("exception 0x%x at %p firstchance=%d Eip=0x%x, Eax=0x%x\n",
882 de
.u
.Exception
.ExceptionRecord
.ExceptionCode
,
883 de
.u
.Exception
.ExceptionRecord
.ExceptionAddress
, de
.u
.Exception
.dwFirstChance
, ctx
.Eip
, ctx
.Eax
);
887 ok(FALSE
, "got way too many exceptions, probably caught in an infinite loop, terminating child\n");
888 pNtTerminateProcess(pi
.hProcess
, 1);
890 else if (counter
>= 2) /* skip startup breakpoint */
894 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at %x instead of %p\n",
895 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
896 /* setting the context from debugger does not affect the context, the exception handlers gets */
897 /* uncomment once wine is fixed */
898 /* ctx.Eip = 0x12345; */
899 ctx
.Eax
= 0xf00f00f1;
901 /* let the debuggee handle the exception */
902 continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
906 if (de
.u
.Exception
.dwFirstChance
)
908 /* debugger gets first chance exception with unmodified ctx.Eip */
909 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at 0x%x instead of %p\n",
910 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
912 /* setting the context from debugger does not affect the context, the exception handlers gets */
913 /* uncomment once wine is fixed */
914 /* ctx.Eip = 0x12345; */
915 ctx
.Eax
= 0xf00f00f1;
917 /* pass exception to debuggee
918 * exception will not be handled and
919 * a second chance exception will be raised */
920 continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
924 /* debugger gets context after exception handler has played with it */
925 /* ctx.Eip is the same value the exception handler got */
926 if (de
.u
.Exception
.ExceptionRecord
.ExceptionCode
== EXCEPTION_BREAKPOINT
)
928 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xa ||
929 broken(is_wow64
&& (char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb),
930 "Eip at 0x%x instead of %p\n",
931 ctx
.Eip
, (char *)code_mem_address
+ 0xa);
932 /* need to fixup Eip for debuggee */
933 if ((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xa)
937 ok((char *)ctx
.Eip
== (char *)code_mem_address
+ 0xb, "Eip at 0x%x instead of %p\n",
938 ctx
.Eip
, (char *)code_mem_address
+ 0xb);
939 /* here we handle exception */
942 else if (stage
== 7 || stage
== 8)
944 ok(de
.u
.Exception
.ExceptionRecord
.ExceptionCode
== EXCEPTION_INVALID_HANDLE
,
945 "unexpected exception code %08x, expected %08x\n", de
.u
.Exception
.ExceptionRecord
.ExceptionCode
,
946 EXCEPTION_INVALID_HANDLE
);
947 ok(de
.u
.Exception
.ExceptionRecord
.NumberParameters
== 0,
948 "unexpected number of parameters %d, expected 0\n", de
.u
.Exception
.ExceptionRecord
.NumberParameters
);
950 if (stage
== 8) continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
953 ok(FALSE
, "unexpected stage %x\n", stage
);
955 status
= pNtSetContextThread(pi
.hThread
, &ctx
);
956 ok(!status
, "NtSetContextThread failed with 0x%x\n", status
);
959 else if (de
.dwDebugEventCode
== OUTPUT_DEBUG_STRING_EVENT
)
963 /* This will catch our DPRINTs, such as
964 * "WARNING: RtlpDphTargetDllsLogicInitialize at ..\..\lib\rtl\heappage.c:1283 is UNIMPLEMENTED!"
965 * so we need a full-size buffer to avoid a stack overflow
972 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
973 sizeof(stage
), &size_read
);
974 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
976 ok(!de
.u
.DebugString
.fUnicode
, "unexpected unicode debug string event\n");
977 ok(de
.u
.DebugString
.nDebugStringLength
< sizeof(buffer
) - 1, "buffer not large enough to hold %d bytes\n",
978 de
.u
.DebugString
.nDebugStringLength
);
980 memset(buffer
, 0, sizeof(buffer
));
981 status
= pNtReadVirtualMemory(pi
.hProcess
, de
.u
.DebugString
.lpDebugStringData
, buffer
,
982 de
.u
.DebugString
.nDebugStringLength
, &size_read
);
983 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
985 if (stage
== 3 || stage
== 4)
986 ok(!strcmp(buffer
, "Hello World"), "got unexpected debug string '%s'\n", buffer
);
987 else /* ignore unrelated debug strings like 'SHIMVIEW: ShimInfo(Complete)' */
988 ok(strstr(buffer
, "SHIMVIEW") != NULL
, "unexpected stage %x, got debug string event '%s'\n", stage
, buffer
);
990 if (stage
== 4) continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
992 else if (de
.dwDebugEventCode
== RIP_EVENT
)
996 status
= pNtReadVirtualMemory(pi
.hProcess
, &test_stage
, &stage
,
997 sizeof(stage
), &size_read
);
998 ok(!status
,"NtReadVirtualMemory failed with 0x%x\n", status
);
1000 if (stage
== 5 || stage
== 6)
1002 ok(de
.u
.RipInfo
.dwError
== 0x11223344, "got unexpected rip error code %08x, expected %08x\n",
1003 de
.u
.RipInfo
.dwError
, 0x11223344);
1004 ok(de
.u
.RipInfo
.dwType
== 0x55667788, "got unexpected rip type %08x, expected %08x\n",
1005 de
.u
.RipInfo
.dwType
, 0x55667788);
1008 ok(FALSE
, "unexpected stage %x\n", stage
);
1010 if (stage
== 6) continuestatus
= DBG_EXCEPTION_NOT_HANDLED
;
1013 ContinueDebugEvent(de
.dwProcessId
, de
.dwThreadId
, continuestatus
);
1015 } while (de
.dwDebugEventCode
!= EXIT_PROCESS_DEBUG_EVENT
);
1017 winetest_wait_child_process( pi
.hProcess
);
1018 ret
= CloseHandle(pi
.hThread
);
1019 ok(ret
, "error %u\n", GetLastError());
1020 ret
= CloseHandle(pi
.hProcess
);
1021 ok(ret
, "error %u\n", GetLastError());
1026 static DWORD
simd_fault_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1027 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1029 int *stage
= *(int **)(frame
+ 1);
1034 /* fault while executing sse instruction */
1035 context
->Eip
+= 3; /* skip addps */
1036 return ExceptionContinueExecution
;
1039 /* stage 2 - divide by zero fault */
1040 if( rec
->ExceptionCode
== EXCEPTION_ILLEGAL_INSTRUCTION
)
1041 skip("system doesn't support SIMD exceptions\n");
1043 ok( rec
->ExceptionCode
== STATUS_FLOAT_MULTIPLE_TRAPS
,
1044 "exception code: %#x, should be %#x\n",
1045 rec
->ExceptionCode
, STATUS_FLOAT_MULTIPLE_TRAPS
);
1046 ok( rec
->NumberParameters
== 1 || broken(is_wow64
&& rec
->NumberParameters
== 2),
1047 "# of params: %i, should be 1\n",
1048 rec
->NumberParameters
);
1049 if( rec
->NumberParameters
== 1 )
1050 ok( rec
->ExceptionInformation
[0] == 0, "param #1: %lx, should be 0\n", rec
->ExceptionInformation
[0]);
1053 context
->Eip
+= 3; /* skip divps */
1055 return ExceptionContinueExecution
;
1058 static const BYTE simd_exception_test
[] = {
1059 0x83, 0xec, 0x4, /* sub $0x4, %esp */
1060 0x0f, 0xae, 0x1c, 0x24, /* stmxcsr (%esp) */
1061 0x66, 0x81, 0x24, 0x24, 0xff, 0xfd, /* andw $0xfdff,(%esp) * enable divide by */
1062 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) * zero exceptions */
1063 0x6a, 0x01, /* push $0x1 */
1064 0x6a, 0x01, /* push $0x1 */
1065 0x6a, 0x01, /* push $0x1 */
1066 0x6a, 0x01, /* push $0x1 */
1067 0x0f, 0x10, 0x0c, 0x24, /* movups (%esp),%xmm1 * fill dividend */
1068 0x0f, 0x57, 0xc0, /* xorps %xmm0,%xmm0 * clear divisor */
1069 0x0f, 0x5e, 0xc8, /* divps %xmm0,%xmm1 * generate fault */
1070 0x83, 0xc4, 0x10, /* add $0x10,%esp */
1071 0x66, 0x81, 0x0c, 0x24, 0x00, 0x02, /* orw $0x200,(%esp) * disable exceptions */
1072 0x0f, 0xae, 0x14, 0x24, /* ldmxcsr (%esp) */
1073 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1077 static const BYTE sse_check
[] = {
1078 0x0f, 0x58, 0xc8, /* addps %xmm0,%xmm1 */
1082 static void test_simd_exceptions(void)
1086 /* test if CPU & OS can do sse */
1089 run_exception_test(simd_fault_handler
, &stage
, sse_check
, sizeof(sse_check
), 0);
1091 skip("system doesn't support SSE\n");
1095 /* generate a SIMD exception */
1098 run_exception_test(simd_fault_handler
, &stage
, simd_exception_test
,
1099 sizeof(simd_exception_test
), 0);
1100 ok( got_exception
== 1, "got exception: %i, should be 1\n", got_exception
);
1103 struct fpu_exception_info
1105 DWORD exception_code
;
1106 DWORD exception_offset
;
1110 static DWORD
fpu_exception_handler(EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1111 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1113 struct fpu_exception_info
*info
= *(struct fpu_exception_info
**)(frame
+ 1);
1115 info
->exception_code
= rec
->ExceptionCode
;
1116 info
->exception_offset
= (BYTE
*)rec
->ExceptionAddress
- (BYTE
*)code_mem
;
1117 info
->eip_offset
= context
->Eip
- (DWORD
)code_mem
;
1120 return ExceptionContinueExecution
;
1123 static void test_fpu_exceptions(void)
1125 static const BYTE fpu_exception_test_ie
[] =
1127 0x83, 0xec, 0x04, /* sub $0x4,%esp */
1128 0x66, 0xc7, 0x04, 0x24, 0xfe, 0x03, /* movw $0x3fe,(%esp) */
1129 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
1130 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
1131 0xd9, 0xee, /* fldz */
1132 0xd9, 0xe8, /* fld1 */
1133 0xde, 0xf1, /* fdivp */
1134 0xdd, 0xd8, /* fstp %st(0) */
1135 0xdd, 0xd8, /* fstp %st(0) */
1137 0xdb, 0xe2, /* fnclex */
1138 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
1139 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1143 static const BYTE fpu_exception_test_de
[] =
1145 0x83, 0xec, 0x04, /* sub $0x4,%esp */
1146 0x66, 0xc7, 0x04, 0x24, 0xfb, 0x03, /* movw $0x3fb,(%esp) */
1147 0x9b, 0xd9, 0x7c, 0x24, 0x02, /* fstcw 0x2(%esp) */
1148 0xd9, 0x2c, 0x24, /* fldcw (%esp) */
1149 0xdd, 0xd8, /* fstp %st(0) */
1150 0xd9, 0xee, /* fldz */
1151 0xd9, 0xe8, /* fld1 */
1152 0xde, 0xf1, /* fdivp */
1154 0xdb, 0xe2, /* fnclex */
1155 0xdd, 0xd8, /* fstp %st(0) */
1156 0xdd, 0xd8, /* fstp %st(0) */
1157 0xd9, 0x6c, 0x24, 0x02, /* fldcw 0x2(%esp) */
1158 0x83, 0xc4, 0x04, /* add $0x4,%esp */
1162 struct fpu_exception_info info
;
1164 memset(&info
, 0, sizeof(info
));
1165 run_exception_test(fpu_exception_handler
, &info
, fpu_exception_test_ie
, sizeof(fpu_exception_test_ie
), 0);
1166 ok(info
.exception_code
== EXCEPTION_FLT_STACK_CHECK
,
1167 "Got exception code %#x, expected EXCEPTION_FLT_STACK_CHECK\n", info
.exception_code
);
1168 ok(info
.exception_offset
== 0x19 ||
1169 broken( is_wow64
&& info
.exception_offset
== info
.eip_offset
),
1170 "Got exception offset %#x, expected 0x19\n", info
.exception_offset
);
1171 ok(info
.eip_offset
== 0x1b, "Got EIP offset %#x, expected 0x1b\n", info
.eip_offset
);
1173 memset(&info
, 0, sizeof(info
));
1174 run_exception_test(fpu_exception_handler
, &info
, fpu_exception_test_de
, sizeof(fpu_exception_test_de
), 0);
1175 ok(info
.exception_code
== EXCEPTION_FLT_DIVIDE_BY_ZERO
,
1176 "Got exception code %#x, expected EXCEPTION_FLT_DIVIDE_BY_ZERO\n", info
.exception_code
);
1177 ok(info
.exception_offset
== 0x17 ||
1178 broken( is_wow64
&& info
.exception_offset
== info
.eip_offset
),
1179 "Got exception offset %#x, expected 0x17\n", info
.exception_offset
);
1180 ok(info
.eip_offset
== 0x19, "Got EIP offset %#x, expected 0x19\n", info
.eip_offset
);
1183 struct dpe_exception_info
{
1184 BOOL exception_caught
;
1185 DWORD exception_info
;
1188 static DWORD
dpe_exception_handler(EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
1189 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
1192 struct dpe_exception_info
*info
= *(struct dpe_exception_info
**)(frame
+ 1);
1194 ok(rec
->ExceptionCode
== EXCEPTION_ACCESS_VIOLATION
,
1195 "Exception code %08x\n", rec
->ExceptionCode
);
1196 ok(rec
->NumberParameters
== 2,
1197 "Parameter count: %d\n", rec
->NumberParameters
);
1198 ok((LPVOID
)rec
->ExceptionInformation
[1] == code_mem
,
1199 "Exception address: %p, expected %p\n",
1200 (LPVOID
)rec
->ExceptionInformation
[1], code_mem
);
1202 info
->exception_info
= rec
->ExceptionInformation
[0];
1203 info
->exception_caught
= TRUE
;
1205 VirtualProtect(code_mem
, 1, PAGE_EXECUTE_READWRITE
, &old_prot
);
1206 return ExceptionContinueExecution
;
1209 static void test_dpe_exceptions(void)
1211 static const BYTE single_ret
[] = {0xC3};
1212 struct dpe_exception_info info
;
1214 BOOL has_hw_support
;
1215 BOOL is_permanent
= FALSE
, can_test_without
= TRUE
, can_test_with
= TRUE
;
1219 /* Query DEP with len too small */
1220 stat
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
- 1, &len
);
1221 if(stat
== STATUS_INVALID_INFO_CLASS
)
1223 skip("This software platform does not support DEP\n");
1226 ok(stat
== STATUS_INFO_LENGTH_MISMATCH
, "buffer too small: %08x\n", stat
);
1229 stat
= pNtQueryInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
, &len
);
1230 ok(stat
== STATUS_SUCCESS
, "querying DEP: status %08x\n", stat
);
1231 if(stat
== STATUS_SUCCESS
)
1233 ok(len
== sizeof val
, "returned length: %d\n", len
);
1234 if(val
& MEM_EXECUTE_OPTION_PERMANENT
)
1236 skip("toggling DEP impossible - status locked\n");
1237 is_permanent
= TRUE
;
1238 if(val
& MEM_EXECUTE_OPTION_DISABLE
)
1239 can_test_without
= FALSE
;
1241 can_test_with
= FALSE
;
1248 val
= MEM_EXECUTE_OPTION_DISABLE
;
1249 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1250 ok(stat
== STATUS_SUCCESS
, "enabling DEP: status %08x\n", stat
);
1255 /* Try access to locked page with DEP on*/
1256 info
.exception_caught
= FALSE
;
1257 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_NOACCESS
);
1258 ok(info
.exception_caught
== TRUE
, "Execution of disabled memory succeeded\n");
1259 ok(info
.exception_info
== EXCEPTION_READ_FAULT
||
1260 info
.exception_info
== EXCEPTION_EXECUTE_FAULT
,
1261 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1262 has_hw_support
= info
.exception_info
== EXCEPTION_EXECUTE_FAULT
;
1263 trace("DEP hardware support: %s\n", has_hw_support
?"Yes":"No");
1265 /* Try execution of data with DEP on*/
1266 info
.exception_caught
= FALSE
;
1267 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_READWRITE
);
1270 ok(info
.exception_caught
== TRUE
, "Execution of data memory succeeded\n");
1271 ok(info
.exception_info
== EXCEPTION_EXECUTE_FAULT
,
1272 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1275 ok(info
.exception_caught
== FALSE
, "Execution trapped without hardware support\n");
1278 skip("DEP is in AlwaysOff state\n");
1283 val
= MEM_EXECUTE_OPTION_ENABLE
;
1284 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1285 ok(stat
== STATUS_SUCCESS
, "disabling DEP: status %08x\n", stat
);
1288 /* page is read without exec here */
1289 if(can_test_without
)
1291 /* Try execution of data with DEP off */
1292 info
.exception_caught
= FALSE
;
1293 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_READWRITE
);
1294 ok(info
.exception_caught
== FALSE
, "Execution trapped with DEP turned off\n");
1296 /* Try access to locked page with DEP off - error code is different than
1297 with hardware DEP on */
1298 info
.exception_caught
= FALSE
;
1299 run_exception_test(dpe_exception_handler
, &info
, single_ret
, sizeof(single_ret
), PAGE_NOACCESS
);
1300 ok(info
.exception_caught
== TRUE
, "Execution of disabled memory succeeded\n");
1301 ok(info
.exception_info
== EXCEPTION_READ_FAULT
,
1302 "Access violation type: %08x\n", (unsigned)info
.exception_info
);
1305 skip("DEP is in AlwaysOn state\n");
1309 /* Turn off DEP permanently */
1310 val
= MEM_EXECUTE_OPTION_ENABLE
| MEM_EXECUTE_OPTION_PERMANENT
;
1311 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1312 ok(stat
== STATUS_SUCCESS
, "disabling DEP permanently: status %08x\n", stat
);
1315 /* Try to turn off DEP */
1316 val
= MEM_EXECUTE_OPTION_ENABLE
;
1317 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1318 ok(stat
== STATUS_ACCESS_DENIED
, "disabling DEP while permanent: status %08x\n", stat
);
1320 /* Try to turn on DEP */
1321 val
= MEM_EXECUTE_OPTION_DISABLE
;
1322 stat
= pNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags
, &val
, sizeof val
);
1323 ok(stat
== STATUS_ACCESS_DENIED
, "enabling DEP while permanent: status %08x\n", stat
);
1326 #elif defined(__x86_64__)
1328 #define UNW_FLAG_NHANDLER 0
1329 #define UNW_FLAG_EHANDLER 1
1330 #define UNW_FLAG_UHANDLER 2
1331 #define UNW_FLAG_CHAININFO 4
1333 #define UWOP_PUSH_NONVOL 0
1334 #define UWOP_ALLOC_LARGE 1
1335 #define UWOP_ALLOC_SMALL 2
1336 #define UWOP_SET_FPREG 3
1337 #define UWOP_SAVE_NONVOL 4
1338 #define UWOP_SAVE_NONVOL_FAR 5
1339 #define UWOP_SAVE_XMM128 8
1340 #define UWOP_SAVE_XMM128_FAR 9
1341 #define UWOP_PUSH_MACHFRAME 10
1345 int rip_offset
; /* rip offset from code start */
1346 int rbp_offset
; /* rbp offset from stack pointer */
1347 int handler
; /* expect handler to be set? */
1348 int rip
; /* expected final rip value */
1349 int frame
; /* expected frame return value */
1350 int regs
[8][2]; /* expected values for registers */
1355 const BYTE
*function
;
1356 size_t function_size
;
1357 const BYTE
*unwind_info
;
1358 const struct results
*results
;
1359 unsigned int nb_results
;
1364 rax
, rcx
, rdx
, rbx
, rsp
, rbp
, rsi
, rdi
,
1365 r8
, r9
, r10
, r11
, r12
, r13
, r14
, r15
1368 static const char * const reg_names
[16] =
1370 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
1371 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
1374 #define UWOP(code,info) (UWOP_##code | ((info) << 4))
1376 static void call_virtual_unwind( int testnum
, const struct unwind_test
*test
)
1378 static const int code_offset
= 1024;
1379 static const int unwind_offset
= 2048;
1380 void *handler
, *data
;
1382 RUNTIME_FUNCTION runtime_func
;
1383 KNONVOLATILE_CONTEXT_POINTERS ctx_ptr
;
1385 ULONG64 fake_stack
[256];
1386 ULONG64 frame
, orig_rip
, orig_rbp
, unset_reg
;
1387 UINT unwind_size
= 4 + 2 * test
->unwind_info
[2] + 8;
1389 memcpy( (char *)code_mem
+ code_offset
, test
->function
, test
->function_size
);
1390 memcpy( (char *)code_mem
+ unwind_offset
, test
->unwind_info
, unwind_size
);
1392 runtime_func
.BeginAddress
= code_offset
;
1393 runtime_func
.EndAddress
= code_offset
+ test
->function_size
;
1394 runtime_func
.UnwindData
= unwind_offset
;
1396 trace( "code: %p stack: %p\n", code_mem
, fake_stack
);
1398 for (i
= 0; i
< test
->nb_results
; i
++)
1400 memset( &ctx_ptr
, 0, sizeof(ctx_ptr
) );
1401 memset( &context
, 0x55, sizeof(context
) );
1402 memset( &unset_reg
, 0x55, sizeof(unset_reg
) );
1403 for (j
= 0; j
< 256; j
++) fake_stack
[j
] = j
* 8;
1405 context
.Rsp
= (ULONG_PTR
)fake_stack
;
1406 context
.Rbp
= (ULONG_PTR
)fake_stack
+ test
->results
[i
].rbp_offset
;
1407 orig_rbp
= context
.Rbp
;
1408 orig_rip
= (ULONG64
)code_mem
+ code_offset
+ test
->results
[i
].rip_offset
;
1410 trace( "%u/%u: rip=%p (%02x) rbp=%p rsp=%p\n", testnum
, i
,
1411 (void *)orig_rip
, *(BYTE
*)orig_rip
, (void *)orig_rbp
, (void *)context
.Rsp
);
1413 data
= (void *)0xdeadbeef;
1414 handler
= RtlVirtualUnwind( UNW_FLAG_EHANDLER
, (ULONG64
)code_mem
, orig_rip
,
1415 &runtime_func
, &context
, &data
, &frame
, &ctx_ptr
);
1416 if (test
->results
[i
].handler
)
1418 ok( (char *)handler
== (char *)code_mem
+ 0x200,
1419 "%u/%u: wrong handler %p/%p\n", testnum
, i
, handler
, (char *)code_mem
+ 0x200 );
1420 if (handler
) ok( *(DWORD
*)data
== 0x08070605,
1421 "%u/%u: wrong handler data %p\n", testnum
, i
, data
);
1425 ok( handler
== NULL
, "%u/%u: handler %p instead of NULL\n", testnum
, i
, handler
);
1426 ok( data
== (void *)0xdeadbeef, "%u/%u: handler data set to %p\n", testnum
, i
, data
);
1429 ok( context
.Rip
== test
->results
[i
].rip
, "%u/%u: wrong rip %p/%x\n",
1430 testnum
, i
, (void *)context
.Rip
, test
->results
[i
].rip
);
1431 ok( frame
== (ULONG64
)fake_stack
+ test
->results
[i
].frame
, "%u/%u: wrong frame %p/%p\n",
1432 testnum
, i
, (void *)frame
, (char *)fake_stack
+ test
->results
[i
].frame
);
1434 for (j
= 0; j
< 16; j
++)
1436 static const UINT nb_regs
= sizeof(test
->results
[i
].regs
) / sizeof(test
->results
[i
].regs
[0]);
1438 for (k
= 0; k
< nb_regs
; k
++)
1440 if (test
->results
[i
].regs
[k
][0] == -1)
1445 if (test
->results
[i
].regs
[k
][0] == j
) break;
1448 if (j
== rsp
) /* rsp is special */
1450 ok( !ctx_ptr
.u2
.IntegerContext
[j
],
1451 "%u/%u: rsp should not be set in ctx_ptr\n", testnum
, i
);
1452 ok( context
.Rsp
== (ULONG64
)fake_stack
+ test
->results
[i
].regs
[k
][1],
1453 "%u/%u: register rsp wrong %p/%p\n",
1454 testnum
, i
, (void *)context
.Rsp
, (char *)fake_stack
+ test
->results
[i
].regs
[k
][1] );
1458 if (ctx_ptr
.u2
.IntegerContext
[j
])
1460 ok( k
< nb_regs
, "%u/%u: register %s should not be set to %lx\n",
1461 testnum
, i
, reg_names
[j
], *(&context
.Rax
+ j
) );
1463 ok( *(&context
.Rax
+ j
) == test
->results
[i
].regs
[k
][1],
1464 "%u/%u: register %s wrong %p/%x\n",
1465 testnum
, i
, reg_names
[j
], (void *)*(&context
.Rax
+ j
), test
->results
[i
].regs
[k
][1] );
1469 ok( k
== nb_regs
, "%u/%u: register %s should be set\n", testnum
, i
, reg_names
[j
] );
1471 ok( context
.Rbp
== orig_rbp
, "%u/%u: register rbp wrong %p/unset\n",
1472 testnum
, i
, (void *)context
.Rbp
);
1474 ok( *(&context
.Rax
+ j
) == unset_reg
,
1475 "%u/%u: register %s wrong %p/unset\n",
1476 testnum
, i
, reg_names
[j
], (void *)*(&context
.Rax
+ j
));
1482 static void test_virtual_unwind(void)
1484 static const BYTE function_0
[] =
1486 0xff, 0xf5, /* 00: push %rbp */
1487 0x48, 0x81, 0xec, 0x10, 0x01, 0x00, 0x00, /* 02: sub $0x110,%rsp */
1488 0x48, 0x8d, 0x6c, 0x24, 0x30, /* 09: lea 0x30(%rsp),%rbp */
1489 0x48, 0x89, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 0e: mov %rbx,0xf0(%rbp) */
1490 0x48, 0x89, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 15: mov %rsi,0xf8(%rbp) */
1492 0x48, 0x8b, 0x9d, 0xf0, 0x00, 0x00, 0x00, /* 1d: mov 0xf0(%rbp),%rbx */
1493 0x48, 0x8b, 0xb5, 0xf8, 0x00, 0x00, 0x00, /* 24: mov 0xf8(%rbp),%rsi */
1494 0x48, 0x8d, 0xa5, 0xe0, 0x00, 0x00, 0x00, /* 2b: lea 0xe0(%rbp),%rsp */
1495 0x5d, /* 32: pop %rbp */
1499 static const BYTE unwind_info_0
[] =
1501 1 | (UNW_FLAG_EHANDLER
<< 3), /* version + flags */
1502 0x1c, /* prolog size */
1503 8, /* opcode count */
1504 (0x03 << 4) | rbp
, /* frame reg rbp offset 0x30 */
1506 0x1c, UWOP(SAVE_NONVOL
, rsi
), 0x25, 0, /* 1c: mov %rsi,0x128(%rsp) */
1507 0x15, UWOP(SAVE_NONVOL
, rbx
), 0x24, 0, /* 15: mov %rbx,0x120(%rsp) */
1508 0x0e, UWOP(SET_FPREG
, rbp
), /* 0e: lea 0x30(%rsp),rbp */
1509 0x09, UWOP(ALLOC_LARGE
, 0), 0x22, 0, /* 09: sub $0x110,%rsp */
1510 0x02, UWOP(PUSH_NONVOL
, rbp
), /* 02: push %rbp */
1512 0x00, 0x02, 0x00, 0x00, /* handler */
1513 0x05, 0x06, 0x07, 0x08, /* data */
1516 static const struct results results_0
[] =
1518 /* offset rbp handler rip frame registers */
1519 { 0x00, 0x40, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1520 { 0x02, 0x40, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbp
,0x000}, {-1,-1} }},
1521 { 0x09, 0x40, FALSE
, 0x118, 0x000, { {rsp
,0x120}, {rbp
,0x110}, {-1,-1} }},
1522 { 0x0e, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {-1,-1} }},
1523 { 0x15, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {-1,-1} }},
1524 { 0x1c, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1525 { 0x1d, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1526 { 0x24, 0x40, TRUE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {rbx
,0x130}, {rsi
,0x138}, {-1,-1}}},
1527 { 0x2b, 0x40, FALSE
, 0x128, 0x010, { {rsp
,0x130}, {rbp
,0x120}, {-1,-1}}},
1528 { 0x32, 0x40, FALSE
, 0x008, 0x010, { {rsp
,0x010}, {rbp
,0x000}, {-1,-1}}},
1529 { 0x33, 0x40, FALSE
, 0x000, 0x010, { {rsp
,0x008}, {-1,-1}}},
1533 static const BYTE function_1
[] =
1535 0x53, /* 00: push %rbx */
1536 0x55, /* 01: push %rbp */
1537 0x56, /* 02: push %rsi */
1538 0x57, /* 03: push %rdi */
1539 0x41, 0x54, /* 04: push %r12 */
1540 0x48, 0x83, 0xec, 0x30, /* 06: sub $0x30,%rsp */
1541 0x90, 0x90, /* 0a: nop; nop */
1542 0x48, 0x83, 0xc4, 0x30, /* 0c: add $0x30,%rsp */
1543 0x41, 0x5c, /* 10: pop %r12 */
1544 0x5f, /* 12: pop %rdi */
1545 0x5e, /* 13: pop %rsi */
1546 0x5d, /* 14: pop %rbp */
1547 0x5b, /* 15: pop %rbx */
1551 static const BYTE unwind_info_1
[] =
1553 1 | (UNW_FLAG_EHANDLER
<< 3), /* version + flags */
1554 0x0a, /* prolog size */
1555 6, /* opcode count */
1558 0x0a, UWOP(ALLOC_SMALL
, 5), /* 0a: sub $0x30,%rsp */
1559 0x06, UWOP(PUSH_NONVOL
, r12
), /* 06: push %r12 */
1560 0x04, UWOP(PUSH_NONVOL
, rdi
), /* 04: push %rdi */
1561 0x03, UWOP(PUSH_NONVOL
, rsi
), /* 03: push %rsi */
1562 0x02, UWOP(PUSH_NONVOL
, rbp
), /* 02: push %rbp */
1563 0x01, UWOP(PUSH_NONVOL
, rbx
), /* 01: push %rbx */
1565 0x00, 0x02, 0x00, 0x00, /* handler */
1566 0x05, 0x06, 0x07, 0x08, /* data */
1569 static const struct results results_1
[] =
1571 /* offset rbp handler rip frame registers */
1572 { 0x00, 0x50, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1573 { 0x01, 0x50, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbx
,0x000}, {-1,-1} }},
1574 { 0x02, 0x50, FALSE
, 0x010, 0x000, { {rsp
,0x018}, {rbx
,0x008}, {rbp
,0x000}, {-1,-1} }},
1575 { 0x03, 0x50, FALSE
, 0x018, 0x000, { {rsp
,0x020}, {rbx
,0x010}, {rbp
,0x008}, {rsi
,0x000}, {-1,-1} }},
1576 { 0x04, 0x50, FALSE
, 0x020, 0x000, { {rsp
,0x028}, {rbx
,0x018}, {rbp
,0x010}, {rsi
,0x008}, {rdi
,0x000}, {-1,-1} }},
1577 { 0x06, 0x50, FALSE
, 0x028, 0x000, { {rsp
,0x030}, {rbx
,0x020}, {rbp
,0x018}, {rsi
,0x010}, {rdi
,0x008}, {r12
,0x000}, {-1,-1} }},
1578 { 0x0a, 0x50, TRUE
, 0x058, 0x000, { {rsp
,0x060}, {rbx
,0x050}, {rbp
,0x048}, {rsi
,0x040}, {rdi
,0x038}, {r12
,0x030}, {-1,-1} }},
1579 { 0x0c, 0x50, FALSE
, 0x058, 0x000, { {rsp
,0x060}, {rbx
,0x050}, {rbp
,0x048}, {rsi
,0x040}, {rdi
,0x038}, {r12
,0x030}, {-1,-1} }},
1580 { 0x10, 0x50, FALSE
, 0x028, 0x000, { {rsp
,0x030}, {rbx
,0x020}, {rbp
,0x018}, {rsi
,0x010}, {rdi
,0x008}, {r12
,0x000}, {-1,-1} }},
1581 { 0x12, 0x50, FALSE
, 0x020, 0x000, { {rsp
,0x028}, {rbx
,0x018}, {rbp
,0x010}, {rsi
,0x008}, {rdi
,0x000}, {-1,-1} }},
1582 { 0x13, 0x50, FALSE
, 0x018, 0x000, { {rsp
,0x020}, {rbx
,0x010}, {rbp
,0x008}, {rsi
,0x000}, {-1,-1} }},
1583 { 0x14, 0x50, FALSE
, 0x010, 0x000, { {rsp
,0x018}, {rbx
,0x008}, {rbp
,0x000}, {-1,-1} }},
1584 { 0x15, 0x50, FALSE
, 0x008, 0x000, { {rsp
,0x010}, {rbx
,0x000}, {-1,-1} }},
1585 { 0x16, 0x50, FALSE
, 0x000, 0x000, { {rsp
,0x008}, {-1,-1} }},
1588 static const struct unwind_test tests
[] =
1590 { function_0
, sizeof(function_0
), unwind_info_0
,
1591 results_0
, sizeof(results_0
)/sizeof(results_0
[0]) },
1592 { function_1
, sizeof(function_1
), unwind_info_1
,
1593 results_1
, sizeof(results_1
)/sizeof(results_1
[0]) }
1597 for (i
= 0; i
< sizeof(tests
)/sizeof(tests
[0]); i
++)
1598 call_virtual_unwind( i
, &tests
[i
] );
1601 static RUNTIME_FUNCTION
* CALLBACK
dynamic_unwind_callback( DWORD64 pc
, PVOID context
)
1603 static const int code_offset
= 1024;
1604 static RUNTIME_FUNCTION runtime_func
;
1605 (*(DWORD
*)context
)++;
1607 runtime_func
.BeginAddress
= code_offset
+ 16;
1608 runtime_func
.EndAddress
= code_offset
+ 32;
1609 runtime_func
.UnwindData
= 0;
1610 return &runtime_func
;
1613 static void test_dynamic_unwind(void)
1615 static const int code_offset
= 1024;
1616 char buf
[sizeof(RUNTIME_FUNCTION
) + 4];
1617 RUNTIME_FUNCTION
*runtime_func
, *func
;
1618 ULONG_PTR table
, base
;
1621 /* Test RtlAddFunctionTable with aligned RUNTIME_FUNCTION pointer */
1622 runtime_func
= (RUNTIME_FUNCTION
*)buf
;
1623 runtime_func
->BeginAddress
= code_offset
;
1624 runtime_func
->EndAddress
= code_offset
+ 16;
1625 runtime_func
->UnwindData
= 0;
1626 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1627 "RtlAddFunctionTable failed for runtime_func = %p (aligned)\n", runtime_func
);
1629 /* Lookup function outside of any function table */
1631 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 16, &base
, NULL
);
1633 "RtlLookupFunctionEntry returned unexpected function, expected: NULL, got: %p\n", func
);
1634 ok( !base
|| broken(base
== 0xdeadbeef),
1635 "RtlLookupFunctionEntry modified base address, expected: 0, got: %lx\n", base
);
1637 /* Test with pointer inside of our function */
1639 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 8, &base
, NULL
);
1640 ok( func
== runtime_func
,
1641 "RtlLookupFunctionEntry didn't return expected function, expected: %p, got: %p\n", runtime_func
, func
);
1642 ok( base
== (ULONG_PTR
)code_mem
,
1643 "RtlLookupFunctionEntry returned invalid base, expected: %lx, got: %lx\n", (ULONG_PTR
)code_mem
, base
);
1645 /* Test RtlDeleteFunctionTable */
1646 ok( pRtlDeleteFunctionTable( runtime_func
),
1647 "RtlDeleteFunctionTable failed for runtime_func = %p (aligned)\n", runtime_func
);
1648 ok( !pRtlDeleteFunctionTable( runtime_func
),
1649 "RtlDeleteFunctionTable returned success for nonexistent table runtime_func = %p\n", runtime_func
);
1651 /* Unaligned RUNTIME_FUNCTION pointer */
1652 runtime_func
= (RUNTIME_FUNCTION
*)((ULONG_PTR
)buf
| 0x3);
1653 runtime_func
->BeginAddress
= code_offset
;
1654 runtime_func
->EndAddress
= code_offset
+ 16;
1655 runtime_func
->UnwindData
= 0;
1656 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1657 "RtlAddFunctionTable failed for runtime_func = %p (unaligned)\n", runtime_func
);
1658 ok( pRtlDeleteFunctionTable( runtime_func
),
1659 "RtlDeleteFunctionTable failed for runtime_func = %p (unaligned)\n", runtime_func
);
1661 /* Attempt to insert the same entry twice */
1662 runtime_func
= (RUNTIME_FUNCTION
*)buf
;
1663 runtime_func
->BeginAddress
= code_offset
;
1664 runtime_func
->EndAddress
= code_offset
+ 16;
1665 runtime_func
->UnwindData
= 0;
1666 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1667 "RtlAddFunctionTable failed for runtime_func = %p (first attempt)\n", runtime_func
);
1668 ok( pRtlAddFunctionTable( runtime_func
, 1, (ULONG_PTR
)code_mem
),
1669 "RtlAddFunctionTable failed for runtime_func = %p (second attempt)\n", runtime_func
);
1670 ok( pRtlDeleteFunctionTable( runtime_func
),
1671 "RtlDeleteFunctionTable failed for runtime_func = %p (first attempt)\n", runtime_func
);
1672 ok( pRtlDeleteFunctionTable( runtime_func
),
1673 "RtlDeleteFunctionTable failed for runtime_func = %p (second attempt)\n", runtime_func
);
1674 ok( !pRtlDeleteFunctionTable( runtime_func
),
1675 "RtlDeleteFunctionTable returned success for nonexistent table runtime_func = %p\n", runtime_func
);
1677 /* Test RtlInstallFunctionTableCallback with both low bits unset */
1678 table
= (ULONG_PTR
)code_mem
;
1679 ok( !pRtlInstallFunctionTableCallback( table
, (ULONG_PTR
)code_mem
, code_offset
+ 32, &dynamic_unwind_callback
, (PVOID
*)&count
, NULL
),
1680 "RtlInstallFunctionTableCallback returned success for table = %lx\n", table
);
1682 /* Test RtlInstallFunctionTableCallback with both low bits set */
1683 table
= (ULONG_PTR
)code_mem
| 0x3;
1684 ok( pRtlInstallFunctionTableCallback( table
, (ULONG_PTR
)code_mem
, code_offset
+ 32, &dynamic_unwind_callback
, (PVOID
*)&count
, NULL
),
1685 "RtlInstallFunctionTableCallback failed for table = %lx\n", table
);
1687 /* Lookup function outside of any function table */
1690 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 32, &base
, NULL
);
1692 "RtlLookupFunctionEntry returned unexpected function, expected: NULL, got: %p\n", func
);
1693 ok( !base
|| broken(base
== 0xdeadbeef),
1694 "RtlLookupFunctionEntry modified base address, expected: 0, got: %lx\n", base
);
1696 "RtlLookupFunctionEntry issued %d unexpected calls to dynamic_unwind_callback\n", count
);
1698 /* Test with pointer inside of our function */
1701 func
= pRtlLookupFunctionEntry( (ULONG_PTR
)code_mem
+ code_offset
+ 24, &base
, NULL
);
1702 ok( func
!= NULL
&& func
->BeginAddress
== code_offset
+ 16 && func
->EndAddress
== code_offset
+ 32,
1703 "RtlLookupFunctionEntry didn't return expected function, got: %p\n", func
);
1704 ok( base
== (ULONG_PTR
)code_mem
,
1705 "RtlLookupFunctionEntry returned invalid base, expected: %lx, got: %lx\n", (ULONG_PTR
)code_mem
, base
);
1707 "RtlLookupFunctionEntry issued %d calls to dynamic_unwind_callback, expected: 1\n", count
);
1709 /* Clean up again */
1710 ok( pRtlDeleteFunctionTable( (PRUNTIME_FUNCTION
)table
),
1711 "RtlDeleteFunctionTable failed for table = %p\n", (PVOID
)table
);
1712 ok( !pRtlDeleteFunctionTable( (PRUNTIME_FUNCTION
)table
),
1713 "RtlDeleteFunctionTable returned success for nonexistent table = %p\n", (PVOID
)table
);
1717 #endif /* __x86_64__ */
1719 #if defined(__i386__) || defined(__x86_64__)
1720 static DWORD outputdebugstring_exceptions
;
1722 static LONG CALLBACK
outputdebugstring_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
1724 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
1725 trace("vect. handler %08x addr:%p\n", rec
->ExceptionCode
, rec
->ExceptionAddress
);
1727 ok(rec
->ExceptionCode
== DBG_PRINTEXCEPTION_C
, "ExceptionCode is %08x instead of %08x\n",
1728 rec
->ExceptionCode
, DBG_PRINTEXCEPTION_C
);
1729 ok(rec
->NumberParameters
== 2, "ExceptionParameters is %d instead of 2\n", rec
->NumberParameters
);
1730 ok(rec
->ExceptionInformation
[0] == 12, "ExceptionInformation[0] = %d instead of 12\n", (DWORD
)rec
->ExceptionInformation
[0]);
1731 ok(!strcmp((char *)rec
->ExceptionInformation
[1], "Hello World"),
1732 "ExceptionInformation[1] = '%s' instead of 'Hello World'\n", (char *)rec
->ExceptionInformation
[1]);
1734 outputdebugstring_exceptions
++;
1735 return EXCEPTION_CONTINUE_SEARCH
;
1738 static void test_outputdebugstring(DWORD numexc
)
1740 PVOID vectored_handler
;
1742 if (!pRtlAddVectoredExceptionHandler
|| !pRtlRemoveVectoredExceptionHandler
)
1744 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n");
1748 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &outputdebugstring_vectored_handler
);
1749 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
1751 outputdebugstring_exceptions
= 0;
1752 OutputDebugStringA("Hello World");
1753 ok(outputdebugstring_exceptions
== numexc
, "OutputDebugStringA generated %d exceptions, expected %d\n",
1754 outputdebugstring_exceptions
, numexc
);
1756 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
1759 static DWORD ripevent_exceptions
;
1761 static LONG CALLBACK
ripevent_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
1763 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
1764 trace("vect. handler %08x addr:%p\n", rec
->ExceptionCode
, rec
->ExceptionAddress
);
1766 ok(rec
->ExceptionCode
== DBG_RIPEXCEPTION
, "ExceptionCode is %08x instead of %08x\n",
1767 rec
->ExceptionCode
, DBG_RIPEXCEPTION
);
1768 ok(rec
->NumberParameters
== 2, "ExceptionParameters is %d instead of 2\n", rec
->NumberParameters
);
1769 ok(rec
->ExceptionInformation
[0] == 0x11223344, "ExceptionInformation[0] = %08x instead of %08x\n",
1770 (NTSTATUS
)rec
->ExceptionInformation
[0], 0x11223344);
1771 ok(rec
->ExceptionInformation
[1] == 0x55667788, "ExceptionInformation[1] = %08x instead of %08x\n",
1772 (NTSTATUS
)rec
->ExceptionInformation
[1], 0x55667788);
1774 ripevent_exceptions
++;
1775 return (rec
->ExceptionCode
== DBG_RIPEXCEPTION
) ? EXCEPTION_CONTINUE_EXECUTION
: EXCEPTION_CONTINUE_SEARCH
;
1778 static void test_ripevent(DWORD numexc
)
1780 EXCEPTION_RECORD record
;
1781 PVOID vectored_handler
;
1783 if (!pRtlAddVectoredExceptionHandler
|| !pRtlRemoveVectoredExceptionHandler
|| !pRtlRaiseException
)
1785 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler or RtlRaiseException not found\n");
1789 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &ripevent_vectored_handler
);
1790 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
1792 record
.ExceptionCode
= DBG_RIPEXCEPTION
;
1793 record
.ExceptionFlags
= 0;
1794 record
.ExceptionRecord
= NULL
;
1795 record
.ExceptionAddress
= NULL
;
1796 record
.NumberParameters
= 2;
1797 record
.ExceptionInformation
[0] = 0x11223344;
1798 record
.ExceptionInformation
[1] = 0x55667788;
1800 ripevent_exceptions
= 0;
1801 pRtlRaiseException(&record
);
1802 ok(ripevent_exceptions
== numexc
, "RtlRaiseException generated %d exceptions, expected %d\n",
1803 ripevent_exceptions
, numexc
);
1805 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
1808 static DWORD invalid_handle_exceptions
;
1810 static LONG CALLBACK
invalid_handle_vectored_handler(EXCEPTION_POINTERS
*ExceptionInfo
)
1812 PEXCEPTION_RECORD rec
= ExceptionInfo
->ExceptionRecord
;
1813 trace("vect. handler %08x addr:%p\n", rec
->ExceptionCode
, rec
->ExceptionAddress
);
1815 ok(rec
->ExceptionCode
== EXCEPTION_INVALID_HANDLE
, "ExceptionCode is %08x instead of %08x\n",
1816 rec
->ExceptionCode
, EXCEPTION_INVALID_HANDLE
);
1817 ok(rec
->NumberParameters
== 0, "ExceptionParameters is %d instead of 0\n", rec
->NumberParameters
);
1819 invalid_handle_exceptions
++;
1820 return (rec
->ExceptionCode
== EXCEPTION_INVALID_HANDLE
) ? EXCEPTION_CONTINUE_EXECUTION
: EXCEPTION_CONTINUE_SEARCH
;
1823 static void test_closehandle(DWORD numexc
)
1825 PVOID vectored_handler
;
1829 if (!pRtlAddVectoredExceptionHandler
|| !pRtlRemoveVectoredExceptionHandler
|| !pRtlRaiseException
)
1831 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler or RtlRaiseException not found\n");
1835 vectored_handler
= pRtlAddVectoredExceptionHandler(TRUE
, &invalid_handle_vectored_handler
);
1836 ok(vectored_handler
!= 0, "RtlAddVectoredExceptionHandler failed\n");
1838 invalid_handle_exceptions
= 0;
1839 res
= CloseHandle((HANDLE
)0xdeadbeef);
1840 ok(!res
, "CloseHandle(0xdeadbeef) unexpectedly succeeded\n");
1841 ok(GetLastError() == ERROR_INVALID_HANDLE
, "wrong error code %d instead of %d\n",
1842 GetLastError(), ERROR_INVALID_HANDLE
);
1843 ok(invalid_handle_exceptions
== numexc
, "CloseHandle generated %d exceptions, expected %d\n",
1844 invalid_handle_exceptions
, numexc
);
1846 invalid_handle_exceptions
= 0;
1847 status
= pNtClose((HANDLE
)0xdeadbeef);
1848 ok(status
== STATUS_INVALID_HANDLE
, "NtClose(0xdeadbeef) returned status %08x\n", status
);
1849 ok(invalid_handle_exceptions
== numexc
, "NtClose generated %d exceptions, expected %d\n",
1850 invalid_handle_exceptions
, numexc
);
1852 pRtlRemoveVectoredExceptionHandler(vectored_handler
);
1855 static void test_vectored_continue_handler(void)
1857 PVOID handler1
, handler2
;
1860 if (!pRtlAddVectoredContinueHandler
|| !pRtlRemoveVectoredContinueHandler
)
1862 skip("RtlAddVectoredContinueHandler or RtlRemoveVectoredContinueHandler not found\n");
1866 handler1
= pRtlAddVectoredContinueHandler(TRUE
, (void *)0xdeadbeef);
1867 ok(handler1
!= 0, "RtlAddVectoredContinueHandler failed\n");
1869 handler2
= pRtlAddVectoredContinueHandler(TRUE
, (void *)0xdeadbeef);
1870 ok(handler2
!= 0, "RtlAddVectoredContinueHandler failed\n");
1871 ok(handler1
!= handler2
, "RtlAddVectoredContinueHandler returned same handler\n");
1873 if (pRtlRemoveVectoredExceptionHandler
)
1875 ret
= pRtlRemoveVectoredExceptionHandler(handler1
);
1876 ok(!ret
, "RtlRemoveVectoredExceptionHandler succeeded\n");
1879 ret
= pRtlRemoveVectoredContinueHandler(handler1
);
1880 ok(ret
, "RtlRemoveVectoredContinueHandler failed\n");
1882 ret
= pRtlRemoveVectoredContinueHandler(handler2
);
1883 ok(ret
, "RtlRemoveVectoredContinueHandler failed\n");
1885 ret
= pRtlRemoveVectoredContinueHandler(handler1
);
1886 ok(!ret
, "RtlRemoveVectoredContinueHandler succeeded\n");
1888 ret
= pRtlRemoveVectoredContinueHandler((void *)0x11223344);
1889 ok(!ret
, "RtlRemoveVectoredContinueHandler succeeded\n");
1891 #endif /* defined(__i386__) || defined(__x86_64__) */
1893 START_TEST(exception
)
1895 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1897 if (!winetest_interactive
&&
1898 !strcmp(winetest_platform
, "windows"))
1900 skip("ROSTESTS-240: Skipping ntdll_winetest:exception because it hangs on WHS-Testbot. Set winetest_interactive to run it anyway.\n");
1904 code_mem
= VirtualAlloc(NULL
, 65536, MEM_RESERVE
| MEM_COMMIT
, PAGE_EXECUTE_READWRITE
);
1906 trace("VirtualAlloc failed\n");
1910 pNtCurrentTeb
= (void *)GetProcAddress( hntdll
, "NtCurrentTeb" );
1911 pNtGetContextThread
= (void *)GetProcAddress( hntdll
, "NtGetContextThread" );
1912 pNtSetContextThread
= (void *)GetProcAddress( hntdll
, "NtSetContextThread" );
1913 pNtReadVirtualMemory
= (void *)GetProcAddress( hntdll
, "NtReadVirtualMemory" );
1914 pNtClose
= (void *)GetProcAddress( hntdll
, "NtClose" );
1915 pRtlUnwind
= (void *)GetProcAddress( hntdll
, "RtlUnwind" );
1916 pRtlRaiseException
= (void *)GetProcAddress( hntdll
, "RtlRaiseException" );
1917 pNtTerminateProcess
= (void *)GetProcAddress( hntdll
, "NtTerminateProcess" );
1918 pRtlAddVectoredExceptionHandler
= (void *)GetProcAddress( hntdll
,
1919 "RtlAddVectoredExceptionHandler" );
1920 pRtlRemoveVectoredExceptionHandler
= (void *)GetProcAddress( hntdll
,
1921 "RtlRemoveVectoredExceptionHandler" );
1922 pRtlAddVectoredContinueHandler
= (void *)GetProcAddress( hntdll
,
1923 "RtlAddVectoredContinueHandler" );
1924 pRtlRemoveVectoredContinueHandler
= (void *)GetProcAddress( hntdll
,
1925 "RtlRemoveVectoredContinueHandler" );
1926 pNtQueryInformationProcess
= (void*)GetProcAddress( hntdll
,
1927 "NtQueryInformationProcess" );
1928 pNtSetInformationProcess
= (void*)GetProcAddress( hntdll
,
1929 "NtSetInformationProcess" );
1930 pIsWow64Process
= (void *)GetProcAddress(GetModuleHandleA("kernel32.dll"), "IsWow64Process");
1935 skip( "NtCurrentTeb not found\n" );
1938 if (!pIsWow64Process
|| !pIsWow64Process( GetCurrentProcess(), &is_wow64
)) is_wow64
= FALSE
;
1940 if (pRtlAddVectoredExceptionHandler
&& pRtlRemoveVectoredExceptionHandler
)
1941 have_vectored_api
= TRUE
;
1943 skip("RtlAddVectoredExceptionHandler or RtlRemoveVectoredExceptionHandler not found\n");
1945 my_argc
= winetest_get_mainargs( &my_argv
);
1949 sscanf( my_argv
[3], "%p", &addr
);
1951 if (addr
!= &test_stage
)
1953 skip( "child process not mapped at same address (%p/%p)\n", &test_stage
, addr
);
1957 /* child must be run under a debugger */
1958 if (!pNtCurrentTeb()->Peb
->BeingDebugged
)
1960 ok(FALSE
, "child process not being debugged?\n");
1964 if (pRtlRaiseException
)
1967 run_rtlraiseexception_test(0x12345);
1968 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
1969 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
1971 run_rtlraiseexception_test(0x12345);
1972 run_rtlraiseexception_test(EXCEPTION_BREAKPOINT
);
1973 run_rtlraiseexception_test(EXCEPTION_INVALID_HANDLE
);
1975 test_outputdebugstring(0);
1977 test_outputdebugstring(2);
1983 test_closehandle(0);
1985 test_closehandle(1);
1988 skip( "RtlRaiseException not found\n" );
1990 /* rest of tests only run in parent */
1996 test_rtlraiseexception();
1997 test_outputdebugstring(1);
1999 test_closehandle(0);
2000 test_vectored_continue_handler();
2002 test_simd_exceptions();
2003 test_fpu_exceptions();
2004 test_dpe_exceptions();
2007 #elif defined(__x86_64__)
2008 pRtlAddFunctionTable
= (void *)GetProcAddress( hntdll
,
2009 "RtlAddFunctionTable" );
2010 pRtlDeleteFunctionTable
= (void *)GetProcAddress( hntdll
,
2011 "RtlDeleteFunctionTable" );
2012 pRtlInstallFunctionTableCallback
= (void *)GetProcAddress( hntdll
,
2013 "RtlInstallFunctionTableCallback" );
2014 pRtlLookupFunctionEntry
= (void *)GetProcAddress( hntdll
,
2015 "RtlLookupFunctionEntry" );
2017 test_outputdebugstring(1);
2019 test_closehandle(0);
2020 test_vectored_continue_handler();
2021 test_virtual_unwind();
2023 if (pRtlAddFunctionTable
&& pRtlDeleteFunctionTable
&& pRtlInstallFunctionTableCallback
&& pRtlLookupFunctionEntry
)
2024 test_dynamic_unwind();
2026 skip( "Dynamic unwind functions not found\n" );
2030 VirtualFree(code_mem
, 0, MEM_FREE
);