wineconsole: Try harder to get a scalable font.
[wine.git] / dlls / msvcrt / except_arm64.c
blob25769289d2360688d8f160ecae818e5344288e7f
1 /*
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
23 #include "config.h"
24 #include "wine/port.h"
26 #ifdef __aarch64__
28 #include <stdarg.h>
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "winternl.h"
35 #include "msvcrt.h"
36 #include "wine/exception.h"
37 #include "excpt.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,
48 ULONG64 frame,
49 CONTEXT *context,
50 struct _DISPATCHER_CONTEXT *dispatch );
52 typedef struct _DISPATCHER_CONTEXT
54 DWORD64 ControlPc;
55 DWORD64 ImageBase;
56 PRUNTIME_FUNCTION FunctionEntry;
57 DWORD64 EstablisherFrame;
58 DWORD64 TargetPc;
59 PCONTEXT ContextRecord;
60 PEXCEPTION_ROUTINE LanguageHandler;
61 PVOID HandlerData;
62 PUNWIND_HISTORY_TABLE HistoryTable;
63 DWORD ScopeIndex;
64 BOOLEAN ControlPcIsUnwound;
65 PBYTE NonVolatileRegisters;
66 } DISPATCHER_CONTEXT;
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;
107 if (!ptrs)
108 return FALSE;
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;
118 return TRUE;
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 /*******************************************************************
134 * _setjmp (MSVCRT.@)
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 */
151 "mov x2, sp\n\t"
152 "str x2, [x0, #0x70]\n\t" /* jmp_buf->Sp */
153 "mrs x2, fpcr\n\t"
154 "str w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
155 "mrs x2, fpsr\n\t"
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] */
161 "mov x0, #0\n\t"
162 "ret");
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 */
174 "mov sp, x2\n\t"
175 "ldr w2, [x0, #0x78]\n\t" /* jmp_buf->Fpcr */
176 "msr fpcr, x2\n\t"
177 "ldr w2, [x0, #0x7c]\n\t" /* jmp_buf->Fpsr */
178 "msr fpsr, x2\n\t"
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 */
184 "ret");
186 /*******************************************************************
187 * longjmp (MSVCRT.@)
189 void __cdecl MSVCRT_longjmp(struct MSVCRT___JUMP_BUFFER *jmp, int retval)
191 EXCEPTION_RECORD rec;
193 if (!retval) retval = 1;
194 if (jmp->Frame)
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__ */