2 * msvcrt C++ exception handling
4 * Copyright 2011 Alexandre Julliard
5 * Copyright 2013 André Hentschel
6 * Copyright 2017 Martin Storsjo
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
24 #include "wine/port.h"
31 #define WIN32_NO_STATUS
36 #include "wine/exception.h"
38 #include "wine/debug.h"
40 #include "cppexcept.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(seh
);
44 struct _DISPATCHER_CONTEXT
;
46 typedef LONG (WINAPI
*PC_LANGUAGE_EXCEPTION_HANDLER
)( EXCEPTION_POINTERS
*ptrs
, ULONG64 frame
);
47 typedef EXCEPTION_DISPOSITION (WINAPI
*PEXCEPTION_ROUTINE
)( EXCEPTION_RECORD
*rec
,
50 struct _DISPATCHER_CONTEXT
*dispatch
);
52 typedef struct _DISPATCHER_CONTEXT
56 PRUNTIME_FUNCTION FunctionEntry
;
57 DWORD64 EstablisherFrame
;
59 PCONTEXT ContextRecord
;
60 PEXCEPTION_ROUTINE LanguageHandler
;
62 PUNWIND_HISTORY_TABLE HistoryTable
;
64 BOOLEAN ControlPcIsUnwound
;
65 PBYTE NonVolatileRegisters
;
68 /*********************************************************************
69 * __CxxExceptionFilter (MSVCRT.@)
71 int CDECL
__CxxExceptionFilter( PEXCEPTION_POINTERS ptrs
,
72 const type_info
*ti
, int flags
, void **copy
)
74 FIXME( "%p %p %x %p: not implemented\n", ptrs
, ti
, flags
, copy
);
75 return EXCEPTION_CONTINUE_SEARCH
;
78 /*********************************************************************
79 * __CxxFrameHandler (MSVCRT.@)
81 EXCEPTION_DISPOSITION CDECL
__CxxFrameHandler(EXCEPTION_RECORD
*rec
, DWORD frame
, CONTEXT
*context
,
82 DISPATCHER_CONTEXT
*dispatch
)
84 FIXME("%p %x %p %p: not implemented\n", rec
, frame
, context
, dispatch
);
85 return ExceptionContinueSearch
;
89 /*********************************************************************
90 * __CppXcptFilter (MSVCRT.@)
92 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
94 /* only filter c++ exceptions */
95 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
96 return _XcptFilter(ex
, ptr
);
100 /*********************************************************************
101 * __CxxDetectRethrow (MSVCRT.@)
103 BOOL CDECL
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs
)
105 PEXCEPTION_RECORD rec
;
110 rec
= ptrs
->ExceptionRecord
;
112 if (rec
->ExceptionCode
== CXX_EXCEPTION
&&
113 rec
->NumberParameters
== 3 &&
114 rec
->ExceptionInformation
[0] == CXX_FRAME_MAGIC_VC6
&&
115 rec
->ExceptionInformation
[2])
117 ptrs
->ExceptionRecord
= msvcrt_get_thread_data()->exc_record
;
120 return (msvcrt_get_thread_data()->exc_record
== rec
);
124 /*********************************************************************
125 * __CxxQueryExceptionSize (MSVCRT.@)
127 unsigned int CDECL
__CxxQueryExceptionSize(void)
129 return sizeof(cxx_exception_type
);
133 /*******************************************************************
136 __ASM_GLOBAL_FUNC(MSVCRT__setjmp
,
137 "mov x1, #0\n\t" /* frame */
138 "b " __ASM_NAME("MSVCRT__setjmpex"));
140 /*******************************************************************
141 * _setjmpex (MSVCRT.@)
143 __ASM_GLOBAL_FUNC(MSVCRT__setjmpex
,
144 "str x1, [x0]\n\t" /* jmp_buf->Frame */
145 "str x19, [x0, #0x10]\n\t" /* jmp_buf->X19 */
146 "str x20, [x0, #0x18]\n\t" /* jmp_buf->X20 */
147 "str x21, [x0, #0x20]\n\t" /* jmp_buf->X21 */
148 "str x22, [x0, #0x28]\n\t" /* jmp_buf->X22 */
149 "str x23, [x0, #0x30]\n\t" /* jmp_buf->X23 */
150 "str x24, [x0, #0x38]\n\t" /* jmp_buf->X24 */
151 "str x25, [x0, #0x40]\n\t" /* jmp_buf->X25 */
152 "str x26, [x0, #0x48]\n\t" /* jmp_buf->X26 */
153 "str x27, [x0, #0x50]\n\t" /* jmp_buf->X27 */
154 "str x28, [x0, #0x58]\n\t" /* jmp_buf->X28 */
155 "str x29, [x0, #0x60]\n\t" /* jmp_buf->Fp */
156 "str x30, [x0, #0x68]\n\t" /* jmp_buf->Lr */
158 "str x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
160 "str w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
162 "str w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
163 "str d8, [x0, #0x80]\n\t" /* jmp_buf->D[0] */
164 "str d9, [x0, #0x88]\n\t" /* jmp_buf->D[1] */
165 "str d10, [x0, #0x90]\n\t" /* jmp_buf->D[2] */
166 "str d11, [x0, #0x98]\n\t" /* jmp_buf->D[3] */
167 "str d12, [x0, #0xa0]\n\t" /* jmp_buf->D[4] */
168 "str d13, [x0, #0xa8]\n\t" /* jmp_buf->D[5] */
169 "str d14, [x0, #0xb0]\n\t" /* jmp_buf->D[6] */
170 "str d15, [x0, #0xb8]\n\t" /* jmp_buf->D[7] */
175 extern void DECLSPEC_NORETURN CDECL
longjmp_set_regs(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
);
176 __ASM_GLOBAL_FUNC(longjmp_set_regs
,
177 "ldr x19, [x0, #0x10]\n\t" /* jmp_buf->X19 */
178 "ldr x20, [x0, #0x18]\n\t" /* jmp_buf->X20 */
179 "ldr x21, [x0, #0x20]\n\t" /* jmp_buf->X21 */
180 "ldr x22, [x0, #0x28]\n\t" /* jmp_buf->X22 */
181 "ldr x23, [x0, #0x30]\n\t" /* jmp_buf->X23 */
182 "ldr x24, [x0, #0x38]\n\t" /* jmp_buf->X24 */
183 "ldr x25, [x0, #0x40]\n\t" /* jmp_buf->X25 */
184 "ldr x26, [x0, #0x48]\n\t" /* jmp_buf->X26 */
185 "ldr x27, [x0, #0x50]\n\t" /* jmp_buf->X27 */
186 "ldr x28, [x0, #0x58]\n\t" /* jmp_buf->X28 */
187 "ldr x29, [x0, #0x60]\n\t" /* jmp_buf->Fp */
188 "ldr x30, [x0, #0x68]\n\t" /* jmp_buf->Lr */
189 "ldr x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
191 "ldr w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
193 "ldr w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
195 "ldr d8, [x0, #0x80]\n\t" /* jmp_buf->D[0] */
196 "ldr d9, [x0, #0x88]\n\t" /* jmp_buf->D[1] */
197 "ldr d10, [x0, #0x90]\n\t" /* jmp_buf->D[2] */
198 "ldr d11, [x0, #0x98]\n\t" /* jmp_buf->D[3] */
199 "ldr d12, [x0, #0xa0]\n\t" /* jmp_buf->D[4] */
200 "ldr d13, [x0, #0xa8]\n\t" /* jmp_buf->D[5] */
201 "ldr d14, [x0, #0xb0]\n\t" /* jmp_buf->D[6] */
202 "ldr d15, [x0, #0xb8]\n\t" /* jmp_buf->D[7] */
203 "mov x0, x1\n\t" /* retval */
206 /*******************************************************************
209 void __cdecl
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
211 EXCEPTION_RECORD rec
;
213 if (!retval
) retval
= 1;
216 rec
.ExceptionCode
= STATUS_LONGJUMP
;
217 rec
.ExceptionFlags
= 0;
218 rec
.ExceptionRecord
= NULL
;
219 rec
.ExceptionAddress
= NULL
;
220 rec
.NumberParameters
= 1;
221 rec
.ExceptionInformation
[0] = (DWORD_PTR
)jmp
;
222 RtlUnwind((void *)jmp
->Frame
, (void *)jmp
->Lr
, &rec
, IntToPtr(retval
));
224 longjmp_set_regs(jmp
, retval
);
227 /*********************************************************************
228 * _fpieee_flt (MSVCRT.@)
230 int __cdecl
_fpieee_flt(ULONG exception_code
, EXCEPTION_POINTERS
*ep
,
231 int (__cdecl
*handler
)(_FPIEEE_RECORD
*))
233 FIXME("(%x %p %p)\n", exception_code
, ep
, handler
);
234 return EXCEPTION_CONTINUE_SEARCH
;
237 #endif /* __aarch64__ */