ReactOS 0.4.16-dev-2122-g1628f5e
except_arm64ec.c
Go to the documentation of this file.
1/*
2 * msvcrt C++ exception handling
3 *
4 * Copyright 2011 Alexandre Julliard
5 * Copyright 2013 André Hentschel
6 * Copyright 2017 Martin Storsjo
7 *
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.
12 *
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.
17 *
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
21 */
22
23#ifdef __arm64ec__
24
25#include <setjmp.h>
26#include <stdarg.h>
27#include <fpieee.h>
28
29#include "ntstatus.h"
30#define WIN32_NO_STATUS
31#include "windef.h"
32#include "winbase.h"
33#include "winternl.h"
34#include "msvcrt.h"
35#include "excpt.h"
36#include "wine/debug.h"
37
38#include "cppexcept.h"
39
41
42
43static void * __attribute__((naked,used)) call_handler_arm64( void *func, uintptr_t frame,
44 UINT flags, BYTE *nonvol_regs )
45{
46 asm( ".seh_proc \"#call_handler_arm64\"\n\t"
47 "stp x29, x30, [sp, #-80]!\n\t"
48 ".seh_save_fplr_x 80\n\t"
49 "stp x19, x20, [sp, #16]\n\t"
50 ".seh_save_regp x19, 16\n\t"
51 "stp x21, x22, [sp, #32]\n\t"
52 ".seh_save_regp x21, 32\n\t"
53 "stp x25, x26, [sp, #48]\n\t"
54 ".seh_save_regp x25, 48\n\t"
55 "str x27, [sp, #64]\n\t"
56 ".seh_save_reg x27, 64\n\t"
57 "str x1, [sp, #-16]!\n\t"
58 ".seh_stackalloc 16\n\t"
59 ".seh_endprologue\n\t"
60 "ldp x19, x20, [x3, #0]\n\t" /* nonvolatile regs */
61 "ldp x21, x22, [x3, #16]\n\t"
62 "ldp x25, x26, [x3, #48]\n\t"
63 "ldr x27, [x3, #64]\n\t"
64 "ldr x29, [x3, #80]\n\t"
65 "blr x0\n\t"
66 "add sp, sp, 16\n\t"
67 "ldp x19, x20, [sp, #16]\n\t"
68 "ldp x21, x22, [sp, #32]\n\t"
69 "ldp x25, x26, [sp, #48]\n\t"
70 "ldr x27, [sp, #64]\n\t"
71 "ldp x29, x30, [sp], #80\n\t"
72 "ret\n\t"
73 ".seh_endproc" );
74}
75
76static void * __attribute__((naked,used)) call_handler_x64( void *func, uintptr_t frame, UINT flags )
77{
78 asm( ".seh_proc \"#call_handler_x64\"\n\t"
79 "stp x29, x30, [sp, #-16]!\n\t"
80 ".seh_save_fplr_x 16\n\t"
81 ".seh_endprologue\n\t"
82 "mov x11, x0\n\t"
83 "adr x10, $iexit_thunk$cdecl$i8$i8i8i8\n\t"
84 "adrp x16, __os_arm64x_dispatch_icall\n\t"
85 "ldr x16, [x16, #:lo12:__os_arm64x_dispatch_icall]\n\t"
86 "blr x16\n\t"
87 "blr x11\n\t"
88 "ldp x29, x30, [sp], #16\n\t"
89 "ret\n\t"
90 ".seh_endproc" );
91}
92
93
94/*******************************************************************
95 * call_catch_handler
96 */
98{
99 ULONG_PTR frame = rec->ExceptionInformation[1];
100 void *handler = (void *)rec->ExceptionInformation[5];
101
102 TRACE( "calling %p frame %Ix\n", handler, frame );
103 if (!RtlIsEcCode( (ULONG_PTR)handler )) return call_handler_x64( handler, frame, 0x100 );
104 return call_handler_arm64( handler, frame, 0x100, (BYTE *)rec->ExceptionInformation[10] );
105}
106
107
108/*******************************************************************
109 * call_unwind_handler
110 */
112{
113 TRACE( "calling %p frame %Ix\n", handler, frame );
114 if (!RtlIsEcCode( (ULONG_PTR)handler )) return call_handler_x64( handler, frame, 0x100 );
115 return call_handler_arm64( handler, frame, 0x100,
116 ((DISPATCHER_CONTEXT_ARM64EC *)dispatch)->NonVolatileRegisters );
117}
118
119
120/*******************************************************************
121 * get_exception_pc
122 */
124{
125 ULONG_PTR pc = dispatch->ControlPc;
126 if (RtlIsEcCode( pc ) && ((DISPATCHER_CONTEXT_ARM64EC *)dispatch)->ControlPcIsUnwound) pc -= 4;
127 return pc;
128}
129
130
131/*********************************************************************
132 * handle_fpieee_flt
133 */
136{
137 FIXME("(%lx %p %p)\n", exception_code, ep, handler);
139}
140
141#if _MSVCR_VER>=110 && _MSVCR_VER<=120
142/*********************************************************************
143 * __crtCapturePreviousContext (MSVCR110.@)
144 */
145void __cdecl __crtCapturePreviousContext( CONTEXT *ctx )
146{
148 RUNTIME_FUNCTION *func;
150 ULONG_PTR pc, frame, base;
151 void *data;
152 ULONG i;
153
155 for (i = 0; i < 2; i++)
156 {
157 pc = ctx->Rip;
158 if ((ctx->ContextFlags & CONTEXT_UNWOUND_TO_CALL) && RtlIsEcCode( pc )) pc -= 4;
159 if (!(func = RtlLookupFunctionEntry( pc, &base, &table ))) break;
161 &data, &frame, NULL, NULL, NULL, &handler, 0 ))
162 break;
163 if (!ctx->Rip) break;
164 if (!frame) break;
165 }
166}
167#endif
168
169#endif /* __arm64ec__ */
static int used
Definition: adh-main.c:39
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
void dispatch(HANDLE hStopEvent)
Definition: dispatch.c:70
#define FIXME(fmt,...)
Definition: precomp.h:53
#define NULL
Definition: types.h:112
#define __attribute__(x)
Definition: wpp_private.h:207
EXCEPTION_ROUTINE * PEXCEPTION_ROUTINE
Definition: compat.h:709
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
void * call_unwind_handler(void *func, uintptr_t frame, DISPATCHER_CONTEXT *dispatch)
int handle_fpieee_flt(__msvcrt_ulong exception_code, EXCEPTION_POINTERS *ep, int(__cdecl *handler)(_FPIEEE_RECORD *))
void * call_catch_handler(EXCEPTION_RECORD *rec)
ULONG_PTR get_exception_pc(DISPATCHER_CONTEXT *dispatch)
#define __cdecl
Definition: corecrt.h:121
unsigned int uintptr_t
Definition: corecrt.h:185
unsigned long __msvcrt_ulong
Definition: corecrt.h:168
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum func
Definition: glext.h:6028
GLbitfield flags
Definition: glext.h:7161
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define UNW_FLAG_NHANDLER
Definition: gs_support.c:32
#define exception_code
Definition: excpt.h:84
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:91
unsigned int UINT
Definition: ndis.h:50
NTSYSAPI VOID NTAPI RtlCaptureContext(_Out_ PCONTEXT ContextRecord)
NTSYSAPI NTSTATUS WINAPI RtlVirtualUnwind2(ULONG, ULONG_PTR, ULONG_PTR, RUNTIME_FUNCTION *, CONTEXT *, BOOLEAN *, void **, ULONG_PTR *, KNONVOLATILE_CONTEXT_POINTERS *, ULONG_PTR *, ULONG_PTR *, PEXCEPTION_ROUTINE *, ULONG)
NTSYSAPI PRUNTIME_FUNCTION WINAPI RtlLookupFunctionEntry(ULONG_PTR, ULONG_PTR *, UNWIND_HISTORY_TABLE *)
#define TRACE(s)
Definition: solgame.cpp:4
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:213
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define CONTEXT_UNWOUND_TO_CALL
Definition: winnt.h:153
unsigned char BYTE
Definition: xxhash.c:193