Author: hyperion
Date: Sun Dec 14 16:44:33 2008
New Revision: 38085
URL:
http://svn.reactos.org/svn/reactos?rev=38085&view=rev
Log:
Revert r38084
Sigh.
Modified:
trunk/reactos/include/reactos/libs/pseh/pseh2.h
trunk/reactos/lib/pseh/framebased-gcchack.c
trunk/reactos/lib/pseh/i386/framebased-gcchack.S
Modified: trunk/reactos/include/reactos/libs/pseh/pseh2.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/libs/pseh/…
==============================================================================
--- trunk/reactos/include/reactos/libs/pseh/pseh2.h [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/libs/pseh/pseh2.h [iso-8859-1] Sun Dec 14 16:44:33 2008
@@ -48,7 +48,6 @@
volatile struct __SEH2TryLevel * volatile SF_TopTryLevel;
void * volatile SF_FramePointer;
void * volatile SF_StackPointer;
- struct _EXCEPTION_POINTERS * volatile SF_ExceptionInformation;
volatile unsigned long SF_Code;
}
_SEH2Frame_t;
@@ -56,6 +55,7 @@
typedef struct __SEH2TryLevel
{
volatile struct __SEH2TryLevel * ST_Next;
+ void * ST_FramePointer;
void * ST_Filter;
void * ST_Body;
}
@@ -119,41 +119,33 @@
/* A no-op without any real side effects, but silences warnings */
#define __SEH_PRETEND_SIDE_EFFECT (void)0
-/* Forces the specified label to be reachable */
-#define __SEH_USE_LABEL(L_) if(__SEH_VOLATILE_FALSE) goto L_;
+/* Forces GCC to consider the specified label reachable */
+#define __SEH_USE_LABEL(L_) __asm__ __volatile__("# %0\n" : : "i"
(&&L_))
/* Makes GCC pretend the specified label is reachable, to silence warnings */
#define __SEH_PRETEND_USE_LABEL(L_) (void)(&&L_)
+/* Forces GCC to emit the specified nested function as a function */
+#define __SEH_USE_NESTED_FUNCTION(F_) (void)(&F_) /* __attribute__((noinline)) seems
to do the trick */
+
/* Soft memory barrier */
#define __SEH_BARRIER __asm__ __volatile__("#":::"memory")
/* GCC doesn't know that this equals zero */
-#define __SEH_VOLATILE_ZERO ({ int zero = 0; __asm__ __volatile__("#" :
"+g" (zero)); zero; })
-
-/* GCC believes this is setjmp */
-#define __SEH_PRETEND_SETJMP() (_SEH2PretendSetjmp(), 0)
-
-#define __SEH_VOLATILE_FALSE __builtin_expect(__SEH_VOLATILE_ZERO, 0)
-#define __SEH_VOLATILE_TRUE __builtin_expect(!__SEH_VOLATILE_ZERO, 1)
-
-#define ___SEH_STRINGIFY(X_) # X_
-#define __SEH_STRINGIFY(X_) ___SEH_STRINGIFY(X_)
-
-static
-__inline__
-__attribute__((returns_twice))
-__attribute__((always_inline))
-void _SEH2PretendSetjmp(void)
-{
-}
+#define __SEH_ZERO ({ int zero = 0; __asm__ __volatile__("#" : "+g"
(zero)); zero; })
+
+#define __SEH_FALSE __builtin_expect(__SEH_ZERO, 0)
+#define __SEH_TRUE __builtin_expect(!__SEH_ZERO, 1)
#define __SEH_FORCE_NEST \
__asm__ __volatile__("#%0" : : "r" (&_SEHFrame))
-#define __SEH_DECLARE_EXCEPT_PFN(NAME_) int (__cdecl * NAME_)(void)
-#define __SEH_DECLARE_EXCEPT(NAME_) int __cdecl NAME_(void)
-#define __SEH_DEFINE_EXCEPT(NAME_) int __cdecl NAME_(void)
+#define __SEH_NESTED_PROLOG \
+ __SEH_FORCE_NEST;
+
+#define __SEH_DECLARE_EXCEPT_PFN(NAME_) int (__cdecl * NAME_)(void *)
+#define __SEH_DECLARE_EXCEPT(NAME_) int __cdecl NAME_(void *)
+#define __SEH_DEFINE_EXCEPT(NAME_) int __cdecl NAME_(void * _SEHExceptionPointers)
#define __SEH_DECLARE_FINALLY_PFN(NAME_) void (__cdecl * NAME_)(void)
#define __SEH_DECLARE_FINALLY(NAME_) void __cdecl NAME_(void)
@@ -163,19 +155,21 @@
#define __SEH_RETURN_FINALLY() return
#define __SEH_BEGIN_TRY \
- if(!__SEH_PRETEND_SETJMP()) \
- { \
+ { \
+ __label__ _SEHBeginTry; \
__label__ _SEHEndTry; \
- \
- __SEH_PRETEND_USE_LABEL(_SEHEndTry); \
- \
+ \
+ __SEH_USE_LABEL(_SEHBeginTry); \
+ __SEH_USE_LABEL(_SEHEndTry); \
+ \
+ _SEHBeginTry: __SEH_SIDE_EFFECT; \
{ \
__SEH_BARRIER;
#define __SEH_END_TRY \
__SEH_BARRIER; \
} \
- _SEHEndTry:; \
+ _SEHEndTry: __SEH_SIDE_EFFECT; \
}
#define __SEH_SET_TRYLEVEL(TRYLEVEL_) \
@@ -194,6 +188,11 @@
#define __SEH_BEGIN_SCOPE \
for(;;) \
{ \
+ __label__ _SEHBeginScope; \
+ __label__ _SEHEndScope; \
+ \
+ _SEHBeginScope: __SEH_SIDE_EFFECT; \
+ \
const int _SEHTopTryLevel = (_SEH2ScopeKind != 0); \
_SEH2Frame_t * const _SEHCurFrameP = _SEH2FrameP; \
volatile _SEH2TryLevel_t * const _SEHPrevTryLevelP = _SEH2TryLevelP; \
@@ -201,6 +200,9 @@
(void)_SEHTopTryLevel; \
(void)_SEHCurFrameP; \
(void)_SEHPrevTryLevelP; \
+ \
+ __SEH_USE_LABEL(_SEHBeginScope); \
+ __SEH_USE_LABEL(_SEHEndScope); \
\
{ \
__label__ _SEHBeforeTry; \
@@ -225,10 +227,15 @@
__SEH_ENTER_TRYLEVEL(); \
\
if(_SEHTopTryLevel) \
+ { \
+ __SEH_BARRIER; __asm__ __volatile__("mov %%ebp, %0\n#%1" : "=m"
(_SEHFrame.SF_FramePointer) : "r" (__builtin_frame_address(0))); __SEH_BARRIER;
\
_SEH2EnterFrame(&_SEHFrame); \
+ } \
#define __SEH_END_SCOPE \
} \
+ \
+ _SEHEndScope: __SEH_SIDE_EFFECT; \
\
break; \
}
@@ -237,13 +244,14 @@
__label__ _SEHBeginExcept; \
__label__ _SEHEndExcept; \
\
+ auto __SEH_DECLARE_EXCEPT(_SEHExcept); \
auto __SEH_DECLARE_FINALLY(_SEHFinally);
#define _SEH2_TRY \
__SEH_BEGIN_SCOPE \
{ \
__SEH_SCOPE_LOCALS; \
- \
+\
__SEH_BEGIN_TRY \
{
@@ -257,8 +265,11 @@
__SEH_PRETEND_USE_LABEL(_SEHBeginExcept); \
__SEH_PRETEND_USE_LABEL(_SEHEndExcept); \
\
+ __SEH_USE_NESTED_FUNCTION(_SEHFinally); \
+ \
+ _SEHTryLevel.ST_FramePointer = _SEHClosureFromTrampoline((_SEHTrampoline_t
*)&_SEHFinally); \
_SEHTryLevel.ST_Filter = 0; \
- _SEHTryLevel.ST_Body = &_SEHFinally; \
+ _SEHTryLevel.ST_Body = _SEHFunctionFromTrampoline((_SEHTrampoline_t
*)&_SEHFinally); \
\
goto _SEHDoTry; \
_SEHAfterTry:; \
@@ -273,9 +284,10 @@
_SEHFinally(); \
goto _SEHEndExcept; \
\
- _SEHBeginExcept:; \
- \
- __attribute__((noinline)) __SEH_DEFINE_FINALLY(_SEHFinally) \
+ _SEHBeginExcept: __SEH_PRETEND_SIDE_EFFECT; \
+ __attribute__((unused)) __SEH_DEFINE_EXCEPT(_SEHExcept) { __SEH_RETURN_EXCEPT(0); } \
+ \
+ __attribute__((noinline)) __attribute__((used)) __SEH_DEFINE_FINALLY(_SEHFinally) \
{ \
__SEH_END_SCOPE_CHAIN; \
\
@@ -283,64 +295,39 @@
(void)_SEH2FrameP; \
(void)_SEH2TryLevelP; \
\
+ __SEH_NESTED_PROLOG; \
+ \
for(;; ({ __SEH_RETURN_FINALLY(); })) \
{
-#define _SEH2_EXCEPT(...) \
+#define _SEH2_EXCEPT(E_) \
} \
__SEH_END_TRY; \
\
goto _SEHAfterTry; \
\
_SEHBeforeTry:; \
- \
- if(__builtin_constant_p((__VA_ARGS__))) \
- { \
- if((__VA_ARGS__) > 0) \
- { \
- _SEHTryLevel.ST_Filter = (void *)1; \
- _SEHTryLevel.ST_Body = &&_SEHBeginExcept; \
- __SEH_USE_LABEL(_SEHBeginExcept); \
- } \
- else if((__VA_ARGS__) < 0) \
- { \
- _SEHTryLevel.ST_Filter = (void *)-1; \
- _SEHTryLevel.ST_Body = NULL; \
- } \
- else \
- { \
- _SEHTryLevel.ST_Filter = (void *)0; \
- _SEHTryLevel.ST_Body = NULL; \
- } \
- } \
- else \
- { \
- __SEH_DEFINE_EXCEPT(_SEHExcept) \
- { \
- __SEH_RETURN_EXCEPT((__VA_ARGS__)); \
- } \
- \
- _SEHTryLevel.ST_Filter = &_SEHExcept; \
- _SEHTryLevel.ST_Body = &&_SEHBeginExcept; \
- __SEH_USE_LABEL(_SEHBeginExcept); \
- } \
- \
- __SEH_BARRIER; \
- \
- __asm__ __volatile__ \
- ( \
- "mov %%ebp, %0\n" \
- "mov %%esp, %1" : \
- "=m" (_SEH2FrameP->SF_FramePointer), \
- "=m" (_SEH2FrameP->SF_StackPointer) \
- ); \
- \
- __SEH_BARRIER; \
- \
+\
+ __SEH_USE_LABEL(_SEHBeginExcept); \
+ __SEH_USE_LABEL(_SEHEndExcept); \
+\
+ __SEH_USE_NESTED_FUNCTION(_SEHExcept); \
+ \
+ _SEHTryLevel.ST_FramePointer = _SEHClosureFromTrampoline((_SEHTrampoline_t
*)&_SEHExcept); \
+ _SEHTryLevel.ST_Filter = _SEHFunctionFromTrampoline((_SEHTrampoline_t
*)&_SEHExcept); \
+ _SEHTryLevel.ST_Body = &&_SEHBeginExcept; \
+ __SEH_BARRIER; __asm__ __volatile__("mov %%esp, %0" : "=m"
(_SEH2FrameP->SF_StackPointer)); __SEH_BARRIER; \
+\
goto _SEHDoTry; \
- \
+\
+ __attribute__((noinline)) __attribute__((used)) __SEH_DEFINE_EXCEPT(_SEHExcept) \
+ { \
+ __SEH_NESTED_PROLOG; \
+ __SEH_RETURN_EXCEPT(E_); \
+ } \
+\
__attribute__((unused)) __SEH_DEFINE_FINALLY(_SEHFinally) { __SEH_RETURN_FINALLY(); }
\
- \
+\
_SEHAfterTry:; \
if(_SEHTopTryLevel) \
_SEH2LeaveFrame(); \
@@ -349,9 +336,12 @@
__SEH_LEAVE_TRYLEVEL(); \
} \
\
- goto _SEHEndExcept; \
- \
- _SEHBeginExcept:; \
+ if(__SEH_FALSE) \
+ goto _SEHBeginExcept; \
+ else \
+ goto _SEHEndExcept; \
+\
+ _SEHBeginExcept: __SEH_SIDE_EFFECT; \
{ \
{ \
_SEH2Frame_t * const _SEH2FrameP = _SEHTopTryLevel ? &_SEHFrame : _SEHCurFrameP;
\
@@ -362,12 +352,11 @@
__SEH_BARRIER; \
} \
} \
- \
- _SEHEndExcept:; \
+ _SEHEndExcept: __SEH_SIDE_EFFECT; \
} \
__SEH_END_SCOPE;
-#define _SEH2_GetExceptionInformation() ((_SEH2FrameP)->SF_ExceptionInformation)
+#define _SEH2_GetExceptionInformation() ((struct _EXCEPTION_POINTERS
*)_SEHExceptionPointers)
#define _SEH2_GetExceptionCode() ((_SEH2FrameP)->SF_Code)
#define _SEH2_AbnormalTermination() (!!_SEH2_GetExceptionCode())
@@ -390,7 +379,7 @@
#define _SEH2_TRY __try
#define _SEH2_FINALLY __finally
-#define _SEH2_EXCEPT(...) __except(__VA_ARGS__)
+#define _SEH2_EXCEPT(E_) __except((E_))
#define _SEH2_END
#define _SEH2_GetExceptionInformation() (GetExceptionInformation())
Modified: trunk/reactos/lib/pseh/framebased-gcchack.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/pseh/framebased-gcchac…
==============================================================================
--- trunk/reactos/lib/pseh/framebased-gcchack.c [iso-8859-1] (original)
+++ trunk/reactos/lib/pseh/framebased-gcchack.c [iso-8859-1] Sun Dec 14 16:44:33 2008
@@ -40,7 +40,7 @@
extern _SEH2Registration_t * __cdecl _SEH2CurrentRegistration(void);
extern void _SEH2GlobalUnwind(void *);
-extern int __SEH2Except(void *, void *);
+extern int __SEH2Except(void *, void *, void *);
extern void __SEH2Finally(void *, void *);
extern DECLSPEC_NORETURN int __SEH2Handle(void *, void *, void *);
@@ -51,27 +51,9 @@
extern int __cdecl __SEH2NestedHandler(struct _EXCEPTION_RECORD *, void *, struct
_CONTEXT *, void *);
FORCEINLINE
-int _SEH2Except(_SEH2Frame_t * frame, volatile _SEH2TryLevel_t * trylevel)
+int _SEH2Except(_SEH2Frame_t * frame, volatile _SEH2TryLevel_t * trylevel,
EXCEPTION_POINTERS * ep)
{
- void * filter = trylevel->ST_Filter;
- void * context = NULL;
-
- if(filter == (void *)0)
- return 0;
-
- if(filter == (void *)1)
- return 1;
-
- if(filter == (void *)-1)
- return -1;
-
- if(_SEHIsTrampoline((_SEHTrampoline_t *)filter))
- {
- context = _SEHClosureFromTrampoline((_SEHTrampoline_t *)filter);
- filter = _SEHFunctionFromTrampoline((_SEHTrampoline_t *)filter);
- }
-
- return __SEH2Except(filter, context);
+ return __SEH2Except(trylevel->ST_Filter, trylevel->ST_FramePointer, ep);
}
static
@@ -80,16 +62,7 @@
#endif
void _SEH2Finally(_SEH2Frame_t * frame, volatile _SEH2TryLevel_t * trylevel)
{
- void * body = trylevel->ST_Body;
- void * context = NULL;
-
- if(_SEHIsTrampoline((_SEHTrampoline_t *)body))
- {
- context = _SEHClosureFromTrampoline((_SEHTrampoline_t *)body);
- body = _SEHFunctionFromTrampoline((_SEHTrampoline_t *)body);
- }
-
- __SEH2Finally(body, context);
+ __SEH2Finally(trylevel->ST_Body, trylevel->ST_FramePointer);
}
extern
@@ -118,7 +91,10 @@
__SEH2EnterFrame(&nestedframe);
for(trylevel = frame->SF_TopTryLevel; trylevel && trylevel != dsttrylevel;
trylevel = trylevel->ST_Next)
- _SEH2Finally(frame, trylevel);
+ {
+ if(!trylevel->ST_Filter)
+ _SEH2Finally(frame, trylevel);
+ }
frame->SF_TopTryLevel = dsttrylevel;
@@ -156,22 +132,25 @@
{
int ret = 0;
volatile _SEH2TryLevel_t * trylevel;
- EXCEPTION_POINTERS ep;
-
- ep.ExceptionRecord = ExceptionRecord;
- ep.ContextRecord = ContextRecord;
frame->SF_Code = ExceptionRecord->ExceptionCode;
- frame->SF_ExceptionInformation = &ep;
for(trylevel = frame->SF_TopTryLevel; trylevel != NULL; trylevel =
trylevel->ST_Next)
{
- ret = _SEH2Except(frame, trylevel);
+ if(trylevel->ST_Filter)
+ {
+ EXCEPTION_POINTERS ep;
- if(ret < 0)
- return ExceptionContinueExecution;
- else if(ret > 0)
- _SEH2Handle(frame, trylevel);
+ ep.ExceptionRecord = ExceptionRecord;
+ ep.ContextRecord = ContextRecord;
+
+ ret = _SEH2Except(frame, trylevel, &ep);
+
+ if(ret < 0)
+ return ExceptionContinueExecution;
+ else if(ret > 0)
+ _SEH2Handle(frame, trylevel);
+ }
}
}
Modified: trunk/reactos/lib/pseh/i386/framebased-gcchack.S
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/pseh/i386/framebased-g…
==============================================================================
--- trunk/reactos/lib/pseh/i386/framebased-gcchack.S [iso-8859-1] (original)
+++ trunk/reactos/lib/pseh/i386/framebased-gcchack.S [iso-8859-1] Sun Dec 14 16:44:33
2008
@@ -49,8 +49,18 @@
jmp eax
.globl ___SEH2Except
+___SEH2Except:
+ mov eax, [esp+4]
+ mov ecx, [esp+8]
+
+ push [esp+12]
+ call eax
+
+ pop ecx
+
+ ret
+
.globl ___SEH2Finally
-___SEH2Except:
___SEH2Finally:
mov eax, [esp+4]
mov ecx, [esp+8]