wined3d: Get rid of redundant DISCARD filtering.
[wine.git] / dlls / msvcrt / except_i386.c
blob86d80d7deda79b313af93939a9fce274f6d61599
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 #ifdef __i386__
30 #include <stdarg.h>
31 #include <fpieee.h>
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winternl.h"
36 #include "msvcrt.h"
37 #include "wine/exception.h"
38 #include "excpt.h"
39 #include "wine/debug.h"
41 #include "cppexcept.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(seh);
46 /* the exception frame used by CxxFrameHandler */
47 typedef struct __cxx_exception_frame
49 EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
50 int trylevel;
51 DWORD ebp;
52 } cxx_exception_frame;
54 /* info about a single catch {} block */
55 typedef struct __catchblock_info
57 UINT flags; /* flags (see below) */
58 const type_info *type_info; /* C++ type caught by this block */
59 int offset; /* stack offset to copy exception object to */
60 void * (*handler)(void);/* catch block handler code */
61 } catchblock_info;
62 #define TYPE_FLAG_CONST 1
63 #define TYPE_FLAG_VOLATILE 2
64 #define TYPE_FLAG_REFERENCE 8
66 /* info about a single try {} block */
67 typedef struct __tryblock_info
69 int start_level; /* start trylevel of that block */
70 int end_level; /* end trylevel of that block */
71 int catch_level; /* initial trylevel of the catch block */
72 int catchblock_count; /* count of catch blocks in array */
73 const catchblock_info *catchblock; /* array of catch blocks */
74 } tryblock_info;
76 /* info about the unwind handler for a given trylevel */
77 typedef struct __unwind_info
79 int prev; /* prev trylevel unwind handler, to run after this one */
80 void * (*handler)(void);/* unwind handler */
81 } unwind_info;
83 /* descriptor of all try blocks of a given function */
84 typedef struct __cxx_function_descr
86 UINT magic; /* must be CXX_FRAME_MAGIC */
87 UINT unwind_count; /* number of unwind handlers */
88 const unwind_info *unwind_table; /* array of unwind handlers */
89 UINT tryblock_count; /* number of try blocks */
90 const tryblock_info *tryblock; /* array of try blocks */
91 UINT ipmap_count;
92 const void *ipmap;
93 const void *expect_list; /* expected exceptions list when magic >= VC7 */
94 UINT flags; /* flags when magic >= VC8 */
95 } cxx_function_descr;
97 /* exception frame for nested exceptions in catch block */
98 typedef struct
100 EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */
101 cxx_exception_frame *cxx_frame; /* frame of parent exception */
102 const cxx_function_descr *descr; /* descriptor of parent exception */
103 int trylevel; /* current try level */
104 cxx_frame_info frame_info;
105 } catch_func_nested_frame;
107 typedef struct
109 cxx_exception_frame *frame;
110 const cxx_function_descr *descr;
111 catch_func_nested_frame *nested_frame;
112 } se_translator_ctx;
114 typedef struct _SCOPETABLE
116 int previousTryLevel;
117 int (*lpfnFilter)(PEXCEPTION_POINTERS);
118 void * (*lpfnHandler)(void);
119 } SCOPETABLE, *PSCOPETABLE;
121 typedef struct MSVCRT_EXCEPTION_FRAME
123 EXCEPTION_REGISTRATION_RECORD *prev;
124 void (*handler)(PEXCEPTION_RECORD, EXCEPTION_REGISTRATION_RECORD*,
125 PCONTEXT, PEXCEPTION_RECORD);
126 PSCOPETABLE scopetable;
127 int trylevel;
128 int _ebp;
129 PEXCEPTION_POINTERS xpointers;
130 } MSVCRT_EXCEPTION_FRAME;
132 typedef struct
134 int gs_cookie_offset;
135 ULONG gs_cookie_xor;
136 int eh_cookie_offset;
137 ULONG eh_cookie_xor;
138 SCOPETABLE entries[1];
139 } SCOPETABLE_V4;
141 #define TRYLEVEL_END (-1) /* End of trylevel list */
143 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
144 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
145 const cxx_function_descr *descr,
146 catch_func_nested_frame* nested_frame ) DECLSPEC_HIDDEN;
148 /* call a copy constructor */
149 extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase );
151 __ASM_GLOBAL_FUNC( call_copy_ctor,
152 "pushl %ebp\n\t"
153 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
154 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
155 "movl %esp, %ebp\n\t"
156 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
157 "pushl $1\n\t"
158 "movl 12(%ebp), %ecx\n\t"
159 "pushl 16(%ebp)\n\t"
160 "call *8(%ebp)\n\t"
161 "leave\n"
162 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
163 __ASM_CFI(".cfi_same_value %ebp\n\t")
164 "ret" );
166 /* continue execution to the specified address after exception is caught */
167 extern void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr );
169 __ASM_GLOBAL_FUNC( continue_after_catch,
170 "movl 4(%esp), %edx\n\t"
171 "movl 8(%esp), %eax\n\t"
172 "movl -4(%edx), %esp\n\t"
173 "leal 12(%edx), %ebp\n\t"
174 "jmp *%eax" );
176 extern void DECLSPEC_NORETURN call_finally_block( void *code_block, void *base_ptr );
178 __ASM_GLOBAL_FUNC( call_finally_block,
179 "movl 8(%esp), %ebp\n\t"
180 "jmp *4(%esp)" );
182 extern int call_filter( int (*func)(PEXCEPTION_POINTERS), void *arg, void *ebp );
184 __ASM_GLOBAL_FUNC( call_filter,
185 "pushl %ebp\n\t"
186 "pushl 12(%esp)\n\t"
187 "movl 20(%esp), %ebp\n\t"
188 "call *12(%esp)\n\t"
189 "popl %ebp\n\t"
190 "popl %ebp\n\t"
191 "ret" );
193 extern void *call_handler( void * (*func)(void), void *ebp );
195 __ASM_GLOBAL_FUNC( call_handler,
196 "pushl %ebp\n\t"
197 "pushl %ebx\n\t"
198 "pushl %esi\n\t"
199 "pushl %edi\n\t"
200 "movl 24(%esp), %ebp\n\t"
201 "call *20(%esp)\n\t"
202 "popl %edi\n\t"
203 "popl %esi\n\t"
204 "popl %ebx\n\t"
205 "popl %ebp\n\t"
206 "ret" );
208 static inline void dump_type( const cxx_type_info *type )
210 TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
211 type->flags, type->type_info, dbgstr_type_info(type->type_info),
212 type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
213 type->size, type->copy_ctor );
216 static void dump_exception_type( const cxx_exception_type *type )
218 UINT i;
220 TRACE( "flags %x destr %p handler %p type info %p\n",
221 type->flags, type->destructor, type->custom_handler, type->type_info_table );
222 for (i = 0; i < type->type_info_table->count; i++)
224 TRACE( " %d: ", i );
225 dump_type( type->type_info_table->info[i] );
229 static void dump_function_descr( const cxx_function_descr *descr )
231 UINT i;
232 int j;
234 TRACE( "magic %x\n", descr->magic );
235 TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count );
236 for (i = 0; i < descr->unwind_count; i++)
238 TRACE( " %d: prev %d func %p\n", i,
239 descr->unwind_table[i].prev, descr->unwind_table[i].handler );
241 TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count );
242 for (i = 0; i < descr->tryblock_count; i++)
244 TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i,
245 descr->tryblock[i].start_level, descr->tryblock[i].end_level,
246 descr->tryblock[i].catch_level, descr->tryblock[i].catchblock,
247 descr->tryblock[i].catchblock_count );
248 for (j = 0; j < descr->tryblock[i].catchblock_count; j++)
250 const catchblock_info *ptr = &descr->tryblock[i].catchblock[j];
251 TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
252 j, ptr->flags, ptr->offset, ptr->handler,
253 ptr->type_info, dbgstr_type_info( ptr->type_info ) );
256 if (descr->magic <= CXX_FRAME_MAGIC_VC6) return;
257 TRACE( "expect list: %p\n", descr->expect_list );
258 if (descr->magic <= CXX_FRAME_MAGIC_VC7) return;
259 TRACE( "flags: %08x\n", descr->flags );
262 /* check if the exception type is caught by a given catch block, and return the type that matched */
263 static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type,
264 const type_info *catch_ti, UINT catch_flags )
266 UINT i;
268 for (i = 0; i < exc_type->type_info_table->count; i++)
270 const cxx_type_info *type = exc_type->type_info_table->info[i];
272 if (!catch_ti) return type; /* catch(...) matches any type */
273 if (catch_ti != type->type_info)
275 if (strcmp( catch_ti->mangled, type->type_info->mangled )) continue;
277 /* type is the same, now check the flags */
278 if ((exc_type->flags & TYPE_FLAG_CONST) &&
279 !(catch_flags & TYPE_FLAG_CONST)) continue;
280 if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
281 !(catch_flags & TYPE_FLAG_VOLATILE)) continue;
282 return type; /* it matched */
284 return NULL;
288 /* copy the exception object where the catch block wants it */
289 static void copy_exception( void *object, cxx_exception_frame *frame,
290 const catchblock_info *catchblock, const cxx_type_info *type )
292 void **dest_ptr;
294 if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return;
295 if (!catchblock->offset) return;
296 dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset);
298 if (catchblock->flags & TYPE_FLAG_REFERENCE)
300 *dest_ptr = get_this_pointer( &type->offsets, object );
302 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
304 memmove( dest_ptr, object, type->size );
305 /* if it is a pointer, adjust it */
306 if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr );
308 else /* copy the object */
310 if (type->copy_ctor)
311 call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object),
312 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
313 else
314 memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size );
318 /* unwind the local function up to a given trylevel */
319 static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level)
321 void * (*handler)(void);
322 int trylevel = frame->trylevel;
324 while (trylevel != last_level)
326 if (trylevel < 0 || trylevel >= descr->unwind_count)
328 ERR( "invalid trylevel %d\n", trylevel );
329 terminate();
331 handler = descr->unwind_table[trylevel].handler;
332 if (handler)
334 TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
335 handler, trylevel, last_level, &frame->ebp );
336 call_handler( handler, &frame->ebp );
338 trylevel = descr->unwind_table[trylevel].prev;
340 frame->trylevel = last_level;
343 /* handler for exceptions happening while calling a catch function */
344 static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
345 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
347 catch_func_nested_frame *nested_frame = (catch_func_nested_frame *)frame;
349 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
351 __CxxUnregisterExceptionObject(&nested_frame->frame_info, FALSE);
352 return ExceptionContinueSearch;
355 TRACE( "got nested exception in catch function\n" );
357 if(rec->ExceptionCode == CXX_EXCEPTION)
359 PEXCEPTION_RECORD prev_rec = msvcrt_get_thread_data()->exc_record;
361 if((rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) ||
362 (prev_rec->ExceptionCode == CXX_EXCEPTION &&
363 rec->ExceptionInformation[1] == prev_rec->ExceptionInformation[1] &&
364 rec->ExceptionInformation[2] == prev_rec->ExceptionInformation[2]))
366 /* exception was rethrown */
367 *rec = *prev_rec;
368 rec->ExceptionFlags &= ~EH_UNWINDING;
369 if(TRACE_ON(seh)) {
370 TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode);
371 if(rec->ExceptionCode == CXX_EXCEPTION)
372 TRACE("re-propagate: obj: %lx, type: %lx\n",
373 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
376 else
378 TRACE("detect threw new exception in catch block\n");
382 return cxx_frame_handler( rec, nested_frame->cxx_frame, context,
383 NULL, nested_frame->descr, nested_frame );
386 /* find and call the appropriate catch block for an exception */
387 /* returns the address to continue execution to after the catch block was called */
388 static inline void call_catch_block( PEXCEPTION_RECORD rec, CONTEXT *context,
389 cxx_exception_frame *frame,
390 const cxx_function_descr *descr,
391 catch_func_nested_frame *catch_frame,
392 cxx_exception_type *info )
394 UINT i;
395 int j;
396 void *addr, *object = (void *)rec->ExceptionInformation[1];
397 catch_func_nested_frame nested_frame;
398 int trylevel = frame->trylevel;
399 DWORD save_esp = ((DWORD*)frame)[-1];
400 thread_data_t *data = msvcrt_get_thread_data();
402 data->processing_throw++;
403 for (i = 0; i < descr->tryblock_count; i++)
405 const tryblock_info *tryblock = &descr->tryblock[i];
407 /* only handle try blocks inside current catch block */
408 if (catch_frame && catch_frame->trylevel > tryblock->start_level) continue;
410 if (trylevel < tryblock->start_level) continue;
411 if (trylevel > tryblock->end_level) continue;
413 /* got a try block */
414 for (j = 0; j < tryblock->catchblock_count; j++)
416 const catchblock_info *catchblock = &tryblock->catchblock[j];
417 if(info)
419 const cxx_type_info *type = find_caught_type( info,
420 catchblock->type_info, catchblock->flags );
421 if (!type) continue;
423 TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j );
425 /* copy the exception to its destination on the stack */
426 copy_exception( object, frame, catchblock, type );
428 else
430 /* no CXX_EXCEPTION only proceed with a catch(...) block*/
431 if(catchblock->type_info)
432 continue;
433 TRACE("found catch(...) block\n");
436 /* Add frame info here so exception is not freed inside RtlUnwind call */
437 _CreateFrameInfo(&nested_frame.frame_info.frame_info,
438 (void*)rec->ExceptionInformation[1]);
440 /* unwind the stack */
441 RtlUnwind( catch_frame ? &catch_frame->frame : &frame->frame, 0, rec, 0 );
442 cxx_local_unwind( frame, descr, tryblock->start_level );
443 frame->trylevel = tryblock->end_level + 1;
445 nested_frame.frame_info.rec = data->exc_record;
446 nested_frame.frame_info.context = data->ctx_record;
447 data->exc_record = rec;
448 data->ctx_record = context;
449 data->processing_throw--;
451 /* call the catch block */
452 TRACE( "calling catch block %p addr %p ebp %p\n",
453 catchblock, catchblock->handler, &frame->ebp );
455 /* setup an exception block for nested exceptions */
456 nested_frame.frame.Handler = catch_function_nested_handler;
457 nested_frame.cxx_frame = frame;
458 nested_frame.descr = descr;
459 nested_frame.trylevel = tryblock->end_level + 1;
461 __wine_push_frame( &nested_frame.frame );
462 addr = call_handler( catchblock->handler, &frame->ebp );
463 __wine_pop_frame( &nested_frame.frame );
465 ((DWORD*)frame)[-1] = save_esp;
466 __CxxUnregisterExceptionObject(&nested_frame.frame_info, FALSE);
467 TRACE( "done, continuing at %p\n", addr );
469 continue_after_catch( frame, addr );
472 data->processing_throw--;
475 /*********************************************************************
476 * __CxxExceptionFilter (MSVCRT.@)
478 int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
479 const type_info *ti, int flags, void **copy)
481 const cxx_type_info *type;
482 PEXCEPTION_RECORD rec;
484 TRACE( "%p %p %x %p\n", ptrs, ti, flags, copy );
486 if (!ptrs) return EXCEPTION_CONTINUE_SEARCH;
488 /* handle catch(...) */
489 if (!ti) return EXCEPTION_EXECUTE_HANDLER;
491 rec = ptrs->ExceptionRecord;
492 if (rec->ExceptionCode != CXX_EXCEPTION || rec->NumberParameters != 3 ||
493 rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 ||
494 rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8)
495 return EXCEPTION_CONTINUE_SEARCH;
497 if (rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
499 rec = msvcrt_get_thread_data()->exc_record;
500 if (!rec) return EXCEPTION_CONTINUE_SEARCH;
503 type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], ti, flags );
504 if (!type) return EXCEPTION_CONTINUE_SEARCH;
506 if (copy)
508 void *object = (void *)rec->ExceptionInformation[1];
510 if (flags & TYPE_FLAG_REFERENCE)
512 *copy = get_this_pointer( &type->offsets, object );
514 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
516 memmove( copy, object, type->size );
517 /* if it is a pointer, adjust it */
518 if (type->size == sizeof(void*)) *copy = get_this_pointer( &type->offsets, *copy );
520 else /* copy the object */
522 if (type->copy_ctor)
523 call_copy_ctor( type->copy_ctor, copy, get_this_pointer(&type->offsets,object),
524 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
525 else
526 memmove( copy, get_this_pointer(&type->offsets,object), type->size );
529 return EXCEPTION_EXECUTE_HANDLER;
532 static LONG CALLBACK se_translation_filter( EXCEPTION_POINTERS *ep, void *c )
534 se_translator_ctx *ctx = (se_translator_ctx *)c;
535 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
536 cxx_exception_type *exc_type;
538 if (rec->ExceptionCode != CXX_EXCEPTION)
540 TRACE( "non-c++ exception thrown in SEH handler: %x\n", rec->ExceptionCode );
541 terminate();
544 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
545 call_catch_block( rec, ep->ContextRecord, ctx->frame, ctx->descr,
546 ctx->nested_frame, exc_type );
548 __DestructExceptionObject( rec );
549 return ExceptionContinueSearch;
552 static void check_noexcept( PEXCEPTION_RECORD rec,
553 const cxx_function_descr *descr, BOOL nested )
555 if (!nested && rec->ExceptionCode == CXX_EXCEPTION &&
556 descr->magic >= CXX_FRAME_MAGIC_VC8 &&
557 (descr->flags & FUNC_DESCR_NOEXCEPT))
559 ERR("noexcept function propagating exception\n");
560 terminate();
564 /*********************************************************************
565 * cxx_frame_handler
567 * Implementation of __CxxFrameHandler.
569 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
570 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
571 const cxx_function_descr *descr,
572 catch_func_nested_frame* nested_frame )
574 cxx_exception_type *exc_type;
576 if (descr->magic < CXX_FRAME_MAGIC_VC6 || descr->magic > CXX_FRAME_MAGIC_VC8)
578 ERR( "invalid frame magic %x\n", descr->magic );
579 return ExceptionContinueSearch;
581 if (descr->magic >= CXX_FRAME_MAGIC_VC8 &&
582 (descr->flags & FUNC_DESCR_SYNCHRONOUS) &&
583 (rec->ExceptionCode != CXX_EXCEPTION))
584 return ExceptionContinueSearch; /* handle only c++ exceptions */
586 if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
588 if (descr->unwind_count && !nested_frame) cxx_local_unwind( frame, descr, -1 );
589 return ExceptionContinueSearch;
591 if (!descr->tryblock_count)
593 check_noexcept(rec, descr, nested_frame != NULL);
594 return ExceptionContinueSearch;
597 if(rec->ExceptionCode == CXX_EXCEPTION &&
598 rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
600 *rec = *msvcrt_get_thread_data()->exc_record;
601 rec->ExceptionFlags &= ~EH_UNWINDING;
602 if(TRACE_ON(seh)) {
603 TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode);
604 if(rec->ExceptionCode == CXX_EXCEPTION)
605 TRACE("re-propagate: obj: %lx, type: %lx\n",
606 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
610 if(rec->ExceptionCode == CXX_EXCEPTION)
612 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
614 if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8 &&
615 exc_type->custom_handler)
617 return exc_type->custom_handler( rec, frame, context, dispatch, descr,
618 nested_frame ? nested_frame->trylevel : 0,
619 nested_frame ? &nested_frame->frame : NULL, 0 );
622 if (TRACE_ON(seh))
624 TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
625 rec, frame, frame->trylevel, descr, nested_frame );
626 dump_exception_type( exc_type );
627 dump_function_descr( descr );
630 else
632 thread_data_t *data = msvcrt_get_thread_data();
634 exc_type = NULL;
635 TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
636 rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame );
638 if (data->se_translator) {
639 EXCEPTION_POINTERS except_ptrs;
640 se_translator_ctx ctx;
642 ctx.frame = frame;
643 ctx.descr = descr;
644 ctx.nested_frame = nested_frame;
645 __TRY
647 except_ptrs.ExceptionRecord = rec;
648 except_ptrs.ContextRecord = context;
649 data->se_translator( rec->ExceptionCode, &except_ptrs );
651 __EXCEPT_CTX(se_translation_filter, &ctx)
654 __ENDTRY
658 call_catch_block( rec, context, frame, descr,
659 nested_frame, exc_type );
660 check_noexcept(rec, descr, nested_frame != NULL);
661 return ExceptionContinueSearch;
665 /*********************************************************************
666 * __CxxFrameHandler (MSVCRT.@)
668 extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame,
669 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch );
670 __ASM_GLOBAL_FUNC( __CxxFrameHandler,
671 "pushl $0\n\t" /* nested_frame */
672 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
673 "pushl %eax\n\t" /* descr */
674 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
675 "pushl 24(%esp)\n\t" /* dispatch */
676 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
677 "pushl 24(%esp)\n\t" /* context */
678 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
679 "pushl 24(%esp)\n\t" /* frame */
680 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
681 "pushl 24(%esp)\n\t" /* rec */
682 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
683 "call " __ASM_NAME("cxx_frame_handler") "\n\t"
684 "add $24,%esp\n\t"
685 __ASM_CFI(".cfi_adjust_cfa_offset -24\n\t")
686 "ret" )
689 /*********************************************************************
690 * __CxxLongjmpUnwind (MSVCRT.@)
692 * Callback meant to be used as UnwindFunc for setjmp/longjmp.
694 void __stdcall __CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER *buf )
696 cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
697 const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
699 TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel );
700 cxx_local_unwind( frame, descr, buf->TryLevel );
703 /*********************************************************************
704 * __CppXcptFilter (MSVCRT.@)
706 int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
708 /* only filter c++ exceptions */
709 if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
710 return _XcptFilter( ex, ptr );
713 /*********************************************************************
714 * __CxxDetectRethrow (MSVCRT.@)
716 BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
718 PEXCEPTION_RECORD rec;
720 if (!ptrs)
721 return FALSE;
723 rec = ptrs->ExceptionRecord;
725 if (rec->ExceptionCode == CXX_EXCEPTION &&
726 rec->NumberParameters == 3 &&
727 rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
728 rec->ExceptionInformation[2])
730 ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
731 return TRUE;
733 return (msvcrt_get_thread_data()->exc_record == rec);
736 /*********************************************************************
737 * __CxxQueryExceptionSize (MSVCRT.@)
739 unsigned int CDECL __CxxQueryExceptionSize(void)
741 return sizeof(cxx_exception_type);
745 /*********************************************************************
746 * _EH_prolog (MSVCRT.@)
749 /* Provided for VC++ binary compatibility only */
750 __ASM_GLOBAL_FUNC(_EH_prolog,
751 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */
752 "pushl $-1\n\t"
753 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
754 "pushl %eax\n\t"
755 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
756 "pushl %fs:0\n\t"
757 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
758 "movl %esp, %fs:0\n\t"
759 "movl 12(%esp), %eax\n\t"
760 "movl %ebp, 12(%esp)\n\t"
761 "leal 12(%esp), %ebp\n\t"
762 "pushl %eax\n\t"
763 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
764 "ret")
766 static const SCOPETABLE_V4 *get_scopetable_v4( MSVCRT_EXCEPTION_FRAME *frame, ULONG_PTR cookie )
768 return (const SCOPETABLE_V4 *)((ULONG_PTR)frame->scopetable ^ cookie);
771 static DWORD MSVCRT_nested_handler(PEXCEPTION_RECORD rec,
772 EXCEPTION_REGISTRATION_RECORD* frame,
773 PCONTEXT context,
774 EXCEPTION_REGISTRATION_RECORD** dispatch)
776 if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
777 return ExceptionContinueSearch;
778 *dispatch = frame;
779 return ExceptionCollidedUnwind;
782 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp)
784 EXCEPTION_REGISTRATION_RECORD reg;
786 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
788 /* Register a handler in case of a nested exception */
789 reg.Handler = MSVCRT_nested_handler;
790 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
791 __wine_push_frame(&reg);
793 while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel)
795 int level = frame->trylevel;
796 frame->trylevel = frame->scopetable[level].previousTryLevel;
797 if (!frame->scopetable[level].lpfnFilter)
799 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
800 level, frame->scopetable[level].lpfnHandler, ebp );
801 call_handler( frame->scopetable[level].lpfnHandler, ebp );
804 __wine_pop_frame(&reg);
805 TRACE("unwound OK\n");
808 static void msvcrt_local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp )
810 EXCEPTION_REGISTRATION_RECORD reg;
811 const SCOPETABLE_V4 *scopetable = get_scopetable_v4( frame, *cookie );
813 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
815 /* Register a handler in case of a nested exception */
816 reg.Handler = MSVCRT_nested_handler;
817 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
818 __wine_push_frame(&reg);
820 while (frame->trylevel != -2 && frame->trylevel != trylevel)
822 int level = frame->trylevel;
823 frame->trylevel = scopetable->entries[level].previousTryLevel;
824 if (!scopetable->entries[level].lpfnFilter)
826 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
827 level, scopetable->entries[level].lpfnHandler, ebp );
828 call_handler( scopetable->entries[level].lpfnHandler, ebp );
831 __wine_pop_frame(&reg);
832 TRACE("unwound OK\n");
835 /*******************************************************************
836 * _local_unwind2 (MSVCRT.@)
838 void CDECL _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel)
840 msvcrt_local_unwind2( frame, trylevel, &frame->_ebp );
843 /*******************************************************************
844 * _local_unwind4 (MSVCRT.@)
846 void CDECL _local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel )
848 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
851 /*******************************************************************
852 * _global_unwind2 (MSVCRT.@)
854 void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame)
856 TRACE("(%p)\n",frame);
857 RtlUnwind( frame, 0, 0, 0 );
860 /*********************************************************************
861 * _except_handler2 (MSVCRT.@)
863 int CDECL _except_handler2(PEXCEPTION_RECORD rec,
864 EXCEPTION_REGISTRATION_RECORD* frame,
865 PCONTEXT context,
866 EXCEPTION_REGISTRATION_RECORD** dispatcher)
868 FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n",
869 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
870 frame->Handler, context, dispatcher);
871 return ExceptionContinueSearch;
874 /*********************************************************************
875 * _except_handler3 (MSVCRT.@)
877 int CDECL _except_handler3(PEXCEPTION_RECORD rec,
878 MSVCRT_EXCEPTION_FRAME* frame,
879 PCONTEXT context, void* dispatcher)
881 int retval, trylevel;
882 EXCEPTION_POINTERS exceptPtrs;
883 PSCOPETABLE pScopeTable;
885 TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n",
886 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
887 frame->handler, context, dispatcher);
889 __asm__ __volatile__ ("cld");
891 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
893 /* Unwinding the current frame */
894 msvcrt_local_unwind2(frame, TRYLEVEL_END, &frame->_ebp);
895 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
896 return ExceptionContinueSearch;
898 else
900 /* Hunting for handler */
901 exceptPtrs.ExceptionRecord = rec;
902 exceptPtrs.ContextRecord = context;
903 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
904 trylevel = frame->trylevel;
905 pScopeTable = frame->scopetable;
907 while (trylevel != TRYLEVEL_END)
909 TRACE( "level %d prev %d filter %p\n", trylevel, pScopeTable[trylevel].previousTryLevel,
910 pScopeTable[trylevel].lpfnFilter );
911 if (pScopeTable[trylevel].lpfnFilter)
913 retval = call_filter( pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
915 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
916 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
917 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
919 if (retval == EXCEPTION_CONTINUE_EXECUTION)
920 return ExceptionContinueExecution;
922 if (retval == EXCEPTION_EXECUTE_HANDLER)
924 /* Unwind all higher frames, this one will handle the exception */
925 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
926 msvcrt_local_unwind2(frame, trylevel, &frame->_ebp);
928 /* Set our trylevel to the enclosing block, and call the __finally
929 * code, which won't return
931 frame->trylevel = pScopeTable[trylevel].previousTryLevel;
932 TRACE("__finally block %p\n",pScopeTable[trylevel].lpfnHandler);
933 call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp);
936 trylevel = pScopeTable[trylevel].previousTryLevel;
939 TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
940 return ExceptionContinueSearch;
943 /*********************************************************************
944 * _except_handler4_common (MSVCRT.@)
946 int CDECL _except_handler4_common( ULONG *cookie, void (*check_cookie)(void),
947 EXCEPTION_RECORD *rec, MSVCRT_EXCEPTION_FRAME *frame,
948 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
950 int retval, trylevel;
951 EXCEPTION_POINTERS exceptPtrs;
952 const SCOPETABLE_V4 *scope_table = get_scopetable_v4( frame, *cookie );
954 TRACE( "exception %x flags=%x at %p handler=%p %p %p cookie=%x scope table=%p cookies=%d/%x,%d/%x\n",
955 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
956 frame->handler, context, dispatcher, *cookie, scope_table,
957 scope_table->gs_cookie_offset, scope_table->gs_cookie_xor,
958 scope_table->eh_cookie_offset, scope_table->eh_cookie_xor );
960 /* FIXME: no cookie validation yet */
962 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
964 /* Unwinding the current frame */
965 msvcrt_local_unwind4( cookie, frame, -2, &frame->_ebp );
966 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
967 return ExceptionContinueSearch;
969 else
971 /* Hunting for handler */
972 exceptPtrs.ExceptionRecord = rec;
973 exceptPtrs.ContextRecord = context;
974 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
975 trylevel = frame->trylevel;
977 while (trylevel != -2)
979 TRACE( "level %d prev %d filter %p\n", trylevel,
980 scope_table->entries[trylevel].previousTryLevel,
981 scope_table->entries[trylevel].lpfnFilter );
982 if (scope_table->entries[trylevel].lpfnFilter)
984 retval = call_filter( scope_table->entries[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
986 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
987 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
988 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
990 if (retval == EXCEPTION_CONTINUE_EXECUTION)
991 return ExceptionContinueExecution;
993 if (retval == EXCEPTION_EXECUTE_HANDLER)
995 __DestructExceptionObject(rec);
997 /* Unwind all higher frames, this one will handle the exception */
998 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
999 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
1001 /* Set our trylevel to the enclosing block, and call the __finally
1002 * code, which won't return
1004 frame->trylevel = scope_table->entries[trylevel].previousTryLevel;
1005 TRACE("__finally block %p\n",scope_table->entries[trylevel].lpfnHandler);
1006 call_finally_block(scope_table->entries[trylevel].lpfnHandler, &frame->_ebp);
1009 trylevel = scope_table->entries[trylevel].previousTryLevel;
1012 TRACE("reached -2, returning ExceptionContinueSearch\n");
1013 return ExceptionContinueSearch;
1018 * setjmp/longjmp implementation
1021 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
1022 typedef void (__stdcall *MSVCRT_unwind_function)(const struct MSVCRT___JUMP_BUFFER *);
1024 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
1025 /* and then jumps to the C backend function */
1026 #define DEFINE_SETJMP_ENTRYPOINT(name) \
1027 __ASM_GLOBAL_FUNC( name, \
1028 "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \
1029 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \
1030 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \
1031 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \
1032 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \
1033 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \
1034 "movl 0(%esp),%eax\n\t" \
1035 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \
1036 "jmp " __ASM_NAME("__regs_") # name )
1038 /*******************************************************************
1039 * _setjmp (MSVCRT.@)
1041 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp)
1042 int CDECL DECLSPEC_HIDDEN __regs_MSVCRT__setjmp(struct MSVCRT___JUMP_BUFFER *jmp)
1044 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1045 if (jmp->Registration == ~0UL)
1046 jmp->TryLevel = TRYLEVEL_END;
1047 else
1048 jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1050 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1051 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1052 return 0;
1055 /*******************************************************************
1056 * _setjmp3 (MSVCRT.@)
1058 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3 )
1059 int WINAPIV DECLSPEC_HIDDEN __regs_MSVCRT__setjmp3(struct MSVCRT___JUMP_BUFFER *jmp, int nb_args, ...)
1061 jmp->Cookie = MSVCRT_JMP_MAGIC;
1062 jmp->UnwindFunc = 0;
1063 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1064 if (jmp->Registration == ~0UL)
1066 jmp->TryLevel = TRYLEVEL_END;
1068 else
1070 int i;
1071 va_list args;
1073 va_start( args, nb_args );
1074 if (nb_args > 0) jmp->UnwindFunc = va_arg( args, unsigned long );
1075 if (nb_args > 1) jmp->TryLevel = va_arg( args, unsigned long );
1076 else jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1077 for (i = 0; i < 6 && i < nb_args - 2; i++)
1078 jmp->UnwindData[i] = va_arg( args, unsigned long );
1079 va_end( args );
1082 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1083 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1084 return 0;
1087 /*********************************************************************
1088 * longjmp (MSVCRT.@)
1090 void CDECL MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER *jmp, int retval)
1092 unsigned long cur_frame = 0;
1094 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
1095 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration, retval );
1097 cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1098 TRACE("cur_frame=%lx\n",cur_frame);
1100 if (cur_frame != jmp->Registration)
1101 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)jmp->Registration);
1103 if (jmp->Registration)
1105 if (IsBadReadPtr(&jmp->Cookie, sizeof(long)) || jmp->Cookie != MSVCRT_JMP_MAGIC)
1107 msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME*)jmp->Registration,
1108 jmp->TryLevel, (void *)jmp->Ebp);
1110 else if(jmp->UnwindFunc)
1112 MSVCRT_unwind_function unwind_func;
1114 unwind_func=(MSVCRT_unwind_function)jmp->UnwindFunc;
1115 unwind_func(jmp);
1119 if (!retval)
1120 retval = 1;
1122 __wine_longjmp( (__wine_jmp_buf *)jmp, retval );
1125 /*********************************************************************
1126 * _seh_longjmp_unwind (MSVCRT.@)
1128 void __stdcall _seh_longjmp_unwind(struct MSVCRT___JUMP_BUFFER *jmp)
1130 msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, jmp->TryLevel, (void *)jmp->Ebp );
1133 /*********************************************************************
1134 * _seh_longjmp_unwind4 (MSVCRT.@)
1136 void __stdcall _seh_longjmp_unwind4(struct MSVCRT___JUMP_BUFFER *jmp)
1138 msvcrt_local_unwind4( (ULONG *)&jmp->Cookie, (MSVCRT_EXCEPTION_FRAME *)jmp->Registration,
1139 jmp->TryLevel, (void *)jmp->Ebp );
1142 /*********************************************************************
1143 * _fpieee_flt (MSVCRT.@)
1145 int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep,
1146 int (__cdecl *handler)(_FPIEEE_RECORD*))
1148 FLOATING_SAVE_AREA *ctx = &ep->ContextRecord->FloatSave;
1149 _FPIEEE_RECORD rec;
1150 int ret;
1152 TRACE("(%lx %p %p)\n", exception_code, ep, handler);
1154 switch(exception_code) {
1155 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1156 case STATUS_FLOAT_INEXACT_RESULT:
1157 case STATUS_FLOAT_INVALID_OPERATION:
1158 case STATUS_FLOAT_OVERFLOW:
1159 case STATUS_FLOAT_UNDERFLOW:
1160 break;
1161 default:
1162 return EXCEPTION_CONTINUE_SEARCH;
1165 memset(&rec, 0, sizeof(rec));
1166 rec.RoundingMode = ctx->ControlWord >> 10;
1167 switch((ctx->ControlWord >> 8) & 0x3) {
1168 case 0: rec.Precision = 2; break;
1169 case 1: rec.Precision = 3; break;
1170 case 2: rec.Precision = 1; break;
1171 case 3: rec.Precision = 0; break;
1173 rec.Status.InvalidOperation = ctx->StatusWord & 0x1;
1174 rec.Status.ZeroDivide = ((ctx->StatusWord & 0x4) != 0);
1175 rec.Status.Overflow = ((ctx->StatusWord & 0x8) != 0);
1176 rec.Status.Underflow = ((ctx->StatusWord & 0x10) != 0);
1177 rec.Status.Inexact = ((ctx->StatusWord & 0x20) != 0);
1178 rec.Enable.InvalidOperation = ((ctx->ControlWord & 0x1) == 0);
1179 rec.Enable.ZeroDivide = ((ctx->ControlWord & 0x4) == 0);
1180 rec.Enable.Overflow = ((ctx->ControlWord & 0x8) == 0);
1181 rec.Enable.Underflow = ((ctx->ControlWord & 0x10) == 0);
1182 rec.Enable.Inexact = ((ctx->ControlWord & 0x20) == 0);
1183 rec.Cause.InvalidOperation = rec.Enable.InvalidOperation & rec.Status.InvalidOperation;
1184 rec.Cause.ZeroDivide = rec.Enable.ZeroDivide & rec.Status.ZeroDivide;
1185 rec.Cause.Overflow = rec.Enable.Overflow & rec.Status.Overflow;
1186 rec.Cause.Underflow = rec.Enable.Underflow & rec.Status.Underflow;
1187 rec.Cause.Inexact = rec.Enable.Inexact & rec.Status.Inexact;
1189 TRACE("opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1191 if(*(WORD*)ctx->ErrorOffset == 0x35dc) { /* fdiv m64fp */
1192 if(exception_code==STATUS_FLOAT_DIVIDE_BY_ZERO || exception_code==STATUS_FLOAT_INVALID_OPERATION) {
1193 rec.Operand1.OperandValid = 1;
1194 rec.Result.OperandValid = 0;
1195 } else {
1196 rec.Operand1.OperandValid = 0;
1197 rec.Result.OperandValid = 1;
1199 rec.Operand2.OperandValid = 1;
1200 rec.Operation = _FpCodeDivide;
1201 rec.Operand1.Format = _FpFormatFp80;
1202 memcpy(&rec.Operand1.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1203 rec.Operand2.Format = _FpFormatFp64;
1204 rec.Operand2.Value.Fp64Value = *(double*)ctx->DataOffset;
1205 rec.Result.Format = _FpFormatFp80;
1206 memcpy(&rec.Result.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1208 ret = handler(&rec);
1210 if(ret == EXCEPTION_CONTINUE_EXECUTION)
1211 memcpy(ctx->RegisterArea, &rec.Result.Value.Fp80Value, sizeof(rec.Operand1.Value.Fp80Value));
1212 return ret;
1215 FIXME("unsupported opcode: %x\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1216 return EXCEPTION_CONTINUE_SEARCH;
1219 #endif /* __i386__ */