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 "stp x19, x20, [x0, #0x10]\n\t" /* jmp_buf->X19, X20 */
146 "stp x21, x22, [x0, #0x20]\n\t" /* jmp_buf->X21, X22 */
147 "stp x23, x24, [x0, #0x30]\n\t" /* jmp_buf->X23, X24 */
148 "stp x25, x26, [x0, #0x40]\n\t" /* jmp_buf->X25, X26 */
149 "stp x27, x28, [x0, #0x50]\n\t" /* jmp_buf->X27, X28 */
150 "stp x29, x30, [x0, #0x60]\n\t" /* jmp_buf->Fp, Lr */
152 "str x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
154 "str w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
156 "str w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
157 "stp d8, d9, [x0, #0x80]\n\t" /* jmp_buf->D[0-1] */
158 "stp d10, d11, [x0, #0x90]\n\t" /* jmp_buf->D[2-3] */
159 "stp d12, d13, [x0, #0xa0]\n\t" /* jmp_buf->D[4-5] */
160 "stp d14, d15, [x0, #0xb0]\n\t" /* jmp_buf->D[6-7] */
165 extern void DECLSPEC_NORETURN CDECL
longjmp_set_regs(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
);
166 __ASM_GLOBAL_FUNC(longjmp_set_regs
,
167 "ldp x19, x20, [x0, #0x10]\n\t" /* jmp_buf->X19, X20 */
168 "ldp x21, x22, [x0, #0x20]\n\t" /* jmp_buf->X21, X22 */
169 "ldp x23, x24, [x0, #0x30]\n\t" /* jmp_buf->X23, X24 */
170 "ldp x25, x26, [x0, #0x40]\n\t" /* jmp_buf->X25, X26 */
171 "ldp x27, x28, [x0, #0x50]\n\t" /* jmp_buf->X27, X28 */
172 "ldp x29, x30, [x0, #0x60]\n\t" /* jmp_buf->Fp, Lr */
173 "ldr x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
175 "ldr w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
177 "ldr w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
179 "ldp d8, d9, [x0, #0x80]\n\t" /* jmp_buf->D[0-1] */
180 "ldp d10, d11, [x0, #0x90]\n\t" /* jmp_buf->D[2-3] */
181 "ldp d12, d13, [x0, #0xa0]\n\t" /* jmp_buf->D[4-5] */
182 "ldp d14, d15, [x0, #0xb0]\n\t" /* jmp_buf->D[6-7] */
183 "mov x0, x1\n\t" /* retval */
186 /*******************************************************************
189 void __cdecl
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
191 EXCEPTION_RECORD rec
;
193 if (!retval
) retval
= 1;
196 rec
.ExceptionCode
= STATUS_LONGJUMP
;
197 rec
.ExceptionFlags
= 0;
198 rec
.ExceptionRecord
= NULL
;
199 rec
.ExceptionAddress
= NULL
;
200 rec
.NumberParameters
= 1;
201 rec
.ExceptionInformation
[0] = (DWORD_PTR
)jmp
;
202 RtlUnwind((void *)jmp
->Frame
, (void *)jmp
->Lr
, &rec
, IntToPtr(retval
));
204 longjmp_set_regs(jmp
, retval
);
207 /*********************************************************************
208 * _fpieee_flt (MSVCRT.@)
210 int __cdecl
_fpieee_flt(ULONG exception_code
, EXCEPTION_POINTERS
*ep
,
211 int (__cdecl
*handler
)(_FPIEEE_RECORD
*))
213 FIXME("(%x %p %p)\n", exception_code
, ep
, handler
);
214 return EXCEPTION_CONTINUE_SEARCH
;
217 #endif /* __aarch64__ */