user32/edit: Handle IME composition result string only when EIMES_GETCOMPSTRATONCE...
[wine.git] / dlls / msvcrt / except_i386.c
blobeb41af36d7e9fbdb1d3c3eab1291c5030615233a
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 <setjmp.h>
31 #include <stdarg.h>
32 #include <fpieee.h>
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winternl.h"
37 #include "msvcrt.h"
38 #include "wine/exception.h"
39 #include "excpt.h"
40 #include "wine/debug.h"
42 #include "cppexcept.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(seh);
47 /* the exception frame used by CxxFrameHandler */
48 typedef struct __cxx_exception_frame
50 EXCEPTION_REGISTRATION_RECORD frame; /* the standard exception frame */
51 int trylevel;
52 DWORD ebp;
53 } cxx_exception_frame;
55 /* info about a single catch {} block */
56 typedef struct __catchblock_info
58 UINT flags; /* flags (see below) */
59 const type_info *type_info; /* C++ type caught by this block */
60 int offset; /* stack offset to copy exception object to */
61 void * (*handler)(void);/* catch block handler code */
62 } catchblock_info;
63 #define TYPE_FLAG_CONST 1
64 #define TYPE_FLAG_VOLATILE 2
65 #define TYPE_FLAG_REFERENCE 8
67 /* info about a single try {} block */
68 typedef struct __tryblock_info
70 int start_level; /* start trylevel of that block */
71 int end_level; /* end trylevel of that block */
72 int catch_level; /* initial trylevel of the catch block */
73 int catchblock_count; /* count of catch blocks in array */
74 const catchblock_info *catchblock; /* array of catch blocks */
75 } tryblock_info;
77 /* info about the unwind handler for a given trylevel */
78 typedef struct __unwind_info
80 int prev; /* prev trylevel unwind handler, to run after this one */
81 void * (*handler)(void);/* unwind handler */
82 } unwind_info;
84 /* descriptor of all try blocks of a given function */
85 typedef struct __cxx_function_descr
87 UINT magic; /* must be CXX_FRAME_MAGIC */
88 UINT unwind_count; /* number of unwind handlers */
89 const unwind_info *unwind_table; /* array of unwind handlers */
90 UINT tryblock_count; /* number of try blocks */
91 const tryblock_info *tryblock; /* array of try blocks */
92 UINT ipmap_count;
93 const void *ipmap;
94 const void *expect_list; /* expected exceptions list when magic >= VC7 */
95 UINT flags; /* flags when magic >= VC8 */
96 } cxx_function_descr;
98 /* exception frame for nested exceptions in catch block */
99 typedef struct
101 EXCEPTION_REGISTRATION_RECORD frame; /* standard exception frame */
102 cxx_exception_frame *cxx_frame; /* frame of parent exception */
103 const cxx_function_descr *descr; /* descriptor of parent exception */
104 int trylevel; /* current try level */
105 cxx_frame_info frame_info;
106 } catch_func_nested_frame;
108 typedef struct
110 cxx_exception_frame *frame;
111 const cxx_function_descr *descr;
112 catch_func_nested_frame *nested_frame;
113 } se_translator_ctx;
115 typedef struct _SCOPETABLE
117 int previousTryLevel;
118 int (*lpfnFilter)(PEXCEPTION_POINTERS);
119 void * (*lpfnHandler)(void);
120 } SCOPETABLE, *PSCOPETABLE;
122 typedef struct MSVCRT_EXCEPTION_FRAME
124 EXCEPTION_REGISTRATION_RECORD *prev;
125 void (*handler)(PEXCEPTION_RECORD, EXCEPTION_REGISTRATION_RECORD*,
126 PCONTEXT, PEXCEPTION_RECORD);
127 PSCOPETABLE scopetable;
128 int trylevel;
129 int _ebp;
130 PEXCEPTION_POINTERS xpointers;
131 } MSVCRT_EXCEPTION_FRAME;
133 typedef struct
135 int gs_cookie_offset;
136 ULONG gs_cookie_xor;
137 int eh_cookie_offset;
138 ULONG eh_cookie_xor;
139 SCOPETABLE entries[1];
140 } SCOPETABLE_V4;
142 #define TRYLEVEL_END (-1) /* End of trylevel list */
144 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
145 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
146 const cxx_function_descr *descr,
147 catch_func_nested_frame* nested_frame ) DECLSPEC_HIDDEN;
149 /* call a copy constructor */
150 extern void call_copy_ctor( void *func, void *this, void *src, int has_vbase );
152 __ASM_GLOBAL_FUNC( call_copy_ctor,
153 "pushl %ebp\n\t"
154 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
155 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
156 "movl %esp, %ebp\n\t"
157 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
158 "pushl $1\n\t"
159 "movl 12(%ebp), %ecx\n\t"
160 "pushl 16(%ebp)\n\t"
161 "call *8(%ebp)\n\t"
162 "leave\n"
163 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
164 __ASM_CFI(".cfi_same_value %ebp\n\t")
165 "ret" );
167 /* continue execution to the specified address after exception is caught */
168 extern void DECLSPEC_NORETURN continue_after_catch( cxx_exception_frame* frame, void *addr );
170 __ASM_GLOBAL_FUNC( continue_after_catch,
171 "movl 4(%esp), %edx\n\t"
172 "movl 8(%esp), %eax\n\t"
173 "movl -4(%edx), %esp\n\t"
174 "leal 12(%edx), %ebp\n\t"
175 "jmp *%eax" );
177 extern void DECLSPEC_NORETURN call_finally_block( void *code_block, void *base_ptr );
179 __ASM_GLOBAL_FUNC( call_finally_block,
180 "movl 8(%esp), %ebp\n\t"
181 "jmp *4(%esp)" );
183 extern int call_filter( int (*func)(PEXCEPTION_POINTERS), void *arg, void *ebp );
185 __ASM_GLOBAL_FUNC( call_filter,
186 "pushl %ebp\n\t"
187 "pushl 12(%esp)\n\t"
188 "movl 20(%esp), %ebp\n\t"
189 "call *12(%esp)\n\t"
190 "popl %ebp\n\t"
191 "popl %ebp\n\t"
192 "ret" );
194 extern void *call_handler( void * (*func)(void), void *ebp );
196 __ASM_GLOBAL_FUNC( call_handler,
197 "pushl %ebp\n\t"
198 "pushl %ebx\n\t"
199 "pushl %esi\n\t"
200 "pushl %edi\n\t"
201 "movl 24(%esp), %ebp\n\t"
202 "call *20(%esp)\n\t"
203 "popl %edi\n\t"
204 "popl %esi\n\t"
205 "popl %ebx\n\t"
206 "popl %ebp\n\t"
207 "ret" );
209 static inline void dump_type( const cxx_type_info *type )
211 TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
212 type->flags, type->type_info, dbgstr_type_info(type->type_info),
213 type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
214 type->size, type->copy_ctor );
217 static void dump_exception_type( const cxx_exception_type *type )
219 UINT i;
221 TRACE( "flags %x destr %p handler %p type info %p\n",
222 type->flags, type->destructor, type->custom_handler, type->type_info_table );
223 for (i = 0; i < type->type_info_table->count; i++)
225 TRACE( " %d: ", i );
226 dump_type( type->type_info_table->info[i] );
230 static void dump_function_descr( const cxx_function_descr *descr )
232 UINT i;
233 int j;
235 TRACE( "magic %x\n", descr->magic );
236 TRACE( "unwind table: %p %d\n", descr->unwind_table, descr->unwind_count );
237 for (i = 0; i < descr->unwind_count; i++)
239 TRACE( " %d: prev %d func %p\n", i,
240 descr->unwind_table[i].prev, descr->unwind_table[i].handler );
242 TRACE( "try table: %p %d\n", descr->tryblock, descr->tryblock_count );
243 for (i = 0; i < descr->tryblock_count; i++)
245 TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i,
246 descr->tryblock[i].start_level, descr->tryblock[i].end_level,
247 descr->tryblock[i].catch_level, descr->tryblock[i].catchblock,
248 descr->tryblock[i].catchblock_count );
249 for (j = 0; j < descr->tryblock[i].catchblock_count; j++)
251 const catchblock_info *ptr = &descr->tryblock[i].catchblock[j];
252 TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
253 j, ptr->flags, ptr->offset, ptr->handler,
254 ptr->type_info, dbgstr_type_info( ptr->type_info ) );
257 if (descr->magic <= CXX_FRAME_MAGIC_VC6) return;
258 TRACE( "expect list: %p\n", descr->expect_list );
259 if (descr->magic <= CXX_FRAME_MAGIC_VC7) return;
260 TRACE( "flags: %08x\n", descr->flags );
263 /* check if the exception type is caught by a given catch block, and return the type that matched */
264 static const cxx_type_info *find_caught_type( cxx_exception_type *exc_type,
265 const type_info *catch_ti, UINT catch_flags )
267 UINT i;
269 for (i = 0; i < exc_type->type_info_table->count; i++)
271 const cxx_type_info *type = exc_type->type_info_table->info[i];
273 if (!catch_ti) return type; /* catch(...) matches any type */
274 if (catch_ti != type->type_info)
276 if (strcmp( catch_ti->mangled, type->type_info->mangled )) continue;
278 /* type is the same, now check the flags */
279 if ((exc_type->flags & TYPE_FLAG_CONST) &&
280 !(catch_flags & TYPE_FLAG_CONST)) continue;
281 if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
282 !(catch_flags & TYPE_FLAG_VOLATILE)) continue;
283 return type; /* it matched */
285 return NULL;
289 /* copy the exception object where the catch block wants it */
290 static void copy_exception( void *object, cxx_exception_frame *frame,
291 const catchblock_info *catchblock, const cxx_type_info *type )
293 void **dest_ptr;
295 if (!catchblock->type_info || !catchblock->type_info->mangled[0]) return;
296 if (!catchblock->offset) return;
297 dest_ptr = (void **)((char *)&frame->ebp + catchblock->offset);
299 if (catchblock->flags & TYPE_FLAG_REFERENCE)
301 *dest_ptr = get_this_pointer( &type->offsets, object );
303 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
305 memmove( dest_ptr, object, type->size );
306 /* if it is a pointer, adjust it */
307 if (type->size == sizeof(void *)) *dest_ptr = get_this_pointer( &type->offsets, *dest_ptr );
309 else /* copy the object */
311 if (type->copy_ctor)
312 call_copy_ctor( type->copy_ctor, dest_ptr, get_this_pointer(&type->offsets,object),
313 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
314 else
315 memmove( dest_ptr, get_this_pointer(&type->offsets,object), type->size );
319 /* unwind the local function up to a given trylevel */
320 static void cxx_local_unwind( cxx_exception_frame* frame, const cxx_function_descr *descr, int last_level)
322 void * (*handler)(void);
323 int trylevel = frame->trylevel;
325 while (trylevel != last_level)
327 if (trylevel < 0 || trylevel >= descr->unwind_count)
329 ERR( "invalid trylevel %d\n", trylevel );
330 terminate();
332 handler = descr->unwind_table[trylevel].handler;
333 if (handler)
335 TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
336 handler, trylevel, last_level, &frame->ebp );
337 call_handler( handler, &frame->ebp );
339 trylevel = descr->unwind_table[trylevel].prev;
341 frame->trylevel = last_level;
344 /* handler for exceptions happening while calling a catch function */
345 static DWORD catch_function_nested_handler( EXCEPTION_RECORD *rec, EXCEPTION_REGISTRATION_RECORD *frame,
346 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
348 catch_func_nested_frame *nested_frame = (catch_func_nested_frame *)frame;
350 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
352 __CxxUnregisterExceptionObject(&nested_frame->frame_info, FALSE);
353 return ExceptionContinueSearch;
356 TRACE( "got nested exception in catch function\n" );
358 if(rec->ExceptionCode == CXX_EXCEPTION)
360 PEXCEPTION_RECORD prev_rec = msvcrt_get_thread_data()->exc_record;
362 if((rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0) ||
363 (prev_rec->ExceptionCode == CXX_EXCEPTION &&
364 rec->ExceptionInformation[1] == prev_rec->ExceptionInformation[1] &&
365 rec->ExceptionInformation[2] == prev_rec->ExceptionInformation[2]))
367 /* exception was rethrown */
368 *rec = *prev_rec;
369 rec->ExceptionFlags &= ~EH_UNWINDING;
370 if(TRACE_ON(seh)) {
371 TRACE("detect rethrow: exception code: %lx\n", rec->ExceptionCode);
372 if(rec->ExceptionCode == CXX_EXCEPTION)
373 TRACE("re-propagate: obj: %lx, type: %lx\n",
374 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
377 else
379 TRACE("detect threw new exception in catch block\n");
383 return cxx_frame_handler( rec, nested_frame->cxx_frame, context,
384 NULL, nested_frame->descr, nested_frame );
387 /* find and call the appropriate catch block for an exception */
388 /* returns the address to continue execution to after the catch block was called */
389 static inline void call_catch_block( PEXCEPTION_RECORD rec, CONTEXT *context,
390 cxx_exception_frame *frame,
391 const cxx_function_descr *descr,
392 catch_func_nested_frame *catch_frame,
393 cxx_exception_type *info )
395 UINT i;
396 int j;
397 void *addr, *object = (void *)rec->ExceptionInformation[1];
398 catch_func_nested_frame nested_frame;
399 int trylevel = frame->trylevel;
400 DWORD save_esp = ((DWORD*)frame)[-1];
401 thread_data_t *data = msvcrt_get_thread_data();
403 data->processing_throw++;
404 for (i = 0; i < descr->tryblock_count; i++)
406 const tryblock_info *tryblock = &descr->tryblock[i];
408 /* only handle try blocks inside current catch block */
409 if (catch_frame && catch_frame->trylevel > tryblock->start_level) continue;
411 if (trylevel < tryblock->start_level) continue;
412 if (trylevel > tryblock->end_level) continue;
414 /* got a try block */
415 for (j = 0; j < tryblock->catchblock_count; j++)
417 const catchblock_info *catchblock = &tryblock->catchblock[j];
418 if(info)
420 const cxx_type_info *type = find_caught_type( info,
421 catchblock->type_info, catchblock->flags );
422 if (!type) continue;
424 TRACE( "matched type %p in tryblock %d catchblock %d\n", type, i, j );
426 /* copy the exception to its destination on the stack */
427 copy_exception( object, frame, catchblock, type );
429 else
431 /* no CXX_EXCEPTION only proceed with a catch(...) block*/
432 if(catchblock->type_info)
433 continue;
434 TRACE("found catch(...) block\n");
437 /* Add frame info here so exception is not freed inside RtlUnwind call */
438 _CreateFrameInfo(&nested_frame.frame_info.frame_info,
439 (void*)rec->ExceptionInformation[1]);
441 /* unwind the stack */
442 RtlUnwind( catch_frame ? &catch_frame->frame : &frame->frame, 0, rec, 0 );
443 cxx_local_unwind( frame, descr, tryblock->start_level );
444 frame->trylevel = tryblock->end_level + 1;
446 nested_frame.frame_info.rec = data->exc_record;
447 nested_frame.frame_info.context = data->ctx_record;
448 data->exc_record = rec;
449 data->ctx_record = context;
450 data->processing_throw--;
452 /* call the catch block */
453 TRACE( "calling catch block %p addr %p ebp %p\n",
454 catchblock, catchblock->handler, &frame->ebp );
456 /* setup an exception block for nested exceptions */
457 nested_frame.frame.Handler = catch_function_nested_handler;
458 nested_frame.cxx_frame = frame;
459 nested_frame.descr = descr;
460 nested_frame.trylevel = tryblock->end_level + 1;
462 __wine_push_frame( &nested_frame.frame );
463 addr = call_handler( catchblock->handler, &frame->ebp );
464 __wine_pop_frame( &nested_frame.frame );
466 ((DWORD*)frame)[-1] = save_esp;
467 __CxxUnregisterExceptionObject(&nested_frame.frame_info, FALSE);
468 TRACE( "done, continuing at %p\n", addr );
470 continue_after_catch( frame, addr );
473 data->processing_throw--;
476 /*********************************************************************
477 * __CxxExceptionFilter (MSVCRT.@)
479 int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
480 const type_info *ti, int flags, void **copy)
482 const cxx_type_info *type;
483 PEXCEPTION_RECORD rec;
485 TRACE( "%p %p %x %p\n", ptrs, ti, flags, copy );
487 if (!ptrs) return EXCEPTION_CONTINUE_SEARCH;
489 /* handle catch(...) */
490 if (!ti) return EXCEPTION_EXECUTE_HANDLER;
492 rec = ptrs->ExceptionRecord;
493 if (rec->ExceptionCode != CXX_EXCEPTION || rec->NumberParameters != 3 ||
494 rec->ExceptionInformation[0] < CXX_FRAME_MAGIC_VC6 ||
495 rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8)
496 return EXCEPTION_CONTINUE_SEARCH;
498 if (rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
500 rec = msvcrt_get_thread_data()->exc_record;
501 if (!rec) return EXCEPTION_CONTINUE_SEARCH;
504 type = find_caught_type( (cxx_exception_type*)rec->ExceptionInformation[2], ti, flags );
505 if (!type) return EXCEPTION_CONTINUE_SEARCH;
507 if (copy)
509 void *object = (void *)rec->ExceptionInformation[1];
511 if (flags & TYPE_FLAG_REFERENCE)
513 *copy = get_this_pointer( &type->offsets, object );
515 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
517 memmove( copy, object, type->size );
518 /* if it is a pointer, adjust it */
519 if (type->size == sizeof(void*)) *copy = get_this_pointer( &type->offsets, *copy );
521 else /* copy the object */
523 if (type->copy_ctor)
524 call_copy_ctor( type->copy_ctor, copy, get_this_pointer(&type->offsets,object),
525 (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS) );
526 else
527 memmove( copy, get_this_pointer(&type->offsets,object), type->size );
530 return EXCEPTION_EXECUTE_HANDLER;
533 static LONG CALLBACK se_translation_filter( EXCEPTION_POINTERS *ep, void *c )
535 se_translator_ctx *ctx = (se_translator_ctx *)c;
536 EXCEPTION_RECORD *rec = ep->ExceptionRecord;
537 cxx_exception_type *exc_type;
539 if (rec->ExceptionCode != CXX_EXCEPTION)
541 TRACE( "non-c++ exception thrown in SEH handler: %lx\n", rec->ExceptionCode );
542 terminate();
545 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
546 call_catch_block( rec, ep->ContextRecord, ctx->frame, ctx->descr,
547 ctx->nested_frame, exc_type );
549 __DestructExceptionObject( rec );
550 return ExceptionContinueSearch;
553 static void check_noexcept( PEXCEPTION_RECORD rec,
554 const cxx_function_descr *descr, BOOL nested )
556 if (!nested && rec->ExceptionCode == CXX_EXCEPTION &&
557 descr->magic >= CXX_FRAME_MAGIC_VC8 &&
558 (descr->flags & FUNC_DESCR_NOEXCEPT))
560 ERR("noexcept function propagating exception\n");
561 terminate();
565 /*********************************************************************
566 * cxx_frame_handler
568 * Implementation of __CxxFrameHandler.
570 DWORD CDECL cxx_frame_handler( PEXCEPTION_RECORD rec, cxx_exception_frame* frame,
571 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch,
572 const cxx_function_descr *descr,
573 catch_func_nested_frame* nested_frame )
575 cxx_exception_type *exc_type;
577 if (descr->magic < CXX_FRAME_MAGIC_VC6 || descr->magic > CXX_FRAME_MAGIC_VC8)
579 ERR( "invalid frame magic %x\n", descr->magic );
580 return ExceptionContinueSearch;
582 if (descr->magic >= CXX_FRAME_MAGIC_VC8 &&
583 (descr->flags & FUNC_DESCR_SYNCHRONOUS) &&
584 (rec->ExceptionCode != CXX_EXCEPTION))
585 return ExceptionContinueSearch; /* handle only c++ exceptions */
587 if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
589 if (descr->unwind_count && !nested_frame) cxx_local_unwind( frame, descr, -1 );
590 return ExceptionContinueSearch;
592 if (!descr->tryblock_count)
594 check_noexcept(rec, descr, nested_frame != NULL);
595 return ExceptionContinueSearch;
598 if(rec->ExceptionCode == CXX_EXCEPTION &&
599 rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
601 *rec = *msvcrt_get_thread_data()->exc_record;
602 rec->ExceptionFlags &= ~EH_UNWINDING;
603 if(TRACE_ON(seh)) {
604 TRACE("detect rethrow: exception code: %lx\n", rec->ExceptionCode);
605 if(rec->ExceptionCode == CXX_EXCEPTION)
606 TRACE("re-propagate: obj: %lx, type: %lx\n",
607 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
611 if(rec->ExceptionCode == CXX_EXCEPTION)
613 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
615 if (rec->ExceptionInformation[0] > CXX_FRAME_MAGIC_VC8 &&
616 exc_type->custom_handler)
618 return exc_type->custom_handler( rec, frame, context, dispatch, descr,
619 nested_frame ? nested_frame->trylevel : 0,
620 nested_frame ? &nested_frame->frame : NULL, 0 );
623 if (TRACE_ON(seh))
625 TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
626 rec, frame, frame->trylevel, descr, nested_frame );
627 dump_exception_type( exc_type );
628 dump_function_descr( descr );
631 else
633 thread_data_t *data = msvcrt_get_thread_data();
635 exc_type = NULL;
636 TRACE("handling C exception code %lx rec %p frame %p trylevel %d descr %p nested_frame %p\n",
637 rec->ExceptionCode, rec, frame, frame->trylevel, descr, nested_frame );
639 if (data->se_translator) {
640 EXCEPTION_POINTERS except_ptrs;
641 se_translator_ctx ctx;
643 ctx.frame = frame;
644 ctx.descr = descr;
645 ctx.nested_frame = nested_frame;
646 __TRY
648 except_ptrs.ExceptionRecord = rec;
649 except_ptrs.ContextRecord = context;
650 data->se_translator( rec->ExceptionCode, &except_ptrs );
652 __EXCEPT_CTX(se_translation_filter, &ctx)
655 __ENDTRY
659 call_catch_block( rec, context, frame, descr,
660 nested_frame, exc_type );
661 check_noexcept(rec, descr, nested_frame != NULL);
662 return ExceptionContinueSearch;
666 /*********************************************************************
667 * __CxxFrameHandler (MSVCRT.@)
669 extern DWORD CDECL __CxxFrameHandler( PEXCEPTION_RECORD rec, EXCEPTION_REGISTRATION_RECORD* frame,
670 PCONTEXT context, EXCEPTION_REGISTRATION_RECORD** dispatch );
671 __ASM_GLOBAL_FUNC( __CxxFrameHandler,
672 "pushl $0\n\t" /* nested_frame */
673 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
674 "pushl %eax\n\t" /* descr */
675 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
676 "pushl 24(%esp)\n\t" /* dispatch */
677 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
678 "pushl 24(%esp)\n\t" /* context */
679 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
680 "pushl 24(%esp)\n\t" /* frame */
681 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
682 "pushl 24(%esp)\n\t" /* rec */
683 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
684 "call " __ASM_NAME("cxx_frame_handler") "\n\t"
685 "add $24,%esp\n\t"
686 __ASM_CFI(".cfi_adjust_cfa_offset -24\n\t")
687 "ret" )
690 /*********************************************************************
691 * __CxxLongjmpUnwind (MSVCRT.@)
693 * Callback meant to be used as UnwindFunc for setjmp/longjmp.
695 void __stdcall __CxxLongjmpUnwind( const _JUMP_BUFFER *buf )
697 cxx_exception_frame *frame = (cxx_exception_frame *)buf->Registration;
698 const cxx_function_descr *descr = (const cxx_function_descr *)buf->UnwindData[0];
700 TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame, descr, buf->TryLevel );
701 cxx_local_unwind( frame, descr, buf->TryLevel );
704 /*********************************************************************
705 * __CppXcptFilter (MSVCRT.@)
707 int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
709 /* only filter c++ exceptions */
710 if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
711 return _XcptFilter( ex, ptr );
714 /*********************************************************************
715 * __CxxDetectRethrow (MSVCRT.@)
717 BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
719 PEXCEPTION_RECORD rec;
721 if (!ptrs)
722 return FALSE;
724 rec = ptrs->ExceptionRecord;
726 if (rec->ExceptionCode == CXX_EXCEPTION &&
727 rec->NumberParameters == 3 &&
728 rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
729 rec->ExceptionInformation[2])
731 ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
732 return TRUE;
734 return (msvcrt_get_thread_data()->exc_record == rec);
737 /*********************************************************************
738 * __CxxQueryExceptionSize (MSVCRT.@)
740 unsigned int CDECL __CxxQueryExceptionSize(void)
742 return sizeof(cxx_exception_type);
746 /*********************************************************************
747 * _EH_prolog (MSVCRT.@)
750 /* Provided for VC++ binary compatibility only */
751 __ASM_GLOBAL_FUNC(_EH_prolog,
752 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */
753 "pushl $-1\n\t"
754 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
755 "pushl %eax\n\t"
756 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
757 "pushl %fs:0\n\t"
758 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
759 "movl %esp, %fs:0\n\t"
760 "movl 12(%esp), %eax\n\t"
761 "movl %ebp, 12(%esp)\n\t"
762 "leal 12(%esp), %ebp\n\t"
763 "pushl %eax\n\t"
764 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
765 "ret")
767 static const SCOPETABLE_V4 *get_scopetable_v4( MSVCRT_EXCEPTION_FRAME *frame, ULONG_PTR cookie )
769 return (const SCOPETABLE_V4 *)((ULONG_PTR)frame->scopetable ^ cookie);
772 static DWORD MSVCRT_nested_handler(PEXCEPTION_RECORD rec,
773 EXCEPTION_REGISTRATION_RECORD* frame,
774 PCONTEXT context,
775 EXCEPTION_REGISTRATION_RECORD** dispatch)
777 if (!(rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND)))
778 return ExceptionContinueSearch;
779 *dispatch = frame;
780 return ExceptionCollidedUnwind;
783 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp)
785 EXCEPTION_REGISTRATION_RECORD reg;
787 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
789 /* Register a handler in case of a nested exception */
790 reg.Handler = MSVCRT_nested_handler;
791 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
792 __wine_push_frame(&reg);
794 while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel)
796 int level = frame->trylevel;
797 frame->trylevel = frame->scopetable[level].previousTryLevel;
798 if (!frame->scopetable[level].lpfnFilter)
800 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
801 level, frame->scopetable[level].lpfnHandler, ebp );
802 call_handler( frame->scopetable[level].lpfnHandler, ebp );
805 __wine_pop_frame(&reg);
806 TRACE("unwound OK\n");
809 static void msvcrt_local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel, void *ebp )
811 EXCEPTION_REGISTRATION_RECORD reg;
812 const SCOPETABLE_V4 *scopetable = get_scopetable_v4( frame, *cookie );
814 TRACE("(%p,%d,%d)\n",frame, frame->trylevel, trylevel);
816 /* Register a handler in case of a nested exception */
817 reg.Handler = MSVCRT_nested_handler;
818 reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
819 __wine_push_frame(&reg);
821 while (frame->trylevel != -2 && frame->trylevel != trylevel)
823 int level = frame->trylevel;
824 frame->trylevel = scopetable->entries[level].previousTryLevel;
825 if (!scopetable->entries[level].lpfnFilter)
827 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
828 level, scopetable->entries[level].lpfnHandler, ebp );
829 call_handler( scopetable->entries[level].lpfnHandler, ebp );
832 __wine_pop_frame(&reg);
833 TRACE("unwound OK\n");
836 /*******************************************************************
837 * _local_unwind2 (MSVCRT.@)
839 void CDECL _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel)
841 msvcrt_local_unwind2( frame, trylevel, &frame->_ebp );
844 /*******************************************************************
845 * _local_unwind4 (MSVCRT.@)
847 void CDECL _local_unwind4( ULONG *cookie, MSVCRT_EXCEPTION_FRAME* frame, int trylevel )
849 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
852 /*******************************************************************
853 * _global_unwind2 (MSVCRT.@)
855 void CDECL _global_unwind2(EXCEPTION_REGISTRATION_RECORD* frame)
857 TRACE("(%p)\n",frame);
858 RtlUnwind( frame, 0, 0, 0 );
861 /*********************************************************************
862 * _except_handler2 (MSVCRT.@)
864 int CDECL _except_handler2(PEXCEPTION_RECORD rec,
865 EXCEPTION_REGISTRATION_RECORD* frame,
866 PCONTEXT context,
867 EXCEPTION_REGISTRATION_RECORD** dispatcher)
869 FIXME("exception %lx flags=%lx at %p handler=%p %p %p stub\n",
870 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
871 frame->Handler, context, dispatcher);
872 return ExceptionContinueSearch;
875 /*********************************************************************
876 * _except_handler3 (MSVCRT.@)
878 int CDECL _except_handler3(PEXCEPTION_RECORD rec,
879 MSVCRT_EXCEPTION_FRAME* frame,
880 PCONTEXT context, void* dispatcher)
882 int retval, trylevel;
883 EXCEPTION_POINTERS exceptPtrs;
884 PSCOPETABLE pScopeTable;
886 TRACE("exception %lx flags=%lx at %p handler=%p %p %p semi-stub\n",
887 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
888 frame->handler, context, dispatcher);
890 __asm__ __volatile__ ("cld");
892 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
894 /* Unwinding the current frame */
895 msvcrt_local_unwind2(frame, TRYLEVEL_END, &frame->_ebp);
896 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
897 return ExceptionContinueSearch;
899 else
901 /* Hunting for handler */
902 exceptPtrs.ExceptionRecord = rec;
903 exceptPtrs.ContextRecord = context;
904 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
905 trylevel = frame->trylevel;
906 pScopeTable = frame->scopetable;
908 while (trylevel != TRYLEVEL_END)
910 TRACE( "level %d prev %d filter %p\n", trylevel, pScopeTable[trylevel].previousTryLevel,
911 pScopeTable[trylevel].lpfnFilter );
912 if (pScopeTable[trylevel].lpfnFilter)
914 retval = call_filter( pScopeTable[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
916 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
917 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
918 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
920 if (retval == EXCEPTION_CONTINUE_EXECUTION)
921 return ExceptionContinueExecution;
923 if (retval == EXCEPTION_EXECUTE_HANDLER)
925 /* Unwind all higher frames, this one will handle the exception */
926 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
927 msvcrt_local_unwind2(frame, trylevel, &frame->_ebp);
929 /* Set our trylevel to the enclosing block, and call the __finally
930 * code, which won't return
932 frame->trylevel = pScopeTable[trylevel].previousTryLevel;
933 TRACE("__finally block %p\n",pScopeTable[trylevel].lpfnHandler);
934 call_finally_block(pScopeTable[trylevel].lpfnHandler, &frame->_ebp);
937 trylevel = pScopeTable[trylevel].previousTryLevel;
940 TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
941 return ExceptionContinueSearch;
944 /*********************************************************************
945 * _except_handler4_common (MSVCRT.@)
947 int CDECL _except_handler4_common( ULONG *cookie, void (*check_cookie)(void),
948 EXCEPTION_RECORD *rec, MSVCRT_EXCEPTION_FRAME *frame,
949 CONTEXT *context, EXCEPTION_REGISTRATION_RECORD **dispatcher )
951 int retval, trylevel;
952 EXCEPTION_POINTERS exceptPtrs;
953 const SCOPETABLE_V4 *scope_table = get_scopetable_v4( frame, *cookie );
955 TRACE( "exception %lx flags=%lx at %p handler=%p %p %p cookie=%lx scope table=%p cookies=%d/%lx,%d/%lx\n",
956 rec->ExceptionCode, rec->ExceptionFlags, rec->ExceptionAddress,
957 frame->handler, context, dispatcher, *cookie, scope_table,
958 scope_table->gs_cookie_offset, scope_table->gs_cookie_xor,
959 scope_table->eh_cookie_offset, scope_table->eh_cookie_xor );
961 /* FIXME: no cookie validation yet */
963 if (rec->ExceptionFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
965 /* Unwinding the current frame */
966 msvcrt_local_unwind4( cookie, frame, -2, &frame->_ebp );
967 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
968 return ExceptionContinueSearch;
970 else
972 /* Hunting for handler */
973 exceptPtrs.ExceptionRecord = rec;
974 exceptPtrs.ContextRecord = context;
975 *((DWORD *)frame-1) = (DWORD)&exceptPtrs;
976 trylevel = frame->trylevel;
978 while (trylevel != -2)
980 TRACE( "level %d prev %d filter %p\n", trylevel,
981 scope_table->entries[trylevel].previousTryLevel,
982 scope_table->entries[trylevel].lpfnFilter );
983 if (scope_table->entries[trylevel].lpfnFilter)
985 retval = call_filter( scope_table->entries[trylevel].lpfnFilter, &exceptPtrs, &frame->_ebp );
987 TRACE("filter returned %s\n", retval == EXCEPTION_CONTINUE_EXECUTION ?
988 "CONTINUE_EXECUTION" : retval == EXCEPTION_EXECUTE_HANDLER ?
989 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
991 if (retval == EXCEPTION_CONTINUE_EXECUTION)
992 return ExceptionContinueExecution;
994 if (retval == EXCEPTION_EXECUTE_HANDLER)
996 __DestructExceptionObject(rec);
998 /* Unwind all higher frames, this one will handle the exception */
999 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)frame);
1000 msvcrt_local_unwind4( cookie, frame, trylevel, &frame->_ebp );
1002 /* Set our trylevel to the enclosing block, and call the __finally
1003 * code, which won't return
1005 frame->trylevel = scope_table->entries[trylevel].previousTryLevel;
1006 TRACE("__finally block %p\n",scope_table->entries[trylevel].lpfnHandler);
1007 call_finally_block(scope_table->entries[trylevel].lpfnHandler, &frame->_ebp);
1010 trylevel = scope_table->entries[trylevel].previousTryLevel;
1013 TRACE("reached -2, returning ExceptionContinueSearch\n");
1014 return ExceptionContinueSearch;
1019 * setjmp/longjmp implementation
1022 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
1023 typedef void (__stdcall *MSVCRT_unwind_function)(const _JUMP_BUFFER *);
1025 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
1026 /* and then jumps to the C backend function */
1027 #define DEFINE_SETJMP_ENTRYPOINT(name) \
1028 __ASM_GLOBAL_FUNC( name, \
1029 "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \
1030 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \
1031 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \
1032 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \
1033 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \
1034 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \
1035 "movl 0(%esp),%eax\n\t" \
1036 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \
1037 "jmp " __ASM_NAME("__regs_") # name )
1039 /*******************************************************************
1040 * _setjmp (MSVCRT.@)
1042 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp)
1043 int CDECL DECLSPEC_HIDDEN __regs_MSVCRT__setjmp(_JUMP_BUFFER *jmp)
1045 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1046 if (jmp->Registration == ~0UL)
1047 jmp->TryLevel = TRYLEVEL_END;
1048 else
1049 jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1051 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1052 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1053 return 0;
1056 /*******************************************************************
1057 * _setjmp3 (MSVCRT.@)
1059 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3 )
1060 int WINAPIV DECLSPEC_HIDDEN __regs_MSVCRT__setjmp3(_JUMP_BUFFER *jmp, int nb_args, ...)
1062 jmp->Cookie = MSVCRT_JMP_MAGIC;
1063 jmp->UnwindFunc = 0;
1064 jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1065 if (jmp->Registration == ~0UL)
1067 jmp->TryLevel = TRYLEVEL_END;
1069 else
1071 int i;
1072 va_list args;
1074 va_start( args, nb_args );
1075 if (nb_args > 0) jmp->UnwindFunc = va_arg( args, unsigned long );
1076 if (nb_args > 1) jmp->TryLevel = va_arg( args, unsigned long );
1077 else jmp->TryLevel = ((MSVCRT_EXCEPTION_FRAME*)jmp->Registration)->trylevel;
1078 for (i = 0; i < 6 && i < nb_args - 2; i++)
1079 jmp->UnwindData[i] = va_arg( args, unsigned long );
1080 va_end( args );
1083 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1084 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration );
1085 return 0;
1088 /*********************************************************************
1089 * longjmp (MSVCRT.@)
1091 void CDECL MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval)
1093 unsigned long cur_frame = 0;
1095 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
1096 jmp, jmp->Ebx, jmp->Esi, jmp->Edi, jmp->Ebp, jmp->Esp, jmp->Eip, jmp->Registration, retval );
1098 cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList;
1099 TRACE("cur_frame=%lx\n",cur_frame);
1101 if (cur_frame != jmp->Registration)
1102 _global_unwind2((EXCEPTION_REGISTRATION_RECORD*)jmp->Registration);
1104 if (jmp->Registration)
1106 if (IsBadReadPtr(&jmp->Cookie, sizeof(long)) || jmp->Cookie != MSVCRT_JMP_MAGIC)
1108 msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME*)jmp->Registration,
1109 jmp->TryLevel, (void *)jmp->Ebp);
1111 else if(jmp->UnwindFunc)
1113 MSVCRT_unwind_function unwind_func;
1115 unwind_func=(MSVCRT_unwind_function)jmp->UnwindFunc;
1116 unwind_func(jmp);
1120 if (!retval)
1121 retval = 1;
1123 __wine_longjmp( (__wine_jmp_buf *)jmp, retval );
1126 /*********************************************************************
1127 * _seh_longjmp_unwind (MSVCRT.@)
1129 void __stdcall _seh_longjmp_unwind(_JUMP_BUFFER *jmp)
1131 msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME *)jmp->Registration, jmp->TryLevel, (void *)jmp->Ebp );
1134 /*********************************************************************
1135 * _seh_longjmp_unwind4 (MSVCRT.@)
1137 void __stdcall _seh_longjmp_unwind4(_JUMP_BUFFER *jmp)
1139 msvcrt_local_unwind4( (ULONG *)&jmp->Cookie, (MSVCRT_EXCEPTION_FRAME *)jmp->Registration,
1140 jmp->TryLevel, (void *)jmp->Ebp );
1143 /*********************************************************************
1144 * _fpieee_flt (MSVCRT.@)
1146 int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep,
1147 int (__cdecl *handler)(_FPIEEE_RECORD*))
1149 FLOATING_SAVE_AREA *ctx = &ep->ContextRecord->FloatSave;
1150 _FPIEEE_RECORD rec;
1151 int ret;
1153 TRACE("(%lx %p %p)\n", exception_code, ep, handler);
1155 switch(exception_code) {
1156 case STATUS_FLOAT_DIVIDE_BY_ZERO:
1157 case STATUS_FLOAT_INEXACT_RESULT:
1158 case STATUS_FLOAT_INVALID_OPERATION:
1159 case STATUS_FLOAT_OVERFLOW:
1160 case STATUS_FLOAT_UNDERFLOW:
1161 break;
1162 default:
1163 return EXCEPTION_CONTINUE_SEARCH;
1166 memset(&rec, 0, sizeof(rec));
1167 rec.RoundingMode = ctx->ControlWord >> 10;
1168 switch((ctx->ControlWord >> 8) & 0x3) {
1169 case 0: rec.Precision = 2; break;
1170 case 1: rec.Precision = 3; break;
1171 case 2: rec.Precision = 1; break;
1172 case 3: rec.Precision = 0; break;
1174 rec.Status.InvalidOperation = ctx->StatusWord & 0x1;
1175 rec.Status.ZeroDivide = ((ctx->StatusWord & 0x4) != 0);
1176 rec.Status.Overflow = ((ctx->StatusWord & 0x8) != 0);
1177 rec.Status.Underflow = ((ctx->StatusWord & 0x10) != 0);
1178 rec.Status.Inexact = ((ctx->StatusWord & 0x20) != 0);
1179 rec.Enable.InvalidOperation = ((ctx->ControlWord & 0x1) == 0);
1180 rec.Enable.ZeroDivide = ((ctx->ControlWord & 0x4) == 0);
1181 rec.Enable.Overflow = ((ctx->ControlWord & 0x8) == 0);
1182 rec.Enable.Underflow = ((ctx->ControlWord & 0x10) == 0);
1183 rec.Enable.Inexact = ((ctx->ControlWord & 0x20) == 0);
1184 rec.Cause.InvalidOperation = rec.Enable.InvalidOperation & rec.Status.InvalidOperation;
1185 rec.Cause.ZeroDivide = rec.Enable.ZeroDivide & rec.Status.ZeroDivide;
1186 rec.Cause.Overflow = rec.Enable.Overflow & rec.Status.Overflow;
1187 rec.Cause.Underflow = rec.Enable.Underflow & rec.Status.Underflow;
1188 rec.Cause.Inexact = rec.Enable.Inexact & rec.Status.Inexact;
1190 TRACE("opcode: %lx\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1192 if(*(WORD*)ctx->ErrorOffset == 0x35dc) { /* fdiv m64fp */
1193 if(exception_code==STATUS_FLOAT_DIVIDE_BY_ZERO || exception_code==STATUS_FLOAT_INVALID_OPERATION) {
1194 rec.Operand1.OperandValid = 1;
1195 rec.Result.OperandValid = 0;
1196 } else {
1197 rec.Operand1.OperandValid = 0;
1198 rec.Result.OperandValid = 1;
1200 rec.Operand2.OperandValid = 1;
1201 rec.Operation = _FpCodeDivide;
1202 rec.Operand1.Format = _FpFormatFp80;
1203 memcpy(&rec.Operand1.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1204 rec.Operand2.Format = _FpFormatFp64;
1205 rec.Operand2.Value.Fp64Value = *(double*)ctx->DataOffset;
1206 rec.Result.Format = _FpFormatFp80;
1207 memcpy(&rec.Result.Value.Fp80Value, ctx->RegisterArea, sizeof(rec.Operand1.Value.Fp80Value));
1209 ret = handler(&rec);
1211 if(ret == EXCEPTION_CONTINUE_EXECUTION)
1212 memcpy(ctx->RegisterArea, &rec.Result.Value.Fp80Value, sizeof(rec.Operand1.Value.Fp80Value));
1213 return ret;
1216 FIXME("unsupported opcode: %lx\n", *(ULONG*)ep->ContextRecord->FloatSave.ErrorOffset);
1217 return EXCEPTION_CONTINUE_SEARCH;
1220 #endif /* __i386__ */