Author: hyperion
Date: Sun Dec 14 13:54:52 2008
New Revision: 38082
URL:
http://svn.reactos.org/svn/reactos?rev=38082&view=rev
Log:
Revert r38081
Modified:
trunk/reactos/include/reactos/libs/pseh/pseh2.h
trunk/reactos/lib/pseh/framebased-gcchack.c
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 13:54:52 2008
@@ -55,6 +55,7 @@
typedef struct __SEH2TryLevel
{
volatile struct __SEH2TryLevel * ST_Next;
+ void * ST_FramePointer;
void * ST_Filter;
void * ST_Body;
}
@@ -119,36 +120,28 @@
#define __SEH_PRETEND_SIDE_EFFECT (void)0
/* Forces GCC to consider the specified label reachable */
-#define __SEH_USE_LABEL(L_) if(__SEH_VOLATILE_FALSE) goto L_;
+#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(), __SEH_VOLATILE_FALSE)
-
-#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_NESTED_PROLOG \
+ __SEH_FORCE_NEST;
#define __SEH_DECLARE_EXCEPT_PFN(NAME_) int (__cdecl * NAME_)(void *)
#define __SEH_DECLARE_EXCEPT(NAME_) int __cdecl NAME_(void *)
@@ -162,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_) \
@@ -193,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; \
@@ -200,6 +200,9 @@
(void)_SEHTopTryLevel; \
(void)_SEHCurFrameP; \
(void)_SEHPrevTryLevelP; \
+ \
+ __SEH_USE_LABEL(_SEHBeginScope); \
+ __SEH_USE_LABEL(_SEHEndScope); \
\
{ \
__label__ _SEHBeforeTry; \
@@ -224,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; \
}
@@ -236,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 \
{
@@ -256,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:; \
@@ -272,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; \
\
@@ -282,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(); \
@@ -348,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;
\
@@ -361,8 +352,7 @@
__SEH_BARRIER; \
} \
} \
- \
- _SEHEndExcept:; \
+ _SEHEndExcept: __SEH_SIDE_EFFECT; \
} \
__SEH_END_SCOPE;
@@ -389,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 13:54:52 2008
@@ -53,25 +53,7 @@
FORCEINLINE
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, ep);
+ 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,21 +132,25 @@
{
int ret = 0;
volatile _SEH2TryLevel_t * trylevel;
- EXCEPTION_POINTERS ep;
-
- ep.ExceptionRecord = ExceptionRecord;
- ep.ContextRecord = ContextRecord;
frame->SF_Code = ExceptionRecord->ExceptionCode;
for(trylevel = frame->SF_TopTryLevel; trylevel != NULL; trylevel =
trylevel->ST_Next)
{
- ret = _SEH2Except(frame, trylevel, &ep);
+ 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);
+ }
}
}