xref: /reactos/sdk/lib/crt/wine/except_arm64.c (revision 9efafd64)
1*9efafd64STimo Kreuzer /*
2*9efafd64STimo Kreuzer  * msvcrt C++ exception handling
3*9efafd64STimo Kreuzer  *
4*9efafd64STimo Kreuzer  * Copyright 2011 Alexandre Julliard
5*9efafd64STimo Kreuzer  * Copyright 2013 André Hentschel
6*9efafd64STimo Kreuzer  * Copyright 2017 Martin Storsjo
7*9efafd64STimo Kreuzer  *
8*9efafd64STimo Kreuzer  * This library is free software; you can redistribute it and/or
9*9efafd64STimo Kreuzer  * modify it under the terms of the GNU Lesser General Public
10*9efafd64STimo Kreuzer  * License as published by the Free Software Foundation; either
11*9efafd64STimo Kreuzer  * version 2.1 of the License, or (at your option) any later version.
12*9efafd64STimo Kreuzer  *
13*9efafd64STimo Kreuzer  * This library is distributed in the hope that it will be useful,
14*9efafd64STimo Kreuzer  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*9efafd64STimo Kreuzer  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*9efafd64STimo Kreuzer  * Lesser General Public License for more details.
17*9efafd64STimo Kreuzer  *
18*9efafd64STimo Kreuzer  * You should have received a copy of the GNU Lesser General Public
19*9efafd64STimo Kreuzer  * License along with this library; if not, write to the Free Software
20*9efafd64STimo Kreuzer  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21*9efafd64STimo Kreuzer  */
22*9efafd64STimo Kreuzer 
23*9efafd64STimo Kreuzer #include "config.h"
24*9efafd64STimo Kreuzer #include "wine/port.h"
25*9efafd64STimo Kreuzer 
26*9efafd64STimo Kreuzer #ifdef __aarch64__
27*9efafd64STimo Kreuzer 
28*9efafd64STimo Kreuzer #include <stdarg.h>
29*9efafd64STimo Kreuzer 
30*9efafd64STimo Kreuzer #include "ntstatus.h"
31*9efafd64STimo Kreuzer #define WIN32_NO_STATUS
32*9efafd64STimo Kreuzer #include "windef.h"
33*9efafd64STimo Kreuzer #include "winbase.h"
34*9efafd64STimo Kreuzer #include "winternl.h"
35*9efafd64STimo Kreuzer #include "msvcrt.h"
36*9efafd64STimo Kreuzer #include "wine/exception.h"
37*9efafd64STimo Kreuzer #include "excpt.h"
38*9efafd64STimo Kreuzer #include "wine/debug.h"
39*9efafd64STimo Kreuzer 
40*9efafd64STimo Kreuzer #include "cppexcept.h"
41*9efafd64STimo Kreuzer 
42*9efafd64STimo Kreuzer WINE_DEFAULT_DEBUG_CHANNEL(seh);
43*9efafd64STimo Kreuzer 
44*9efafd64STimo Kreuzer 
45*9efafd64STimo Kreuzer /*********************************************************************
46*9efafd64STimo Kreuzer  *		__CxxExceptionFilter (MSVCRT.@)
47*9efafd64STimo Kreuzer  */
48*9efafd64STimo Kreuzer int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
49*9efafd64STimo Kreuzer                                 const type_info *ti, int flags, void **copy )
50*9efafd64STimo Kreuzer {
51*9efafd64STimo Kreuzer     FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy );
52*9efafd64STimo Kreuzer     return EXCEPTION_CONTINUE_SEARCH;
53*9efafd64STimo Kreuzer }
54*9efafd64STimo Kreuzer 
55*9efafd64STimo Kreuzer /*********************************************************************
56*9efafd64STimo Kreuzer  *		__CxxFrameHandler (MSVCRT.@)
57*9efafd64STimo Kreuzer  */
58*9efafd64STimo Kreuzer EXCEPTION_DISPOSITION CDECL __CxxFrameHandler(EXCEPTION_RECORD *rec, DWORD frame, CONTEXT *context,
59*9efafd64STimo Kreuzer                                               DISPATCHER_CONTEXT *dispatch)
60*9efafd64STimo Kreuzer {
61*9efafd64STimo Kreuzer     FIXME("%p %x %p %p: not implemented\n", rec, frame, context, dispatch);
62*9efafd64STimo Kreuzer     return ExceptionContinueSearch;
63*9efafd64STimo Kreuzer }
64*9efafd64STimo Kreuzer 
65*9efafd64STimo Kreuzer 
66*9efafd64STimo Kreuzer /*********************************************************************
67*9efafd64STimo Kreuzer  *		__CppXcptFilter (MSVCRT.@)
68*9efafd64STimo Kreuzer  */
69*9efafd64STimo Kreuzer int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
70*9efafd64STimo Kreuzer {
71*9efafd64STimo Kreuzer     /* only filter c++ exceptions */
72*9efafd64STimo Kreuzer     if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
73*9efafd64STimo Kreuzer     return _XcptFilter(ex, ptr);
74*9efafd64STimo Kreuzer }
75*9efafd64STimo Kreuzer 
76*9efafd64STimo Kreuzer 
77*9efafd64STimo Kreuzer /*********************************************************************
78*9efafd64STimo Kreuzer  *		__CxxDetectRethrow (MSVCRT.@)
79*9efafd64STimo Kreuzer  */
80*9efafd64STimo Kreuzer BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
81*9efafd64STimo Kreuzer {
82*9efafd64STimo Kreuzer     PEXCEPTION_RECORD rec;
83*9efafd64STimo Kreuzer 
84*9efafd64STimo Kreuzer     if (!ptrs)
85*9efafd64STimo Kreuzer         return FALSE;
86*9efafd64STimo Kreuzer 
87*9efafd64STimo Kreuzer     rec = ptrs->ExceptionRecord;
88*9efafd64STimo Kreuzer 
89*9efafd64STimo Kreuzer     if (rec->ExceptionCode == CXX_EXCEPTION &&
90*9efafd64STimo Kreuzer         rec->NumberParameters == 3 &&
91*9efafd64STimo Kreuzer         rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
92*9efafd64STimo Kreuzer         rec->ExceptionInformation[2])
93*9efafd64STimo Kreuzer     {
94*9efafd64STimo Kreuzer         ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
95*9efafd64STimo Kreuzer         return TRUE;
96*9efafd64STimo Kreuzer     }
97*9efafd64STimo Kreuzer     return (msvcrt_get_thread_data()->exc_record == rec);
98*9efafd64STimo Kreuzer }
99*9efafd64STimo Kreuzer 
100*9efafd64STimo Kreuzer 
101*9efafd64STimo Kreuzer /*********************************************************************
102*9efafd64STimo Kreuzer  *		__CxxQueryExceptionSize (MSVCRT.@)
103*9efafd64STimo Kreuzer  */
104*9efafd64STimo Kreuzer unsigned int CDECL __CxxQueryExceptionSize(void)
105*9efafd64STimo Kreuzer {
106*9efafd64STimo Kreuzer     return sizeof(cxx_exception_type);
107*9efafd64STimo Kreuzer }
108*9efafd64STimo Kreuzer 
109*9efafd64STimo Kreuzer 
110*9efafd64STimo Kreuzer /*******************************************************************
111*9efafd64STimo Kreuzer  *		_setjmp (MSVCRT.@)
112*9efafd64STimo Kreuzer  */
113*9efafd64STimo Kreuzer __ASM_GLOBAL_FUNC(MSVCRT__setjmp,
114*9efafd64STimo Kreuzer                   "mov x1, #0\n\t"  /* frame */
115*9efafd64STimo Kreuzer                   "b " __ASM_NAME("__wine_setjmpex"));
116*9efafd64STimo Kreuzer 
117*9efafd64STimo Kreuzer /*******************************************************************
118*9efafd64STimo Kreuzer  *		longjmp (MSVCRT.@)
119*9efafd64STimo Kreuzer  */
120*9efafd64STimo Kreuzer void __cdecl MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER *jmp, int retval)
121*9efafd64STimo Kreuzer {
122*9efafd64STimo Kreuzer     EXCEPTION_RECORD rec;
123*9efafd64STimo Kreuzer 
124*9efafd64STimo Kreuzer     if (!retval) retval = 1;
125*9efafd64STimo Kreuzer     if (jmp->Frame)
126*9efafd64STimo Kreuzer     {
127*9efafd64STimo Kreuzer         rec.ExceptionCode = STATUS_LONGJUMP;
128*9efafd64STimo Kreuzer         rec.ExceptionFlags = 0;
129*9efafd64STimo Kreuzer         rec.ExceptionRecord = NULL;
130*9efafd64STimo Kreuzer         rec.ExceptionAddress = NULL;
131*9efafd64STimo Kreuzer         rec.NumberParameters = 1;
132*9efafd64STimo Kreuzer         rec.ExceptionInformation[0] = (DWORD_PTR)jmp;
133*9efafd64STimo Kreuzer         RtlUnwind((void *)jmp->Frame, (void *)jmp->Lr, &rec, IntToPtr(retval));
134*9efafd64STimo Kreuzer     }
135*9efafd64STimo Kreuzer     __wine_longjmp( (__wine_jmp_buf *)jmp, retval );
136*9efafd64STimo Kreuzer }
137*9efafd64STimo Kreuzer 
138*9efafd64STimo Kreuzer /*********************************************************************
139*9efafd64STimo Kreuzer  *              _fpieee_flt (MSVCRT.@)
140*9efafd64STimo Kreuzer  */
141*9efafd64STimo Kreuzer int __cdecl _fpieee_flt(ULONG exception_code, EXCEPTION_POINTERS *ep,
142*9efafd64STimo Kreuzer         int (__cdecl *handler)(_FPIEEE_RECORD*))
143*9efafd64STimo Kreuzer {
144*9efafd64STimo Kreuzer     FIXME("(%x %p %p)\n", exception_code, ep, handler);
145*9efafd64STimo Kreuzer     return EXCEPTION_CONTINUE_SEARCH;
146*9efafd64STimo Kreuzer }
147*9efafd64STimo Kreuzer 
148*9efafd64STimo Kreuzer #endif  /* __aarch64__ */
149