msvcrt: Add i386 __CxxExceptionFilter implementation.
[wine/multimedia.git] / dlls / msvcrt / except_x86_64.c
blob27d0a15d889a48494c980c4040c4266ebbf9458e
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 /*********************************************************************
65 * __CxxExceptionFilter (MSVCRT.@)
67 int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
68 const type_info *ti, int flags, void **copy )
70 FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy );
71 return EXCEPTION_CONTINUE_SEARCH;
74 /*********************************************************************
75 * __CxxFrameHandler (MSVCRT.@)
77 EXCEPTION_DISPOSITION CDECL __CxxFrameHandler( EXCEPTION_RECORD *rec, ULONG64 frame,
78 CONTEXT *context, DISPATCHER_CONTEXT *dispatch )
80 FIXME( "%p %lx %p %p: not implemented\n", rec, frame, context, dispatch );
81 return ExceptionContinueSearch;
85 /*********************************************************************
86 * __CppXcptFilter (MSVCRT.@)
88 int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
90 /* only filter c++ exceptions */
91 if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
92 return _XcptFilter( ex, ptr );
96 /*********************************************************************
97 * __CxxDetectRethrow (MSVCRT.@)
99 BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
101 PEXCEPTION_RECORD rec;
103 if (!ptrs)
104 return FALSE;
106 rec = ptrs->ExceptionRecord;
108 if (rec->ExceptionCode == CXX_EXCEPTION &&
109 rec->NumberParameters == 3 &&
110 rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
111 rec->ExceptionInformation[2])
113 ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
114 return TRUE;
116 return (msvcrt_get_thread_data()->exc_record == rec);
120 /*********************************************************************
121 * __CxxQueryExceptionSize (MSVCRT.@)
123 unsigned int CDECL __CxxQueryExceptionSize(void)
125 return sizeof(cxx_exception_type);
129 /*******************************************************************
130 * _setjmp (MSVCRT.@)
132 __ASM_GLOBAL_FUNC( MSVCRT__setjmp,
133 "xorq %rdx,%rdx\n\t" /* frame */
134 "jmp " __ASM_NAME("MSVCRT__setjmpex") );
136 /*******************************************************************
137 * _setjmpex (MSVCRT.@)
139 __ASM_GLOBAL_FUNC( MSVCRT__setjmpex,
140 "movq %rdx,(%rcx)\n\t" /* jmp_buf->Frame */
141 "movq %rbx,0x8(%rcx)\n\t" /* jmp_buf->Rbx */
142 "leaq 0x8(%rsp),%rax\n\t"
143 "movq %rax,0x10(%rcx)\n\t" /* jmp_buf->Rsp */
144 "movq %rbp,0x18(%rcx)\n\t" /* jmp_buf->Rbp */
145 "movq %rsi,0x20(%rcx)\n\t" /* jmp_buf->Rsi */
146 "movq %rdi,0x28(%rcx)\n\t" /* jmp_buf->Rdi */
147 "movq %r12,0x30(%rcx)\n\t" /* jmp_buf->R12 */
148 "movq %r13,0x38(%rcx)\n\t" /* jmp_buf->R13 */
149 "movq %r14,0x40(%rcx)\n\t" /* jmp_buf->R14 */
150 "movq %r15,0x48(%rcx)\n\t" /* jmp_buf->R15 */
151 "movq (%rsp),%rax\n\t"
152 "movq %rax,0x50(%rcx)\n\t" /* jmp_buf->Rip */
153 "movdqa %xmm6,0x60(%rcx)\n\t" /* jmp_buf->Xmm6 */
154 "movdqa %xmm7,0x70(%rcx)\n\t" /* jmp_buf->Xmm7 */
155 "movdqa %xmm8,0x80(%rcx)\n\t" /* jmp_buf->Xmm8 */
156 "movdqa %xmm9,0x90(%rcx)\n\t" /* jmp_buf->Xmm9 */
157 "movdqa %xmm10,0xa0(%rcx)\n\t" /* jmp_buf->Xmm10 */
158 "movdqa %xmm11,0xb0(%rcx)\n\t" /* jmp_buf->Xmm11 */
159 "movdqa %xmm12,0xc0(%rcx)\n\t" /* jmp_buf->Xmm12 */
160 "movdqa %xmm13,0xd0(%rcx)\n\t" /* jmp_buf->Xmm13 */
161 "movdqa %xmm14,0xe0(%rcx)\n\t" /* jmp_buf->Xmm14 */
162 "movdqa %xmm15,0xf0(%rcx)\n\t" /* jmp_buf->Xmm15 */
163 "xorq %rax,%rax\n\t"
164 "retq" );
167 extern void DECLSPEC_NORETURN CDECL longjmp_set_regs( struct MSVCRT___JUMP_BUFFER *jmp, int retval );
168 __ASM_GLOBAL_FUNC( longjmp_set_regs,
169 "movq %rdx,%rax\n\t" /* retval */
170 "movq 0x8(%rcx),%rbx\n\t" /* jmp_buf->Rbx */
171 "movq 0x18(%rcx),%rbp\n\t" /* jmp_buf->Rbp */
172 "movq 0x20(%rcx),%rsi\n\t" /* jmp_buf->Rsi */
173 "movq 0x28(%rcx),%rdi\n\t" /* jmp_buf->Rdi */
174 "movq 0x30(%rcx),%r12\n\t" /* jmp_buf->R12 */
175 "movq 0x38(%rcx),%r13\n\t" /* jmp_buf->R13 */
176 "movq 0x40(%rcx),%r14\n\t" /* jmp_buf->R14 */
177 "movq 0x48(%rcx),%r15\n\t" /* jmp_buf->R15 */
178 "movdqa 0x60(%rcx),%xmm6\n\t" /* jmp_buf->Xmm6 */
179 "movdqa 0x70(%rcx),%xmm7\n\t" /* jmp_buf->Xmm7 */
180 "movdqa 0x80(%rcx),%xmm8\n\t" /* jmp_buf->Xmm8 */
181 "movdqa 0x90(%rcx),%xmm9\n\t" /* jmp_buf->Xmm9 */
182 "movdqa 0xa0(%rcx),%xmm10\n\t" /* jmp_buf->Xmm10 */
183 "movdqa 0xb0(%rcx),%xmm11\n\t" /* jmp_buf->Xmm11 */
184 "movdqa 0xc0(%rcx),%xmm12\n\t" /* jmp_buf->Xmm12 */
185 "movdqa 0xd0(%rcx),%xmm13\n\t" /* jmp_buf->Xmm13 */
186 "movdqa 0xe0(%rcx),%xmm14\n\t" /* jmp_buf->Xmm14 */
187 "movdqa 0xf0(%rcx),%xmm15\n\t" /* jmp_buf->Xmm15 */
188 "movq 0x50(%rcx),%rdx\n\t" /* jmp_buf->Rip */
189 "movq 0x10(%rcx),%rsp\n\t" /* jmp_buf->Rsp */
190 "jmp *%rdx" );
192 /*******************************************************************
193 * longjmp (MSVCRT.@)
195 void __cdecl MSVCRT_longjmp( struct MSVCRT___JUMP_BUFFER *jmp, int retval )
197 EXCEPTION_RECORD rec;
199 if (!retval) retval = 1;
200 if (jmp->Frame)
202 rec.ExceptionCode = STATUS_LONGJUMP;
203 rec.ExceptionFlags = 0;
204 rec.ExceptionRecord = NULL;
205 rec.ExceptionAddress = NULL;
206 rec.NumberParameters = 1;
207 rec.ExceptionInformation[0] = (DWORD_PTR)jmp;
208 RtlUnwind( (void *)jmp->Frame, (void *)jmp->Rip, &rec, IntToPtr(retval) );
210 longjmp_set_regs( jmp, retval );
213 /*******************************************************************
214 * _local_unwind (MSVCRT.@)
216 void __cdecl _local_unwind( void *frame, void *target )
218 RtlUnwind( frame, target, NULL, 0 );
221 #endif /* __x86_64__ */