ReactOS  0.4.14-dev-376-gaedba84
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 52 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 }
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 _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 {
77 }
typedef void struct _CONTEXT void *struct __SEH2Registration _SEH2Registration_t
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 }
Definition: http.c:6587
FORCEINLINE void * _SEHFunctionFromTrampoline(_SEHTrampoline_t *trampoline_)
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
smooth NULL
Definition: ftsmooth.c:416
int ret
FORCEINLINE void * _SEHClosureFromTrampoline(_SEHTrampoline_t *trampoline_)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glext.h:7005

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 }
Definition: http.c:6587
FORCEINLINE void * _SEHFunctionFromTrampoline(_SEHTrampoline_t *trampoline_)
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
smooth NULL
Definition: ftsmooth.c:416
FORCEINLINE void * _SEHClosureFromTrampoline(_SEHTrampoline_t *trampoline_)
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 239 of file framebased-gcchack.c.

245 {
246  _SEH2Frame_t * frame;
247 
248  frame = EstablisherFrame;
249 
250  /* Unwinding */
251  if(ExceptionRecord->ExceptionFlags & (EXCEPTION_EXIT_UNWIND | EXCEPTION_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 }
#define EXCEPTION_UNWINDING
_IRQL_requires_same_ _In_ PVOID EstablisherFrame
Definition: ntbasedef.h:660
static __SEH_EXCEPT_RET _SEH2Except(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel, struct _EXCEPTION_POINTERS *ep)
DWORD ExceptionCode
Definition: compat.h:196
smooth NULL
Definition: ftsmooth.c:416
PCONTEXT ContextRecord
Definition: rtltypes.h:197
#define EXCEPTION_EXIT_UNWIND
static DECLSPEC_NORETURN void _SEH2Handle(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT * ContextRecord
Definition: ntbasedef.h:661
int ret
DWORD ExceptionFlags
Definition: compat.h:197
PEXCEPTION_RECORD ExceptionRecord
Definition: rtltypes.h:196
static void _SEH2LocalUnwind(_SEH2Frame_t *, volatile _SEH2TryLevel_t *)

◆ _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 }
NTSYSAPI VOID NTAPI RtlUnwind(_In_opt_ PVOID TargetFrame, _In_opt_ PVOID TargetIp, _In_opt_ PEXCEPTION_RECORD ExceptionRecord, _In_ PVOID ReturnValue)
Definition: except.c:47
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
GLenum target
Definition: glext.h:7315

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 *)
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
FORCEINLINE void _SEH2GlobalUnwind(void *target)
static void _SEH2LocalUnwind(_SEH2Frame_t *, volatile _SEH2TryLevel_t *)

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;
206  __SEH2EnterFrame(&unwindframe.SUF_Registration);
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 }
FORCEINLINE void __cdecl __SEH2LeaveFrame(void)
volatile _SEH2TryLevel_t * SUF_TargetTryLevel
static void _SEH2Finally(_SEH2Frame_t *frame, volatile _SEH2TryLevel_t *trylevel)
_SEH2Frame_t * SUF_Frame
_SEH2Registration_t SUF_Registration
FORCEINLINE void __cdecl __SEH2EnterFrame(_SEH2Registration_t *frame)
int __cdecl __SEH2UnwindHandler(struct _EXCEPTION_RECORD *, void *, struct _CONTEXT *, void *)

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);
307  _SEH2LeaveFrame();
308 }
FORCEINLINE _SEH2Registration_t *__cdecl _SEH2CurrentRegistration(void)
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
void __cdecl _SEH2LeaveFrame(void)
static void _SEH2LocalUnwind(_SEH2Frame_t *, volatile _SEH2TryLevel_t *)

◆ _SEH2UnwindHandler()

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

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

184 {
185  if(ExceptionRecord->ExceptionFlags & (EXCEPTION_EXIT_UNWIND | EXCEPTION_UNWINDING))
186  {
187  _SEH2UnwindFrame_t * unwindframe = CONTAINING_RECORD(EstablisherFrame, _SEH2UnwindFrame_t, SUF_Registration);
188  _SEH2LocalUnwind(unwindframe->SUF_Frame, unwindframe->SUF_TargetTryLevel);
189  *((void **)DispatcherContext) = EstablisherFrame;
191  }
192 
194 }
#define EXCEPTION_UNWINDING
_IRQL_requires_same_ _In_ PVOID EstablisherFrame
Definition: ntbasedef.h:660
volatile _SEH2TryLevel_t * SUF_TargetTryLevel
_IRQL_requires_same_ _In_ PVOID _Inout_ struct _CONTEXT _In_ PVOID DispatcherContext
Definition: ntbasedef.h:661
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_SEH2Frame_t * SUF_Frame
#define EXCEPTION_EXIT_UNWIND
DWORD ExceptionFlags
Definition: compat.h:197
static void _SEH2LocalUnwind(_SEH2Frame_t *, volatile _SEH2TryLevel_t *)

◆ _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 45 of file framebased-gcchack.c.

◆ STR_Function

unsigned char* STR_Function

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

◆ STR_Jmp

unsigned char STR_Jmp

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

◆ STR_MovEcx

unsigned char STR_MovEcx

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