ReactOS 0.4.15-dev-8145-ga541a46
framebased-gcchack.c File Reference
#include <windef.h>
#include <stdarg.h>
#include <pseh/pseh2.h>
#include <excpt.h>
#include <intrin.h>
Include dependency graph for framebased-gcchack.c:

Go to the source code of this file.

Classes

struct  __SEHTrampoline
 
struct  __SEH2UnwindFrame
 

Macros

#define _NTSYSTEM_   /* removes dllimport attribute from RtlUnwind */
 
#define STRICT
 
#define EXCEPTION_EXIT_UNWIND   4
 
#define EXCEPTION_UNWINDING   2
 

Typedefs

typedef struct __SEH2UnwindFrame _SEH2UnwindFrame_t
 

Functions

DECLSPEC_NORETURN int __SEH2Handle (void *, void *, void *, void *, void *, void *)
 
int __cdecl __SEH2FrameHandler (struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *)
 
int __cdecl __SEH2UnwindHandler (struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *)
 
struct __SEHTrampoline __attribute__ ((packed))
 
FORCEINLINE void_SEHFunctionFromTrampoline (_SEHTrampoline_t *trampoline_)
 
FORCEINLINE void_SEHClosureFromTrampoline (_SEHTrampoline_t *trampoline_)
 
FORCEINLINE _SEH2Registration_t *__cdecl _SEH2CurrentRegistration (void)
 
FORCEINLINE void __cdecl __SEH2EnterFrame (_SEH2Registration_t *frame)
 
FORCEINLINE void __cdecl __SEH2LeaveFrame (void)
 
FORCEINLINE void _SEH2GlobalUnwind (void *target)
 
static __SEH_EXCEPT_RET _SEH2Except (_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel, struct _EXCEPTION_POINTERS *ep)
 
static void _SEH2Finally (_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
 
static void _SEH2LocalUnwind (_SEH2Frame_t *, volatile _SEH2TryLevel_t *)
 
int __cdecl _SEH2UnwindHandler (struct _EXCEPTION_RECORD *ExceptionRecord, void *EstablisherFrame, struct _CONTEXT *ContextRecord, void *DispatcherContext)
 
static DECLSPEC_NORETURN void _SEH2Handle (_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
 
int __cdecl _SEH2FrameHandler (struct _EXCEPTION_RECORD *ExceptionRecord, void *EstablisherFrame, struct _CONTEXT *ContextRecord, void *DispatcherContext)
 
void __cdecl _SEH2EnterFrame (_SEH2Frame_t *frame)
 
int __cdecl _SEH2EnterFrameAndTrylevel (_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
 
void __cdecl _SEH2LeaveFrame (void)
 
void __cdecl _SEH2Return (void)
 

Variables

unsigned char STR_MovEcx
 
unsigned charSTR_Closure
 
unsigned char STR_Jmp
 
unsigned charSTR_Function
 

Macro Definition Documentation

◆ _NTSYSTEM_

#define _NTSYSTEM_   /* removes dllimport attribute from RtlUnwind */

Definition at line 23 of file framebased-gcchack.c.

◆ EXCEPTION_EXIT_UNWIND

#define EXCEPTION_EXIT_UNWIND   4

Definition at line 34 of file framebased-gcchack.c.

◆ EXCEPTION_UNWINDING

#define EXCEPTION_UNWINDING   2

Definition at line 38 of file framebased-gcchack.c.

◆ STRICT

#define STRICT

Definition at line 25 of file framebased-gcchack.c.

Typedef Documentation

◆ _SEH2UnwindFrame_t

Function Documentation

◆ __attribute__()

Definition at line 43 of file framebased-gcchack.c.

57{
58 return trampoline_->STR_MovEcx == 0xb9 && trampoline_->STR_Jmp == 0xe9;
59}

◆ __SEH2EnterFrame()

FORCEINLINE void __cdecl __SEH2EnterFrame ( _SEH2Registration_t *  frame)

Definition at line 80 of file framebased-gcchack.c.

81{
82 frame->SER_Prev = _SEH2CurrentRegistration();
83 __writefsdword(0, (unsigned long)frame);
84}
FORCEINLINE _SEH2Registration_t *__cdecl _SEH2CurrentRegistration(void)
PPC_QUAL void __writefsdword(const unsigned long Offset, const unsigned long Data)
Definition: intrin_ppc.h:354

Referenced by _SEH2EnterFrame(), and _SEH2LocalUnwind().

◆ __SEH2FrameHandler()

int __cdecl __SEH2FrameHandler ( struct _EXCEPTION_RECORD ,
void ,
struct _CONTEXT ,
void  
)

Referenced by _SEH2EnterFrame().

◆ __SEH2Handle()

DECLSPEC_NORETURN int __SEH2Handle ( void ,
void ,
void ,
void ,
void ,
void  
)

Referenced by _SEH2Handle().

◆ __SEH2LeaveFrame()

FORCEINLINE void __cdecl __SEH2LeaveFrame ( void  )

Definition at line 87 of file framebased-gcchack.c.

88{
89 __writefsdword(0, (unsigned long)_SEH2CurrentRegistration()->SER_Prev);
90}

Referenced by _SEH2LeaveFrame(), and _SEH2LocalUnwind().

◆ __SEH2UnwindHandler()

int __cdecl __SEH2UnwindHandler ( struct _EXCEPTION_RECORD ,
void ,
struct _CONTEXT ,
void  
)

Referenced by _SEH2LocalUnwind().

◆ _SEH2CurrentRegistration()

FORCEINLINE _SEH2Registration_t *__cdecl _SEH2CurrentRegistration ( void  )

Definition at line 74 of file framebased-gcchack.c.

75{
76 return (_SEH2Registration_t *)__readfsdword(0);
77}
PPC_QUAL unsigned long __readfsdword(const unsigned long Offset)
Definition: intrin_ppc.h:382

Referenced by __SEH2EnterFrame(), __SEH2LeaveFrame(), and _SEH2Return().

◆ _SEH2EnterFrame()

void __cdecl _SEH2EnterFrame ( _SEH2Frame_t *  frame)

Definition at line 282 of file framebased-gcchack.c.

283{
284 frame->SF_Registration.SER_Handler = __SEH2FrameHandler;
285 frame->SF_Code = 0;
286 __SEH2EnterFrame(&frame->SF_Registration);
287}
int __cdecl __SEH2FrameHandler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *)
FORCEINLINE void __cdecl __SEH2EnterFrame(_SEH2Registration_t *frame)

Referenced by _SEH2EnterFrameAndTrylevel().

◆ _SEH2EnterFrameAndTrylevel()

int __cdecl _SEH2EnterFrameAndTrylevel ( _SEH2Frame_t *  frame,
volatile _SEH2TryLevel_t *  trylevel 
)

Definition at line 290 of file framebased-gcchack.c.

291{
292 frame->SF_TopTryLevel = trylevel;
293 _SEH2EnterFrame(frame);
294 return 0;
295}
void __cdecl _SEH2EnterFrame(_SEH2Frame_t *frame)

◆ _SEH2Except()

static __SEH_EXCEPT_RET _SEH2Except ( _SEH2Frame_t *  frame,
volatile _SEH2TryLevel_t *  trylevel,
struct _EXCEPTION_POINTERS ep 
)
static

Definition at line 112 of file framebased-gcchack.c.

113{
114 void * filter = trylevel->ST_Filter;
115 void * context = NULL;
116 __SEH_EXCEPT_RET ret;
117
118 if(filter == (void *)0)
119 return 0;
120
121 if(filter == (void *)1)
122 return 1;
123
124 if(filter == (void *)-1)
125 return -1;
126
127 if(_SEHIsTrampoline((_SEHTrampoline_t *)filter))
128 {
129 context = _SEHClosureFromTrampoline((_SEHTrampoline_t *)filter);
130 filter = _SEHFunctionFromTrampoline((_SEHTrampoline_t *)filter);
131 }
132
133 __asm__ __volatile__
134 (
135 "push %[ep]\n\t"
136 "push %[frame]\n\t"
137 "call *%[filter]\n\t"
138 "pop %%edx\n\t"
139 "pop %%edx" :
140 [ret] "=a" (ret) :
141 "c" (context), [filter] "r" (filter), [frame] "r" (frame), [ep] "r" (ep) :
142 "edx", "flags", "memory"
143 );
144
145 return ret;
146}
#define NULL
Definition: types.h:112
FORCEINLINE void * _SEHFunctionFromTrampoline(_SEHTrampoline_t *trampoline_)
FORCEINLINE void * _SEHClosureFromTrampoline(_SEHTrampoline_t *trampoline_)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
Definition: http.c:7252
int ret

Referenced by _SEH2FrameHandler().

◆ _SEH2Finally()

static void _SEH2Finally ( _SEH2Frame_t *  frame,
volatile _SEH2TryLevel_t *  trylevel 
)
static

Definition at line 149 of file framebased-gcchack.c.

150{
151 if(trylevel->ST_Filter == NULL && trylevel->ST_Body != NULL)
152 {
153 void * body = trylevel->ST_Body;
154 void * context = NULL;
155
156 if(_SEHIsTrampoline((_SEHTrampoline_t *)body))
157 {
158 context = _SEHClosureFromTrampoline((_SEHTrampoline_t *)body);
159 body = _SEHFunctionFromTrampoline((_SEHTrampoline_t *)body);
160 }
161
162 __asm__ __volatile__("call *%1" : : "c" (context), "r" (body) : "eax", "edx", "flags", "memory");
163 }
164}
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:100

Referenced by _SEH2LocalUnwind().

◆ _SEH2FrameHandler()

int __cdecl _SEH2FrameHandler ( struct _EXCEPTION_RECORD ExceptionRecord,
void EstablisherFrame,
struct _CONTEXT ContextRecord,
void DispatcherContext 
)

Definition at line 238 of file framebased-gcchack.c.

245{
246 _SEH2Frame_t * frame;
247
248 frame = EstablisherFrame;
249
250 /* Unwinding */
252 {
253 _SEH2LocalUnwind(frame, NULL);
254 }
255 /* Handling */
256 else
257 {
258 int ret = 0;
259 volatile _SEH2TryLevel_t * trylevel;
261
262 ep.ExceptionRecord = ExceptionRecord;
264
265 frame->SF_Code = ExceptionRecord->ExceptionCode;
266
267 for(trylevel = frame->SF_TopTryLevel; trylevel != NULL; trylevel = trylevel->ST_Next)
268 {
269 ret = _SEH2Except(frame, trylevel, &ep);
270
271 if(ret < 0)
273 else if(ret > 0)
274 _SEH2Handle(frame, trylevel);
275 }
276 }
277
279}
@ ExceptionContinueSearch
Definition: compat.h:91
@ ExceptionContinueExecution
Definition: compat.h:90
#define EXCEPTION_EXIT_UNWIND
static __SEH_EXCEPT_RET _SEH2Except(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel, struct _EXCEPTION_POINTERS *ep)
static void _SEH2LocalUnwind(_SEH2Frame_t *, volatile _SEH2TryLevel_t *)
static DECLSPEC_NORETURN void _SEH2Handle(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
#define EXCEPTION_UNWINDING
_IRQL_requires_same_ _In_ PVOID EstablisherFrame
Definition: ntbasedef.h:653
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:654
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:200
PCONTEXT ContextRecord
Definition: rtltypes.h:201
DWORD ExceptionCode
Definition: compat.h:208
DWORD ExceptionFlags
Definition: compat.h:209

◆ _SEH2GlobalUnwind()

FORCEINLINE void _SEH2GlobalUnwind ( void target)

Definition at line 93 of file framebased-gcchack.c.

94{
95 __asm__ __volatile__
96 (
97 "push %%ebp\n\t"
98 "push $0\n\t"
99 "push $0\n\t"
100 "push $Return%=\n\t"
101 "push %[target]\n\t"
102 "call %c[RtlUnwind]\n"
103 "Return%=:\n\t"
104 "pop %%ebp" :
105 :
106 [target] "g" (target), [RtlUnwind] "g" (&RtlUnwind) :
107 "eax", "ebx", "ecx", "edx", "esi", "edi", "flags", "memory"
108 );
109}
GLenum target
Definition: glext.h:7315
NTSYSAPI VOID NTAPI RtlUnwind(_In_opt_ PVOID TargetFrame, _In_opt_ PVOID TargetIp, _In_opt_ PEXCEPTION_RECORD ExceptionRecord, _In_ PVOID ReturnValue)
Definition: unwind.c:912

Referenced by _SEH2Handle().

◆ _SEH2Handle()

static DECLSPEC_NORETURN void _SEH2Handle ( _SEH2Frame_t *  frame,
volatile _SEH2TryLevel_t *  trylevel 
)
static

Definition at line 218 of file framebased-gcchack.c.

219{
220 volatile _SEH2HandleTryLevel_t * fulltrylevel = CONTAINING_RECORD(trylevel, _SEH2HandleTryLevel_t, SHT_Common);
221
222 _SEH2GlobalUnwind(frame);
223 _SEH2LocalUnwind(frame, &fulltrylevel->SHT_Common);
224 frame->SF_TopTryLevel = fulltrylevel->SHT_Common.ST_Next;
225
227 (
228 fulltrylevel->SHT_Common.ST_Body,
229 fulltrylevel->SHT_Esp,
230 fulltrylevel->SHT_Ebp,
231 fulltrylevel->SHT_Ebx,
232 fulltrylevel->SHT_Esi,
233 fulltrylevel->SHT_Edi
234 );
235}
DECLSPEC_NORETURN int __SEH2Handle(void *, void *, void *, void *, void *, void *)
FORCEINLINE void _SEH2GlobalUnwind(void *target)
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by _SEH2FrameHandler().

◆ _SEH2LeaveFrame()

void __cdecl _SEH2LeaveFrame ( void  )

Definition at line 298 of file framebased-gcchack.c.

299{
301}
FORCEINLINE void __cdecl __SEH2LeaveFrame(void)

Referenced by _SEH2Return().

◆ _SEH2LocalUnwind()

static void _SEH2LocalUnwind ( _SEH2Frame_t *  frame,
volatile _SEH2TryLevel_t *  dsttrylevel 
)
static

Definition at line 197 of file framebased-gcchack.c.

198{
199 volatile _SEH2TryLevel_t * trylevel;
200 _SEH2UnwindFrame_t unwindframe;
201
202 unwindframe.SUF_Frame = frame;
203 unwindframe.SUF_TargetTryLevel = dsttrylevel;
204
205 unwindframe.SUF_Registration.SER_Handler = &__SEH2UnwindHandler;
207
208 for(trylevel = frame->SF_TopTryLevel; trylevel && trylevel != dsttrylevel; trylevel = trylevel->ST_Next)
209 {
210 frame->SF_TopTryLevel = trylevel->ST_Next;
211 _SEH2Finally(frame, trylevel);
212 }
213
215}
int __cdecl __SEH2UnwindHandler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *)
static void _SEH2Finally(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
volatile _SEH2TryLevel_t * SUF_TargetTryLevel
_SEH2Frame_t * SUF_Frame
_SEH2Registration_t SUF_Registration

Referenced by _SEH2FrameHandler(), _SEH2Handle(), _SEH2Return(), and _SEH2UnwindHandler().

◆ _SEH2Return()

void __cdecl _SEH2Return ( void  )

Definition at line 304 of file framebased-gcchack.c.

305{
306 _SEH2LocalUnwind(CONTAINING_RECORD(_SEH2CurrentRegistration(), _SEH2Frame_t, SF_Registration), NULL);
308}
void __cdecl _SEH2LeaveFrame(void)

◆ _SEH2UnwindHandler()

int __cdecl _SEH2UnwindHandler ( struct _EXCEPTION_RECORD ExceptionRecord,
void EstablisherFrame,
struct _CONTEXT ContextRecord,
void DispatcherContext 
)

Definition at line 177 of file framebased-gcchack.c.

184{
186 {
188 _SEH2LocalUnwind(unwindframe->SUF_Frame, unwindframe->SUF_TargetTryLevel);
191 }
192
194}
@ ExceptionCollidedUnwind
Definition: compat.h:93
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT _In_ PVOID DispatcherContext
Definition: ntbasedef.h:655

◆ _SEHClosureFromTrampoline()

FORCEINLINE void * _SEHClosureFromTrampoline ( _SEHTrampoline_t *  trampoline_)

Definition at line 68 of file framebased-gcchack.c.

69{
70 return trampoline_->STR_Closure;
71}

Referenced by _SEH2Except(), and _SEH2Finally().

◆ _SEHFunctionFromTrampoline()

FORCEINLINE void * _SEHFunctionFromTrampoline ( _SEHTrampoline_t *  trampoline_)

Definition at line 62 of file framebased-gcchack.c.

63{
64 return (int)(trampoline_ + 1) + trampoline_->STR_Function;
65}

Referenced by _SEH2Except(), and _SEH2Finally().

Variable Documentation

◆ STR_Closure

unsigned char* STR_Closure

Definition at line 54 of file framebased-gcchack.c.

◆ STR_Function

unsigned char* STR_Function

Definition at line 56 of file framebased-gcchack.c.

◆ STR_Jmp

unsigned char STR_Jmp

Definition at line 55 of file framebased-gcchack.c.

◆ STR_MovEcx

unsigned char STR_MovEcx

Definition at line 53 of file framebased-gcchack.c.