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
;
68 /*********************************************************************
69 * __CxxFrameHandler (MSVCRT.@)
71 EXCEPTION_DISPOSITION CDECL
__CxxFrameHandler(EXCEPTION_RECORD
*rec
, DWORD frame
, CONTEXT
*context
,
72 DISPATCHER_CONTEXT
*dispatch
)
74 FIXME("%p %x %p %p: not implemented\n", rec
, frame
, context
, dispatch
);
75 return ExceptionContinueSearch
;
79 /*********************************************************************
80 * __CppXcptFilter (MSVCRT.@)
82 int CDECL
__CppXcptFilter(NTSTATUS ex
, PEXCEPTION_POINTERS ptr
)
84 /* only filter c++ exceptions */
85 if (ex
!= CXX_EXCEPTION
) return EXCEPTION_CONTINUE_SEARCH
;
86 return _XcptFilter(ex
, ptr
);
90 /*********************************************************************
91 * __CxxDetectRethrow (MSVCRT.@)
93 BOOL CDECL
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs
)
95 PEXCEPTION_RECORD rec
;
100 rec
= ptrs
->ExceptionRecord
;
102 if (rec
->ExceptionCode
== CXX_EXCEPTION
&&
103 rec
->NumberParameters
== 3 &&
104 rec
->ExceptionInformation
[0] == CXX_FRAME_MAGIC_VC6
&&
105 rec
->ExceptionInformation
[2])
107 ptrs
->ExceptionRecord
= msvcrt_get_thread_data()->exc_record
;
110 return (msvcrt_get_thread_data()->exc_record
== rec
);
114 /*********************************************************************
115 * __CxxQueryExceptionSize (MSVCRT.@)
117 unsigned int CDECL
__CxxQueryExceptionSize(void)
119 return sizeof(cxx_exception_type
);
123 /*******************************************************************
126 __ASM_GLOBAL_FUNC(MSVCRT__setjmp
,
127 "mov r1, #0\n\t" /* frame */
128 "b " __ASM_NAME("MSVCRT__setjmpex"));
130 /*******************************************************************
131 * _setjmpex (MSVCRT.@)
133 __ASM_GLOBAL_FUNC(MSVCRT__setjmpex
,
134 "str r1, [r0]\n\t" /* jmp_buf->Frame */
135 "str r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
136 "str r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
137 "str r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
138 "str r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
139 "str r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
140 "str r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
141 "str r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
142 "str r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
143 "str sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
144 "str lr, [r0, #0x28]\n\t" /* jmp_buf->Pc */
145 /* FIXME: Save floating point data */
150 extern void DECLSPEC_NORETURN CDECL
longjmp_set_regs(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
);
151 __ASM_GLOBAL_FUNC(longjmp_set_regs
,
152 "ldr r4, [r0, #0x4]\n\t" /* jmp_buf->R4 */
153 "ldr r5, [r0, #0x8]\n\t" /* jmp_buf->R5 */
154 "ldr r6, [r0, #0xc]\n\t" /* jmp_buf->R6 */
155 "ldr r7, [r0, #0x10]\n\t" /* jmp_buf->R7 */
156 "ldr r8, [r0, #0x14]\n\t" /* jmp_buf->R8 */
157 "ldr r9, [r0, #0x18]\n\t" /* jmp_buf->R9 */
158 "ldr r10, [r0, #0x1c]\n\t" /* jmp_buf->R10 */
159 "ldr r11, [r0, #0x20]\n\t" /* jmp_buf->R11 */
160 "ldr sp, [r0, #0x24]\n\t" /* jmp_buf->Sp */
161 "ldr r2, [r0, #0x28]\n\t" /* jmp_buf->Pc */
162 /* FIXME: Restore floating point data */
163 "mov r0, r1\n\t" /* retval */
166 /*******************************************************************
169 void __cdecl
MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER
*jmp
, int retval
)
171 EXCEPTION_RECORD rec
;
173 if (!retval
) retval
= 1;
176 rec
.ExceptionCode
= STATUS_LONGJUMP
;
177 rec
.ExceptionFlags
= 0;
178 rec
.ExceptionRecord
= NULL
;
179 rec
.ExceptionAddress
= NULL
;
180 rec
.NumberParameters
= 1;
181 rec
.ExceptionInformation
[0] = (DWORD_PTR
)jmp
;
182 RtlUnwind((void *)jmp
->Frame
, (void *)jmp
->Pc
, &rec
, IntToPtr(retval
));
184 longjmp_set_regs(jmp
, retval
);