wined3d: Fix a trailing new-line in an ERR() message.
[wine.git] / dlls / msvcrt / except_x86_64.c
blob80780aee337824c98df14c93909cbf9fbc910f45
1 /*
2 * msvcrt C++ exception handling
4 * Copyright 2011 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #ifdef __x86_64__
26 #include <stdarg.h>
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winternl.h"
33 #include "msvcrt.h"
34 #include "wine/exception.h"
35 #include "excpt.h"
36 #include "wine/debug.h"
38 #include "cppexcept.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(seh);
42 struct _DISPATCHER_CONTEXT;
44 typedef LONG (WINAPI *PC_LANGUAGE_EXCEPTION_HANDLER)( EXCEPTION_POINTERS *ptrs, ULONG64 frame );
45 typedef EXCEPTION_DISPOSITION (WINAPI *PEXCEPTION_ROUTINE)( EXCEPTION_RECORD *rec,
46 ULONG64 frame,
47 CONTEXT *context,
48 struct _DISPATCHER_CONTEXT *dispatch );
50 typedef struct _DISPATCHER_CONTEXT
52 ULONG64 ControlPc;
53 ULONG64 ImageBase;
54 PRUNTIME_FUNCTION FunctionEntry;
55 ULONG64 EstablisherFrame;
56 ULONG64 TargetIp;
57 PCONTEXT ContextRecord;
58 PEXCEPTION_ROUTINE LanguageHandler;
59 PVOID HandlerData;
60 PUNWIND_HISTORY_TABLE HistoryTable;
61 ULONG ScopeIndex;
62 } DISPATCHER_CONTEXT;
64 typedef struct
66 int prev;
67 UINT handler;
68 } unwind_info;
70 typedef struct
72 UINT flags;
73 UINT type_info;
74 int offset;
75 UINT handler;
76 UINT frame;
77 } catchblock_info;
78 #define TYPE_FLAG_CONST 1
79 #define TYPE_FLAG_VOLATILE 2
80 #define TYPE_FLAG_REFERENCE 8
82 typedef struct
84 int start_level;
85 int end_level;
86 int catch_level;
87 int catchblock_count;
88 UINT catchblock;
89 } tryblock_info;
91 typedef struct
93 int ip;
94 int state;
95 } ipmap_info;
97 typedef struct __cxx_function_descr
99 UINT magic;
100 UINT unwind_count;
101 UINT unwind_table;
102 UINT tryblock_count;
103 UINT tryblock;
104 UINT ipmap_count;
105 UINT ipmap;
106 UINT unwind_help;
107 UINT expect_list;
108 UINT flags;
109 } cxx_function_descr;
111 static inline void* rva_to_ptr(UINT rva, ULONG64 base)
113 return rva ? (void*)(base+rva) : NULL;
116 static inline void dump_type(UINT type_rva, ULONG64 base)
118 const cxx_type_info *type = rva_to_ptr(type_rva, base);
120 TRACE("flags %x type %x %s offsets %d,%d,%d size %d copy ctor %x(%p)\n",
121 type->flags, type->type_info, dbgstr_type_info(rva_to_ptr(type->type_info, base)),
122 type->offsets.this_offset, type->offsets.vbase_descr, type->offsets.vbase_offset,
123 type->size, type->copy_ctor, rva_to_ptr(type->copy_ctor, base));
126 static void dump_exception_type(const cxx_exception_type *type, ULONG64 base)
128 const cxx_type_info_table *type_info_table = rva_to_ptr(type->type_info_table, base);
129 UINT i;
131 TRACE("flags %x destr %x(%p) handler %x(%p) type info %x(%p)\n",
132 type->flags, type->destructor, rva_to_ptr(type->destructor, base),
133 type->custom_handler, rva_to_ptr(type->custom_handler, base),
134 type->type_info_table, type_info_table);
135 for (i = 0; i < type_info_table->count; i++)
137 TRACE(" %d: ", i);
138 dump_type(type_info_table->info[i], base);
142 static void dump_function_descr(const cxx_function_descr *descr, ULONG64 image_base)
144 unwind_info *unwind_table = rva_to_ptr(descr->unwind_table, image_base);
145 tryblock_info *tryblock = rva_to_ptr(descr->tryblock, image_base);
146 ipmap_info *ipmap = rva_to_ptr(descr->ipmap, image_base);
147 UINT i, j;
149 TRACE("magic %x\n", descr->magic);
150 TRACE("unwind table: %x(%p) %d\n", descr->unwind_table, unwind_table, descr->unwind_count);
151 for (i=0; i<descr->unwind_count; i++)
153 TRACE(" %d: prev %d func %x(%p)\n", i, unwind_table[i].prev,
154 unwind_table[i].handler, rva_to_ptr(unwind_table[i].handler, image_base));
156 TRACE("try table: %x(%p) %d\n", descr->tryblock, tryblock, descr->tryblock_count);
157 for (i=0; i<descr->tryblock_count; i++)
159 catchblock_info *catchblock = rva_to_ptr(tryblock[i].catchblock, image_base);
161 TRACE(" %d: start %d end %d catchlevel %d catch %x(%p) %d\n", i,
162 tryblock[i].start_level, tryblock[i].end_level,
163 tryblock[i].catch_level, tryblock[i].catchblock,
164 catchblock, tryblock[i].catchblock_count);
165 for (j=0; j<tryblock[i].catchblock_count; j++)
167 TRACE(" %d: flags %x offset %d handler %x(%p) frame %x type %x %s\n",
168 j, catchblock[j].flags, catchblock[j].offset, catchblock[j].handler,
169 rva_to_ptr(catchblock[j].handler, image_base), catchblock[j].frame,
170 catchblock[j].type_info,
171 dbgstr_type_info(rva_to_ptr(catchblock[j].type_info, image_base)));
174 TRACE("ipmap: %x(%p) %d\n", descr->ipmap, ipmap, descr->ipmap_count);
175 for (i=0; i<descr->ipmap_count; i++)
177 TRACE(" %d: ip %x state %d\n", i, ipmap[i].ip, ipmap[i].state);
179 TRACE("unwind_help %d\n", descr->unwind_help);
180 if (descr->magic <= CXX_FRAME_MAGIC_VC6) return;
181 TRACE("expect list: %x\n", descr->expect_list);
182 if (descr->magic <= CXX_FRAME_MAGIC_VC7) return;
183 TRACE("flags: %08x\n", descr->flags);
186 static inline int ip_to_state(ipmap_info *ipmap, UINT count, int ip)
188 UINT low = 0, high = count-1, med;
190 while (low < high) {
191 med = low + (high-low)/2;
193 if (ipmap[med].ip <= ip && ipmap[med+1].ip > ip)
195 low = med;
196 break;
198 if (ipmap[med].ip < ip) low = med+1;
199 else high = med-1;
202 TRACE("%x -> %d\n", ip, ipmap[low].state);
203 return ipmap[low].state;
206 /* check if the exception type is caught by a given catch block, and return the type that matched */
207 static const cxx_type_info *find_caught_type(cxx_exception_type *exc_type, ULONG64 exc_base,
208 const type_info *catch_ti, UINT catch_flags)
210 const cxx_type_info_table *type_info_table = rva_to_ptr(exc_type->type_info_table, exc_base);
211 UINT i;
213 for (i = 0; i < type_info_table->count; i++)
215 const cxx_type_info *type = rva_to_ptr(type_info_table->info[i], exc_base);
216 const type_info *ti = rva_to_ptr(type->type_info, exc_base);
218 if (!catch_ti) return type; /* catch(...) matches any type */
219 if (catch_ti != ti)
221 if (strcmp( catch_ti->mangled, ti->mangled )) continue;
223 /* type is the same, now check the flags */
224 if ((exc_type->flags & TYPE_FLAG_CONST) &&
225 !(catch_flags & TYPE_FLAG_CONST)) continue;
226 if ((exc_type->flags & TYPE_FLAG_VOLATILE) &&
227 !(catch_flags & TYPE_FLAG_VOLATILE)) continue;
228 return type; /* it matched */
230 return NULL;
233 static inline void copy_exception(void *object, ULONG64 frame,
234 DISPATCHER_CONTEXT *dispatch,
235 const catchblock_info *catchblock,
236 const cxx_type_info *type)
238 const type_info *catch_ti = rva_to_ptr(catchblock->type_info, dispatch->ImageBase);
239 void **dest = rva_to_ptr(catchblock->offset, frame);
241 if (!catch_ti || !catch_ti->mangled[0]) return;
242 if (!catchblock->offset) return;
244 if (catchblock->flags & TYPE_FLAG_REFERENCE)
246 *dest = get_this_pointer(&type->offsets, object);
248 else if (type->flags & CLASS_IS_SIMPLE_TYPE)
250 memmove(dest, object, type->size);
251 /* if it is a pointer, adjust it */
252 if (type->size == sizeof(void*)) *dest = get_this_pointer(&type->offsets, *dest);
254 else /* copy the object */
256 if (type->copy_ctor)
258 if (type->flags & CLASS_HAS_VIRTUAL_BASE_CLASS)
260 void (__cdecl *copy_ctor)(void*, void*, int) =
261 rva_to_ptr(type->copy_ctor, dispatch->ImageBase);
262 copy_ctor(dest, get_this_pointer(&type->offsets, object), 1);
264 else
266 void (__cdecl *copy_ctor)(void*, void*) =
267 rva_to_ptr(type->copy_ctor, dispatch->ImageBase);
268 copy_ctor(dest, get_this_pointer(&type->offsets, object));
271 else
272 memmove(dest, get_this_pointer(&type->offsets,object), type->size);
276 static void cxx_local_unwind(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
277 const cxx_function_descr *descr, int last_level)
279 const unwind_info *unwind_table = rva_to_ptr(descr->unwind_table, dispatch->ImageBase);
280 void (__cdecl *handler)(ULONG64 unk, ULONG64 rbp);
281 int *unwind_help = rva_to_ptr(descr->unwind_help, frame);
282 int trylevel;
284 if (unwind_help[0] == -2)
286 trylevel = ip_to_state(rva_to_ptr(descr->ipmap, dispatch->ImageBase),
287 descr->ipmap_count, dispatch->ControlPc-dispatch->ImageBase);
289 else
291 trylevel = unwind_help[0];
294 TRACE("current level: %d, last level: %d\n", trylevel, last_level);
295 while (trylevel != last_level)
297 if (trylevel<0 || trylevel>=descr->unwind_count)
299 ERR("invalid trylevel %d\n", trylevel);
300 MSVCRT_terminate();
302 handler = rva_to_ptr(unwind_table[trylevel].handler, dispatch->ImageBase);
303 if (handler)
305 TRACE("handler: %p\n", handler);
306 handler(0, frame);
308 trylevel = unwind_table[trylevel].prev;
310 unwind_help[0] = last_level;
313 static inline void* WINAPI call_catch_block(EXCEPTION_RECORD *rec)
315 ULONG64 frame = rec->ExceptionInformation[1];
316 const cxx_function_descr *descr = (void*)rec->ExceptionInformation[2];
317 EXCEPTION_RECORD *prev_rec = (void*)rec->ExceptionInformation[4];
318 void* (__cdecl *handler)(ULONG64 unk, ULONG64 rbp) = (void*)rec->ExceptionInformation[5];
319 int *unwind_help = rva_to_ptr(descr->unwind_help, frame);
320 cxx_frame_info frame_info;
321 void *ret_addr;
323 TRACE("calling handler %p\n", handler);
325 /* FIXME: native does local_unwind here in case of exception rethrow */
326 __CxxRegisterExceptionObject(&prev_rec, &frame_info);
327 ret_addr = handler(0, frame);
328 __CxxUnregisterExceptionObject(&frame_info, FALSE);
329 unwind_help[0] = -2;
330 unwind_help[1] = -1;
331 return ret_addr;
334 static inline void find_catch_block(EXCEPTION_RECORD *rec, ULONG64 frame,
335 DISPATCHER_CONTEXT *dispatch,
336 const cxx_function_descr *descr,
337 cxx_exception_type *info)
339 ULONG64 exc_base = (rec->NumberParameters == 4 ? rec->ExceptionInformation[3] : 0);
340 int trylevel = ip_to_state(rva_to_ptr(descr->ipmap, dispatch->ImageBase),
341 descr->ipmap_count, dispatch->ControlPc-dispatch->ImageBase);
342 const tryblock_info *in_catch;
343 EXCEPTION_RECORD catch_record;
344 CONTEXT context;
345 UINT i, j;
346 ULONG64 orig_frame = frame, throw_base;
347 DWORD throw_func_off;
348 void *throw_func;
349 INT *unwind_help;
351 /* update orig_frame if it's a nested exception */
352 throw_func_off = RtlLookupFunctionEntry(dispatch->ControlPc, &throw_base, NULL)->BeginAddress;
353 throw_func = rva_to_ptr(throw_func_off, throw_base);
354 TRACE("reconstructed handler pointer: %p\n", throw_func);
355 for (i=descr->tryblock_count; i>0; i--)
357 const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
358 tryblock = &tryblock[i-1];
360 if (trylevel>tryblock->end_level && trylevel<=tryblock->catch_level)
362 for (j=0; j<tryblock->catchblock_count; j++)
364 /* TODO: is it possible to have the same handler for multiple catch blocks? */
365 const catchblock_info *catchblock = rva_to_ptr(tryblock->catchblock, dispatch->ImageBase);
366 catchblock = &catchblock[j];
368 if (rva_to_ptr(catchblock->handler, dispatch->ImageBase) == throw_func)
370 TRACE("nested exception detected\n");
371 orig_frame = *(ULONG64*)rva_to_ptr(catchblock->frame, frame);
372 TRACE("setting orig_frame to %lx\n", orig_frame);
378 for (i=descr->tryblock_count; i>0; i--)
380 in_catch = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
381 in_catch = &in_catch[i-1];
383 if (trylevel>in_catch->end_level && trylevel<=in_catch->catch_level)
384 break;
386 if (!i)
387 in_catch = NULL;
389 unwind_help = rva_to_ptr(descr->unwind_help, orig_frame);
390 if (trylevel > unwind_help[1])
391 unwind_help[0] = unwind_help[1] = trylevel;
392 else
393 trylevel = unwind_help[1];
394 TRACE("current trylevel: %d\n", trylevel);
396 for (i=0; i<descr->tryblock_count; i++)
398 const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
399 tryblock = &tryblock[i];
401 if (trylevel < tryblock->start_level) continue;
402 if (trylevel > tryblock->end_level) continue;
404 if (in_catch)
406 if(tryblock->start_level <= in_catch->end_level) continue;
407 if(tryblock->end_level > in_catch->catch_level) continue;
410 /* got a try block */
411 for (j=0; j<tryblock->catchblock_count; j++)
413 const catchblock_info *catchblock = rva_to_ptr(tryblock->catchblock, dispatch->ImageBase);
414 catchblock = &catchblock[j];
416 if (info)
418 const cxx_type_info *type = find_caught_type(info, exc_base,
419 rva_to_ptr(catchblock->type_info, dispatch->ImageBase),
420 catchblock->flags);
421 if (!type) continue;
423 TRACE("matched type %p in tryblock %d catchblock %d\n", type, i, j);
425 /* copy the exception to its destination on the stack */
426 copy_exception((void*)rec->ExceptionInformation[1],
427 orig_frame, dispatch, 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 /* unwind stack and call catch */
438 memset(&catch_record, 0, sizeof(catch_record));
439 catch_record.ExceptionCode = STATUS_UNWIND_CONSOLIDATE;
440 catch_record.ExceptionFlags = EXCEPTION_NONCONTINUABLE;
441 catch_record.NumberParameters = 6;
442 catch_record.ExceptionInformation[0] = (ULONG_PTR)call_catch_block;
443 catch_record.ExceptionInformation[1] = orig_frame;
444 catch_record.ExceptionInformation[2] = (ULONG_PTR)descr;
445 catch_record.ExceptionInformation[3] = tryblock->start_level;
446 catch_record.ExceptionInformation[4] = (ULONG_PTR)rec;
447 catch_record.ExceptionInformation[5] =
448 (ULONG_PTR)rva_to_ptr(catchblock->handler, dispatch->ImageBase);
449 RtlUnwindEx((void*)frame, (void*)dispatch->ControlPc, &catch_record, NULL, &context, NULL);
453 TRACE("no matching catch block found\n");
456 static DWORD cxx_frame_handler(EXCEPTION_RECORD *rec, ULONG64 frame,
457 CONTEXT *context, DISPATCHER_CONTEXT *dispatch,
458 const cxx_function_descr *descr)
460 cxx_exception_type *exc_type;
462 if (descr->magic<CXX_FRAME_MAGIC_VC6 || descr->magic>CXX_FRAME_MAGIC_VC8)
464 FIXME("unhandled frame magic %x\n", descr->magic);
465 return ExceptionContinueSearch;
468 if (rec->ExceptionFlags & (EH_UNWINDING|EH_EXIT_UNWIND))
470 if (rec->ExceptionCode==STATUS_UNWIND_CONSOLIDATE && rec->NumberParameters==6 &&
471 rec->ExceptionInformation[0]==(ULONG_PTR)call_catch_block)
473 EXCEPTION_RECORD *new_rec = (void*)rec->ExceptionInformation[4];
474 thread_data_t *data = msvcrt_get_thread_data();
475 frame_info *cur;
477 if (rec->ExceptionFlags & EH_TARGET_UNWIND)
479 ULONG64 orig_frame = rec->ExceptionInformation[1];
480 const cxx_function_descr *orig_descr = (void*)rec->ExceptionInformation[2];
481 int end_level = rec->ExceptionInformation[3];
483 cxx_local_unwind(orig_frame, dispatch, orig_descr, end_level);
485 else
486 cxx_local_unwind(frame, dispatch, descr, -1);
488 /* FIXME: we should only unregister frames registered by call_catch_block here */
489 for (cur = data->frame_info_head; cur; cur = cur->next)
491 if ((ULONG64)cur <= frame)
493 __CxxUnregisterExceptionObject((cxx_frame_info*)cur,
494 new_rec->ExceptionCode == CXX_EXCEPTION &&
495 data->exc_record->ExceptionCode == CXX_EXCEPTION &&
496 new_rec->ExceptionInformation[1] == data->exc_record->ExceptionInformation[1]);
499 return ExceptionContinueSearch;
502 cxx_local_unwind(frame, dispatch, descr, -1);
503 return ExceptionContinueSearch;
505 if (!descr->tryblock_count) return ExceptionContinueSearch;
507 if (rec->ExceptionCode == CXX_EXCEPTION &&
508 rec->ExceptionInformation[1] == 0 && rec->ExceptionInformation[2] == 0)
510 *rec = *msvcrt_get_thread_data()->exc_record;
511 rec->ExceptionFlags &= ~EH_UNWINDING;
512 if (TRACE_ON(seh)) {
513 TRACE("detect rethrow: exception code: %x\n", rec->ExceptionCode);
514 if (rec->ExceptionCode == CXX_EXCEPTION)
515 TRACE("re-propage: obj: %lx, type: %lx\n",
516 rec->ExceptionInformation[1], rec->ExceptionInformation[2]);
520 if (rec->ExceptionCode == CXX_EXCEPTION)
522 exc_type = (cxx_exception_type *)rec->ExceptionInformation[2];
524 if (TRACE_ON(seh))
526 TRACE("handling C++ exception rec %p frame %lx descr %p\n", rec, frame, descr);
527 dump_exception_type(exc_type, rec->ExceptionInformation[3]);
528 dump_function_descr(descr, dispatch->ImageBase);
531 else
533 thread_data_t *data = msvcrt_get_thread_data();
535 exc_type = NULL;
536 TRACE("handling C exception code %x rec %p frame %lx descr %p\n",
537 rec->ExceptionCode, rec, frame, descr);
539 if (data->se_translator) {
540 EXCEPTION_POINTERS except_ptrs;
542 except_ptrs.ExceptionRecord = rec;
543 except_ptrs.ContextRecord = context;
544 data->se_translator(rec->ExceptionCode, &except_ptrs);
548 find_catch_block(rec, frame, dispatch, descr, exc_type);
549 return ExceptionContinueSearch;
552 /*********************************************************************
553 * __CxxExceptionFilter (MSVCRT.@)
555 int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
556 const type_info *ti, int flags, void **copy )
558 FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy );
559 return EXCEPTION_CONTINUE_SEARCH;
562 /*********************************************************************
563 * __CxxFrameHandler (MSVCRT.@)
565 EXCEPTION_DISPOSITION CDECL __CxxFrameHandler( EXCEPTION_RECORD *rec, ULONG64 frame,
566 CONTEXT *context, DISPATCHER_CONTEXT *dispatch )
568 TRACE( "%p %lx %p %p\n", rec, frame, context, dispatch );
569 return cxx_frame_handler( rec, frame, context, dispatch,
570 rva_to_ptr(*(UINT*)dispatch->HandlerData, dispatch->ImageBase) );
574 /*********************************************************************
575 * __CppXcptFilter (MSVCRT.@)
577 int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
579 /* only filter c++ exceptions */
580 if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
581 return _XcptFilter( ex, ptr );
585 /*********************************************************************
586 * __CxxDetectRethrow (MSVCRT.@)
588 BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
590 PEXCEPTION_RECORD rec;
592 if (!ptrs)
593 return FALSE;
595 rec = ptrs->ExceptionRecord;
597 if (rec->ExceptionCode == CXX_EXCEPTION &&
598 rec->NumberParameters == 4 &&
599 rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
600 rec->ExceptionInformation[2])
602 ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
603 return TRUE;
605 return (msvcrt_get_thread_data()->exc_record == rec);
609 /*********************************************************************
610 * __CxxQueryExceptionSize (MSVCRT.@)
612 unsigned int CDECL __CxxQueryExceptionSize(void)
614 return sizeof(cxx_exception_type);
618 /*******************************************************************
619 * _setjmp (MSVCRT.@)
621 __ASM_GLOBAL_FUNC( MSVCRT__setjmp,
622 "jmp " __ASM_NAME("MSVCRT__setjmpex") );
624 /*******************************************************************
625 * _setjmpex (MSVCRT.@)
627 __ASM_GLOBAL_FUNC( MSVCRT__setjmpex,
628 "movq %rdx,(%rcx)\n\t" /* jmp_buf->Frame */
629 "movq %rbx,0x8(%rcx)\n\t" /* jmp_buf->Rbx */
630 "leaq 0x8(%rsp),%rax\n\t"
631 "movq %rax,0x10(%rcx)\n\t" /* jmp_buf->Rsp */
632 "movq %rbp,0x18(%rcx)\n\t" /* jmp_buf->Rbp */
633 "movq %rsi,0x20(%rcx)\n\t" /* jmp_buf->Rsi */
634 "movq %rdi,0x28(%rcx)\n\t" /* jmp_buf->Rdi */
635 "movq %r12,0x30(%rcx)\n\t" /* jmp_buf->R12 */
636 "movq %r13,0x38(%rcx)\n\t" /* jmp_buf->R13 */
637 "movq %r14,0x40(%rcx)\n\t" /* jmp_buf->R14 */
638 "movq %r15,0x48(%rcx)\n\t" /* jmp_buf->R15 */
639 "movq (%rsp),%rax\n\t"
640 "movq %rax,0x50(%rcx)\n\t" /* jmp_buf->Rip */
641 "movdqa %xmm6,0x60(%rcx)\n\t" /* jmp_buf->Xmm6 */
642 "movdqa %xmm7,0x70(%rcx)\n\t" /* jmp_buf->Xmm7 */
643 "movdqa %xmm8,0x80(%rcx)\n\t" /* jmp_buf->Xmm8 */
644 "movdqa %xmm9,0x90(%rcx)\n\t" /* jmp_buf->Xmm9 */
645 "movdqa %xmm10,0xa0(%rcx)\n\t" /* jmp_buf->Xmm10 */
646 "movdqa %xmm11,0xb0(%rcx)\n\t" /* jmp_buf->Xmm11 */
647 "movdqa %xmm12,0xc0(%rcx)\n\t" /* jmp_buf->Xmm12 */
648 "movdqa %xmm13,0xd0(%rcx)\n\t" /* jmp_buf->Xmm13 */
649 "movdqa %xmm14,0xe0(%rcx)\n\t" /* jmp_buf->Xmm14 */
650 "movdqa %xmm15,0xf0(%rcx)\n\t" /* jmp_buf->Xmm15 */
651 "xorq %rax,%rax\n\t"
652 "retq" );
655 extern void DECLSPEC_NORETURN CDECL longjmp_set_regs( struct MSVCRT___JUMP_BUFFER *jmp, int retval );
656 __ASM_GLOBAL_FUNC( longjmp_set_regs,
657 "movq %rdx,%rax\n\t" /* retval */
658 "movq 0x8(%rcx),%rbx\n\t" /* jmp_buf->Rbx */
659 "movq 0x18(%rcx),%rbp\n\t" /* jmp_buf->Rbp */
660 "movq 0x20(%rcx),%rsi\n\t" /* jmp_buf->Rsi */
661 "movq 0x28(%rcx),%rdi\n\t" /* jmp_buf->Rdi */
662 "movq 0x30(%rcx),%r12\n\t" /* jmp_buf->R12 */
663 "movq 0x38(%rcx),%r13\n\t" /* jmp_buf->R13 */
664 "movq 0x40(%rcx),%r14\n\t" /* jmp_buf->R14 */
665 "movq 0x48(%rcx),%r15\n\t" /* jmp_buf->R15 */
666 "movdqa 0x60(%rcx),%xmm6\n\t" /* jmp_buf->Xmm6 */
667 "movdqa 0x70(%rcx),%xmm7\n\t" /* jmp_buf->Xmm7 */
668 "movdqa 0x80(%rcx),%xmm8\n\t" /* jmp_buf->Xmm8 */
669 "movdqa 0x90(%rcx),%xmm9\n\t" /* jmp_buf->Xmm9 */
670 "movdqa 0xa0(%rcx),%xmm10\n\t" /* jmp_buf->Xmm10 */
671 "movdqa 0xb0(%rcx),%xmm11\n\t" /* jmp_buf->Xmm11 */
672 "movdqa 0xc0(%rcx),%xmm12\n\t" /* jmp_buf->Xmm12 */
673 "movdqa 0xd0(%rcx),%xmm13\n\t" /* jmp_buf->Xmm13 */
674 "movdqa 0xe0(%rcx),%xmm14\n\t" /* jmp_buf->Xmm14 */
675 "movdqa 0xf0(%rcx),%xmm15\n\t" /* jmp_buf->Xmm15 */
676 "movq 0x50(%rcx),%rdx\n\t" /* jmp_buf->Rip */
677 "movq 0x10(%rcx),%rsp\n\t" /* jmp_buf->Rsp */
678 "jmp *%rdx" );
680 /*******************************************************************
681 * longjmp (MSVCRT.@)
683 void __cdecl MSVCRT_longjmp( struct MSVCRT___JUMP_BUFFER *jmp, int retval )
685 EXCEPTION_RECORD rec;
687 if (!retval) retval = 1;
688 if (jmp->Frame)
690 rec.ExceptionCode = STATUS_LONGJUMP;
691 rec.ExceptionFlags = 0;
692 rec.ExceptionRecord = NULL;
693 rec.ExceptionAddress = NULL;
694 rec.NumberParameters = 1;
695 rec.ExceptionInformation[0] = (DWORD_PTR)jmp;
696 RtlUnwind( (void *)jmp->Frame, (void *)jmp->Rip, &rec, IntToPtr(retval) );
698 longjmp_set_regs( jmp, retval );
701 /*******************************************************************
702 * _local_unwind (MSVCRT.@)
704 void __cdecl _local_unwind( void *frame, void *target )
706 RtlUnwind( frame, target, NULL, 0 );
709 /*********************************************************************
710 * _fpieee_flt (MSVCRT.@)
712 int __cdecl _fpieee_flt(ULONG exception_code, EXCEPTION_POINTERS *ep,
713 int (__cdecl *handler)(_FPIEEE_RECORD*))
715 FIXME("(%x %p %p) opcode: %s\n", exception_code, ep, handler,
716 wine_dbgstr_longlong(*(ULONG64*)ep->ContextRecord->Rip));
717 return EXCEPTION_CONTINUE_SEARCH;
720 #endif /* __x86_64__ */