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
23 * A good reference is the article "How a C++ compiler implements
24 * exception handling" by Vishal Kochhar, available on
25 * www.thecodeproject.com.
29 #include "wine/port.h"
39 #include "wine/exception.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 */
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 */
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 */
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 */
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 */
95 const void *expect_list
; /* expected exceptions list when magic >= VC7 */
96 UINT flags
; /* flags when magic >= VC8 */
101 cxx_exception_frame
*frame
;
102 const cxx_function_descr
*descr
;
103 EXCEPTION_REGISTRATION_RECORD
*nested_frame
;
106 typedef struct _SCOPETABLE
108 int previousTryLevel
;
109 int (*lpfnFilter
)(PEXCEPTION_POINTERS
);
110 void * (*lpfnHandler
)(void);
111 } SCOPETABLE
, *PSCOPETABLE
;
113 typedef struct _MSVCRT_EXCEPTION_FRAME
115 EXCEPTION_REGISTRATION_RECORD
*prev
;
116 void (*handler
)(PEXCEPTION_RECORD
, EXCEPTION_REGISTRATION_RECORD
*,
117 PCONTEXT
, PEXCEPTION_RECORD
);
118 PSCOPETABLE scopetable
;
121 PEXCEPTION_POINTERS xpointers
;
122 } MSVCRT_EXCEPTION_FRAME
;
126 int gs_cookie_offset
;
128 int eh_cookie_offset
;
130 SCOPETABLE entries
[1];
133 #define TRYLEVEL_END (-1) /* End of trylevel list */
135 DWORD CDECL
cxx_frame_handler( PEXCEPTION_RECORD rec
, cxx_exception_frame
* frame
,
136 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
,
137 const cxx_function_descr
*descr
,
138 EXCEPTION_REGISTRATION_RECORD
* nested_frame
, int nested_trylevel
) DECLSPEC_HIDDEN
;
140 /* call a copy constructor */
141 extern void call_copy_ctor( void *func
, void *this, void *src
, int has_vbase
);
143 __ASM_GLOBAL_FUNC( call_copy_ctor
,
145 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
146 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
147 "movl %esp, %ebp\n\t"
148 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
150 "movl 12(%ebp), %ecx\n\t"
154 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
155 __ASM_CFI(".cfi_same_value %ebp\n\t")
158 /* continue execution to the specified address after exception is caught */
159 extern void DECLSPEC_NORETURN
continue_after_catch( cxx_exception_frame
* frame
, void *addr
);
161 __ASM_GLOBAL_FUNC( continue_after_catch
,
162 "movl 4(%esp), %edx\n\t"
163 "movl 8(%esp), %eax\n\t"
164 "movl -4(%edx), %esp\n\t"
165 "leal 12(%edx), %ebp\n\t"
168 extern void DECLSPEC_NORETURN
call_finally_block( void *code_block
, void *base_ptr
);
170 __ASM_GLOBAL_FUNC( call_finally_block
,
171 "movl 8(%esp), %ebp\n\t"
174 extern int call_filter( int (*func
)(PEXCEPTION_POINTERS
), void *arg
, void *ebp
);
176 __ASM_GLOBAL_FUNC( call_filter
,
179 "movl 20(%esp), %ebp\n\t"
185 extern void *call_handler( void * (*func
)(void), void *ebp
);
187 __ASM_GLOBAL_FUNC( call_handler
,
192 "movl 24(%esp), %ebp\n\t"
200 static inline void dump_type( const cxx_type_info
*type
)
202 TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
203 type
->flags
, type
->type_info
, dbgstr_type_info(type
->type_info
),
204 type
->offsets
.this_offset
, type
->offsets
.vbase_descr
, type
->offsets
.vbase_offset
,
205 type
->size
, type
->copy_ctor
);
208 static void dump_exception_type( const cxx_exception_type
*type
)
212 TRACE( "flags %x destr %p handler %p type info %p\n",
213 type
->flags
, type
->destructor
, type
->custom_handler
, type
->type_info_table
);
214 for (i
= 0; i
< type
->type_info_table
->count
; i
++)
217 dump_type( type
->type_info_table
->info
[i
] );
221 static void dump_function_descr( const cxx_function_descr
*descr
)
226 TRACE( "magic %x\n", descr
->magic
);
227 TRACE( "unwind table: %p %d\n", descr
->unwind_table
, descr
->unwind_count
);
228 for (i
= 0; i
< descr
->unwind_count
; i
++)
230 TRACE( " %d: prev %d func %p\n", i
,
231 descr
->unwind_table
[i
].prev
, descr
->unwind_table
[i
].handler
);
233 TRACE( "try table: %p %d\n", descr
->tryblock
, descr
->tryblock_count
);
234 for (i
= 0; i
< descr
->tryblock_count
; i
++)
236 TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i
,
237 descr
->tryblock
[i
].start_level
, descr
->tryblock
[i
].end_level
,
238 descr
->tryblock
[i
].catch_level
, descr
->tryblock
[i
].catchblock
,
239 descr
->tryblock
[i
].catchblock_count
);
240 for (j
= 0; j
< descr
->tryblock
[i
].catchblock_count
; j
++)
242 const catchblock_info
*ptr
= &descr
->tryblock
[i
].catchblock
[j
];
243 TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
244 j
, ptr
->flags
, ptr
->offset
, ptr
->handler
,
245 ptr
->type_info
, dbgstr_type_info( ptr
->type_info
) );
248 if (descr
->magic
<= CXX_FRAME_MAGIC_VC6
) return;
249 TRACE( "expect list: %p\n", descr
->expect_list
);
250 if (descr
->magic
<= CXX_FRAME_MAGIC_VC7
) return;
251 TRACE( "flags: %08x\n", descr
->flags
);
254 /* check if the exception type is caught by a given catch block, and return the type that matched */
255 static const cxx_type_info
*find_caught_type( cxx_exception_type
*exc_type
,
256 const type_info
*catch_ti
, UINT catch_flags
)
260 for (i
= 0; i
< exc_type
->type_info_table
->count
; i
++)
262 const cxx_type_info
*type
= exc_type
->type_info_table
->info
[i
];
264 if (!catch_ti
) return type
; /* catch(...) matches any type */
265 if (catch_ti
!= type
->type_info
)
267 if (strcmp( catch_ti
->mangled
, type
->type_info
->mangled
)) continue;
269 /* type is the same, now check the flags */
270 if ((exc_type
->flags
& TYPE_FLAG_CONST
) &&
271 !(catch_flags
& TYPE_FLAG_CONST
)) continue;
272 if ((exc_type
->flags
& TYPE_FLAG_VOLATILE
) &&
273 !(catch_flags
& TYPE_FLAG_VOLATILE
)) continue;
274 return type
; /* it matched */
280 /* copy the exception object where the catch block wants it */
281 static void copy_exception( void *object
, cxx_exception_frame
*frame
,
282 const catchblock_info
*catchblock
, const cxx_type_info
*type
)
286 if (!catchblock
->type_info
|| !catchblock
->type_info
->mangled
[0]) return;
287 if (!catchblock
->offset
) return;
288 dest_ptr
= (void **)((char *)&frame
->ebp
+ catchblock
->offset
);
290 if (catchblock
->flags
& TYPE_FLAG_REFERENCE
)
292 *dest_ptr
= get_this_pointer( &type
->offsets
, object
);
294 else if (type
->flags
& CLASS_IS_SIMPLE_TYPE
)
296 memmove( dest_ptr
, object
, type
->size
);
297 /* if it is a pointer, adjust it */
298 if (type
->size
== sizeof(void *)) *dest_ptr
= get_this_pointer( &type
->offsets
, *dest_ptr
);
300 else /* copy the object */
303 call_copy_ctor( type
->copy_ctor
, dest_ptr
, get_this_pointer(&type
->offsets
,object
),
304 (type
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
) );
306 memmove( dest_ptr
, get_this_pointer(&type
->offsets
,object
), type
->size
);
310 /* unwind the local function up to a given trylevel */
311 static void cxx_local_unwind( cxx_exception_frame
* frame
, const cxx_function_descr
*descr
, int last_level
)
313 void * (*handler
)(void);
314 int trylevel
= frame
->trylevel
;
316 while (trylevel
!= last_level
)
318 if (trylevel
< 0 || trylevel
>= descr
->unwind_count
)
320 ERR( "invalid trylevel %d\n", trylevel
);
323 handler
= descr
->unwind_table
[trylevel
].handler
;
326 TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
327 handler
, trylevel
, last_level
, &frame
->ebp
);
328 call_handler( handler
, &frame
->ebp
);
330 trylevel
= descr
->unwind_table
[trylevel
].prev
;
332 frame
->trylevel
= last_level
;
335 /* exception frame for nested exceptions in catch block */
336 struct catch_func_nested_frame
338 EXCEPTION_REGISTRATION_RECORD frame
; /* standard exception frame */
339 cxx_exception_frame
*cxx_frame
; /* frame of parent exception */
340 const cxx_function_descr
*descr
; /* descriptor of parent exception */
341 int trylevel
; /* current try level */
342 cxx_frame_info frame_info
;
345 /* handler for exceptions happening while calling a catch function */
346 static DWORD
catch_function_nested_handler( EXCEPTION_RECORD
*rec
, EXCEPTION_REGISTRATION_RECORD
*frame
,
347 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
349 struct catch_func_nested_frame
*nested_frame
= (struct catch_func_nested_frame
*)frame
;
351 if (rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
))
353 __CxxUnregisterExceptionObject(&nested_frame
->frame_info
, FALSE
);
354 return ExceptionContinueSearch
;
357 TRACE( "got nested exception in catch function\n" );
359 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
361 PEXCEPTION_RECORD prev_rec
= msvcrt_get_thread_data()->exc_record
;
363 if((rec
->ExceptionInformation
[1] == 0 && rec
->ExceptionInformation
[2] == 0) ||
364 (prev_rec
->ExceptionCode
== CXX_EXCEPTION
&&
365 rec
->ExceptionInformation
[1] == prev_rec
->ExceptionInformation
[1] &&
366 rec
->ExceptionInformation
[2] == prev_rec
->ExceptionInformation
[2]))
368 /* exception was rethrown */
370 rec
->ExceptionFlags
&= ~EH_UNWINDING
;
372 TRACE("detect rethrow: exception code: %x\n", rec
->ExceptionCode
);
373 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
374 TRACE("re-propage: obj: %lx, type: %lx\n",
375 rec
->ExceptionInformation
[1], rec
->ExceptionInformation
[2]);
380 TRACE("detect threw new exception in catch block\n");
384 return cxx_frame_handler( rec
, nested_frame
->cxx_frame
, context
,
385 NULL
, nested_frame
->descr
, &nested_frame
->frame
,
386 nested_frame
->trylevel
);
389 /* find and call the appropriate catch block for an exception */
390 /* returns the address to continue execution to after the catch block was called */
391 static inline void call_catch_block( PEXCEPTION_RECORD rec
, CONTEXT
*context
,
392 cxx_exception_frame
*frame
,
393 const cxx_function_descr
*descr
, int nested_trylevel
,
394 EXCEPTION_REGISTRATION_RECORD
*catch_frame
,
395 cxx_exception_type
*info
)
399 void *addr
, *object
= (void *)rec
->ExceptionInformation
[1];
400 struct catch_func_nested_frame nested_frame
;
401 int trylevel
= frame
->trylevel
;
402 DWORD save_esp
= ((DWORD
*)frame
)[-1];
403 thread_data_t
*data
= msvcrt_get_thread_data();
405 data
->processing_throw
++;
406 for (i
= 0; i
< descr
->tryblock_count
; i
++)
408 const tryblock_info
*tryblock
= &descr
->tryblock
[i
];
410 /* only handle try blocks inside current catch block */
411 if (catch_frame
&& nested_trylevel
> tryblock
->start_level
) continue;
413 if (trylevel
< tryblock
->start_level
) continue;
414 if (trylevel
> tryblock
->end_level
) continue;
416 /* got a try block */
417 for (j
= 0; j
< tryblock
->catchblock_count
; j
++)
419 const catchblock_info
*catchblock
= &tryblock
->catchblock
[j
];
422 const cxx_type_info
*type
= find_caught_type( info
,
423 catchblock
->type_info
, catchblock
->flags
);
426 TRACE( "matched type %p in tryblock %d catchblock %d\n", type
, i
, j
);
428 /* copy the exception to its destination on the stack */
429 copy_exception( object
, frame
, catchblock
, type
);
433 /* no CXX_EXCEPTION only proceed with a catch(...) block*/
434 if(catchblock
->type_info
)
436 TRACE("found catch(...) block\n");
439 /* Add frame info here so exception is not freed inside RtlUnwind call */
440 _CreateFrameInfo(&nested_frame
.frame_info
.frame_info
,
441 (void*)rec
->ExceptionInformation
[1]);
443 /* unwind the stack */
444 RtlUnwind( catch_frame
? catch_frame
: &frame
->frame
, 0, rec
, 0 );
445 cxx_local_unwind( frame
, descr
, tryblock
->start_level
);
446 frame
->trylevel
= tryblock
->end_level
+ 1;
448 nested_frame
.frame_info
.rec
= data
->exc_record
;
449 nested_frame
.frame_info
.context
= data
->ctx_record
;
450 data
->exc_record
= rec
;
451 data
->ctx_record
= context
;
452 data
->processing_throw
--;
454 /* call the catch block */
455 TRACE( "calling catch block %p addr %p ebp %p\n",
456 catchblock
, catchblock
->handler
, &frame
->ebp
);
458 /* setup an exception block for nested exceptions */
459 nested_frame
.frame
.Handler
= catch_function_nested_handler
;
460 nested_frame
.cxx_frame
= frame
;
461 nested_frame
.descr
= descr
;
462 nested_frame
.trylevel
= nested_trylevel
+ 1;
464 __wine_push_frame( &nested_frame
.frame
);
465 addr
= call_handler( catchblock
->handler
, &frame
->ebp
);
466 __wine_pop_frame( &nested_frame
.frame
);
468 ((DWORD
*)frame
)[-1] = save_esp
;
469 __CxxUnregisterExceptionObject(&nested_frame
.frame_info
, FALSE
);
470 TRACE( "done, continuing at %p\n", addr
);
472 continue_after_catch( frame
, addr
);
475 data
->processing_throw
--;
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
;
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 */
526 call_copy_ctor( type
->copy_ctor
, copy
, get_this_pointer(&type
->offsets
,object
),
527 (type
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
) );
529 memmove( copy
, get_this_pointer(&type
->offsets
,object
), type
->size
);
532 return EXCEPTION_EXECUTE_HANDLER
;
535 static LONG CALLBACK
se_translation_filter( EXCEPTION_POINTERS
*ep
, void *c
)
537 se_translator_ctx
*ctx
= (se_translator_ctx
*)c
;
538 EXCEPTION_RECORD
*rec
= ep
->ExceptionRecord
;
539 cxx_exception_type
*exc_type
;
541 if (rec
->ExceptionCode
!= CXX_EXCEPTION
)
543 TRACE( "non-c++ exception thrown in SEH handler: %x\n", rec
->ExceptionCode
);
547 exc_type
= (cxx_exception_type
*)rec
->ExceptionInformation
[2];
548 call_catch_block( rec
, ep
->ContextRecord
, ctx
->frame
, ctx
->descr
,
549 ctx
->frame
->trylevel
, ctx
->nested_frame
, exc_type
);
551 __DestructExceptionObject( rec
);
552 return ExceptionContinueSearch
;
555 /*********************************************************************
558 * Implementation of __CxxFrameHandler.
560 DWORD CDECL
cxx_frame_handler( PEXCEPTION_RECORD rec
, cxx_exception_frame
* frame
,
561 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
,
562 const cxx_function_descr
*descr
,
563 EXCEPTION_REGISTRATION_RECORD
* nested_frame
,
564 int nested_trylevel
)
566 cxx_exception_type
*exc_type
;
568 if (descr
->magic
< CXX_FRAME_MAGIC_VC6
|| descr
->magic
> CXX_FRAME_MAGIC_VC8
)
570 ERR( "invalid frame magic %x\n", descr
->magic
);
571 return ExceptionContinueSearch
;
573 if (descr
->magic
>= CXX_FRAME_MAGIC_VC8
&&
574 (descr
->flags
& FUNC_DESCR_SYNCHRONOUS
) &&
575 (rec
->ExceptionCode
!= CXX_EXCEPTION
))
576 return ExceptionContinueSearch
; /* handle only c++ exceptions */
578 if (rec
->ExceptionFlags
& (EH_UNWINDING
|EH_EXIT_UNWIND
))
580 if (descr
->unwind_count
&& !nested_trylevel
) cxx_local_unwind( frame
, descr
, -1 );
581 return ExceptionContinueSearch
;
583 if (!descr
->tryblock_count
) return ExceptionContinueSearch
;
585 if(rec
->ExceptionCode
== CXX_EXCEPTION
&&
586 rec
->ExceptionInformation
[1] == 0 && rec
->ExceptionInformation
[2] == 0)
588 *rec
= *msvcrt_get_thread_data()->exc_record
;
589 rec
->ExceptionFlags
&= ~EH_UNWINDING
;
591 TRACE("detect rethrow: exception code: %x\n", rec
->ExceptionCode
);
592 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
593 TRACE("re-propage: obj: %lx, type: %lx\n",
594 rec
->ExceptionInformation
[1], rec
->ExceptionInformation
[2]);
598 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
600 exc_type
= (cxx_exception_type
*)rec
->ExceptionInformation
[2];
602 if (rec
->ExceptionInformation
[0] > CXX_FRAME_MAGIC_VC8
&&
603 exc_type
->custom_handler
)
605 return exc_type
->custom_handler( rec
, frame
, context
, dispatch
,
606 descr
, nested_trylevel
, nested_frame
, 0 );
611 TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
612 rec
, frame
, frame
->trylevel
, descr
, nested_frame
);
613 dump_exception_type( exc_type
);
614 dump_function_descr( descr
);
619 thread_data_t
*data
= msvcrt_get_thread_data();
622 TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
623 rec
->ExceptionCode
, rec
, frame
, frame
->trylevel
, descr
, nested_frame
);
625 if (data
->se_translator
) {
626 EXCEPTION_POINTERS except_ptrs
;
627 se_translator_ctx ctx
;
631 ctx
.nested_frame
= nested_frame
;
634 except_ptrs
.ExceptionRecord
= rec
;
635 except_ptrs
.ContextRecord
= context
;
636 data
->se_translator( rec
->ExceptionCode
, &except_ptrs
);
638 __EXCEPT_CTX(se_translation_filter
, &ctx
)
645 call_catch_block( rec
, context
, frame
, descr
,
646 frame
->trylevel
, nested_frame
, exc_type
);
647 return ExceptionContinueSearch
;
651 /*********************************************************************
652 * __CxxFrameHandler (MSVCRT.@)
654 extern DWORD CDECL
__CxxFrameHandler( PEXCEPTION_RECORD rec
, EXCEPTION_REGISTRATION_RECORD
* frame
,
655 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
);
656 __ASM_GLOBAL_FUNC( __CxxFrameHandler
,
657 "pushl $0\n\t" /* nested_trylevel */
658 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
659 "pushl $0\n\t" /* nested_frame */
660 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
661 "pushl %eax\n\t" /* descr */
662 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
663 "pushl 28(%esp)\n\t" /* dispatch */
664 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
665 "pushl 28(%esp)\n\t" /* context */
666 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
667 "pushl 28(%esp)\n\t" /* frame */
668 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
669 "pushl 28(%esp)\n\t" /* rec */
670 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
671 "call " __ASM_NAME("cxx_frame_handler") "\n\t"
673 __ASM_CFI(".cfi_adjust_cfa_offset -28\n\t")
677 /*********************************************************************
678 * __CxxLongjmpUnwind (MSVCRT.@)
680 * Callback meant to be used as UnwindFunc for setjmp/longjmp.
682 void __stdcall
__CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER
*buf
)
684 cxx_exception_frame
*frame
= (cxx_exception_frame
*)buf
->Registration
;
685 const cxx_function_descr
*descr
= (const cxx_function_descr
*)buf
->UnwindData
[0];
687 TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame
, descr
, buf
->TryLevel
);
688 cxx_local_unwind( frame
, descr
, buf
->TryLevel
);
691 /*********************************************************************
692 * __CppXcptFilter (MSVCRT.@)
694 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
696 /* only filter c++ exceptions */
697 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
698 return _XcptFilter( ex
, ptr
);
701 /*********************************************************************
702 * __CxxDetectRethrow (MSVCRT.@)
704 BOOL CDECL
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs
)
706 PEXCEPTION_RECORD rec
;
711 rec
= ptrs
->ExceptionRecord
;
713 if (rec
->ExceptionCode
== CXX_EXCEPTION
&&
714 rec
->NumberParameters
== 3 &&
715 rec
->ExceptionInformation
[0] == CXX_FRAME_MAGIC_VC6
&&
716 rec
->ExceptionInformation
[2])
718 ptrs
->ExceptionRecord
= msvcrt_get_thread_data()->exc_record
;
721 return (msvcrt_get_thread_data()->exc_record
== rec
);
724 /*********************************************************************
725 * __CxxQueryExceptionSize (MSVCRT.@)
727 unsigned int CDECL
__CxxQueryExceptionSize(void)
729 return sizeof(cxx_exception_type
);
733 /*********************************************************************
734 * _EH_prolog (MSVCRT.@)
737 /* Provided for VC++ binary compatibility only */
738 __ASM_GLOBAL_FUNC(_EH_prolog
,
739 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */
741 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
743 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
745 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
746 "movl %esp, %fs:0\n\t"
747 "movl 12(%esp), %eax\n\t"
748 "movl %ebp, 12(%esp)\n\t"
749 "leal 12(%esp), %ebp\n\t"
751 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
754 static const SCOPETABLE_V4
*get_scopetable_v4( MSVCRT_EXCEPTION_FRAME
*frame
, ULONG_PTR cookie
)
756 return (const SCOPETABLE_V4
*)((ULONG_PTR
)frame
->scopetable
^ cookie
);
759 static DWORD
MSVCRT_nested_handler(PEXCEPTION_RECORD rec
,
760 EXCEPTION_REGISTRATION_RECORD
* frame
,
762 EXCEPTION_REGISTRATION_RECORD
** dispatch
)
764 if (!(rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
)))
765 return ExceptionContinueSearch
;
767 return ExceptionCollidedUnwind
;
770 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
, void *ebp
)
772 EXCEPTION_REGISTRATION_RECORD reg
;
774 TRACE("(%p,%d,%d)\n",frame
, frame
->trylevel
, trylevel
);
776 /* Register a handler in case of a nested exception */
777 reg
.Handler
= MSVCRT_nested_handler
;
778 reg
.Prev
= NtCurrentTeb()->Tib
.ExceptionList
;
779 __wine_push_frame(®
);
781 while (frame
->trylevel
!= TRYLEVEL_END
&& frame
->trylevel
!= trylevel
)
783 int level
= frame
->trylevel
;
784 frame
->trylevel
= frame
->scopetable
[level
].previousTryLevel
;
785 if (!frame
->scopetable
[level
].lpfnFilter
)
787 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
788 level
, frame
->scopetable
[level
].lpfnHandler
, ebp
);
789 call_handler( frame
->scopetable
[level
].lpfnHandler
, ebp
);
792 __wine_pop_frame(®
);
793 TRACE("unwound OK\n");
796 static void msvcrt_local_unwind4( ULONG
*cookie
, MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
, void *ebp
)
798 EXCEPTION_REGISTRATION_RECORD reg
;
799 const SCOPETABLE_V4
*scopetable
= get_scopetable_v4( frame
, *cookie
);
801 TRACE("(%p,%d,%d)\n",frame
, frame
->trylevel
, trylevel
);
803 /* Register a handler in case of a nested exception */
804 reg
.Handler
= MSVCRT_nested_handler
;
805 reg
.Prev
= NtCurrentTeb()->Tib
.ExceptionList
;
806 __wine_push_frame(®
);
808 while (frame
->trylevel
!= -2 && frame
->trylevel
!= trylevel
)
810 int level
= frame
->trylevel
;
811 frame
->trylevel
= scopetable
->entries
[level
].previousTryLevel
;
812 if (!scopetable
->entries
[level
].lpfnFilter
)
814 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
815 level
, scopetable
->entries
[level
].lpfnHandler
, ebp
);
816 call_handler( scopetable
->entries
[level
].lpfnHandler
, ebp
);
819 __wine_pop_frame(®
);
820 TRACE("unwound OK\n");
823 /*******************************************************************
824 * _local_unwind2 (MSVCRT.@)
826 void CDECL
_local_unwind2(MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
)
828 msvcrt_local_unwind2( frame
, trylevel
, &frame
->_ebp
);
831 /*******************************************************************
832 * _local_unwind4 (MSVCRT.@)
834 void CDECL
_local_unwind4( ULONG
*cookie
, MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
)
836 msvcrt_local_unwind4( cookie
, frame
, trylevel
, &frame
->_ebp
);
839 /*******************************************************************
840 * _global_unwind2 (MSVCRT.@)
842 void CDECL
_global_unwind2(EXCEPTION_REGISTRATION_RECORD
* frame
)
844 TRACE("(%p)\n",frame
);
845 RtlUnwind( frame
, 0, 0, 0 );
848 /*********************************************************************
849 * _except_handler2 (MSVCRT.@)
851 int CDECL
_except_handler2(PEXCEPTION_RECORD rec
,
852 EXCEPTION_REGISTRATION_RECORD
* frame
,
854 EXCEPTION_REGISTRATION_RECORD
** dispatcher
)
856 FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n",
857 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
858 frame
->Handler
, context
, dispatcher
);
859 return ExceptionContinueSearch
;
862 /*********************************************************************
863 * _except_handler3 (MSVCRT.@)
865 int CDECL
_except_handler3(PEXCEPTION_RECORD rec
,
866 MSVCRT_EXCEPTION_FRAME
* frame
,
867 PCONTEXT context
, void* dispatcher
)
869 int retval
, trylevel
;
870 EXCEPTION_POINTERS exceptPtrs
;
871 PSCOPETABLE pScopeTable
;
873 TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n",
874 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
875 frame
->handler
, context
, dispatcher
);
877 __asm__
__volatile__ ("cld");
879 if (rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
))
881 /* Unwinding the current frame */
882 msvcrt_local_unwind2(frame
, TRYLEVEL_END
, &frame
->_ebp
);
883 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
884 return ExceptionContinueSearch
;
888 /* Hunting for handler */
889 exceptPtrs
.ExceptionRecord
= rec
;
890 exceptPtrs
.ContextRecord
= context
;
891 *((DWORD
*)frame
-1) = (DWORD
)&exceptPtrs
;
892 trylevel
= frame
->trylevel
;
893 pScopeTable
= frame
->scopetable
;
895 while (trylevel
!= TRYLEVEL_END
)
897 TRACE( "level %d prev %d filter %p\n", trylevel
, pScopeTable
[trylevel
].previousTryLevel
,
898 pScopeTable
[trylevel
].lpfnFilter
);
899 if (pScopeTable
[trylevel
].lpfnFilter
)
901 retval
= call_filter( pScopeTable
[trylevel
].lpfnFilter
, &exceptPtrs
, &frame
->_ebp
);
903 TRACE("filter returned %s\n", retval
== EXCEPTION_CONTINUE_EXECUTION
?
904 "CONTINUE_EXECUTION" : retval
== EXCEPTION_EXECUTE_HANDLER
?
905 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
907 if (retval
== EXCEPTION_CONTINUE_EXECUTION
)
908 return ExceptionContinueExecution
;
910 if (retval
== EXCEPTION_EXECUTE_HANDLER
)
912 /* Unwind all higher frames, this one will handle the exception */
913 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)frame
);
914 msvcrt_local_unwind2(frame
, trylevel
, &frame
->_ebp
);
916 /* Set our trylevel to the enclosing block, and call the __finally
917 * code, which won't return
919 frame
->trylevel
= pScopeTable
[trylevel
].previousTryLevel
;
920 TRACE("__finally block %p\n",pScopeTable
[trylevel
].lpfnHandler
);
921 call_finally_block(pScopeTable
[trylevel
].lpfnHandler
, &frame
->_ebp
);
924 trylevel
= pScopeTable
[trylevel
].previousTryLevel
;
927 TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
928 return ExceptionContinueSearch
;
931 /*********************************************************************
932 * _except_handler4_common (MSVCRT.@)
934 int CDECL
_except_handler4_common( ULONG
*cookie
, void (*check_cookie
)(void),
935 EXCEPTION_RECORD
*rec
, MSVCRT_EXCEPTION_FRAME
*frame
,
936 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
938 int retval
, trylevel
;
939 EXCEPTION_POINTERS exceptPtrs
;
940 const SCOPETABLE_V4
*scope_table
= get_scopetable_v4( frame
, *cookie
);
942 TRACE( "exception %x flags=%x at %p handler=%p %p %p cookie=%x scope table=%p cookies=%d/%x,%d/%x\n",
943 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
944 frame
->handler
, context
, dispatcher
, *cookie
, scope_table
,
945 scope_table
->gs_cookie_offset
, scope_table
->gs_cookie_xor
,
946 scope_table
->eh_cookie_offset
, scope_table
->eh_cookie_xor
);
948 /* FIXME: no cookie validation yet */
950 if (rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
))
952 /* Unwinding the current frame */
953 msvcrt_local_unwind4( cookie
, frame
, -2, &frame
->_ebp
);
954 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
955 return ExceptionContinueSearch
;
959 /* Hunting for handler */
960 exceptPtrs
.ExceptionRecord
= rec
;
961 exceptPtrs
.ContextRecord
= context
;
962 *((DWORD
*)frame
-1) = (DWORD
)&exceptPtrs
;
963 trylevel
= frame
->trylevel
;
965 while (trylevel
!= -2)
967 TRACE( "level %d prev %d filter %p\n", trylevel
,
968 scope_table
->entries
[trylevel
].previousTryLevel
,
969 scope_table
->entries
[trylevel
].lpfnFilter
);
970 if (scope_table
->entries
[trylevel
].lpfnFilter
)
972 retval
= call_filter( scope_table
->entries
[trylevel
].lpfnFilter
, &exceptPtrs
, &frame
->_ebp
);
974 TRACE("filter returned %s\n", retval
== EXCEPTION_CONTINUE_EXECUTION
?
975 "CONTINUE_EXECUTION" : retval
== EXCEPTION_EXECUTE_HANDLER
?
976 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
978 if (retval
== EXCEPTION_CONTINUE_EXECUTION
)
979 return ExceptionContinueExecution
;
981 if (retval
== EXCEPTION_EXECUTE_HANDLER
)
983 __DestructExceptionObject(rec
);
985 /* Unwind all higher frames, this one will handle the exception */
986 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)frame
);
987 msvcrt_local_unwind4( cookie
, frame
, trylevel
, &frame
->_ebp
);
989 /* Set our trylevel to the enclosing block, and call the __finally
990 * code, which won't return
992 frame
->trylevel
= scope_table
->entries
[trylevel
].previousTryLevel
;
993 TRACE("__finally block %p\n",scope_table
->entries
[trylevel
].lpfnHandler
);
994 call_finally_block(scope_table
->entries
[trylevel
].lpfnHandler
, &frame
->_ebp
);
997 trylevel
= scope_table
->entries
[trylevel
].previousTryLevel
;
1000 TRACE("reached -2, returning ExceptionContinueSearch\n");
1001 return ExceptionContinueSearch
;
1006 * setjmp/longjmp implementation
1009 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
1010 typedef void (__stdcall
*MSVCRT_unwind_function
)(const struct MSVCRT___JUMP_BUFFER
*);
1012 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
1013 /* and then jumps to the C backend function */
1014 #define DEFINE_SETJMP_ENTRYPOINT(name) \
1015 __ASM_GLOBAL_FUNC( name, \
1016 "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \
1017 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \
1018 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \
1019 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \
1020 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \
1021 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \
1022 "movl 0(%esp),%eax\n\t" \
1023 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \
1024 "jmp " __ASM_NAME("__regs_") # name )
1026 /* restore the registers from the jmp buf upon longjmp */
1027 extern void DECLSPEC_NORETURN
longjmp_set_regs( struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
);
1028 __ASM_GLOBAL_FUNC( longjmp_set_regs
,
1029 "movl 4(%esp),%ecx\n\t" /* jmp_buf */
1030 "movl 8(%esp),%eax\n\t" /* retval */
1031 "movl 0(%ecx),%ebp\n\t" /* jmp_buf.Ebp */
1032 "movl 4(%ecx),%ebx\n\t" /* jmp_buf.Ebx */
1033 "movl 8(%ecx),%edi\n\t" /* jmp_buf.Edi */
1034 "movl 12(%ecx),%esi\n\t" /* jmp_buf.Esi */
1035 "movl 16(%ecx),%esp\n\t" /* jmp_buf.Esp */
1036 "addl $4,%esp\n\t" /* get rid of return address */
1037 "jmp *20(%ecx)\n\t" /* jmp_buf.Eip */ )
1040 * The signatures of the setjmp/longjmp functions do not match that
1041 * declared in the setjmp header so they don't follow the regular naming
1042 * convention to avoid conflicts.
1045 /*******************************************************************
1046 * _setjmp (MSVCRT.@)
1048 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp
)
1049 int CDECL DECLSPEC_HIDDEN
__regs_MSVCRT__setjmp(struct MSVCRT___JUMP_BUFFER
*jmp
)
1051 jmp
->Registration
= (unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1052 if (jmp
->Registration
== ~0UL)
1053 jmp
->TryLevel
= TRYLEVEL_END
;
1055 jmp
->TryLevel
= ((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
)->trylevel
;
1057 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1058 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
);
1062 /*******************************************************************
1063 * _setjmp3 (MSVCRT.@)
1065 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3
)
1066 int WINAPIV DECLSPEC_HIDDEN
__regs_MSVCRT__setjmp3(struct MSVCRT___JUMP_BUFFER
*jmp
, int nb_args
, ...)
1068 jmp
->Cookie
= MSVCRT_JMP_MAGIC
;
1069 jmp
->UnwindFunc
= 0;
1070 jmp
->Registration
= (unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1071 if (jmp
->Registration
== ~0UL)
1073 jmp
->TryLevel
= TRYLEVEL_END
;
1080 va_start( args
, nb_args
);
1081 if (nb_args
> 0) jmp
->UnwindFunc
= va_arg( args
, unsigned long );
1082 if (nb_args
> 1) jmp
->TryLevel
= va_arg( args
, unsigned long );
1083 else jmp
->TryLevel
= ((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
)->trylevel
;
1084 for (i
= 0; i
< 6 && i
< nb_args
- 2; i
++)
1085 jmp
->UnwindData
[i
] = va_arg( args
, unsigned long );
1089 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1090 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
);
1094 /*********************************************************************
1095 * longjmp (MSVCRT.@)
1097 void CDECL
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
1099 unsigned long cur_frame
= 0;
1101 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
1102 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
, retval
);
1104 cur_frame
=(unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1105 TRACE("cur_frame=%lx\n",cur_frame
);
1107 if (cur_frame
!= jmp
->Registration
)
1108 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)jmp
->Registration
);
1110 if (jmp
->Registration
)
1112 if (IsBadReadPtr(&jmp
->Cookie
, sizeof(long)) || jmp
->Cookie
!= MSVCRT_JMP_MAGIC
)
1114 msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
,
1115 jmp
->TryLevel
, (void *)jmp
->Ebp
);
1117 else if(jmp
->UnwindFunc
)
1119 MSVCRT_unwind_function unwind_func
;
1121 unwind_func
=(MSVCRT_unwind_function
)jmp
->UnwindFunc
;
1129 longjmp_set_regs( jmp
, retval
);
1132 /*********************************************************************
1133 * _seh_longjmp_unwind (MSVCRT.@)
1135 void __stdcall
_seh_longjmp_unwind(struct MSVCRT___JUMP_BUFFER
*jmp
)
1137 msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
, jmp
->TryLevel
, (void *)jmp
->Ebp
);
1140 /*********************************************************************
1141 * _seh_longjmp_unwind4 (MSVCRT.@)
1143 void __stdcall
_seh_longjmp_unwind4(struct MSVCRT___JUMP_BUFFER
*jmp
)
1145 msvcrt_local_unwind4( (ULONG
*)&jmp
->Cookie
, (MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
,
1146 jmp
->TryLevel
, (void *)jmp
->Ebp
);
1149 /*********************************************************************
1150 * _fpieee_flt (MSVCRT.@)
1152 int __cdecl
_fpieee_flt(ULONG exception_code
, EXCEPTION_POINTERS
*ep
,
1153 int (__cdecl
*handler
)(_FPIEEE_RECORD
*))
1155 FLOATING_SAVE_AREA
*ctx
= &ep
->ContextRecord
->FloatSave
;
1159 TRACE("(%x %p %p)\n", exception_code
, ep
, handler
);
1161 switch(exception_code
) {
1162 case STATUS_FLOAT_DIVIDE_BY_ZERO
:
1163 case STATUS_FLOAT_INEXACT_RESULT
:
1164 case STATUS_FLOAT_INVALID_OPERATION
:
1165 case STATUS_FLOAT_OVERFLOW
:
1166 case STATUS_FLOAT_UNDERFLOW
:
1169 return EXCEPTION_CONTINUE_SEARCH
;
1172 memset(&rec
, 0, sizeof(rec
));
1173 rec
.RoundingMode
= ctx
->ControlWord
>> 10;
1174 switch((ctx
->ControlWord
>> 8) & 0x3) {
1175 case 0: rec
.Precision
= 2; break;
1176 case 1: rec
.Precision
= 3; break;
1177 case 2: rec
.Precision
= 1; break;
1178 case 3: rec
.Precision
= 0; break;
1180 rec
.Status
.InvalidOperation
= ctx
->StatusWord
& 0x1;
1181 rec
.Status
.ZeroDivide
= ((ctx
->StatusWord
& 0x4) != 0);
1182 rec
.Status
.Overflow
= ((ctx
->StatusWord
& 0x8) != 0);
1183 rec
.Status
.Underflow
= ((ctx
->StatusWord
& 0x10) != 0);
1184 rec
.Status
.Inexact
= ((ctx
->StatusWord
& 0x20) != 0);
1185 rec
.Enable
.InvalidOperation
= ((ctx
->ControlWord
& 0x1) == 0);
1186 rec
.Enable
.ZeroDivide
= ((ctx
->ControlWord
& 0x4) == 0);
1187 rec
.Enable
.Overflow
= ((ctx
->ControlWord
& 0x8) == 0);
1188 rec
.Enable
.Underflow
= ((ctx
->ControlWord
& 0x10) == 0);
1189 rec
.Enable
.Inexact
= ((ctx
->ControlWord
& 0x20) == 0);
1190 rec
.Cause
.InvalidOperation
= rec
.Enable
.InvalidOperation
& rec
.Status
.InvalidOperation
;
1191 rec
.Cause
.ZeroDivide
= rec
.Enable
.ZeroDivide
& rec
.Status
.ZeroDivide
;
1192 rec
.Cause
.Overflow
= rec
.Enable
.Overflow
& rec
.Status
.Overflow
;
1193 rec
.Cause
.Underflow
= rec
.Enable
.Underflow
& rec
.Status
.Underflow
;
1194 rec
.Cause
.Inexact
= rec
.Enable
.Inexact
& rec
.Status
.Inexact
;
1196 TRACE("opcode: %x\n", *(ULONG
*)ep
->ContextRecord
->FloatSave
.ErrorOffset
);
1198 if(*(WORD
*)ctx
->ErrorOffset
== 0x35dc) { /* fdiv m64fp */
1199 if(exception_code
==STATUS_FLOAT_DIVIDE_BY_ZERO
|| exception_code
==STATUS_FLOAT_INVALID_OPERATION
) {
1200 rec
.Operand1
.OperandValid
= 1;
1201 rec
.Result
.OperandValid
= 0;
1203 rec
.Operand1
.OperandValid
= 0;
1204 rec
.Result
.OperandValid
= 1;
1206 rec
.Operand2
.OperandValid
= 1;
1207 rec
.Operation
= _FpCodeDivide
;
1208 rec
.Operand1
.Format
= _FpFormatFp80
;
1209 memcpy(&rec
.Operand1
.Value
.Fp80Value
, ctx
->RegisterArea
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1210 rec
.Operand2
.Format
= _FpFormatFp64
;
1211 rec
.Operand2
.Value
.Fp64Value
= *(double*)ctx
->DataOffset
;
1212 rec
.Result
.Format
= _FpFormatFp80
;
1213 memcpy(&rec
.Result
.Value
.Fp80Value
, ctx
->RegisterArea
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1215 ret
= handler(&rec
);
1217 if(ret
== EXCEPTION_CONTINUE_EXECUTION
)
1218 memcpy(ctx
->RegisterArea
, &rec
.Result
.Value
.Fp80Value
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1222 FIXME("unsupported opcode: %x\n", *(ULONG
*)ep
->ContextRecord
->FloatSave
.ErrorOffset
);
1223 return EXCEPTION_CONTINUE_SEARCH
;
1226 #endif /* __i386__ */