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 */
99 /* exception frame for nested exceptions in catch block */
102 EXCEPTION_REGISTRATION_RECORD frame
; /* standard exception frame */
103 cxx_exception_frame
*cxx_frame
; /* frame of parent exception */
104 const cxx_function_descr
*descr
; /* descriptor of parent exception */
105 int trylevel
; /* current try level */
106 cxx_frame_info frame_info
;
107 } catch_func_nested_frame
;
111 cxx_exception_frame
*frame
;
112 const cxx_function_descr
*descr
;
113 catch_func_nested_frame
*nested_frame
;
116 typedef struct _SCOPETABLE
118 int previousTryLevel
;
119 int (*lpfnFilter
)(PEXCEPTION_POINTERS
);
120 void * (*lpfnHandler
)(void);
121 } SCOPETABLE
, *PSCOPETABLE
;
123 typedef struct _MSVCRT_EXCEPTION_FRAME
125 EXCEPTION_REGISTRATION_RECORD
*prev
;
126 void (*handler
)(PEXCEPTION_RECORD
, EXCEPTION_REGISTRATION_RECORD
*,
127 PCONTEXT
, PEXCEPTION_RECORD
);
128 PSCOPETABLE scopetable
;
131 PEXCEPTION_POINTERS xpointers
;
132 } MSVCRT_EXCEPTION_FRAME
;
136 int gs_cookie_offset
;
138 int eh_cookie_offset
;
140 SCOPETABLE entries
[1];
143 #define TRYLEVEL_END (-1) /* End of trylevel list */
145 DWORD CDECL
cxx_frame_handler( PEXCEPTION_RECORD rec
, cxx_exception_frame
* frame
,
146 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
,
147 const cxx_function_descr
*descr
,
148 catch_func_nested_frame
* nested_frame
) DECLSPEC_HIDDEN
;
150 /* call a copy constructor */
151 extern void call_copy_ctor( void *func
, void *this, void *src
, int has_vbase
);
153 __ASM_GLOBAL_FUNC( call_copy_ctor
,
155 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
156 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
157 "movl %esp, %ebp\n\t"
158 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
160 "movl 12(%ebp), %ecx\n\t"
164 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
165 __ASM_CFI(".cfi_same_value %ebp\n\t")
168 /* continue execution to the specified address after exception is caught */
169 extern void DECLSPEC_NORETURN
continue_after_catch( cxx_exception_frame
* frame
, void *addr
);
171 __ASM_GLOBAL_FUNC( continue_after_catch
,
172 "movl 4(%esp), %edx\n\t"
173 "movl 8(%esp), %eax\n\t"
174 "movl -4(%edx), %esp\n\t"
175 "leal 12(%edx), %ebp\n\t"
178 extern void DECLSPEC_NORETURN
call_finally_block( void *code_block
, void *base_ptr
);
180 __ASM_GLOBAL_FUNC( call_finally_block
,
181 "movl 8(%esp), %ebp\n\t"
184 extern int call_filter( int (*func
)(PEXCEPTION_POINTERS
), void *arg
, void *ebp
);
186 __ASM_GLOBAL_FUNC( call_filter
,
189 "movl 20(%esp), %ebp\n\t"
195 extern void *call_handler( void * (*func
)(void), void *ebp
);
197 __ASM_GLOBAL_FUNC( call_handler
,
202 "movl 24(%esp), %ebp\n\t"
210 static inline void dump_type( const cxx_type_info
*type
)
212 TRACE( "flags %x type %p %s offsets %d,%d,%d size %d copy ctor %p\n",
213 type
->flags
, type
->type_info
, dbgstr_type_info(type
->type_info
),
214 type
->offsets
.this_offset
, type
->offsets
.vbase_descr
, type
->offsets
.vbase_offset
,
215 type
->size
, type
->copy_ctor
);
218 static void dump_exception_type( const cxx_exception_type
*type
)
222 TRACE( "flags %x destr %p handler %p type info %p\n",
223 type
->flags
, type
->destructor
, type
->custom_handler
, type
->type_info_table
);
224 for (i
= 0; i
< type
->type_info_table
->count
; i
++)
227 dump_type( type
->type_info_table
->info
[i
] );
231 static void dump_function_descr( const cxx_function_descr
*descr
)
236 TRACE( "magic %x\n", descr
->magic
);
237 TRACE( "unwind table: %p %d\n", descr
->unwind_table
, descr
->unwind_count
);
238 for (i
= 0; i
< descr
->unwind_count
; i
++)
240 TRACE( " %d: prev %d func %p\n", i
,
241 descr
->unwind_table
[i
].prev
, descr
->unwind_table
[i
].handler
);
243 TRACE( "try table: %p %d\n", descr
->tryblock
, descr
->tryblock_count
);
244 for (i
= 0; i
< descr
->tryblock_count
; i
++)
246 TRACE( " %d: start %d end %d catchlevel %d catch %p %d\n", i
,
247 descr
->tryblock
[i
].start_level
, descr
->tryblock
[i
].end_level
,
248 descr
->tryblock
[i
].catch_level
, descr
->tryblock
[i
].catchblock
,
249 descr
->tryblock
[i
].catchblock_count
);
250 for (j
= 0; j
< descr
->tryblock
[i
].catchblock_count
; j
++)
252 const catchblock_info
*ptr
= &descr
->tryblock
[i
].catchblock
[j
];
253 TRACE( " %d: flags %x offset %d handler %p type %p %s\n",
254 j
, ptr
->flags
, ptr
->offset
, ptr
->handler
,
255 ptr
->type_info
, dbgstr_type_info( ptr
->type_info
) );
258 if (descr
->magic
<= CXX_FRAME_MAGIC_VC6
) return;
259 TRACE( "expect list: %p\n", descr
->expect_list
);
260 if (descr
->magic
<= CXX_FRAME_MAGIC_VC7
) return;
261 TRACE( "flags: %08x\n", descr
->flags
);
264 /* check if the exception type is caught by a given catch block, and return the type that matched */
265 static const cxx_type_info
*find_caught_type( cxx_exception_type
*exc_type
,
266 const type_info
*catch_ti
, UINT catch_flags
)
270 for (i
= 0; i
< exc_type
->type_info_table
->count
; i
++)
272 const cxx_type_info
*type
= exc_type
->type_info_table
->info
[i
];
274 if (!catch_ti
) return type
; /* catch(...) matches any type */
275 if (catch_ti
!= type
->type_info
)
277 if (strcmp( catch_ti
->mangled
, type
->type_info
->mangled
)) continue;
279 /* type is the same, now check the flags */
280 if ((exc_type
->flags
& TYPE_FLAG_CONST
) &&
281 !(catch_flags
& TYPE_FLAG_CONST
)) continue;
282 if ((exc_type
->flags
& TYPE_FLAG_VOLATILE
) &&
283 !(catch_flags
& TYPE_FLAG_VOLATILE
)) continue;
284 return type
; /* it matched */
290 /* copy the exception object where the catch block wants it */
291 static void copy_exception( void *object
, cxx_exception_frame
*frame
,
292 const catchblock_info
*catchblock
, const cxx_type_info
*type
)
296 if (!catchblock
->type_info
|| !catchblock
->type_info
->mangled
[0]) return;
297 if (!catchblock
->offset
) return;
298 dest_ptr
= (void **)((char *)&frame
->ebp
+ catchblock
->offset
);
300 if (catchblock
->flags
& TYPE_FLAG_REFERENCE
)
302 *dest_ptr
= get_this_pointer( &type
->offsets
, object
);
304 else if (type
->flags
& CLASS_IS_SIMPLE_TYPE
)
306 memmove( dest_ptr
, object
, type
->size
);
307 /* if it is a pointer, adjust it */
308 if (type
->size
== sizeof(void *)) *dest_ptr
= get_this_pointer( &type
->offsets
, *dest_ptr
);
310 else /* copy the object */
313 call_copy_ctor( type
->copy_ctor
, dest_ptr
, get_this_pointer(&type
->offsets
,object
),
314 (type
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
) );
316 memmove( dest_ptr
, get_this_pointer(&type
->offsets
,object
), type
->size
);
320 /* unwind the local function up to a given trylevel */
321 static void cxx_local_unwind( cxx_exception_frame
* frame
, const cxx_function_descr
*descr
, int last_level
)
323 void * (*handler
)(void);
324 int trylevel
= frame
->trylevel
;
326 while (trylevel
!= last_level
)
328 if (trylevel
< 0 || trylevel
>= descr
->unwind_count
)
330 ERR( "invalid trylevel %d\n", trylevel
);
333 handler
= descr
->unwind_table
[trylevel
].handler
;
336 TRACE( "calling unwind handler %p trylevel %d last %d ebp %p\n",
337 handler
, trylevel
, last_level
, &frame
->ebp
);
338 call_handler( handler
, &frame
->ebp
);
340 trylevel
= descr
->unwind_table
[trylevel
].prev
;
342 frame
->trylevel
= last_level
;
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 catch_func_nested_frame
*nested_frame
= (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-propagate: 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
);
388 /* find and call the appropriate catch block for an exception */
389 /* returns the address to continue execution to after the catch block was called */
390 static inline void call_catch_block( PEXCEPTION_RECORD rec
, CONTEXT
*context
,
391 cxx_exception_frame
*frame
,
392 const cxx_function_descr
*descr
,
393 catch_func_nested_frame
*catch_frame
,
394 cxx_exception_type
*info
)
398 void *addr
, *object
= (void *)rec
->ExceptionInformation
[1];
399 catch_func_nested_frame nested_frame
;
400 int trylevel
= frame
->trylevel
;
401 DWORD save_esp
= ((DWORD
*)frame
)[-1];
402 thread_data_t
*data
= msvcrt_get_thread_data();
404 data
->processing_throw
++;
405 for (i
= 0; i
< descr
->tryblock_count
; i
++)
407 const tryblock_info
*tryblock
= &descr
->tryblock
[i
];
409 /* only handle try blocks inside current catch block */
410 if (catch_frame
&& catch_frame
->trylevel
> tryblock
->start_level
) continue;
412 if (trylevel
< tryblock
->start_level
) continue;
413 if (trylevel
> tryblock
->end_level
) continue;
415 /* got a try block */
416 for (j
= 0; j
< tryblock
->catchblock_count
; j
++)
418 const catchblock_info
*catchblock
= &tryblock
->catchblock
[j
];
421 const cxx_type_info
*type
= find_caught_type( info
,
422 catchblock
->type_info
, catchblock
->flags
);
425 TRACE( "matched type %p in tryblock %d catchblock %d\n", type
, i
, j
);
427 /* copy the exception to its destination on the stack */
428 copy_exception( object
, frame
, catchblock
, type
);
432 /* no CXX_EXCEPTION only proceed with a catch(...) block*/
433 if(catchblock
->type_info
)
435 TRACE("found catch(...) block\n");
438 /* Add frame info here so exception is not freed inside RtlUnwind call */
439 _CreateFrameInfo(&nested_frame
.frame_info
.frame_info
,
440 (void*)rec
->ExceptionInformation
[1]);
442 /* unwind the stack */
443 RtlUnwind( catch_frame
? &catch_frame
->frame
: &frame
->frame
, 0, rec
, 0 );
444 cxx_local_unwind( frame
, descr
, tryblock
->start_level
);
445 frame
->trylevel
= tryblock
->end_level
+ 1;
447 nested_frame
.frame_info
.rec
= data
->exc_record
;
448 nested_frame
.frame_info
.context
= data
->ctx_record
;
449 data
->exc_record
= rec
;
450 data
->ctx_record
= context
;
451 data
->processing_throw
--;
453 /* call the catch block */
454 TRACE( "calling catch block %p addr %p ebp %p\n",
455 catchblock
, catchblock
->handler
, &frame
->ebp
);
457 /* setup an exception block for nested exceptions */
458 nested_frame
.frame
.Handler
= catch_function_nested_handler
;
459 nested_frame
.cxx_frame
= frame
;
460 nested_frame
.descr
= descr
;
461 nested_frame
.trylevel
= tryblock
->end_level
+ 1;
463 __wine_push_frame( &nested_frame
.frame
);
464 addr
= call_handler( catchblock
->handler
, &frame
->ebp
);
465 __wine_pop_frame( &nested_frame
.frame
);
467 ((DWORD
*)frame
)[-1] = save_esp
;
468 __CxxUnregisterExceptionObject(&nested_frame
.frame_info
, FALSE
);
469 TRACE( "done, continuing at %p\n", addr
);
471 continue_after_catch( frame
, addr
);
474 data
->processing_throw
--;
477 /*********************************************************************
478 * __CxxExceptionFilter (MSVCRT.@)
480 int CDECL
__CxxExceptionFilter( PEXCEPTION_POINTERS ptrs
,
481 const type_info
*ti
, int flags
, void **copy
)
483 const cxx_type_info
*type
;
484 PEXCEPTION_RECORD rec
;
486 TRACE( "%p %p %x %p\n", ptrs
, ti
, flags
, copy
);
488 if (!ptrs
) return EXCEPTION_CONTINUE_SEARCH
;
490 /* handle catch(...) */
491 if (!ti
) return EXCEPTION_EXECUTE_HANDLER
;
493 rec
= ptrs
->ExceptionRecord
;
494 if (rec
->ExceptionCode
!= CXX_EXCEPTION
|| rec
->NumberParameters
!= 3 ||
495 rec
->ExceptionInformation
[0] < CXX_FRAME_MAGIC_VC6
||
496 rec
->ExceptionInformation
[0] > CXX_FRAME_MAGIC_VC8
)
497 return EXCEPTION_CONTINUE_SEARCH
;
499 if (rec
->ExceptionInformation
[1] == 0 && rec
->ExceptionInformation
[2] == 0)
501 rec
= msvcrt_get_thread_data()->exc_record
;
502 if (!rec
) return EXCEPTION_CONTINUE_SEARCH
;
505 type
= find_caught_type( (cxx_exception_type
*)rec
->ExceptionInformation
[2], ti
, flags
);
506 if (!type
) return EXCEPTION_CONTINUE_SEARCH
;
510 void *object
= (void *)rec
->ExceptionInformation
[1];
512 if (flags
& TYPE_FLAG_REFERENCE
)
514 *copy
= get_this_pointer( &type
->offsets
, object
);
516 else if (type
->flags
& CLASS_IS_SIMPLE_TYPE
)
518 memmove( copy
, object
, type
->size
);
519 /* if it is a pointer, adjust it */
520 if (type
->size
== sizeof(void*)) *copy
= get_this_pointer( &type
->offsets
, *copy
);
522 else /* copy the object */
525 call_copy_ctor( type
->copy_ctor
, copy
, get_this_pointer(&type
->offsets
,object
),
526 (type
->flags
& CLASS_HAS_VIRTUAL_BASE_CLASS
) );
528 memmove( copy
, get_this_pointer(&type
->offsets
,object
), type
->size
);
531 return EXCEPTION_EXECUTE_HANDLER
;
534 static LONG CALLBACK
se_translation_filter( EXCEPTION_POINTERS
*ep
, void *c
)
536 se_translator_ctx
*ctx
= (se_translator_ctx
*)c
;
537 EXCEPTION_RECORD
*rec
= ep
->ExceptionRecord
;
538 cxx_exception_type
*exc_type
;
540 if (rec
->ExceptionCode
!= CXX_EXCEPTION
)
542 TRACE( "non-c++ exception thrown in SEH handler: %x\n", rec
->ExceptionCode
);
546 exc_type
= (cxx_exception_type
*)rec
->ExceptionInformation
[2];
547 call_catch_block( rec
, ep
->ContextRecord
, ctx
->frame
, ctx
->descr
,
548 ctx
->nested_frame
, exc_type
);
550 __DestructExceptionObject( rec
);
551 return ExceptionContinueSearch
;
554 static void check_noexcept( PEXCEPTION_RECORD rec
,
555 const cxx_function_descr
*descr
, BOOL nested
)
557 if (!nested
&& rec
->ExceptionCode
== CXX_EXCEPTION
&&
558 descr
->magic
>= CXX_FRAME_MAGIC_VC8
&&
559 (descr
->flags
& FUNC_DESCR_NOEXCEPT
))
561 ERR("noexcept function propagating exception\n");
566 /*********************************************************************
569 * Implementation of __CxxFrameHandler.
571 DWORD CDECL
cxx_frame_handler( PEXCEPTION_RECORD rec
, cxx_exception_frame
* frame
,
572 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
,
573 const cxx_function_descr
*descr
,
574 catch_func_nested_frame
* nested_frame
)
576 cxx_exception_type
*exc_type
;
578 if (descr
->magic
< CXX_FRAME_MAGIC_VC6
|| descr
->magic
> CXX_FRAME_MAGIC_VC8
)
580 ERR( "invalid frame magic %x\n", descr
->magic
);
581 return ExceptionContinueSearch
;
583 if (descr
->magic
>= CXX_FRAME_MAGIC_VC8
&&
584 (descr
->flags
& FUNC_DESCR_SYNCHRONOUS
) &&
585 (rec
->ExceptionCode
!= CXX_EXCEPTION
))
586 return ExceptionContinueSearch
; /* handle only c++ exceptions */
588 if (rec
->ExceptionFlags
& (EH_UNWINDING
|EH_EXIT_UNWIND
))
590 if (descr
->unwind_count
&& !nested_frame
) cxx_local_unwind( frame
, descr
, -1 );
591 return ExceptionContinueSearch
;
593 if (!descr
->tryblock_count
)
595 check_noexcept(rec
, descr
, nested_frame
!= NULL
);
596 return ExceptionContinueSearch
;
599 if(rec
->ExceptionCode
== CXX_EXCEPTION
&&
600 rec
->ExceptionInformation
[1] == 0 && rec
->ExceptionInformation
[2] == 0)
602 *rec
= *msvcrt_get_thread_data()->exc_record
;
603 rec
->ExceptionFlags
&= ~EH_UNWINDING
;
605 TRACE("detect rethrow: exception code: %x\n", rec
->ExceptionCode
);
606 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
607 TRACE("re-propagate: obj: %lx, type: %lx\n",
608 rec
->ExceptionInformation
[1], rec
->ExceptionInformation
[2]);
612 if(rec
->ExceptionCode
== CXX_EXCEPTION
)
614 exc_type
= (cxx_exception_type
*)rec
->ExceptionInformation
[2];
616 if (rec
->ExceptionInformation
[0] > CXX_FRAME_MAGIC_VC8
&&
617 exc_type
->custom_handler
)
619 return exc_type
->custom_handler( rec
, frame
, context
, dispatch
, descr
,
620 nested_frame
? nested_frame
->trylevel
: 0,
621 nested_frame
? &nested_frame
->frame
: NULL
, 0 );
626 TRACE("handling C++ exception rec %p frame %p trylevel %d descr %p nested_frame %p\n",
627 rec
, frame
, frame
->trylevel
, descr
, nested_frame
);
628 dump_exception_type( exc_type
);
629 dump_function_descr( descr
);
634 thread_data_t
*data
= msvcrt_get_thread_data();
637 TRACE("handling C exception code %x rec %p frame %p trylevel %d descr %p nested_frame %p\n",
638 rec
->ExceptionCode
, rec
, frame
, frame
->trylevel
, descr
, nested_frame
);
640 if (data
->se_translator
) {
641 EXCEPTION_POINTERS except_ptrs
;
642 se_translator_ctx ctx
;
646 ctx
.nested_frame
= nested_frame
;
649 except_ptrs
.ExceptionRecord
= rec
;
650 except_ptrs
.ContextRecord
= context
;
651 data
->se_translator( rec
->ExceptionCode
, &except_ptrs
);
653 __EXCEPT_CTX(se_translation_filter
, &ctx
)
660 call_catch_block( rec
, context
, frame
, descr
,
661 nested_frame
, exc_type
);
662 check_noexcept(rec
, descr
, nested_frame
!= NULL
);
663 return ExceptionContinueSearch
;
667 /*********************************************************************
668 * __CxxFrameHandler (MSVCRT.@)
670 extern DWORD CDECL
__CxxFrameHandler( PEXCEPTION_RECORD rec
, EXCEPTION_REGISTRATION_RECORD
* frame
,
671 PCONTEXT context
, EXCEPTION_REGISTRATION_RECORD
** dispatch
);
672 __ASM_GLOBAL_FUNC( __CxxFrameHandler
,
673 "pushl $0\n\t" /* nested_frame */
674 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
675 "pushl %eax\n\t" /* descr */
676 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
677 "pushl 24(%esp)\n\t" /* dispatch */
678 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
679 "pushl 24(%esp)\n\t" /* context */
680 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
681 "pushl 24(%esp)\n\t" /* frame */
682 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
683 "pushl 24(%esp)\n\t" /* rec */
684 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
685 "call " __ASM_NAME("cxx_frame_handler") "\n\t"
687 __ASM_CFI(".cfi_adjust_cfa_offset -24\n\t")
691 /*********************************************************************
692 * __CxxLongjmpUnwind (MSVCRT.@)
694 * Callback meant to be used as UnwindFunc for setjmp/longjmp.
696 void __stdcall
__CxxLongjmpUnwind( const struct MSVCRT___JUMP_BUFFER
*buf
)
698 cxx_exception_frame
*frame
= (cxx_exception_frame
*)buf
->Registration
;
699 const cxx_function_descr
*descr
= (const cxx_function_descr
*)buf
->UnwindData
[0];
701 TRACE( "unwinding frame %p descr %p trylevel %ld\n", frame
, descr
, buf
->TryLevel
);
702 cxx_local_unwind( frame
, descr
, buf
->TryLevel
);
705 /*********************************************************************
706 * __CppXcptFilter (MSVCRT.@)
708 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
710 /* only filter c++ exceptions */
711 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
712 return _XcptFilter( ex
, ptr
);
715 /*********************************************************************
716 * __CxxDetectRethrow (MSVCRT.@)
718 BOOL CDECL
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs
)
720 PEXCEPTION_RECORD rec
;
725 rec
= ptrs
->ExceptionRecord
;
727 if (rec
->ExceptionCode
== CXX_EXCEPTION
&&
728 rec
->NumberParameters
== 3 &&
729 rec
->ExceptionInformation
[0] == CXX_FRAME_MAGIC_VC6
&&
730 rec
->ExceptionInformation
[2])
732 ptrs
->ExceptionRecord
= msvcrt_get_thread_data()->exc_record
;
735 return (msvcrt_get_thread_data()->exc_record
== rec
);
738 /*********************************************************************
739 * __CxxQueryExceptionSize (MSVCRT.@)
741 unsigned int CDECL
__CxxQueryExceptionSize(void)
743 return sizeof(cxx_exception_type
);
747 /*********************************************************************
748 * _EH_prolog (MSVCRT.@)
751 /* Provided for VC++ binary compatibility only */
752 __ASM_GLOBAL_FUNC(_EH_prolog
,
753 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") /* skip ret addr */
755 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
757 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
759 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
760 "movl %esp, %fs:0\n\t"
761 "movl 12(%esp), %eax\n\t"
762 "movl %ebp, 12(%esp)\n\t"
763 "leal 12(%esp), %ebp\n\t"
765 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
768 static const SCOPETABLE_V4
*get_scopetable_v4( MSVCRT_EXCEPTION_FRAME
*frame
, ULONG_PTR cookie
)
770 return (const SCOPETABLE_V4
*)((ULONG_PTR
)frame
->scopetable
^ cookie
);
773 static DWORD
MSVCRT_nested_handler(PEXCEPTION_RECORD rec
,
774 EXCEPTION_REGISTRATION_RECORD
* frame
,
776 EXCEPTION_REGISTRATION_RECORD
** dispatch
)
778 if (!(rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
)))
779 return ExceptionContinueSearch
;
781 return ExceptionCollidedUnwind
;
784 static void msvcrt_local_unwind2(MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
, void *ebp
)
786 EXCEPTION_REGISTRATION_RECORD reg
;
788 TRACE("(%p,%d,%d)\n",frame
, frame
->trylevel
, trylevel
);
790 /* Register a handler in case of a nested exception */
791 reg
.Handler
= MSVCRT_nested_handler
;
792 reg
.Prev
= NtCurrentTeb()->Tib
.ExceptionList
;
793 __wine_push_frame(®
);
795 while (frame
->trylevel
!= TRYLEVEL_END
&& frame
->trylevel
!= trylevel
)
797 int level
= frame
->trylevel
;
798 frame
->trylevel
= frame
->scopetable
[level
].previousTryLevel
;
799 if (!frame
->scopetable
[level
].lpfnFilter
)
801 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
802 level
, frame
->scopetable
[level
].lpfnHandler
, ebp
);
803 call_handler( frame
->scopetable
[level
].lpfnHandler
, ebp
);
806 __wine_pop_frame(®
);
807 TRACE("unwound OK\n");
810 static void msvcrt_local_unwind4( ULONG
*cookie
, MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
, void *ebp
)
812 EXCEPTION_REGISTRATION_RECORD reg
;
813 const SCOPETABLE_V4
*scopetable
= get_scopetable_v4( frame
, *cookie
);
815 TRACE("(%p,%d,%d)\n",frame
, frame
->trylevel
, trylevel
);
817 /* Register a handler in case of a nested exception */
818 reg
.Handler
= MSVCRT_nested_handler
;
819 reg
.Prev
= NtCurrentTeb()->Tib
.ExceptionList
;
820 __wine_push_frame(®
);
822 while (frame
->trylevel
!= -2 && frame
->trylevel
!= trylevel
)
824 int level
= frame
->trylevel
;
825 frame
->trylevel
= scopetable
->entries
[level
].previousTryLevel
;
826 if (!scopetable
->entries
[level
].lpfnFilter
)
828 TRACE( "__try block cleanup level %d handler %p ebp %p\n",
829 level
, scopetable
->entries
[level
].lpfnHandler
, ebp
);
830 call_handler( scopetable
->entries
[level
].lpfnHandler
, ebp
);
833 __wine_pop_frame(®
);
834 TRACE("unwound OK\n");
837 /*******************************************************************
838 * _local_unwind2 (MSVCRT.@)
840 void CDECL
_local_unwind2(MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
)
842 msvcrt_local_unwind2( frame
, trylevel
, &frame
->_ebp
);
845 /*******************************************************************
846 * _local_unwind4 (MSVCRT.@)
848 void CDECL
_local_unwind4( ULONG
*cookie
, MSVCRT_EXCEPTION_FRAME
* frame
, int trylevel
)
850 msvcrt_local_unwind4( cookie
, frame
, trylevel
, &frame
->_ebp
);
853 /*******************************************************************
854 * _global_unwind2 (MSVCRT.@)
856 void CDECL
_global_unwind2(EXCEPTION_REGISTRATION_RECORD
* frame
)
858 TRACE("(%p)\n",frame
);
859 RtlUnwind( frame
, 0, 0, 0 );
862 /*********************************************************************
863 * _except_handler2 (MSVCRT.@)
865 int CDECL
_except_handler2(PEXCEPTION_RECORD rec
,
866 EXCEPTION_REGISTRATION_RECORD
* frame
,
868 EXCEPTION_REGISTRATION_RECORD
** dispatcher
)
870 FIXME("exception %x flags=%x at %p handler=%p %p %p stub\n",
871 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
872 frame
->Handler
, context
, dispatcher
);
873 return ExceptionContinueSearch
;
876 /*********************************************************************
877 * _except_handler3 (MSVCRT.@)
879 int CDECL
_except_handler3(PEXCEPTION_RECORD rec
,
880 MSVCRT_EXCEPTION_FRAME
* frame
,
881 PCONTEXT context
, void* dispatcher
)
883 int retval
, trylevel
;
884 EXCEPTION_POINTERS exceptPtrs
;
885 PSCOPETABLE pScopeTable
;
887 TRACE("exception %x flags=%x at %p handler=%p %p %p semi-stub\n",
888 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
889 frame
->handler
, context
, dispatcher
);
891 __asm__
__volatile__ ("cld");
893 if (rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
))
895 /* Unwinding the current frame */
896 msvcrt_local_unwind2(frame
, TRYLEVEL_END
, &frame
->_ebp
);
897 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
898 return ExceptionContinueSearch
;
902 /* Hunting for handler */
903 exceptPtrs
.ExceptionRecord
= rec
;
904 exceptPtrs
.ContextRecord
= context
;
905 *((DWORD
*)frame
-1) = (DWORD
)&exceptPtrs
;
906 trylevel
= frame
->trylevel
;
907 pScopeTable
= frame
->scopetable
;
909 while (trylevel
!= TRYLEVEL_END
)
911 TRACE( "level %d prev %d filter %p\n", trylevel
, pScopeTable
[trylevel
].previousTryLevel
,
912 pScopeTable
[trylevel
].lpfnFilter
);
913 if (pScopeTable
[trylevel
].lpfnFilter
)
915 retval
= call_filter( pScopeTable
[trylevel
].lpfnFilter
, &exceptPtrs
, &frame
->_ebp
);
917 TRACE("filter returned %s\n", retval
== EXCEPTION_CONTINUE_EXECUTION
?
918 "CONTINUE_EXECUTION" : retval
== EXCEPTION_EXECUTE_HANDLER
?
919 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
921 if (retval
== EXCEPTION_CONTINUE_EXECUTION
)
922 return ExceptionContinueExecution
;
924 if (retval
== EXCEPTION_EXECUTE_HANDLER
)
926 /* Unwind all higher frames, this one will handle the exception */
927 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)frame
);
928 msvcrt_local_unwind2(frame
, trylevel
, &frame
->_ebp
);
930 /* Set our trylevel to the enclosing block, and call the __finally
931 * code, which won't return
933 frame
->trylevel
= pScopeTable
[trylevel
].previousTryLevel
;
934 TRACE("__finally block %p\n",pScopeTable
[trylevel
].lpfnHandler
);
935 call_finally_block(pScopeTable
[trylevel
].lpfnHandler
, &frame
->_ebp
);
938 trylevel
= pScopeTable
[trylevel
].previousTryLevel
;
941 TRACE("reached TRYLEVEL_END, returning ExceptionContinueSearch\n");
942 return ExceptionContinueSearch
;
945 /*********************************************************************
946 * _except_handler4_common (MSVCRT.@)
948 int CDECL
_except_handler4_common( ULONG
*cookie
, void (*check_cookie
)(void),
949 EXCEPTION_RECORD
*rec
, MSVCRT_EXCEPTION_FRAME
*frame
,
950 CONTEXT
*context
, EXCEPTION_REGISTRATION_RECORD
**dispatcher
)
952 int retval
, trylevel
;
953 EXCEPTION_POINTERS exceptPtrs
;
954 const SCOPETABLE_V4
*scope_table
= get_scopetable_v4( frame
, *cookie
);
956 TRACE( "exception %x flags=%x at %p handler=%p %p %p cookie=%x scope table=%p cookies=%d/%x,%d/%x\n",
957 rec
->ExceptionCode
, rec
->ExceptionFlags
, rec
->ExceptionAddress
,
958 frame
->handler
, context
, dispatcher
, *cookie
, scope_table
,
959 scope_table
->gs_cookie_offset
, scope_table
->gs_cookie_xor
,
960 scope_table
->eh_cookie_offset
, scope_table
->eh_cookie_xor
);
962 /* FIXME: no cookie validation yet */
964 if (rec
->ExceptionFlags
& (EH_UNWINDING
| EH_EXIT_UNWIND
))
966 /* Unwinding the current frame */
967 msvcrt_local_unwind4( cookie
, frame
, -2, &frame
->_ebp
);
968 TRACE("unwound current frame, returning ExceptionContinueSearch\n");
969 return ExceptionContinueSearch
;
973 /* Hunting for handler */
974 exceptPtrs
.ExceptionRecord
= rec
;
975 exceptPtrs
.ContextRecord
= context
;
976 *((DWORD
*)frame
-1) = (DWORD
)&exceptPtrs
;
977 trylevel
= frame
->trylevel
;
979 while (trylevel
!= -2)
981 TRACE( "level %d prev %d filter %p\n", trylevel
,
982 scope_table
->entries
[trylevel
].previousTryLevel
,
983 scope_table
->entries
[trylevel
].lpfnFilter
);
984 if (scope_table
->entries
[trylevel
].lpfnFilter
)
986 retval
= call_filter( scope_table
->entries
[trylevel
].lpfnFilter
, &exceptPtrs
, &frame
->_ebp
);
988 TRACE("filter returned %s\n", retval
== EXCEPTION_CONTINUE_EXECUTION
?
989 "CONTINUE_EXECUTION" : retval
== EXCEPTION_EXECUTE_HANDLER
?
990 "EXECUTE_HANDLER" : "CONTINUE_SEARCH");
992 if (retval
== EXCEPTION_CONTINUE_EXECUTION
)
993 return ExceptionContinueExecution
;
995 if (retval
== EXCEPTION_EXECUTE_HANDLER
)
997 __DestructExceptionObject(rec
);
999 /* Unwind all higher frames, this one will handle the exception */
1000 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)frame
);
1001 msvcrt_local_unwind4( cookie
, frame
, trylevel
, &frame
->_ebp
);
1003 /* Set our trylevel to the enclosing block, and call the __finally
1004 * code, which won't return
1006 frame
->trylevel
= scope_table
->entries
[trylevel
].previousTryLevel
;
1007 TRACE("__finally block %p\n",scope_table
->entries
[trylevel
].lpfnHandler
);
1008 call_finally_block(scope_table
->entries
[trylevel
].lpfnHandler
, &frame
->_ebp
);
1011 trylevel
= scope_table
->entries
[trylevel
].previousTryLevel
;
1014 TRACE("reached -2, returning ExceptionContinueSearch\n");
1015 return ExceptionContinueSearch
;
1020 * setjmp/longjmp implementation
1023 #define MSVCRT_JMP_MAGIC 0x56433230 /* ID value for new jump structure */
1024 typedef void (__stdcall
*MSVCRT_unwind_function
)(const struct MSVCRT___JUMP_BUFFER
*);
1026 /* define an entrypoint for setjmp/setjmp3 that stores the registers in the jmp buf */
1027 /* and then jumps to the C backend function */
1028 #define DEFINE_SETJMP_ENTRYPOINT(name) \
1029 __ASM_GLOBAL_FUNC( name, \
1030 "movl 4(%esp),%ecx\n\t" /* jmp_buf */ \
1031 "movl %ebp,0(%ecx)\n\t" /* jmp_buf.Ebp */ \
1032 "movl %ebx,4(%ecx)\n\t" /* jmp_buf.Ebx */ \
1033 "movl %edi,8(%ecx)\n\t" /* jmp_buf.Edi */ \
1034 "movl %esi,12(%ecx)\n\t" /* jmp_buf.Esi */ \
1035 "movl %esp,16(%ecx)\n\t" /* jmp_buf.Esp */ \
1036 "movl 0(%esp),%eax\n\t" \
1037 "movl %eax,20(%ecx)\n\t" /* jmp_buf.Eip */ \
1038 "jmp " __ASM_NAME("__regs_") # name )
1040 /*******************************************************************
1041 * _setjmp (MSVCRT.@)
1043 DEFINE_SETJMP_ENTRYPOINT(MSVCRT__setjmp
)
1044 int CDECL DECLSPEC_HIDDEN
__regs_MSVCRT__setjmp(struct MSVCRT___JUMP_BUFFER
*jmp
)
1046 jmp
->Registration
= (unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1047 if (jmp
->Registration
== ~0UL)
1048 jmp
->TryLevel
= TRYLEVEL_END
;
1050 jmp
->TryLevel
= ((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
)->trylevel
;
1052 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1053 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
);
1057 /*******************************************************************
1058 * _setjmp3 (MSVCRT.@)
1060 DEFINE_SETJMP_ENTRYPOINT( MSVCRT__setjmp3
)
1061 int WINAPIV DECLSPEC_HIDDEN
__regs_MSVCRT__setjmp3(struct MSVCRT___JUMP_BUFFER
*jmp
, int nb_args
, ...)
1063 jmp
->Cookie
= MSVCRT_JMP_MAGIC
;
1064 jmp
->UnwindFunc
= 0;
1065 jmp
->Registration
= (unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1066 if (jmp
->Registration
== ~0UL)
1068 jmp
->TryLevel
= TRYLEVEL_END
;
1075 va_start( args
, nb_args
);
1076 if (nb_args
> 0) jmp
->UnwindFunc
= va_arg( args
, unsigned long );
1077 if (nb_args
> 1) jmp
->TryLevel
= va_arg( args
, unsigned long );
1078 else jmp
->TryLevel
= ((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
)->trylevel
;
1079 for (i
= 0; i
< 6 && i
< nb_args
- 2; i
++)
1080 jmp
->UnwindData
[i
] = va_arg( args
, unsigned long );
1084 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx\n",
1085 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
);
1089 /*********************************************************************
1090 * longjmp (MSVCRT.@)
1092 void CDECL
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
1094 unsigned long cur_frame
= 0;
1096 TRACE("buf=%p ebx=%08lx esi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx frame=%08lx retval=%08x\n",
1097 jmp
, jmp
->Ebx
, jmp
->Esi
, jmp
->Edi
, jmp
->Ebp
, jmp
->Esp
, jmp
->Eip
, jmp
->Registration
, retval
);
1099 cur_frame
=(unsigned long)NtCurrentTeb()->Tib
.ExceptionList
;
1100 TRACE("cur_frame=%lx\n",cur_frame
);
1102 if (cur_frame
!= jmp
->Registration
)
1103 _global_unwind2((EXCEPTION_REGISTRATION_RECORD
*)jmp
->Registration
);
1105 if (jmp
->Registration
)
1107 if (IsBadReadPtr(&jmp
->Cookie
, sizeof(long)) || jmp
->Cookie
!= MSVCRT_JMP_MAGIC
)
1109 msvcrt_local_unwind2((MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
,
1110 jmp
->TryLevel
, (void *)jmp
->Ebp
);
1112 else if(jmp
->UnwindFunc
)
1114 MSVCRT_unwind_function unwind_func
;
1116 unwind_func
=(MSVCRT_unwind_function
)jmp
->UnwindFunc
;
1124 __wine_longjmp( (__wine_jmp_buf
*)jmp
, retval
);
1127 /*********************************************************************
1128 * _seh_longjmp_unwind (MSVCRT.@)
1130 void __stdcall
_seh_longjmp_unwind(struct MSVCRT___JUMP_BUFFER
*jmp
)
1132 msvcrt_local_unwind2( (MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
, jmp
->TryLevel
, (void *)jmp
->Ebp
);
1135 /*********************************************************************
1136 * _seh_longjmp_unwind4 (MSVCRT.@)
1138 void __stdcall
_seh_longjmp_unwind4(struct MSVCRT___JUMP_BUFFER
*jmp
)
1140 msvcrt_local_unwind4( (ULONG
*)&jmp
->Cookie
, (MSVCRT_EXCEPTION_FRAME
*)jmp
->Registration
,
1141 jmp
->TryLevel
, (void *)jmp
->Ebp
);
1144 /*********************************************************************
1145 * _fpieee_flt (MSVCRT.@)
1147 int __cdecl
_fpieee_flt(ULONG exception_code
, EXCEPTION_POINTERS
*ep
,
1148 int (__cdecl
*handler
)(_FPIEEE_RECORD
*))
1150 FLOATING_SAVE_AREA
*ctx
= &ep
->ContextRecord
->FloatSave
;
1154 TRACE("(%x %p %p)\n", exception_code
, ep
, handler
);
1156 switch(exception_code
) {
1157 case STATUS_FLOAT_DIVIDE_BY_ZERO
:
1158 case STATUS_FLOAT_INEXACT_RESULT
:
1159 case STATUS_FLOAT_INVALID_OPERATION
:
1160 case STATUS_FLOAT_OVERFLOW
:
1161 case STATUS_FLOAT_UNDERFLOW
:
1164 return EXCEPTION_CONTINUE_SEARCH
;
1167 memset(&rec
, 0, sizeof(rec
));
1168 rec
.RoundingMode
= ctx
->ControlWord
>> 10;
1169 switch((ctx
->ControlWord
>> 8) & 0x3) {
1170 case 0: rec
.Precision
= 2; break;
1171 case 1: rec
.Precision
= 3; break;
1172 case 2: rec
.Precision
= 1; break;
1173 case 3: rec
.Precision
= 0; break;
1175 rec
.Status
.InvalidOperation
= ctx
->StatusWord
& 0x1;
1176 rec
.Status
.ZeroDivide
= ((ctx
->StatusWord
& 0x4) != 0);
1177 rec
.Status
.Overflow
= ((ctx
->StatusWord
& 0x8) != 0);
1178 rec
.Status
.Underflow
= ((ctx
->StatusWord
& 0x10) != 0);
1179 rec
.Status
.Inexact
= ((ctx
->StatusWord
& 0x20) != 0);
1180 rec
.Enable
.InvalidOperation
= ((ctx
->ControlWord
& 0x1) == 0);
1181 rec
.Enable
.ZeroDivide
= ((ctx
->ControlWord
& 0x4) == 0);
1182 rec
.Enable
.Overflow
= ((ctx
->ControlWord
& 0x8) == 0);
1183 rec
.Enable
.Underflow
= ((ctx
->ControlWord
& 0x10) == 0);
1184 rec
.Enable
.Inexact
= ((ctx
->ControlWord
& 0x20) == 0);
1185 rec
.Cause
.InvalidOperation
= rec
.Enable
.InvalidOperation
& rec
.Status
.InvalidOperation
;
1186 rec
.Cause
.ZeroDivide
= rec
.Enable
.ZeroDivide
& rec
.Status
.ZeroDivide
;
1187 rec
.Cause
.Overflow
= rec
.Enable
.Overflow
& rec
.Status
.Overflow
;
1188 rec
.Cause
.Underflow
= rec
.Enable
.Underflow
& rec
.Status
.Underflow
;
1189 rec
.Cause
.Inexact
= rec
.Enable
.Inexact
& rec
.Status
.Inexact
;
1191 TRACE("opcode: %x\n", *(ULONG
*)ep
->ContextRecord
->FloatSave
.ErrorOffset
);
1193 if(*(WORD
*)ctx
->ErrorOffset
== 0x35dc) { /* fdiv m64fp */
1194 if(exception_code
==STATUS_FLOAT_DIVIDE_BY_ZERO
|| exception_code
==STATUS_FLOAT_INVALID_OPERATION
) {
1195 rec
.Operand1
.OperandValid
= 1;
1196 rec
.Result
.OperandValid
= 0;
1198 rec
.Operand1
.OperandValid
= 0;
1199 rec
.Result
.OperandValid
= 1;
1201 rec
.Operand2
.OperandValid
= 1;
1202 rec
.Operation
= _FpCodeDivide
;
1203 rec
.Operand1
.Format
= _FpFormatFp80
;
1204 memcpy(&rec
.Operand1
.Value
.Fp80Value
, ctx
->RegisterArea
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1205 rec
.Operand2
.Format
= _FpFormatFp64
;
1206 rec
.Operand2
.Value
.Fp64Value
= *(double*)ctx
->DataOffset
;
1207 rec
.Result
.Format
= _FpFormatFp80
;
1208 memcpy(&rec
.Result
.Value
.Fp80Value
, ctx
->RegisterArea
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1210 ret
= handler(&rec
);
1212 if(ret
== EXCEPTION_CONTINUE_EXECUTION
)
1213 memcpy(ctx
->RegisterArea
, &rec
.Result
.Value
.Fp80Value
, sizeof(rec
.Operand1
.Value
.Fp80Value
));
1217 FIXME("unsupported opcode: %x\n", *(ULONG
*)ep
->ContextRecord
->FloatSave
.ErrorOffset
);
1218 return EXCEPTION_CONTINUE_SEARCH
;
1221 #endif /* __i386__ */