msi: Only insert entries into listbox if property value matches.
[wine] / dlls / ntdll / tests / exception.c
1 /*
2  * Unit test suite for ntdll exceptions
3  *
4  * Copyright 2005 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdarg.h>
22
23 #ifndef _WIN32_WINNT
24 #define _WIN32_WINNT 0x500 /* For NTSTATUS */
25 #endif
26
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnt.h"
32 #include "winreg.h"
33 #include "winternl.h"
34 #include "excpt.h"
35 #include "wine/test.h"
36
37 #ifdef __i386__
38
39 static struct _TEB * (WINAPI *pNtCurrentTeb)(void);
40 static NTSTATUS  (WINAPI *pNtGetContextThread)(HANDLE,CONTEXT*);
41 static NTSTATUS  (WINAPI *pNtSetContextThread)(HANDLE,CONTEXT*);
42 static void *code_mem;
43
44 /* Test various instruction combinations that cause a protection fault on the i386,
45  * and check what the resulting exception looks like.
46  */
47
48 static const struct exception
49 {
50     BYTE     code[18];   /* asm code */
51     BYTE     offset;     /* offset of faulting instruction */
52     BYTE     length;     /* length of faulting instruction */
53     NTSTATUS status;     /* expected status code */
54     DWORD    nb_params;  /* expected number of parameters */
55     DWORD    params[4];  /* expected parameters */
56 } exceptions[] =
57 {
58     /* test some privileged instructions */
59     { { 0xfb, 0xc3 },  /* sti; ret */
60       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
61     { { 0x6c, 0xc3 },  /* insb (%dx); ret */
62       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
63     { { 0x6d, 0xc3 },  /* insl (%dx); ret */
64       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
65     { { 0x6e, 0xc3 },  /* outsb (%dx); ret */
66       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
67     { { 0x6f, 0xc3 },  /* outsl (%dx); ret */
68       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
69     { { 0xe4, 0x11, 0xc3 },  /* inb $0x11,%al; ret */
70       0, 2, STATUS_PRIVILEGED_INSTRUCTION, 0 },
71     { { 0xe5, 0x11, 0xc3 },  /* inl $0x11,%eax; ret */
72       0, 2, STATUS_PRIVILEGED_INSTRUCTION, 0 },
73     { { 0xe6, 0x11, 0xc3 },  /* outb %al,$0x11; ret */
74       0, 2, STATUS_PRIVILEGED_INSTRUCTION, 0 },
75     { { 0xe7, 0x11, 0xc3 },  /* outl %eax,$0x11; ret */
76       0, 2, STATUS_PRIVILEGED_INSTRUCTION, 0 },
77     { { 0xed, 0xc3 },  /* inl (%dx),%eax; ret */
78       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
79     { { 0xee, 0xc3 },  /* outb %al,(%dx); ret */
80       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
81     { { 0xef, 0xc3 },  /* outl %eax,(%dx); ret */
82       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
83     { { 0xf4, 0xc3 },  /* hlt; ret */
84       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
85     { { 0xfa, 0xc3 },  /* cli; ret */
86       0, 1, STATUS_PRIVILEGED_INSTRUCTION, 0 },
87
88     /* test long jump to invalid selector */
89     { { 0xea, 0, 0, 0, 0, 0, 0, 0xc3 },  /* ljmp $0,$0; ret */
90       0, 7, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
91
92     /* test iret to invalid selector */
93     { { 0x6a, 0x00, 0x6a, 0x00, 0x6a, 0x00, 0xcf, 0x83, 0xc4, 0x0c, 0xc3 },
94       /* pushl $0; pushl $0; pushl $0; iret; addl $12,%esp; ret */
95       6, 1, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
96
97     /* test loading an invalid selector */
98     { { 0xb8, 0xef, 0xbe, 0x00, 0x00, 0x8e, 0xe8, 0xc3 },  /* mov $beef,%ax; mov %ax,%gs; ret */
99       5, 2, STATUS_ACCESS_VIOLATION, 2, { 0, 0xbee8 } },
100
101     /* test accessing a zero selector */
102     { { 0x06, 0x31, 0xc0, 0x8e, 0xc0, 0x26, 0xa1, 0, 0, 0, 0, 0x07, 0xc3 },
103           /* push %es; xor %eax,%eax; mov %ax,%es; mov %es:(0),%ax; pop %es */
104       5, 6, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
105
106     /* test moving %cs -> %ss */
107     { { 0x0e, 0x17, 0x58, 0xc3 },  /* pushl %cs; popl %ss; popl %eax; ret */
108       1, 1, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
109
110     /* test overlong instruction (limit is 16 bytes) */
111     { { 0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xfa,0xc3 },
112       0, 16, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
113     { { 0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0x64,0xfa,0xc3 },
114       0, 15, STATUS_PRIVILEGED_INSTRUCTION, 0 },
115
116     /* test invalid interrupt */
117     { { 0xcd, 0xff, 0xc3 },   /* int $0xff; ret */
118       0, 2, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
119
120     /* test moves to/from Crx */
121     { { 0x0f, 0x20, 0xc0, 0xc3 },  /* movl %cr0,%eax; ret */
122       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
123     { { 0x0f, 0x20, 0xe0, 0xc3 },  /* movl %cr4,%eax; ret */
124       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
125     { { 0x0f, 0x22, 0xc0, 0xc3 },  /* movl %eax,%cr0; ret */
126       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
127     { { 0x0f, 0x22, 0xe0, 0xc3 },  /* movl %eax,%cr4; ret */
128       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
129
130     /* test moves to/from Drx */
131     { { 0x0f, 0x21, 0xc0, 0xc3 },  /* movl %dr0,%eax; ret */
132       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
133     { { 0x0f, 0x21, 0xc8, 0xc3 },  /* movl %dr1,%eax; ret */
134       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
135     { { 0x0f, 0x21, 0xf8, 0xc3 },  /* movl %dr7,%eax; ret */
136       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
137     { { 0x0f, 0x23, 0xc0, 0xc3 },  /* movl %eax,%dr0; ret */
138       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
139     { { 0x0f, 0x23, 0xc8, 0xc3 },  /* movl %eax,%dr1; ret */
140       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
141     { { 0x0f, 0x23, 0xf8, 0xc3 },  /* movl %eax,%dr7; ret */
142       0, 3, STATUS_PRIVILEGED_INSTRUCTION, 0 },
143
144     /* test memory reads */
145     { { 0xa1, 0xfc, 0xff, 0xff, 0xff, 0xc3 },  /* movl 0xfffffffc,%eax; ret */
146       0, 5, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffc } },
147     { { 0xa1, 0xfd, 0xff, 0xff, 0xff, 0xc3 },  /* movl 0xfffffffd,%eax; ret */
148       0, 5, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffd } },
149     { { 0xa1, 0xfe, 0xff, 0xff, 0xff, 0xc3 },  /* movl 0xfffffffe,%eax; ret */
150       0, 5, STATUS_ACCESS_VIOLATION, 2, { 0, 0xfffffffe } },
151     { { 0xa1, 0xff, 0xff, 0xff, 0xff, 0xc3 },  /* movl 0xffffffff,%eax; ret */
152       0, 5, STATUS_ACCESS_VIOLATION, 2, { 0, 0xffffffff } },
153
154     /* test memory writes */
155     { { 0xa3, 0xfc, 0xff, 0xff, 0xff, 0xc3 },  /* movl %eax,0xfffffffc; ret */
156       0, 5, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffc } },
157     { { 0xa3, 0xfd, 0xff, 0xff, 0xff, 0xc3 },  /* movl %eax,0xfffffffd; ret */
158       0, 5, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffd } },
159     { { 0xa3, 0xfe, 0xff, 0xff, 0xff, 0xc3 },  /* movl %eax,0xfffffffe; ret */
160       0, 5, STATUS_ACCESS_VIOLATION, 2, { 1, 0xfffffffe } },
161     { { 0xa3, 0xff, 0xff, 0xff, 0xff, 0xc3 },  /* movl %eax,0xffffffff; ret */
162       0, 5, STATUS_ACCESS_VIOLATION, 2, { 1, 0xffffffff } },
163 };
164
165 static int got_exception;
166
167 static void run_exception_test(const void *handler, const void* context,
168                                const void *code, unsigned int code_size)
169 {
170     struct {
171         EXCEPTION_REGISTRATION_RECORD frame;
172         const void *context;
173     } exc_frame;
174     void (*func)(void) = code_mem;
175
176     exc_frame.frame.Handler = handler;
177     exc_frame.frame.Prev = pNtCurrentTeb()->Tib.ExceptionList;
178     exc_frame.context = context;
179
180     memcpy(code_mem, code, code_size);
181
182     pNtCurrentTeb()->Tib.ExceptionList = &exc_frame.frame;
183     func();
184     pNtCurrentTeb()->Tib.ExceptionList = exc_frame.frame.Prev;
185 }
186
187 static DWORD handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
188                       CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
189 {
190     const struct exception *except = *(const struct exception **)(frame + 1);
191     unsigned int i, entry = except - exceptions;
192
193     got_exception++;
194     trace( "exception: %x flags:%x addr:%p\n",
195            rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress );
196
197     ok( rec->ExceptionCode == except->status,
198         "%u: Wrong exception code %x/%x\n", entry, rec->ExceptionCode, except->status );
199     ok( rec->ExceptionAddress == (char*)code_mem + except->offset,
200         "%u: Wrong exception address %p/%p\n", entry,
201         rec->ExceptionAddress, (char*)code_mem + except->offset );
202
203     ok( rec->NumberParameters == except->nb_params,
204         "%u: Wrong number of parameters %u/%u\n", entry, rec->NumberParameters, except->nb_params );
205
206     /* Most CPUs (except Intel Core apparently) report a segment limit violation */
207     /* instead of page faults for accesses beyond 0xffffffff */
208     if (except->nb_params == 2 && except->params[1] >= 0xfffffffd)
209     {
210         if (rec->ExceptionInformation[0] == 0 && rec->ExceptionInformation[1] == 0xffffffff)
211             goto skip_params;
212     }
213
214     for (i = 0; i < rec->NumberParameters; i++)
215         ok( rec->ExceptionInformation[i] == except->params[i],
216             "%u: Wrong parameter %d: %lx/%x\n",
217             entry, i, rec->ExceptionInformation[i], except->params[i] );
218
219 skip_params:
220     /* don't handle exception if it's not the address we expected */
221     if (rec->ExceptionAddress != (char*)code_mem + except->offset) return ExceptionContinueSearch;
222
223     context->Eip += except->length;
224     return ExceptionContinueExecution;
225 }
226
227 static void test_prot_fault(void)
228 {
229     unsigned int i;
230
231     for (i = 0; i < sizeof(exceptions)/sizeof(exceptions[0]); i++)
232     {
233         got_exception = 0;
234         run_exception_test(handler, &exceptions[i], &exceptions[i].code,
235                            sizeof(exceptions[i].code));
236         if (!i && !got_exception)
237         {
238             trace( "No exception, assuming win9x, no point in testing further\n" );
239             break;
240         }
241         ok( got_exception == (exceptions[i].status != 0),
242             "%u: bad exception count %d\n", i, got_exception );
243     }
244 }
245
246 /* test handling of debug registers */
247 static DWORD dreg_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
248                       CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
249 {
250     context->Eip += 2;  /* Skips the popl (%eax) */
251     context->Dr0 = 0x42424242;
252     context->Dr1 = 0;
253     context->Dr2 = 0;
254     context->Dr3 = 0;
255     context->Dr6 = 0;
256     context->Dr7 = 0x155;
257     return ExceptionContinueExecution;
258 }
259
260 static const BYTE segfault_code[5] = {
261         0x31, 0xc0, /* xor    %eax,%eax */
262         0x8f, 0x00, /* popl   (%eax) - cause exception */
263         0xc3        /* ret */
264 };
265
266 /* test the single step exception behaviour */
267 static DWORD single_step_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
268                                   CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
269 {
270     got_exception++;
271     ok (!(context->EFlags & 0x100), "eflags has single stepping bit set\n");
272
273     if( got_exception < 3)
274         context->EFlags |= 0x100;  /* single step until popf instruction */
275     else {
276         /* show that the last single step exception on the popf instruction
277          * (which removed the TF bit), still is a EXCEPTION_SINGLE_STEP exception */
278         ok( rec->ExceptionCode == EXCEPTION_SINGLE_STEP,
279             "exception is not EXCEPTION_SINGLE_STEP: %x\n", rec->ExceptionCode);
280     }
281
282     return ExceptionContinueExecution;
283 }
284
285 static const BYTE single_stepcode[] = {
286     0x9c,               /* pushf */
287     0x58,               /* pop   %eax */
288     0x0d,0,1,0,0,       /* or    $0x100,%eax */
289     0x50,               /* push   %eax */
290     0x9d,               /* popf    */
291     0x35,0,1,0,0,       /* xor    $0x100,%eax */
292     0x50,               /* push   %eax */
293     0x9d,               /* popf    */
294     0xc3
295 };
296
297 /* Test the alignment check (AC) flag handling. */
298 static const BYTE align_check_code[] = {
299     0x55,                       /* push   %ebp */
300     0x89,0xe5,                  /* mov    %esp,%ebp */
301     0x9c,                       /* pushf   */
302     0x58,                       /* pop    %eax */
303     0x0d,0,0,4,0,               /* or     $0x40000,%eax */
304     0x50,                       /* push   %eax */
305     0x9d,                       /* popf    */
306     0x89,0xe0,                  /* mov %esp, %eax */
307     0x8b,0x40,0x1,              /* mov 0x1(%eax), %eax - cause exception */
308     0x9c,                       /* pushf   */
309     0x58,                       /* pop    %eax */
310     0x35,0,0,4,0,               /* xor    $0x40000,%eax */
311     0x50,                       /* push   %eax */
312     0x9d,                       /* popf    */
313     0x5d,                       /* pop    %ebp */
314     0xc3,                       /* ret     */
315 };
316
317 static DWORD align_check_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
318                                   CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
319 {
320     ok (!(context->EFlags & 0x40000), "eflags has AC bit set\n");
321     got_exception++;
322     return ExceptionContinueExecution;
323 }
324
325 /* test single stepping over hardware breakpoint */
326 static DWORD bpx_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
327                           CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
328 {
329     got_exception++;
330     ok( rec->ExceptionCode == EXCEPTION_SINGLE_STEP,
331         "wrong exception code: %x\n", rec->ExceptionCode);
332
333     if(got_exception == 1) {
334         /* hw bp exception on first nop */
335         ok( context->Eip == (DWORD)code_mem, "eip is wrong:  %x instead of %x\n",
336                                              context->Eip, (DWORD)code_mem);
337         ok( (context->Dr6 & 0xf) == 1, "B0 flag is not set in Dr6\n");
338         ok( !(context->Dr6 & 0x4000), "BS flag is set in Dr6\n");
339         context->Dr0 = context->Dr0 + 1;  /* set hw bp again on next instruction */
340         context->EFlags |= 0x100;       /* enable single stepping */
341     } else if(  got_exception == 2) {
342         /* single step exception on second nop */
343         ok( context->Eip == (DWORD)code_mem + 1, "eip is wrong: %x instead of %x\n",
344                                                  context->Eip, (DWORD)code_mem + 1);
345         todo_wine{ ok( (context->Dr6 & 0x4000), "BS flag is not set in Dr6\n"); };
346         ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n");
347         context->EFlags |= 0x100;
348     } else if( got_exception == 3) {
349         /* hw bp exception on second nop */
350         ok( context->Eip == (DWORD)code_mem + 1, "eip is wrong: %x instead of %x\n",
351                                                  context->Eip, (DWORD)code_mem + 1);
352         todo_wine{ ok( (context->Dr6 & 0xf) == 1, "B0 flag is not set in Dr6\n"); };
353         ok( !(context->Dr6 & 0x4000), "BS flag is set in Dr6\n");
354         context->Dr0 = 0;       /* clear breakpoint */
355         context->EFlags |= 0x100;
356     } else {
357         /* single step exception on ret */
358         ok( context->Eip == (DWORD)code_mem + 2, "eip is wrong: %x instead of %x\n",
359                                                  context->Eip, (DWORD)code_mem + 2);
360         ok( (context->Dr6 & 0xf) == 0, "B0...3 flags in Dr6 shouldn't be set\n");
361         todo_wine{ ok( (context->Dr6 & 0x4000), "BS flag is not set in Dr6\n"); };
362     }
363
364     context->Dr6 = 0;  /* clear status register */
365     return ExceptionContinueExecution;
366 }
367
368 static const BYTE dummy_code[] = { 0x90, 0x90, 0xc3 };  /* nop, nop, ret */
369
370 /* test int3 handling */
371 static DWORD int3_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
372                            CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
373 {
374     ok( rec->ExceptionAddress == code_mem, "exception address not at: %p, but at %p\n",
375                                            code_mem,  rec->ExceptionAddress);
376     todo_wine {
377         ok( context->Eip == (DWORD)code_mem, "eip not at: %p, but at %#x\n", code_mem, context->Eip);
378     }
379     if(context->Eip == (DWORD)code_mem) context->Eip++; /* skip breakpoint */
380
381     return ExceptionContinueExecution;
382 }
383
384 static const BYTE int3_code[] = { 0xCC, 0xc3 };  /* int 3, ret */
385
386
387 static void test_exceptions(void)
388 {
389     CONTEXT ctx;
390     NTSTATUS res;
391
392     pNtGetContextThread = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtGetContextThread" );
393     pNtSetContextThread = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtSetContextThread" );
394     if (!pNtGetContextThread || !pNtSetContextThread)
395     {
396         trace( "NtGetContextThread/NtSetContextThread not found, skipping tests\n" );
397         return;
398     }
399
400     /* test handling of debug registers */
401     run_exception_test(dreg_handler, NULL, &segfault_code, sizeof(segfault_code));
402
403     ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
404     res = pNtGetContextThread(GetCurrentThread(), &ctx);
405     ok (res == STATUS_SUCCESS,"NtGetContextThread failed with %x\n", res);
406     ok(ctx.Dr0 == 0x42424242,"failed to set debugregister 0 to 0x42424242, got %x\n", ctx.Dr0);
407     ok(ctx.Dr7 == 0x155,"failed to set debugregister 7 to 0x155, got %x\n", ctx.Dr7);
408
409     /* test single stepping behavior */
410     got_exception = 0;
411     run_exception_test(single_step_handler, NULL, &single_stepcode, sizeof(single_stepcode));
412     ok(got_exception == 3, "expected 3 single step exceptions, got %d\n", got_exception);
413
414     /* test alignment exceptions */
415     got_exception = 0;
416     run_exception_test(align_check_handler, NULL, align_check_code, sizeof(align_check_code));
417     ok(got_exception == 0, "got %d alignment faults, expected 0\n", got_exception);
418
419     /* test single stepping over hardware breakpoint */
420     memset(&ctx, 0, sizeof(ctx));
421     ctx.Dr0 = (DWORD) code_mem;  /* set hw bp on first nop */
422     ctx.Dr7 = 3;
423     ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
424     res = pNtSetContextThread( GetCurrentThread(), &ctx);
425     ok( res == STATUS_SUCCESS, "NtSetContextThread faild with %x\n", res);
426
427     got_exception = 0;
428     run_exception_test(bpx_handler, NULL, dummy_code, sizeof(dummy_code));
429     ok( got_exception == 4,"expected 4 exceptions, got %d\n", got_exception);
430
431     /* test int3 handling */
432     run_exception_test(int3_handler, NULL, int3_code, sizeof(int3_code));
433 }
434
435 #endif  /* __i386__ */
436
437 START_TEST(exception)
438 {
439 #ifdef __i386__
440     pNtCurrentTeb = (void *)GetProcAddress( GetModuleHandleA("ntdll.dll"), "NtCurrentTeb" );
441     if (!pNtCurrentTeb)
442     {
443         trace( "NtCurrentTeb not found, skipping tests\n" );
444         return;
445     }
446
447     /* 1024 byte should be sufficient */
448     code_mem = VirtualAlloc(NULL, 1024, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
449     if(!code_mem) {
450         trace("VirtualAlloc failed\n");
451         return;
452     }
453     test_prot_fault();
454     test_exceptions();
455
456     VirtualFree(code_mem, 1024, MEM_RELEASE);
457 #endif
458 }