19efafd64STimo Kreuzer /*
29efafd64STimo Kreuzer * msvcrt C++ exception handling
39efafd64STimo Kreuzer *
49efafd64STimo Kreuzer * Copyright 2011 Alexandre Julliard
59efafd64STimo Kreuzer * Copyright 2013 André Hentschel
69efafd64STimo Kreuzer * Copyright 2017 Martin Storsjo
79efafd64STimo Kreuzer *
89efafd64STimo Kreuzer * This library is free software; you can redistribute it and/or
99efafd64STimo Kreuzer * modify it under the terms of the GNU Lesser General Public
109efafd64STimo Kreuzer * License as published by the Free Software Foundation; either
119efafd64STimo Kreuzer * version 2.1 of the License, or (at your option) any later version.
129efafd64STimo Kreuzer *
139efafd64STimo Kreuzer * This library is distributed in the hope that it will be useful,
149efafd64STimo Kreuzer * but WITHOUT ANY WARRANTY; without even the implied warranty of
159efafd64STimo Kreuzer * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
169efafd64STimo Kreuzer * Lesser General Public License for more details.
179efafd64STimo Kreuzer *
189efafd64STimo Kreuzer * You should have received a copy of the GNU Lesser General Public
199efafd64STimo Kreuzer * License along with this library; if not, write to the Free Software
209efafd64STimo Kreuzer * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
219efafd64STimo Kreuzer */
229efafd64STimo Kreuzer
239efafd64STimo Kreuzer #ifdef __aarch64__
249efafd64STimo Kreuzer
25*3a61dd7fSTimo Kreuzer #include <setjmp.h>
269efafd64STimo Kreuzer #include <stdarg.h>
27*3a61dd7fSTimo Kreuzer #include <fpieee.h>
289efafd64STimo Kreuzer
299efafd64STimo Kreuzer #include "ntstatus.h"
309efafd64STimo Kreuzer #define WIN32_NO_STATUS
319efafd64STimo Kreuzer #include "windef.h"
329efafd64STimo Kreuzer #include "winbase.h"
339efafd64STimo Kreuzer #include "winternl.h"
349efafd64STimo Kreuzer #include "msvcrt.h"
359efafd64STimo Kreuzer #include "wine/exception.h"
369efafd64STimo Kreuzer #include "excpt.h"
379efafd64STimo Kreuzer #include "wine/debug.h"
389efafd64STimo Kreuzer
399efafd64STimo Kreuzer #include "cppexcept.h"
409efafd64STimo Kreuzer
419efafd64STimo Kreuzer WINE_DEFAULT_DEBUG_CHANNEL(seh);
429efafd64STimo Kreuzer
439efafd64STimo Kreuzer
449efafd64STimo Kreuzer /*********************************************************************
459efafd64STimo Kreuzer * __CxxExceptionFilter (MSVCRT.@)
469efafd64STimo Kreuzer */
__CxxExceptionFilter(PEXCEPTION_POINTERS ptrs,const type_info * ti,int flags,void ** copy)479efafd64STimo Kreuzer int CDECL __CxxExceptionFilter( PEXCEPTION_POINTERS ptrs,
489efafd64STimo Kreuzer const type_info *ti, int flags, void **copy )
499efafd64STimo Kreuzer {
509efafd64STimo Kreuzer FIXME( "%p %p %x %p: not implemented\n", ptrs, ti, flags, copy );
519efafd64STimo Kreuzer return EXCEPTION_CONTINUE_SEARCH;
529efafd64STimo Kreuzer }
539efafd64STimo Kreuzer
549efafd64STimo Kreuzer /*********************************************************************
559efafd64STimo Kreuzer * __CxxFrameHandler (MSVCRT.@)
569efafd64STimo Kreuzer */
__CxxFrameHandler(EXCEPTION_RECORD * rec,DWORD frame,CONTEXT * context,DISPATCHER_CONTEXT * dispatch)579efafd64STimo Kreuzer EXCEPTION_DISPOSITION CDECL __CxxFrameHandler(EXCEPTION_RECORD *rec, DWORD frame, CONTEXT *context,
589efafd64STimo Kreuzer DISPATCHER_CONTEXT *dispatch)
599efafd64STimo Kreuzer {
609efafd64STimo Kreuzer FIXME("%p %x %p %p: not implemented\n", rec, frame, context, dispatch);
619efafd64STimo Kreuzer return ExceptionContinueSearch;
629efafd64STimo Kreuzer }
639efafd64STimo Kreuzer
649efafd64STimo Kreuzer
659efafd64STimo Kreuzer /*********************************************************************
669efafd64STimo Kreuzer * __CppXcptFilter (MSVCRT.@)
679efafd64STimo Kreuzer */
__CppXcptFilter(NTSTATUS ex,PEXCEPTION_POINTERS ptr)689efafd64STimo Kreuzer int CDECL __CppXcptFilter(NTSTATUS ex, PEXCEPTION_POINTERS ptr)
699efafd64STimo Kreuzer {
709efafd64STimo Kreuzer /* only filter c++ exceptions */
719efafd64STimo Kreuzer if (ex != CXX_EXCEPTION) return EXCEPTION_CONTINUE_SEARCH;
729efafd64STimo Kreuzer return _XcptFilter(ex, ptr);
739efafd64STimo Kreuzer }
749efafd64STimo Kreuzer
759efafd64STimo Kreuzer
769efafd64STimo Kreuzer /*********************************************************************
779efafd64STimo Kreuzer * __CxxDetectRethrow (MSVCRT.@)
789efafd64STimo Kreuzer */
__CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)799efafd64STimo Kreuzer BOOL CDECL __CxxDetectRethrow(PEXCEPTION_POINTERS ptrs)
809efafd64STimo Kreuzer {
819efafd64STimo Kreuzer PEXCEPTION_RECORD rec;
829efafd64STimo Kreuzer
839efafd64STimo Kreuzer if (!ptrs)
849efafd64STimo Kreuzer return FALSE;
859efafd64STimo Kreuzer
869efafd64STimo Kreuzer rec = ptrs->ExceptionRecord;
879efafd64STimo Kreuzer
889efafd64STimo Kreuzer if (rec->ExceptionCode == CXX_EXCEPTION &&
899efafd64STimo Kreuzer rec->NumberParameters == 3 &&
909efafd64STimo Kreuzer rec->ExceptionInformation[0] == CXX_FRAME_MAGIC_VC6 &&
919efafd64STimo Kreuzer rec->ExceptionInformation[2])
929efafd64STimo Kreuzer {
939efafd64STimo Kreuzer ptrs->ExceptionRecord = msvcrt_get_thread_data()->exc_record;
949efafd64STimo Kreuzer return TRUE;
959efafd64STimo Kreuzer }
969efafd64STimo Kreuzer return (msvcrt_get_thread_data()->exc_record == rec);
979efafd64STimo Kreuzer }
989efafd64STimo Kreuzer
999efafd64STimo Kreuzer
1009efafd64STimo Kreuzer /*********************************************************************
1019efafd64STimo Kreuzer * __CxxQueryExceptionSize (MSVCRT.@)
1029efafd64STimo Kreuzer */
__CxxQueryExceptionSize(void)1039efafd64STimo Kreuzer unsigned int CDECL __CxxQueryExceptionSize(void)
1049efafd64STimo Kreuzer {
1059efafd64STimo Kreuzer return sizeof(cxx_exception_type);
1069efafd64STimo Kreuzer }
1079efafd64STimo Kreuzer
1089efafd64STimo Kreuzer
1099efafd64STimo Kreuzer /*******************************************************************
1109efafd64STimo Kreuzer * _setjmp (MSVCRT.@)
1119efafd64STimo Kreuzer */
1129efafd64STimo Kreuzer __ASM_GLOBAL_FUNC(MSVCRT__setjmp,
1139efafd64STimo Kreuzer "b " __ASM_NAME("__wine_setjmpex"));
1149efafd64STimo Kreuzer
1159efafd64STimo Kreuzer /*******************************************************************
1169efafd64STimo Kreuzer * longjmp (MSVCRT.@)
1179efafd64STimo Kreuzer */
MSVCRT_longjmp(_JUMP_BUFFER * jmp,int retval)118*3a61dd7fSTimo Kreuzer void __cdecl MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval)
1199efafd64STimo Kreuzer {
1209efafd64STimo Kreuzer EXCEPTION_RECORD rec;
1219efafd64STimo Kreuzer
1229efafd64STimo Kreuzer if (!retval) retval = 1;
1239efafd64STimo Kreuzer if (jmp->Frame)
1249efafd64STimo Kreuzer {
1259efafd64STimo Kreuzer rec.ExceptionCode = STATUS_LONGJUMP;
1269efafd64STimo Kreuzer rec.ExceptionFlags = 0;
1279efafd64STimo Kreuzer rec.ExceptionRecord = NULL;
1289efafd64STimo Kreuzer rec.ExceptionAddress = NULL;
1299efafd64STimo Kreuzer rec.NumberParameters = 1;
1309efafd64STimo Kreuzer rec.ExceptionInformation[0] = (DWORD_PTR)jmp;
1319efafd64STimo Kreuzer RtlUnwind((void *)jmp->Frame, (void *)jmp->Lr, &rec, IntToPtr(retval));
1329efafd64STimo Kreuzer }
1339efafd64STimo Kreuzer __wine_longjmp( (__wine_jmp_buf *)jmp, retval );
1349efafd64STimo Kreuzer }
1359efafd64STimo Kreuzer
1369efafd64STimo Kreuzer /*********************************************************************
1379efafd64STimo Kreuzer * _fpieee_flt (MSVCRT.@)
1389efafd64STimo Kreuzer */
_fpieee_flt(__msvcrt_ulong exception_code,EXCEPTION_POINTERS * ep,int (__cdecl * handler)(_FPIEEE_RECORD *))139*3a61dd7fSTimo Kreuzer int __cdecl _fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep,
1409efafd64STimo Kreuzer int (__cdecl *handler)(_FPIEEE_RECORD*))
1419efafd64STimo Kreuzer {
142*3a61dd7fSTimo Kreuzer FIXME("(%lx %p %p)\n", exception_code, ep, handler);
1439efafd64STimo Kreuzer return EXCEPTION_CONTINUE_SEARCH;
1449efafd64STimo Kreuzer }
1459efafd64STimo Kreuzer
1469efafd64STimo Kreuzer #endif /* __aarch64__ */
147