gdi32: Allocate smaller buffer in delete_external_font_keys helper.
[wine.git] / dlls / msvcrt / except_i386.c
blob963bd58165ebc95876357554dc86da0c06e41401
1 /*
2 * msvcrt C++ exception handling
4 * Copyright 2000 Jon Griffiths
5 * Copyright 2002 Alexandre Julliard
6 * Copyright 2005 Juan Lang
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * NOTES
23 * A good reference is the article "How a C++ compiler implements
24 * exception handling" by Vishal Kochhar, available on
25 * www.thecodeproject.com.
28 #include "config.h"
29 #include "wine/port.h"
31 #ifdef __i386__
33 #include <stdarg.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "winternl.h"
38 #include "msvcrt.h"
39 #include "wine/exception.h"
40 #include "excpt.h"
41 #include "wine/debug.h"
43 #include "cppexcept.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(seh);
48 /* the exception frame used by CxxFrameHandler */
49 typedef struct __cxx_exception_frame
51 EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
52 int trylevel;
53 DWORD ebp;
54 } cxx_exception_frame;
56 /* info about a single catch {} block */
57 typedef struct __catchblock_info
59 UINT flags; /* flags (see below) */
60 const type_info *type_info; /* C++ type caught by this block */
61 int offset; /* stack offset to copy exception object to */
62 void (*handler)(void);/* catch block handler code */
63 } catchblock_info;
64 #define TYPE_FLAG_CONST 1
65 #define TYPE_FLAG_VOLATILE 2
66 #define TYPE_FLAG_REFERENCE 8
68 /* info about a single try {} block */
69 typedef struct __tryblock_info
71 int start_level; /* start trylevel of that block */
72 int end_level; /* end trylevel of that block */
73 int catch_level; /* initial trylevel of the catch block */
74 int catchblock_count; /* count of catch blocks in array */
75 const catchblock_info *catchblock; /* array of catch blocks */
76 } tryblock_info;
78 /* info about the unwind handler for a given trylevel */
79 typedef struct __unwind_info
81 int prev; /* prev trylevel unwind handler, to run after this one */
82 void (*handler)(void);/* unwind handler */
83 } unwind_info;
85 /* descriptor of all try blocks of a given function */
86 typedef struct __cxx_function_descr
88 UINT magic; /* must be CXX_FRAME_MAGIC */
89 UINT unwind_count; /* number of unwind handlers */
90 const unwind_info *unwind_table; /* array of unwind handlers */
91 UINT tryblock_count; /* number of try blocks */
92 const tryblock_info *tryblock; /* array of try blocks */
93 UINT ipmap_count;
94 const void *ipmap;
95 const void *expect_list; /* expected exceptions list when magic >= VC7 */
96 UINT flags; /* flags when magic >= VC8 */
97 } cxx_function_descr;
99 typedef struct _SCOPETABLE
101 int previousTryLevel;
102 int (*lpfnFilter)(PEXCEPTION_POINTERS);
103 int (*lpfnHandler)(void);
104 } SCOPETABLE, *PSCOPETABLE;
106 typedef struct _MSVCRT_EXCEPTION_FRAME
108 EXCEPTION_REGISTRATION_RECORD *prev;
109 void (*handler)(PEXCEPTION_RECORD, EXCEPTION_REGISTRATION_RECORD*,
110 PCONTEXT, PEXCEPTION_RECORD);
111 PSCOPETABLE scopetable;
112 int trylevel;
113 int _ebp;
114 PEXCEPTION_POINTERS xpointers;
115 } MSVCRT_EXCEPTION_FRAME;
117 typedef struct
119 int gs_cookie_offset;
120 ULONG gs_cookie_xor;
121 int eh_cookie_offset;
122 ULONG eh_cookie_xor;
123 SCOPETABLE entries[1];
124 } SCOPETABLE_V4;
126 #define TRYLEVEL_END (-1) /* End of trylevel list */
128 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
129 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
130 const cxx_function_descr *descr,
131 EXCEPTION_REGISTRATION_RECORD* nested_frame, int nested_trylevel );
133 /* call a function with a given ebp */
134 static inline void *call_ebp_func( void *func, void *ebp )
136 void *ret;
137 int dummy;
138 __asm__ __volatile__ ("pushl %%ebx\n\t"
139 "pushl %%ebp\n\t"
140 "movl %4,%%ebp\n\t"
141 "call *%%eax\n\t"
142 "popl %%ebp\n\t"
143 "popl %%ebx"
144 : "=a" (ret), "=S" (dummy), "=D" (dummy)
145 : "0" (func), "1" (ebp) : "ecx", "edx", "memory" );
146 return ret;
149 /* call a copy constructor */
150 static inline void call_copy_ctor( void *func, void *this, void *src, int has_vbase )
152 TRACE( "calling copy ctor %p object %p src %p\n", func, this, src );
153 if (has_vbase)
154 /* in that case copy ctor takes an extra bool indicating whether to copy the base class */
155 __asm__ __volatile__("pushl $1; pushl %2; call *%0"
156 : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
157 else
158 __asm__ __volatile__("pushl %2; call *%0"
159 : : "r" (func), "c" (this), "r" (src) : "eax", "edx", "memory" );
162 /* continue execution to the specified address after exception is caught */
163 static inline void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr )
165 __asm__ __volatile__("movl -4(%0),%%esp; leal 12(%0),%%ebp; jmp *%1"
166 : : "r" (frame), "a" (addr) );
167 for (;;) ; /* unreached */
170 static inline void call_finally_block( void *code_block, void *base_ptr )
172 __asm__ __volatile__ ("movl %1,%%ebp; call *%%eax"
173 : : "a" (code_block), "g" (base_ptr));
176 static inline int call_filter( int (*func)(PEXCEPTION_POINTERS), void *arg, void *ebp )
178 int ret;
179 __asm__ __volatile__ ("pushl %%ebp; pushl %3; movl %2,%%ebp; call *%%eax; popl %%ebp; popl %%ebp"
180 : "=a" (ret)
181 : "0" (func), "r" (ebp), "r" (arg)
182 : "ecx", "edx", "memory" );
183 return ret;
186 static inline int call_unwind_func( int (*func)(void), void *ebp )
188 int ret;
189 __asm__ __volatile__ ("pushl %%ebp\n\t"
190 "pushl %%ebx\n\t"
191 "pushl %%esi\n\t"
192 "pushl %%edi\n\t"
193 "movl %2,%%ebp\n\t"
194 "call *%0\n\t"
195 "popl %%edi\n\t"
196 "popl %%esi\n\t"
197 "popl %%ebx\n\t"
198 "popl %%ebp"
199 : "=a" (ret)
200 : "0" (func), "r" (ebp)
201 : "ecx", "edx", "memory" );
202 return ret;
205 static inline void dump_type( const cxx_type_info *type )
207 TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
208 type->flags, type->type_info, dbgstr_type_info(type->type_info),
209 type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
210 type->size, type->copy_ctor );
213 static void dump_exception_type( const cxx_exception_type *type )
215 UINT i;
217 TRACE( "flags %x destr %p handler %p type info %p\n",
218 type->flags, type->destructor, type->custom_handler, type->type_info_table );
219 for (i = 0; i < type->type_info_table->count; i++)
221 TRACE( " %d: ", i );
222 dump_type( type->type_info_table->info[i] );
226 static void dump_function_descr( const cxx_function_descr *descr )
228 UINT i;
229 int j;
231 TRACE( "magic %x\n", descr->magic );
232 TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count );
233 for (i = 0; i < descr->unwind_count; i++)
235 TRACE( " %d: prev %d func %p\n", i,
236 descr->unwind_table[i].prev, descr->unwind_table[i].handler );
238 TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count );
239 for (i = 0; i < descr->tryblock_count; i++)
241 TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i,
242 descr->tryblock[i].start_level, descr->tryblock[i].end_level,
243 descr->tryblock[i].catch_level, descr->tryblock[i].catchblock,
244 descr->tryblock[i].catchblock_count );
245 for (j = 0; j < descr->tryblock[i].catchblock_count; j++)
247 const catchblock_info *ptr = &descr->tryblock[i].catchblock[j];
248 TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
249 j, ptr->flags, ptr->offset, ptr->handler,
250 ptr->type_info, dbgstr_type_info( ptr->type_info ) );
253 if (descr->magic <= CXX_FRAME_MAGIC_VC6) return;
254 TRACE( "expect list: %p\n", descr->expect_list );
255 if (descr->magic <= CXX_FRAME_MAGIC_VC7) return;
256 TRACE( "flags: %08x\n", descr->flags );
259 /* check if the exception type is caught by a given catch block, and return the type that matched */
260 static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type,
261 const type_info *catch_ti, UINT catch_flags )
263 UINT i;
265 for (i = 0; i < exc_type->type_info_table->count; i++)
267 const cxx_type_info *type = exc_type->type_info_table->info[i];
269 if (!catch_ti) return type; /* catch(...) matches any type */
270 if (catch_ti != type->type_info)
272 if (strcmp( catch_ti->mangled, type->type_info->mangled )) continue;
274 /* type is the same, now check the flags */
275 if ((exc_type->flags & TYPE_FLAG_CONST) &&
276 !(catch_flags & TYPE_FLAG_CONST)) continue;
277 if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
278 !(catch_flags & TYPE_FLAG_VOLATILE)) continue;
279 return type; /* it matched */
281 return NULL;
285 /* copy the exception object where the catch block wants it */
286 static void copy_exception( void *object, cxx_exception_frame *frame,
287 const catchblock_info *catchblock, const cxx_type_info *type )
289 void **dest_ptr;
291 if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return;
292 if (!catchblock->offset) return;
293 dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset);
295 if (catchblock->flags & TYPE_FLAG_REFERENCE)
297 *dest_ptr = get_this_pointer( &type->offsets, object );
299 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
301 memmove( dest_ptr, object, type->size );
302 /* if it is a pointer, adjust it */
303 if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr );
305 else /* copy the object */
307 if (type->copy_ctor)
308 call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object),
309 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
310 else
311 memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size );
315 /* unwind the local function up to a given trylevel */
316 static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level)
318 void (*handler)(void);
319 int trylevel = frame->trylevel;
321 while (trylevel != last_level)
323 if (trylevel < 0 || trylevel >= descr->unwind_count)
325 ERR( "invalid trylevel %d\n", trylevel );
326 MSVCRT_terminate();
328 handler = descr->unwind_table[trylevel].handler;
329 if (handler)
331 TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
332 handler, trylevel, last_level, &frame->ebp );
333 call_ebp_func( handler, &frame->ebp );
335 trylevel = descr->unwind_table[trylevel].prev;
337 frame->trylevel = last_level;
340 /* exception frame for nested exceptions in catch block */
341 struct catch_func_nested_frame
343 EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */
344 cxx_exception_frame *cxx_frame; /* frame of parent exception */
345 const cxx_function_descr *descr; /* descriptor of parent exception */
346 int trylevel; /* current try level */
347 cxx_frame_info frame_info;
350 /* handler for exceptions happening while calling a catch function */
351 static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
352 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
354 struct catch_func_nested_frame *nested_frame = (struct catch_func_nested_frame *)frame;
356 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
358 __CxxUnregisterExceptionObject(&nested_frame->frame_info, FALSE);
359 return ExceptionContinueSearch;
362 TRACE( "got nested exception in catch function\n" );
364 if(rec->ExceptionCode == CXX_EXCEPTION)
366 PEXCEPTION_RECORD prev_rec = msvcrt_get_thread_data()->exc_record;
368 if((rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) ||
369 (prev_rec->ExceptionCode == CXX_EXCEPTION &&
370 rec->ExceptionInformation[1] == prev_rec->ExceptionInformation[1] &&
371 rec->ExceptionInformation[2] == prev_rec->ExceptionInformation[2]))
373 /* exception was rethrown */
374 *rec = *prev_rec;
375 rec->ExceptionFlags &= ~EH_UNWINDING;
376 if(TRACE_ON(seh)) {
377 TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode);
378 if(rec->ExceptionCode == CXX_EXCEPTION)
379 TRACE("re-propage: obj: %lx, type: %lx\n",
380 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
383 else
385 TRACE("detect threw new exception in catch block\n");
389 return cxx_frame_handler( rec, nested_frame->cxx_frame, context,
390 NULL, nested_frame->descr, &nested_frame->frame,
391 nested_frame->trylevel );
394 /* find and call the appropriate catch block for an exception */
395 /* returns the address to continue execution to after the catch block was called */
396 static inline void call_catch_block( PEXCEPTION_RECORD rec, cxx_exception_frame *frame,
397 const cxx_function_descr *descr, int nested_trylevel,
398 EXCEPTION_REGISTRATION_RECORD *catch_frame,
399 cxx_exception_type *info )
401 UINT i;
402 int j;
403 void *addr, *object = (void *)rec->ExceptionInformation[1];
404 struct catch_func_nested_frame nested_frame;
405 int trylevel = frame->trylevel;
406 DWORD save_esp = ((DWORD*)frame)[-1];
407 thread_data_t *data;
409 for (i = 0; i < descr->tryblock_count; i++)
411 const tryblock_info *tryblock = &descr->tryblock[i];
413 /* only handle try blocks inside current catch block */
414 if (catch_frame && nested_trylevel > tryblock->start_level) continue;
416 if (trylevel < tryblock->start_level) continue;
417 if (trylevel > tryblock->end_level) continue;
419 /* got a try block */
420 for (j = 0; j < tryblock->catchblock_count; j++)
422 const catchblock_info *catchblock = &tryblock->catchblock[j];
423 if(info)
425 const cxx_type_info *type = find_caught_type( info,
426 catchblock->type_info, catchblock->flags );
427 if (!type) continue;
429 TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j );
431 /* copy the exception to its destination on the stack */
432 copy_exception( object, frame, catchblock, type );
434 else
436 /* no CXX_EXCEPTION only proceed with a catch(...) block*/
437 if(catchblock->type_info)
438 continue;
439 TRACE("found catch(...) block\n");
442 /* Add frame info here so exception is not freed inside RtlUnwind call */
443 _CreateFrameInfo(&nested_frame.frame_info.frame_info,
444 (void*)rec->ExceptionInformation[1]);
446 /* unwind the stack */
447 RtlUnwind( catch_frame ? catch_frame : &frame->frame, 0, rec, 0 );
448 cxx_local_unwind( frame, descr, tryblock->start_level );
449 frame->trylevel = tryblock->end_level + 1;
451 data = msvcrt_get_thread_data();
452 nested_frame.frame_info.rec = data->exc_record;
453 data->exc_record = rec;
455 /* call the catch block */
456 TRACE( "calling catch block %p addr %p ebp %p\n",
457 catchblock, catchblock->handler, &frame->ebp );
459 /* setup an exception block for nested exceptions */
460 nested_frame.frame.Handler = catch_function_nested_handler;
461 nested_frame.cxx_frame = frame;
462 nested_frame.descr = descr;
463 nested_frame.trylevel = nested_trylevel + 1;
465 __wine_push_frame( &nested_frame.frame );
466 addr = call_ebp_func( catchblock->handler, &frame->ebp );
467 __wine_pop_frame( &nested_frame.frame );
469 ((DWORD*)frame)[-1] = save_esp;
470 __CxxUnregisterExceptionObject(&nested_frame.frame_info, FALSE);
471 TRACE( "done, continuing at %p\n", addr );
473 continue_after_catch( frame, addr );
478 /*********************************************************************
479 * __CxxExceptionFilter (MSVCRT.@)
481 int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
482 const type_info *ti, int flags, void **copy)
484 const cxx_type_info *type;
485 PEXCEPTION_RECORD rec;
487 TRACE( "%p %p %x %p\n", ptrs, ti, flags, copy );
489 if (!ptrs) return EXCEPTION_CONTINUE_SEARCH;
491 /* handle catch(...) */
492 if (!ti) return EXCEPTION_EXECUTE_HANDLER;
494 rec = ptrs->ExceptionRecord;
495 if (rec->ExceptionCode != CXX_EXCEPTION || rec->NumberParameters != 3 ||
496 rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 ||
497 rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8)
498 return EXCEPTION_CONTINUE_SEARCH;
500 if (rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
502 rec = msvcrt_get_thread_data()->exc_record;
503 if (!rec) return EXCEPTION_CONTINUE_SEARCH;
506 type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], ti, flags );
507 if (!type) return EXCEPTION_CONTINUE_SEARCH;
509 if (copy)
511 void *object = (void *)rec->ExceptionInformation[1];
513 if (flags & TYPE_FLAG_REFERENCE)
515 *copy = get_this_pointer( &type->offsets, object );
517 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
519 memmove( copy, object, type->size );
520 /* if it is a pointer, adjust it */
521 if (type->size == sizeof(void*)) *copy = get_this_pointer( &type->offsets, *copy );
523 else /* copy the object */
525 if (type->copy_ctor)
526 call_copy_ctor( type->copy_ctor, copy, get_this_pointer(&type->offsets,object),
527 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
528 else
529 memmove( copy, get_this_pointer(&type->offsets,object), type->size );
532 return EXCEPTION_EXECUTE_HANDLER;
535 /*********************************************************************
536 * cxx_frame_handler
538 * Implementation of __CxxFrameHandler.
540 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
541 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
542 const cxx_function_descr *descr,
543 EXCEPTION_REGISTRATION_RECORD* nested_frame,
544 int nested_trylevel )
546 cxx_exception_type *exc_type;
548 if (descr->magic < CXX_FRAME_MAGIC_VC6 || descr->magic > CXX_FRAME_MAGIC_VC8)
550 ERR( "invalid frame magic %x\n", descr->magic );
551 return ExceptionContinueSearch;
553 if (descr->magic >= CXX_FRAME_MAGIC_VC8 &&
554 (descr->flags & FUNC_DESCR_SYNCHRONOUS) &&
555 (rec->ExceptionCode != CXX_EXCEPTION))
556 return ExceptionContinueSearch; /* handle only c++ exceptions */
558 if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
560 if (descr->unwind_count && !nested_trylevel) cxx_local_unwind( frame, descr, -1 );
561 return ExceptionContinueSearch;
563 if (!descr->tryblock_count) return ExceptionContinueSearch;
565 if(rec->ExceptionCode == CXX_EXCEPTION &&
566 rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
568 *rec = *msvcrt_get_thread_data()->exc_record;
569 rec->ExceptionFlags &= ~EH_UNWINDING;
570 if(TRACE_ON(seh)) {
571 TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode);
572 if(rec->ExceptionCode == CXX_EXCEPTION)
573 TRACE("re-propage: obj: %lx, type: %lx\n",
574 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
578 if(rec->ExceptionCode == CXX_EXCEPTION)
580 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
582 if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8 &&
583 exc_type->custom_handler)
585 return exc_type->custom_handler( rec, frame, context, dispatch,
586 descr, nested_trylevel, nested_frame, 0 );
589 if (TRACE_ON(seh))
591 TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
592 rec, frame, frame->trylevel, descr, nested_frame );
593 dump_exception_type( exc_type );
594 dump_function_descr( descr );
597 else
599 thread_data_t *data = msvcrt_get_thread_data();
601 exc_type = NULL;
602 TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
603 rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame );
605 if (data->se_translator) {
606 EXCEPTION_POINTERS except_ptrs;
608 except_ptrs.ExceptionRecord = rec;
609 except_ptrs.ContextRecord = context;
610 data->se_translator(rec->ExceptionCode, &except_ptrs);
614 call_catch_block( rec, frame, descr, frame->trylevel, nested_frame, exc_type );
615 return ExceptionContinueSearch;
619 /*********************************************************************
620 * __CxxFrameHandler (MSVCRT.@)
622 extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame,
623 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch );
624 __ASM_GLOBAL_FUNC( __CxxFrameHandler,
625 "pushl $0\n\t" /* nested_trylevel */
626 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
627 "pushl $0\n\t" /* nested_frame */
628 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
629 "pushl %eax\n\t" /* descr */
630 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
631 "pushl 28(%esp)\n\t" /* dispatch */
632 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
633 "pushl 28(%esp)\n\t" /* context */
634 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
635 "pushl 28(%esp)\n\t" /* frame */
636 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
637 "pushl 28(%esp)\n\t" /* rec */
638 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
639 "call " __ASM_NAME("cxx_frame_handler") "\n\t"
640 "add $28,%esp\n\t"
641 __ASM_CFI(".cfi_adjust_cfa_offset -28\n\t")
642 "ret" )
645 /*********************************************************************
646 * __CxxLongjmpUnwind (MSVCRT.@)
648 * Callback meant to be used as UnwindFunc for setjmp/longjmp.
650 void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf )
652 cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
653 const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
655 TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel );
656 cxx_local_unwind( frame, descr, buf->TryLevel );
659 /*********************************************************************
660 * __CppXcptFilter (MSVCRT.@)
662 int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
664 /* only filter c++ exceptions */
665 if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
666 return _XcptFilter( ex, ptr );
669 /*********************************************************************
670 * __CxxDetectRethrow (MSVCRT.@)
672 BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
674 PEXCEPTION_RECORD rec;
676 if (!ptrs)
677 return FALSE;
679 rec = ptrs->ExceptionRecord;
681 if (rec->ExceptionCode == CXX_EXCEPTION &&
682 rec->NumberParameters == 3 &&
683 rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
684 rec->ExceptionInformation[2])
686 ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
687 return TRUE;
689 return (msvcrt_get_thread_data()->exc_record == rec);
692 /*********************************************************************
693 * __CxxQueryExceptionSize (MSVCRT.@)
695 unsigned int CDECL __CxxQueryExceptionSize(void)
697 return sizeof(cxx_exception_type);
701 /*********************************************************************
702 * _EH_prolog (MSVCRT.@)
705 /* Provided for VC++ binary compatibility only */
706 __ASM_GLOBAL_FUNC(_EH_prolog,
707 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */
708 "pushl $-1\n\t"
709 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
710 "pushl %eax\n\t"
711 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
712 "pushl %fs:0\n\t"
713 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
714 "movl %esp, %fs:0\n\t"
715 "movl 12(%esp), %eax\n\t"
716 "movl %ebp, 12(%esp)\n\t"
717 "leal 12(%esp), %ebp\n\t"
718 "pushl %eax\n\t"
719 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
720 "ret")
722 static const SCOPETABLE_V4 *get_scopetable_v4( MSVCRT_EXCEPTION_FRAME *frame, ULONG_PTR cookie )
724 return (const SCOPETABLE_V4 *)((ULONG_PTR)frame->scopetable ^ cookie);
727 static DWORD MSVCRT_nested_handler(PEXCEPTION_RECORD rec,
728 EXCEPTION_REGISTRATION_RECORD* frame,
729 PCONTEXT context,
730 EXCEPTION_REGISTRATION_RECORD** dispatch)
732 if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
733 return ExceptionContinueSearch;
734 *dispatch = frame;
735 return ExceptionCollidedUnwind;
738 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp)
740 EXCEPTION_REGISTRATION_RECORD reg;
742 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
744 /* Register a handler in case of a nested exception */
745 reg.Handler = MSVCRT_nested_handler;
746 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
747 __wine_push_frame(&reg);
749 while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel)
751 int level = frame->trylevel;
752 frame->trylevel = frame->scopetable[level].previousTryLevel;
753 if (!frame->scopetable[level].lpfnFilter)
755 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
756 level, frame->scopetable[level].lpfnHandler, ebp );
757 call_unwind_func( frame->scopetable[level].lpfnHandler, ebp );
760 __wine_pop_frame(&reg);
761 TRACE("unwound OK\n");
764 static void msvcrt_local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp )
766 EXCEPTION_REGISTRATION_RECORD reg;
767 const SCOPETABLE_V4 *scopetable = get_scopetable_v4( frame, *cookie );
769 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
771 /* Register a handler in case of a nested exception */
772 reg.Handler = MSVCRT_nested_handler;
773 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
774 __wine_push_frame(&reg);
776 while (frame->trylevel != -2 && frame->trylevel != trylevel)
778 int level = frame->trylevel;
779 frame->trylevel = scopetable->entries[level].previousTryLevel;
780 if (!scopetable->entries[level].lpfnFilter)
782 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
783 level, scopetable->entries[level].lpfnHandler, ebp );
784 call_unwind_func( scopetable->entries[level].lpfnHandler, ebp );
787 __wine_pop_frame(&reg);
788 TRACE("unwound OK\n");
791 /*******************************************************************
792 * _local_unwind2 (MSVCRT.@)
794 void CDECL _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel)
796 msvcrt_local_unwind2( frame, trylevel, &frame->_ebp );
799 /*******************************************************************
800 * _local_unwind4 (MSVCRT.@)
802 void CDECL _local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel )
804 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
807 /*******************************************************************
808 * _global_unwind2 (MSVCRT.@)
810 void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame)
812 TRACE("(%p)\n",frame);
813 RtlUnwind( frame, 0, 0, 0 );
816 /*********************************************************************
817 * _except_handler2 (MSVCRT.@)
819 int CDECL _except_handler2(PEXCEPTION_RECORD rec,
820 EXCEPTION_REGISTRATION_RECORD* frame,
821 PCONTEXT context,
822 EXCEPTION_REGISTRATION_RECORD** dispatcher)
824 FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n",
825 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
826 frame->Handler, context, dispatcher);
827 return ExceptionContinueSearch;
830 /*********************************************************************
831 * _except_handler3 (MSVCRT.@)
833 int CDECL _except_handler3(PEXCEPTION_RECORD rec,
834 MSVCRT_EXCEPTION_FRAME* frame,
835 PCONTEXT context, void* dispatcher)
837 int retval, trylevel;
838 EXCEPTION_POINTERS exceptPtrs;
839 PSCOPETABLE pScopeTable;
841 TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n",
842 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
843 frame->handler, context, dispatcher);
845 __asm__ __volatile__ ("cld");
847 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
849 /* Unwinding the current frame */
850 msvcrt_local_unwind2(frame, TRYLEVEL_END, &frame->_ebp);
851 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
852 return ExceptionContinueSearch;
854 else
856 /* Hunting for handler */
857 exceptPtrs.ExceptionRecord = rec;
858 exceptPtrs.ContextRecord = context;
859 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
860 trylevel = frame->trylevel;
861 pScopeTable = frame->scopetable;
863 while (trylevel != TRYLEVEL_END)
865 TRACE( "level %d prev %d filter %p\n", trylevel, pScopeTable[trylevel].previousTryLevel,
866 pScopeTable[trylevel].lpfnFilter );
867 if (pScopeTable[trylevel].lpfnFilter)
869 retval = call_filter( pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
871 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
872 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
873 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
875 if (retval == EXCEPTION_CONTINUE_EXECUTION)
876 return ExceptionContinueExecution;
878 if (retval == EXCEPTION_EXECUTE_HANDLER)
880 /* Unwind all higher frames, this one will handle the exception */
881 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
882 msvcrt_local_unwind2(frame, trylevel, &frame->_ebp);
884 /* Set our trylevel to the enclosing block, and call the __finally
885 * code, which won't return
887 frame->trylevel = pScopeTable[trylevel].previousTryLevel;
888 TRACE("__finally block %p\n",pScopeTable[trylevel].lpfnHandler);
889 call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp);
890 ERR("Returned from __finally block - expect crash!\n");
893 trylevel = pScopeTable[trylevel].previousTryLevel;
896 TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
897 return ExceptionContinueSearch;
900 /*********************************************************************
901 * _except_handler4_common (MSVCRT.@)
903 int CDECL _except_handler4_common( ULONG *cookie, void (*check_cookie)(void),
904 EXCEPTION_RECORD *rec, MSVCRT_EXCEPTION_FRAME *frame,
905 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
907 int retval, trylevel;
908 EXCEPTION_POINTERS exceptPtrs;
909 const SCOPETABLE_V4 *scope_table = get_scopetable_v4( frame, *cookie );
911 TRACE( "exception %x flags=%x at %p handler=%p %p %p cookie=%x scope table=%p cookies=%d/%x,%d/%x\n",
912 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
913 frame->handler, context, dispatcher, *cookie, scope_table,
914 scope_table->gs_cookie_offset, scope_table->gs_cookie_xor,
915 scope_table->eh_cookie_offset, scope_table->eh_cookie_xor );
917 /* FIXME: no cookie validation yet */
919 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
921 /* Unwinding the current frame */
922 msvcrt_local_unwind4( cookie, frame, -2, &frame->_ebp );
923 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
924 return ExceptionContinueSearch;
926 else
928 /* Hunting for handler */
929 exceptPtrs.ExceptionRecord = rec;
930 exceptPtrs.ContextRecord = context;
931 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
932 trylevel = frame->trylevel;
934 while (trylevel != -2)
936 TRACE( "level %d prev %d filter %p\n", trylevel,
937 scope_table->entries[trylevel].previousTryLevel,
938 scope_table->entries[trylevel].lpfnFilter );
939 if (scope_table->entries[trylevel].lpfnFilter)
941 retval = call_filter( scope_table->entries[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
943 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
944 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
945 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
947 if (retval == EXCEPTION_CONTINUE_EXECUTION)
948 return ExceptionContinueExecution;
950 if (retval == EXCEPTION_EXECUTE_HANDLER)
952 __DestructExceptionObject(rec);
954 /* Unwind all higher frames, this one will handle the exception */
955 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
956 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
958 /* Set our trylevel to the enclosing block, and call the __finally
959 * code, which won't return
961 frame->trylevel = scope_table->entries[trylevel].previousTryLevel;
962 TRACE("__finally block %p\n",scope_table->entries[trylevel].lpfnHandler);
963 call_finally_block(scope_table->entries[trylevel].lpfnHandler, &frame->_ebp);
964 ERR("Returned from __finally block - expect crash!\n");
967 trylevel = scope_table->entries[trylevel].previousTryLevel;
970 TRACE("reached -2, returning ExceptionContinueSearch\n");
971 return ExceptionContinueSearch;
976 * setjmp/longjmp implementation
979 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
980 typedef void (__stdcall *MSVCRT_unwind_function)(const struct MSVCRT___JUMP_BUFFER *);
982 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
983 /* and then jumps to the C backend function */
984 #define DEFINE_SETJMP_ENTRYPOINT(name) \
985 __ASM_GLOBAL_FUNC( name, \
986 "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \
987 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \
988 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \
989 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \
990 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \
991 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \
992 "movl 0(%esp),%eax\n\t" \
993 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \
994 "jmp " __ASM_NAME("__regs_") # name )
996 /* restore the registers from the jmp buf upon longjmp */
997 extern void DECLSPEC_NORETURN longjmp_set_regs( struct MSVCRT___JUMP_BUFFER *jmp, int retval );
998 __ASM_GLOBAL_FUNC( longjmp_set_regs,
999 "movl 4(%esp),%ecx\n\t" /* jmp_buf */
1000 "movl 8(%esp),%eax\n\t" /* retval */
1001 "movl 0(%ecx),%ebp\n\t" /* jmp_buf.Ebp */
1002 "movl 4(%ecx),%ebx\n\t" /* jmp_buf.Ebx */
1003 "movl 8(%ecx),%edi\n\t" /* jmp_buf.Edi */
1004 "movl 12(%ecx),%esi\n\t" /* jmp_buf.Esi */
1005 "movl 16(%ecx),%esp\n\t" /* jmp_buf.Esp */
1006 "addl $4,%esp\n\t" /* get rid of return address */
1007 "jmp *20(%ecx)\n\t" /* jmp_buf.Eip */ )
1010 * The signatures of the setjmp/longjmp functions do not match that
1011 * declared in the setjmp header so they don't follow the regular naming
1012 * convention to avoid conflicts.
1015 /*******************************************************************
1016 * _setjmp (MSVCRT.@)
1018 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp)
1019 int CDECL __regs_MSVCRT__setjmp(struct MSVCRT___JUMP_BUFFER *jmp)
1021 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1022 if (jmp->Registration == ~0UL)
1023 jmp->TryLevel = TRYLEVEL_END;
1024 else
1025 jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1027 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1028 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1029 return 0;
1032 /*******************************************************************
1033 * _setjmp3 (MSVCRT.@)
1035 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3 )
1036 int CDECL __regs_MSVCRT__setjmp3(struct MSVCRT___JUMP_BUFFER *jmp, int nb_args, ...)
1038 jmp->Cookie = MSVCRT_JMP_MAGIC;
1039 jmp->UnwindFunc = 0;
1040 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1041 if (jmp->Registration == ~0UL)
1043 jmp->TryLevel = TRYLEVEL_END;
1045 else
1047 int i;
1048 va_list args;
1050 va_start( args, nb_args );
1051 if (nb_args > 0) jmp->UnwindFunc = va_arg( args, unsigned long );
1052 if (nb_args > 1) jmp->TryLevel = va_arg( args, unsigned long );
1053 else jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1054 for (i = 0; i < 6 && i < nb_args - 2; i++)
1055 jmp->UnwindData[i] = va_arg( args, unsigned long );
1056 va_end( args );
1059 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1060 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1061 return 0;
1064 /*********************************************************************
1065 * longjmp (MSVCRT.@)
1067 void CDECL MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER *jmp, int retval)
1069 unsigned long cur_frame = 0;
1071 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
1072 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration, retval );
1074 cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1075 TRACE("cur_frame=%lx\n",cur_frame);
1077 if (cur_frame != jmp->Registration)
1078 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)jmp->Registration);
1080 if (jmp->Registration)
1082 if (IsBadReadPtr(&jmp->Cookie, sizeof(long)) || jmp->Cookie != MSVCRT_JMP_MAGIC)
1084 msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME*)jmp->Registration,
1085 jmp->TryLevel, (void *)jmp->Ebp);
1087 else if(jmp->UnwindFunc)
1089 MSVCRT_unwind_function unwind_func;
1091 unwind_func=(MSVCRT_unwind_function)jmp->UnwindFunc;
1092 unwind_func(jmp);
1096 if (!retval)
1097 retval = 1;
1099 longjmp_set_regs( jmp, retval );
1102 /*********************************************************************
1103 * _seh_longjmp_unwind (MSVCRT.@)
1105 void __stdcall _seh_longjmp_unwind(struct MSVCRT___JUMP_BUFFER *jmp)
1107 msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, jmp->TryLevel, (void *)jmp->Ebp );
1110 /*********************************************************************
1111 * _seh_longjmp_unwind4 (MSVCRT.@)
1113 void __stdcall _seh_longjmp_unwind4(struct MSVCRT___JUMP_BUFFER *jmp)
1115 msvcrt_local_unwind4( (ULONG *)&jmp->Cookie, (MSVCRT_EXCEPTION_FRAME *)jmp->Registration,
1116 jmp->TryLevel, (void *)jmp->Ebp );
1119 /*********************************************************************
1120 * _fpieee_flt (MSVCRT.@)
1122 int __cdecl _fpieee_flt(ULONG exception_code, EXCEPTION_POINTERS *ep,
1123 int (__cdecl *handler)(_FPIEEE_RECORD*))
1125 FLOATING_SAVE_AREA *ctx = &ep->ContextRecord->FloatSave;
1126 _FPIEEE_RECORD rec;
1127 int ret;
1129 TRACE("(%x %p %p)\n", exception_code, ep, handler);
1131 switch(exception_code) {
1132 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1133 case STATUS_FLOAT_INEXACT_RESULT:
1134 case STATUS_FLOAT_INVALID_OPERATION:
1135 case STATUS_FLOAT_OVERFLOW:
1136 case STATUS_FLOAT_UNDERFLOW:
1137 break;
1138 default:
1139 return EXCEPTION_CONTINUE_SEARCH;
1142 memset(&rec, 0, sizeof(rec));
1143 rec.RoundingMode = ctx->ControlWord >> 10;
1144 switch((ctx->ControlWord >> 8) & 0x3) {
1145 case 0: rec.Precision = 2; break;
1146 case 1: rec.Precision = 3; break;
1147 case 2: rec.Precision = 1; break;
1148 case 3: rec.Precision = 0; break;
1150 rec.Status.InvalidOperation = ctx->StatusWord & 0x1;
1151 rec.Status.ZeroDivide = ((ctx->StatusWord & 0x4) != 0);
1152 rec.Status.Overflow = ((ctx->StatusWord & 0x8) != 0);
1153 rec.Status.Underflow = ((ctx->StatusWord & 0x10) != 0);
1154 rec.Status.Inexact = ((ctx->StatusWord & 0x20) != 0);
1155 rec.Enable.InvalidOperation = ((ctx->ControlWord & 0x1) == 0);
1156 rec.Enable.ZeroDivide = ((ctx->ControlWord & 0x4) == 0);
1157 rec.Enable.Overflow = ((ctx->ControlWord & 0x8) == 0);
1158 rec.Enable.Underflow = ((ctx->ControlWord & 0x10) == 0);
1159 rec.Enable.Inexact = ((ctx->ControlWord & 0x20) == 0);
1160 rec.Cause.InvalidOperation = rec.Enable.InvalidOperation & rec.Status.InvalidOperation;
1161 rec.Cause.ZeroDivide = rec.Enable.ZeroDivide & rec.Status.ZeroDivide;
1162 rec.Cause.Overflow = rec.Enable.Overflow & rec.Status.Overflow;
1163 rec.Cause.Underflow = rec.Enable.Underflow & rec.Status.Underflow;
1164 rec.Cause.Inexact = rec.Enable.Inexact & rec.Status.Inexact;
1166 TRACE("opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1168 if(*(WORD*)ctx->ErrorOffset == 0x35dc) { /* fdiv m64fp */
1169 if(exception_code==STATUS_FLOAT_DIVIDE_BY_ZERO || exception_code==STATUS_FLOAT_INVALID_OPERATION) {
1170 rec.Operand1.OperandValid = 1;
1171 rec.Result.OperandValid = 0;
1172 } else {
1173 rec.Operand1.OperandValid = 0;
1174 rec.Result.OperandValid = 1;
1176 rec.Operand2.OperandValid = 1;
1177 rec.Operation = _FpCodeDivide;
1178 rec.Operand1.Format = _FpFormatFp80;
1179 memcpy(&rec.Operand1.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1180 rec.Operand2.Format = _FpFormatFp64;
1181 rec.Operand2.Value.Fp64Value = *(double*)ctx->DataOffset;
1182 rec.Result.Format = _FpFormatFp80;
1183 memcpy(&rec.Result.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1185 ret = handler(&rec);
1187 if(ret == EXCEPTION_CONTINUE_EXECUTION)
1188 memcpy(ctx->RegisterArea, &rec.Result.Value.Fp80Value, sizeof(rec.Operand1.Value.Fp80Value));
1189 return ret;
1192 FIXME("unsupported opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1193 return EXCEPTION_CONTINUE_SEARCH;
1196 #endif /* __i386__ */