2 * msvcrt C++ exception handling
4 * Copyright 2011 Alexandre Julliard
5 * Copyright 2013 André Hentschel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
30 #define WIN32_NO_STATUS
35 #include "wine/exception.h"
37 #include "wine/debug.h"
39 #include "cppexcept.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(seh
);
43 struct _DISPATCHER_CONTEXT
;
45 typedef LONG (WINAPI
*PC_LANGUAGE_EXCEPTION_HANDLER
)(EXCEPTION_POINTERS
*ptrs
, DWORD frame
);
46 typedef EXCEPTION_DISPOSITION (WINAPI
*PEXCEPTION_ROUTINE
)(EXCEPTION_RECORD
*rec
, DWORD frame
,
48 struct _DISPATCHER_CONTEXT
*dispatch
);
50 typedef struct _DISPATCHER_CONTEXT
54 PRUNTIME_FUNCTION FunctionEntry
;
55 DWORD EstablisherFrame
;
57 PCONTEXT ContextRecord
;
58 PEXCEPTION_ROUTINE LanguageHandler
;
60 PUNWIND_HISTORY_TABLE HistoryTable
;
62 BOOLEAN ControlPcIsUnwound
;
63 PBYTE NonVolatileRegisters
;
67 /*********************************************************************
68 * __CxxExceptionFilter (MSVCRT.@)
70 int CDECL
__CxxExceptionFilter( PEXCEPTION_POINTERS ptrs
,
71 const type_info
*ti
, int flags
, void **copy
)
73 FIXME( "%p %p %x %p: not implemented\n", ptrs
, ti
, flags
, copy
);
74 return EXCEPTION_CONTINUE_SEARCH
;
77 /*********************************************************************
78 * __CxxFrameHandler (MSVCRT.@)
80 EXCEPTION_DISPOSITION CDECL
__CxxFrameHandler(EXCEPTION_RECORD
*rec
, DWORD frame
, CONTEXT
*context
,
81 DISPATCHER_CONTEXT
*dispatch
)
83 FIXME("%p %x %p %p: not implemented\n", rec
, frame
, context
, dispatch
);
84 return ExceptionContinueSearch
;
88 /*********************************************************************
89 * __CppXcptFilter (MSVCRT.@)
91 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
93 /* only filter c++ exceptions */
94 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
95 return _XcptFilter(ex
, ptr
);
99 /*********************************************************************
100 * __CxxDetectRethrow (MSVCRT.@)
102 BOOL CDECL
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs
)
104 PEXCEPTION_RECORD rec
;
109 rec
= ptrs
->ExceptionRecord
;
111 if (rec
->ExceptionCode
== CXX_EXCEPTION
&&
112 rec
->NumberParameters
== 3 &&
113 rec
->ExceptionInformation
[0] == CXX_FRAME_MAGIC_VC6
&&
114 rec
->ExceptionInformation
[2])
116 ptrs
->ExceptionRecord
= msvcrt_get_thread_data()->exc_record
;
119 return (msvcrt_get_thread_data()->exc_record
== rec
);
123 /*********************************************************************
124 * __CxxQueryExceptionSize (MSVCRT.@)
126 unsigned int CDECL
__CxxQueryExceptionSize(void)
128 return sizeof(cxx_exception_type
);
132 /*******************************************************************
135 __ASM_GLOBAL_FUNC(MSVCRT__setjmp
,
136 "mov r1, #0\n\t" /* frame */
137 "b " __ASM_NAME("MSVCRT__setjmpex"));
139 /*******************************************************************
140 * _setjmpex (MSVCRT.@)
142 __ASM_GLOBAL_FUNC(MSVCRT__setjmpex
,
143 "str r1, [r0]\n\t" /* jmp_buf->Frame */
144 "str r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
145 "str r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
146 "str r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
147 "str r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
148 "str r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
149 "str r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
150 "str r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
151 "str r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
152 "str sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
153 "str lr, [r0, #0x28]\n\t" /* jmp_buf->Pc */
156 "str r2, [r0, #0x2c]\n\t" /* jmp_buf->Fpscr */
157 "vstr d8, [r0, #0x30]\n\t" /* jmp_buf->D[0] */
158 "vstr d9, [r0, #0x38]\n\t" /* jmp_buf->D[1] */
159 "vstr d10, [r0, #0x40]\n\t" /* jmp_buf->D[2] */
160 "vstr d11, [r0, #0x48]\n\t" /* jmp_buf->D[3] */
161 "vstr d12, [r0, #0x50]\n\t" /* jmp_buf->D[4] */
162 "vstr d13, [r0, #0x58]\n\t" /* jmp_buf->D[5] */
163 "vstr d14, [r0, #0x60]\n\t" /* jmp_buf->D[6] */
164 "vstr d15, [r0, #0x68]\n\t" /* jmp_buf->D[7] */
170 extern void DECLSPEC_NORETURN CDECL
longjmp_set_regs(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
);
171 __ASM_GLOBAL_FUNC(longjmp_set_regs
,
172 "ldr r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
173 "ldr r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
174 "ldr r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
175 "ldr r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
176 "ldr r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
177 "ldr r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
178 "ldr r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
179 "ldr r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
180 "ldr sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
181 "ldr r2, [r0, #0x28]\n\t" /* jmp_buf->Pc */
183 "ldr r3, [r0, #0x2c]\n\t" /* jmp_buf->Fpscr */
185 "vldr d8, [r0, #0x30]\n\t" /* jmp_buf->D[0] */
186 "vldr d9, [r0, #0x38]\n\t" /* jmp_buf->D[1] */
187 "vldr d10, [r0, #0x40]\n\t" /* jmp_buf->D[2] */
188 "vldr d11, [r0, #0x48]\n\t" /* jmp_buf->D[3] */
189 "vldr d12, [r0, #0x50]\n\t" /* jmp_buf->D[4] */
190 "vldr d13, [r0, #0x58]\n\t" /* jmp_buf->D[5] */
191 "vldr d14, [r0, #0x60]\n\t" /* jmp_buf->D[6] */
192 "vldr d15, [r0, #0x68]\n\t" /* jmp_buf->D[7] */
194 "mov r0, r1\n\t" /* retval */
197 /*******************************************************************
200 void __cdecl
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
202 EXCEPTION_RECORD rec
;
204 if (!retval
) retval
= 1;
207 rec
.ExceptionCode
= STATUS_LONGJUMP
;
208 rec
.ExceptionFlags
= 0;
209 rec
.ExceptionRecord
= NULL
;
210 rec
.ExceptionAddress
= NULL
;
211 rec
.NumberParameters
= 1;
212 rec
.ExceptionInformation
[0] = (DWORD_PTR
)jmp
;
213 RtlUnwind((void *)jmp
->Frame
, (void *)jmp
->Pc
, &rec
, IntToPtr(retval
));
215 longjmp_set_regs(jmp
, retval
);
218 /*********************************************************************
219 * _fpieee_flt (MSVCRT.@)
221 int __cdecl
_fpieee_flt(ULONG exception_code
, EXCEPTION_POINTERS
*ep
,
222 int (__cdecl
*handler
)(_FPIEEE_RECORD
*))
224 FIXME("(%x %p %p)\n", exception_code
, ep
, handler
);
225 return EXCEPTION_CONTINUE_SEARCH
;