Add PSEH
Added: branches/new_headers/reactos/include/pseh/
Added: branches/new_headers/reactos/include/pseh/excpt.h
Added: branches/new_headers/reactos/include/pseh/framebased/
Added: branches/new_headers/reactos/include/pseh/framebased/internal.h
Added: branches/new_headers/reactos/include/pseh/framebased.h
Added: branches/new_headers/reactos/include/pseh/native.h
Added: branches/new_headers/reactos/include/pseh/prettybased.h
Added: branches/new_headers/reactos/include/pseh/setjmp.h

Added: branches/new_headers/reactos/include/pseh/excpt.h
--- branches/new_headers/reactos/include/pseh/excpt.h	2005-05-08 01:38:42 UTC (rev 15099)
+++ branches/new_headers/reactos/include/pseh/excpt.h	2005-05-08 01:39:14 UTC (rev 15100)
@@ -0,0 +1,32 @@
+/*
+ Copyright (c) 2004/2005 KJK::Hyperion
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+#ifndef KJK_PSEH_EXCPT_H_
+#define KJK_PSEH_EXCPT_H_
+
+#define _SEH_CONTINUE_EXECUTION (-1)
+#define _SEH_CONTINUE_SEARCH (0)
+#define _SEH_EXECUTE_HANDLER (1)
+
+#endif
+
+/* EOF */

Added: branches/new_headers/reactos/include/pseh/framebased/internal.h
--- branches/new_headers/reactos/include/pseh/framebased/internal.h	2005-05-08 01:38:42 UTC (rev 15099)
+++ branches/new_headers/reactos/include/pseh/framebased/internal.h	2005-05-08 01:39:14 UTC (rev 15100)
@@ -0,0 +1,132 @@
+/*
+ Copyright (c) 2004/2005 KJK::Hyperion
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+#ifndef KJK_PSEH_FRAMEBASED_INTERNAL_H_
+#define KJK_PSEH_FRAMEBASED_INTERNAL_H_
+
+struct _EXCEPTION_RECORD;
+struct _EXCEPTION_POINTERS;
+struct _CONTEXT;
+ 
+typedef int (__cdecl * _SEHFrameHandler_t)
+(
+ struct _EXCEPTION_RECORD *,
+ void *,
+ struct _CONTEXT *,
+ void *
+);
+
+typedef struct __SEHRegistration
+{
+ struct __SEHRegistration * SER_Prev;
+ _SEHFrameHandler_t SER_Handler;
+}
+_SEHRegistration_t;
+
+struct __SEHPortableFrame;
+struct __SEHPortableTryLevel;
+
+typedef long (__stdcall * _SEHFilter_t)
+(
+ struct _EXCEPTION_POINTERS *,
+ struct __SEHPortableFrame *
+);
+
+typedef __declspec(noreturn) void (__stdcall * _SEHHandler_t)
+(
+ struct __SEHPortableTryLevel *
+);
+
+typedef void (__stdcall * _SEHFinally_t)
+(
+ struct __SEHPortableFrame *
+);
+
+typedef struct __SEHHandlers
+{
+ _SEHFilter_t SH_Filter;
+ _SEHFinally_t SH_Finally;
+}
+_SEHHandlers_t;
+
+typedef struct __SEHPortableTryLevel
+{
+ struct __SEHPortableTryLevel * SPT_Next;
+ const _SEHHandlers_t * SPT_Handlers;
+}
+_SEHPortableTryLevel_t;
+
+typedef struct __SEHPortableFrame
+{
+ _SEHRegistration_t SPF_Registration;
+ unsigned long SPF_Code;
+ _SEHHandler_t SPF_Handler;
+ _SEHPortableTryLevel_t * SPF_TopTryLevel;
+}
+_SEHPortableFrame_t;
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+extern void __stdcall _SEHEnterFrame_s
+(
+ _SEHPortableFrame_t *,
+ _SEHPortableTryLevel_t *
+);
+
+extern void __stdcall _SEHEnterTry_s(_SEHPortableTryLevel_t *);
+extern void __stdcall _SEHLeave_s(void);
+
+#if !defined(_SEH_NO_FASTCALL)
+# ifdef _M_IX86
+#  define _SEH_FASTCALL __fastcall
+# else
+#  define _SEH_FASTCALL __stdcall
+# endif
+
+extern void _SEH_FASTCALL _SEHEnterFrame_f
+(
+ _SEHPortableFrame_t *,
+ _SEHPortableTryLevel_t *
+);
+
+extern void _SEH_FASTCALL _SEHEnterTry_f(_SEHPortableTryLevel_t *);
+extern void _SEH_FASTCALL _SEHLeave_f(void);
+
+# define _SEHEnterFrame _SEHEnterFrame_f
+# define _SEHEnterTry   _SEHEnterTry_f
+# define _SEHLeave      _SEHLeave_f
+#else
+# define _SEHEnterFrame _SEHEnterFrame_s
+# define _SEHEnterTry   _SEHEnterTry_s
+# define _SEHLeave      _SEHLeave_s
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+/* EOF */

Added: branches/new_headers/reactos/include/pseh/framebased.h
--- branches/new_headers/reactos/include/pseh/framebased.h	2005-05-08 01:38:42 UTC (rev 15099)
+++ branches/new_headers/reactos/include/pseh/framebased.h	2005-05-08 01:39:14 UTC (rev 15100)
@@ -0,0 +1,389 @@
+/*
+ Copyright (c) 2004/2005 KJK::Hyperion
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+#ifndef KJK_PSEH_FRAMEBASED_H_
+#define KJK_PSEH_FRAMEBASED_H_
+
+#include <pseh/framebased/internal.h>
+#include <pseh/excpt.h>
+
+#ifndef offsetof
+# include <stddef.h>
+#endif
+
+/*
+ Fall back to non-optimal, non-native NLG implementation for environments
+ without their own (e.g., currently, kernel-mode ReactOS/Windows). THIS IS NOT
+ RECOMMENDED AND IT WILL BE DROPPED IN A FUTURE VERSION BECAUSE IT MAY CAUSE
+ SEVERE STACK CORRUPTION. REIMPLEMENT OR PORT YOUR COMPILER'S NATIVE NLG
+ IMPLEMENTATION INSTEAD.
+*/
+#ifdef _SEH_NO_NATIVE_NLG
+# include <pseh/setjmp.h>
+#else
+# include <setjmp.h>
+# define _SEHLongJmp longjmp
+# define _SEHSetJmp setjmp
+# define _SEHJmpBuf_t jmp_buf
+#endif
+unsigned long DbgPrint(char * Format,...);
+typedef struct __SEHFrame
+{
+ _SEHPortableFrame_t SEH_Header;
+ void * SEH_Locals;
+}
+_SEHFrame_t;
+
+typedef struct __SEHTryLevel
+{
+ _SEHPortableTryLevel_t ST_Header;
+ _SEHJmpBuf_t ST_JmpBuf;
+}
+_SEHTryLevel_t;
+
+static __declspec(noreturn) __inline void __stdcall _SEHCompilerSpecificHandler
+(
+ _SEHPortableTryLevel_t * trylevel
+)
+{
+ _SEHTryLevel_t * mytrylevel;
+ mytrylevel = _SEH_CONTAINING_RECORD(trylevel, _SEHTryLevel_t, ST_Header);
+ _SEHLongJmp(mytrylevel->ST_JmpBuf, 1);
+}
+
+static const int _SEHScopeKind = 1;
+static _SEHPortableFrame_t * const _SEHPortableFrame = 0;
+
+/* SHARED LOCALS */
+/* Access the locals for the current frame */
+#define _SEH_ACCESS_LOCALS(LOCALS_) \
+ _SEH_LOCALS_TYPENAME(LOCALS_) * _SEHPLocals; \
+ _SEHPLocals = \
+  _SEH_PVOID_CAST \
+  ( \
+   _SEH_LOCALS_TYPENAME(LOCALS_) *, \
+   _SEH_CONTAINING_RECORD(_SEHPortableFrame, _SEHFrame_t, SEH_Header) \
+    ->SEH_Locals \
+  );
+
+/* Access local variable VAR_ */
+#define _SEH_VAR(VAR_) _SEHPLocals->VAR_
+
+/* FILTER FUNCTIONS */
+/* Declares a filter function's prototype */
+#define _SEH_FILTER(NAME_) \
+ long __stdcall NAME_ \
+ ( \
+  struct _EXCEPTION_POINTERS * _SEHExceptionPointers, \
+  struct __SEHPortableFrame * _SEHPortableFrame \
+ )
+
+/* Declares a static filter */
+#define _SEH_STATIC_FILTER(ACTION_) ((_SEHFilter_t)((ACTION_) + 2))
+
+/* Declares a PSEH filter wrapping a regular filter function */
+#define _SEH_WRAP_FILTER(WRAPPER_, NAME_) \
+ static __inline _SEH_FILTER(WRAPPER_) \
+ { \
+  return (NAME_)(_SEHExceptionPointers); \
+ }
+
+/* FINALLY FUNCTIONS */
+/* Declares a finally function's prototype */
+#define _SEH_FINALLYFUNC(NAME_) \
+ void __stdcall NAME_ \
+ ( \
+  struct __SEHPortableFrame * _SEHPortableFrame \
+ )
+
+/* Declares a PSEH finally function wrapping a regular function */
+#define _SEH_WRAP_FINALLY(WRAPPER_, NAME_) \
+ _SEH_WRAP_FINALLY_ARGS(WRAPPER_, NAME_, ())
+
+#define _SEH_WRAP_FINALLY_ARGS(WRAPPER_, NAME_, ARGS_) \
+ static __inline _SEH_FINALLYFUNC(WRAPPER_) \
+ { \
+  NAME_ ARGS_; \
+ }
+
+#define _SEH_WRAP_FINALLY_LOCALS_ARGS(WRAPPER_, LOCALS_, NAME_, ARGS_) \
+ static __inline _SEH_FINALLYFUNC(WRAPPER_) \
+ { \
+  _SEH_ACCESS_LOCALS(LOCALS_); \
+  NAME_ ARGS_; \
+ }
+
+/* SAFE BLOCKS */
+#define _SEHX_TRY_FINALLY(FINALLY_) \
+ _SEH_TRY_FILTER_FINALLY \
+ ( \
+  _SEH_STATIC_FILTER(_SEH_CONTINUE_SEARCH), \
+  (FINALLY_) \
+ )
+
+#define _SEHX_END_FINALLY _SEH_HANDLE _SEH_END
+
+#define _SEHX_TRY_FILTER(FILTER_) \
+ _SEH_TRY_FILTER_FINALLY((FILTER_), 0)
+
+#define _SEHX_TRY_HANDLE_FINALLY(FINALLY_) \
+ _SEH_TRY_FILTER_FINALLY \
+ ( \
+  _SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER), \
+  (FINALLY_) \
+ )
+
+#define _SEHX_TRY \
+ _SEH_TRY_HANDLE_FINALLY(0)
+
+#ifdef __cplusplus
+# define _SEH_DECLARE_HANDLERS(FILTER_, FINALLY_) \
+  static const _SEHHandlers_t _SEHHandlers = { (FILTER_), (FINALLY_) };
+#else
+# define _SEH_DECLARE_HANDLERS(FILTER_, FINALLY_) \
+  _SEHHandlers_t _SEHHandlers = { (0), (0) };                                  \
+  _SEHHandlers.SH_Filter = (FILTER_);                                          \
+  _SEHHandlers.SH_Finally = (FINALLY_);
+#endif
+
+#define _SEHX_TRY_FILTER_FINALLY(FILTER_, FINALLY_) \
+ {                                                                             \
+  _SEHPortableFrame_t * const _SEHCurPortableFrame = _SEHPortableFrame;        \
+                                                                               \
+  {                                                                            \
+   _SEHFrame_t _SEHFrame;                                                      \
+   _SEHTryLevel_t _SEHTryLevel;                                                \
+   _SEHPortableFrame_t * const _SEHPortableFrame =                             \
+    _SEHScopeKind ? &_SEHFrame.SEH_Header : _SEHCurPortableFrame;              \
+                                                                               \
+   (void)_SEHPortableFrame;                                                    \
+                                                                               \
+   _SEH_DECLARE_HANDLERS((FILTER_), (FINALLY_));                               \
+                                                                               \
+   _SEHTryLevel.ST_Header.SPT_Handlers = &_SEHHandlers;                        \
+                                                                               \
+   if(_SEHScopeKind)                                                           \
+   {                                                                           \
+    if(&_SEHLocals != _SEHDummyLocals)                                         \
+     _SEHFrame.SEH_Locals = &_SEHLocals;                                       \
+                                                                               \
+    _SEHFrame.SEH_Header.SPF_Handler = _SEHCompilerSpecificHandler;            \
+    _SEHEnterFrame(&_SEHFrame.SEH_Header, &_SEHTryLevel.ST_Header);            \
+   }                                                                           \
+   else                                                                        \
+    _SEHEnterTry(&_SEHTryLevel.ST_Header);                                     \
+                                                                               \
+   {                                                                           \
+    static const int _SEHScopeKind = 0;                                        \
+    (void)_SEHScopeKind;                                                       \
+                                                                               \
+    if(_SEHSetJmp(_SEHTryLevel.ST_JmpBuf) == 0)                                \
+    {                                                                          \
+     for(;;)                                                                   \
+     {
+
+#define _SEHX_HANDLE \
+                                                                               \
+      break;                                                                   \
+     }                                                                         \
+                                                                               \
+     _SEHLeave();                                                              \
+    }                                                                          \
+    else                                                                       \
+    {                                                                          \
+     _SEHLeave();
+
+#define _SEHX_END \
+    }                                                                          \
+                                                                               \
+    if(_SEHHandlers.SH_Finally)                                                \
+     _SEHHandlers.SH_Finally(_SEHPortableFrame);                               \
+   }                                                                           \
+  }                                                                            \
+ }
+
+#define _SEHX_LEAVE break
+
+#define _SEHX_GetExceptionCode() (unsigned long)(_SEHPortableFrame->SPF_Code)
+
+#define _SEHX_GetExceptionPointers() \
+ ((struct _EXCEPTION_POINTERS *)_SEHExceptionPointers)
+
+#define _SEHX_AbnormalTermination() (_SEHPortableFrame->SPF_Code != 0)
+
+/* New syntax */
+
+/*
+ NOTE: do not move, remove or modify any instance of _SEH2_ASSUME and
+ _SEH2_ASSUMING without doing extensive tests for correctness. Compilers can
+ generate the wrong code in presence of __assume in unpredictable ways. BE SURE
+ IT DOESN'T HAPPEN
+*/
+#if defined(_MSC_VER) && (_MSC_VER > 1200)
+# define _SEH2_ASSUME(X_) __assume(X_)
+# if !defined(_SEH_NO_NATIVE_NLG)
+ /*
+  If we use the native setjmp, the compiler stops keeping track of variables, so
+  their actual values don't matter anymore. Optimize out some assignments
+ */
+#  define _SEH2_ASSUMING(X_)
+# else
+ /* No native setjmp, no magic, no assumptions. Actually set the values */
+#  define _SEH2_ASSUMING(X_) X_
+# endif
+#else
+# define _SEH2_ASSUME(X_)
+# define _SEH2_ASSUMING(X_) X_
+#endif
+
+#ifdef __cplusplus
+# define _SEH2_INIT_CONST static const
+#else
+# define _SEH2_INIT_CONST register const
+#endif
+
+#define _SEH_LEAVE break
+
+#define _SEH_TRY \
+ {                                                                             \
+  _SEH2_INIT_CONST int _SEH2TopTryLevel = (_SEHScopeKind != 0);                \
+  _SEHPortableFrame_t * const _SEH2CurPortableFrame = _SEHPortableFrame;       \
+                                                                               \
+  {                                                                            \
+   static const int _SEHScopeKind = 0;                                         \
+   register int _SEH2State = 0;                                                \
+   register int _SEH2Handle = 0;                                               \
+   _SEHFrame_t _SEH2Frame;                                                     \
+   _SEHTryLevel_t _SEH2TryLevel;                                               \
+   _SEHPortableFrame_t * const _SEHPortableFrame =                             \
+    _SEH2TopTryLevel ? &_SEH2Frame.SEH_Header : _SEH2CurPortableFrame;         \
+                                                                               \
+   (void)_SEHScopeKind;                                                        \
+   (void)_SEHPortableFrame;                                                    \
+   (void)_SEH2Handle;                                                          \
+                                                                               \
+   for(;;)                                                                     \
+   {                                                                           \
+    if(_SEH2State)                                                             \
+    {                                                                          \
+     for(;;)                                                                   \
+     {                                                                         \
+      {
+
+#define _SEH_EXCEPT(FILTER_) \
+      }                                                                        \
+                                                                               \
+      break;                                                                   \
+     }                                                                         \
+                                                                               \
+     _SEH2_ASSUME(_SEH2Handle == 0);                                           \
+     break;                                                                    \
+    }                                                                          \
+    else                                                                       \
+    {                                                                          \
+     _SEH_DECLARE_HANDLERS((FILTER_), 0);                                      \
+                                                                               \
+     _SEH2TryLevel.ST_Header.SPT_Handlers = &_SEHHandlers;                     \
+                                                                               \
+     if(_SEH2TopTryLevel)                                                      \
+     {                                                                         \
+      if(&_SEHLocals != _SEHDummyLocals)                                       \
+       _SEH2Frame.SEH_Locals = &_SEHLocals;                                    \
+                                                                               \
+      _SEH2Frame.SEH_Header.SPF_Handler = _SEHCompilerSpecificHandler;         \
+      _SEHEnterFrame(&_SEH2Frame.SEH_Header, &_SEH2TryLevel.ST_Header);        \
+     }                                                                         \
+     else                                                                      \
+      _SEHEnterTry(&_SEH2TryLevel.ST_Header);                                  \
+                                                                               \
+     if((_SEH2Handle = _SEHSetJmp(_SEH2TryLevel.ST_JmpBuf)) == 0)              \
+     {                                                                         \
+      _SEH2_ASSUMING(++ _SEH2State);                                           \
+      _SEH2_ASSUME(_SEH2State != 0);                                           \
+      continue;                                                                \
+     }                                                                         \
+     else                                                                      \
+     {                                                                         \
+      break;                                                                   \
+     }                                                                         \
+    }                                                                          \
+                                                                               \
+    break;                                                                     \
+   }                                                                           \
+                                                                               \
+   _SEHLeave();                                                                \
+                                                                               \
+   if(_SEH2Handle) \
+   {
+
+#define _SEH_FINALLY(FINALLY_) \
+      }                                                                        \
+                                                                               \
+      break;                                                                   \
+     }                                                                         \
+                                                                               \
+     _SEHLeave();                                                              \
+     break;                                                                    \
+    }                                                                          \
+    else                                                                       \
+    {                                                                          \
+     _SEH_DECLARE_HANDLERS(0, (FINALLY_));                                     \
+                                                                               \
+     _SEH2TryLevel.ST_Header.SPT_Handlers = &_SEHHandlers;                     \
+                                                                               \
+     if(_SEH2TopTryLevel)                                                      \
+     {                                                                         \
+      if(&_SEHLocals != _SEHDummyLocals)                                       \
+       _SEH2Frame.SEH_Locals = &_SEHLocals;                                    \
+                                                                               \
+      _SEH2Frame.SEH_Header.SPF_Handler = 0;                                   \
+      _SEHEnterFrame(&_SEH2Frame.SEH_Header, &_SEH2TryLevel.ST_Header);        \
+     }                                                                         \
+     else                                                                      \
+      _SEHEnterTry(&_SEH2TryLevel.ST_Header);                                  \
+                                                                               \
+     ++ _SEH2State;                                                            \
+     _SEH2_ASSUME(_SEH2State != 0);                                            \
+     continue;                                                                 \
+    }                                                                          \
+                                                                               \
+    break;                                                                     \
+   }                                                                           \
+                                                                               \
+   (FINALLY_)(&_SEH2Frame.SEH_Header);                                         \
+   if(0)                                                                       \
+   {
+
+#define _SEH_END \
+   } \
+  }                                                                            \
+ }
+
+#define _SEH_HANDLE _SEH_EXCEPT(_SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER))
+
+#define _SEH_GetExceptionCode     _SEHX_GetExceptionCode
+#define _SEH_GetExceptionPointers _SEHX_GetExceptionPointers
+#define _SEH_AbnormalTermination  _SEHX_AbnormalTermination
+
+#endif
+
+/* EOF */

Added: branches/new_headers/reactos/include/pseh/native.h
--- branches/new_headers/reactos/include/pseh/native.h	2005-05-08 01:38:42 UTC (rev 15099)
+++ branches/new_headers/reactos/include/pseh/native.h	2005-05-08 01:39:14 UTC (rev 15100)
@@ -0,0 +1,242 @@
+/*
+ Copyright (c) 2004/2005 KJK::Hyperion
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+
+#ifndef KJK_PSEH_NATIVE_H_
+#define KJK_PSEH_NATIVE_H_
+
+#include <excpt.h>
+#include <pseh/excpt.h>
+
+/*
+ Note: just define __inline to an empty symbol if your C compiler doesn't
+ support it
+*/
+#ifdef __cplusplus
+# ifndef __inline
+#  define __inline inline
+# endif
+#endif
+
+typedef long (__stdcall * _SEHFilter_t)
+(
+ long,
+ struct _EXCEPTION_POINTERS *,
+ void *
+);
+
+typedef void (__stdcall * _SEHFinally_t)
+(
+ int,
+ void *
+);
+
+static __inline long _SEHCallFilter
+(
+ _SEHFilter_t _SEHFilter,
+ long _SEHExceptionCode,
+ struct _EXCEPTION_POINTERS * _SEHExceptionPointers,
+ void * _SEHPVLocals
+)
+{
+ if(_SEHFilter == _SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER))
+  return _SEH_EXECUTE_HANDLER;
+ else if(_SEHFilter == _SEH_STATIC_FILTER(_SEH_CONTINUE_SEARCH))
+  return _SEH_CONTINUE_SEARCH;
+ else if(_SEHFilter == _SEH_STATIC_FILTER(_SEH_CONTINUE_EXECUTION))
+  return _SEH_CONTINUE_EXECUTION;
+ else if(_SEHFilter)
+  return _SEHFilter(_SEHExceptionCode, _SEHExceptionPointers, _SEHPVLocals);
+ else
+  return _SEH_CONTINUE_SEARCH;
+}
+
+static __inline void _SEHCallFinally
+(
+ _SEHFinally_t _SEHFinally,
+ int _SEHAbnormalTermination,
+ void * _SEHPVLocals
+)
+{
+ if(_SEHFinally)
+  (_SEHFinally)(_SEHAbnormalTermination, _SEHPVLocals);
+}
+
+/* SHARED LOCALS */
+/* Access the locals for the current frame */
+#define _SEH_ACCESS_LOCALS(LOCALS_) \
+ _SEH_LOCALS_TYPENAME(LOCALS_) * _SEHPLocals; \
+ _SEHPLocals = _SEH_PVOID_CAST(_SEH_LOCALS_TYPENAME(LOCALS_) *, _SEHPVLocals);
+
+/* Access local variable VAR_ */
+#define _SEH_VAR(VAR_) _SEHPLocals->VAR_
+
+/* FILTER FUNCTIONS */
+/* Declares a filter function's prototype */
+#define _SEH_FILTER(NAME_) \
+ long __stdcall NAME_ \
+ ( \
+  long _SEHExceptionCode, \
+  struct _EXCEPTION_POINTERS * _SEHExceptionPointers, \
+  void * _SEHPVLocals \
+ )
+
+/* Declares a static filter */
+#define _SEH_STATIC_FILTER(ACTION_) ((_SEHFilter_t)((ACTION_) + 2))
+
+/* Declares a PSEH filter wrapping a regular filter function */
+#define _SEH_WRAP_FILTER(WRAPPER_, NAME_) \
+ static __inline _SEH_FILTER(WRAPPER_) \
+ { \
+  return (NAME_)(_SEHExceptionPointers); \
+ }
+
+/* FINALLY FUNCTIONS */
+/* Declares a finally function's prototype */
+#define _SEH_FINALLYFUNC(NAME_) \
+ void __stdcall NAME_ \
+ ( \
+  int _SEHAbnormalTermination, \
+  void * _SEHPVLocals \
+ )
+
+/* Declares a PSEH finally function wrapping a regular function */
+#define _SEH_WRAP_FINALLY(WRAPPER_, NAME_) \
+ _SEH_WRAP_FINALLY_ARGS(WRAPPER_, NAME_, ())
+
+#define _SEH_WRAP_FINALLY_ARGS(WRAPPER_, NAME_, ARGS_) \
+ static __inline _SEH_FINALLYFUNC(WRAPPER_) \
+ { \
+  NAME_ ARGS_; \
+ }
+
+#define _SEH_WRAP_FINALLY_LOCALS_ARGS(WRAPPER_, LOCALS_, NAME_, ARGS_) \
+ static __inline _SEH_FINALLYFUNC(WRAPPER_) \
+ { \
+  _SEH_ACCESS_LOCALS(LOCALS_); \
+  NAME_ ARGS_; \
+ }
+
+/* SAFE BLOCKS */
+#define _SEH_TRY_FINALLY(FINALLY_) \
+ _SEH_TRY_FILTER_FINALLY \
+ ( \
+  _SEH_STATIC_FILTER(_SEH_CONTINUE_SEARCH), \
+  (FINALLY_) \
+ )
+
+#define _SEH_END_FINALLY _SEH_HANDLE _SEH_END
+
+#define _SEH_TRY_FILTER(FILTER_) \
+ _SEH_TRY_FILTER_FINALLY((FILTER_), NULL)
+
+#define _SEH_TRY_HANDLE_FINALLY(FINALLY_) \
+ _SEH_TRY_FILTER_FINALLY \
+ ( \
+  _SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER), \
+  (FINALLY_) \
+ )
+
+#define _SEH_TRY \
+ _SEH_TRY_HANDLE_FINALLY(NULL)
+
+#define _SEH_CALL_FILTER(FILTER_) \
+ _SEHCallFilter                                                                \
+ (                                                                             \
+  (FILTER_),                                                                   \
+  GetExceptionCode(),                                                          \
+  GetExceptionPointers(),                                                      \
+  _SEHPVLocals                                                                 \
+ )
+
+#define _SEH_CALL_FINALLY(FINALLY_) \
+ _SEHCallFinally((FINALLY_), (AbnormalTermination() != 0), _SEHPVLocals)
+
+#define _SEH_TRY_FILTER_FINALLY(FILTER_, FINALLY_) \
+ __try                                                                         \
+ {                                                                             \
+  _SEHFinally_t _SEHFinally = (FINALLY_);                                      \
+  _SEHFilter_t _SEHFilter = (FILTER_);                                         \
+  void * _SEHPVLocals = &_SEHLocals;                                           \
+  (void)_SEHPVLocals;                                                          \
+                                                                               \
+  __try                                                                        \
+  {
+
+#define _SEH_HANDLE \
+  }                                                                            \
+  __except(_SEH_CALL_FILTER(_SEHFilter))                                       \
+  {                                                                            \
+   struct _EXCEPTION_POINTERS * _SEHExceptionPointers = GetExceptionPointers();\
+   long _SEHExceptionCode = GetExceptionCode();                                \
+
+#define _SEH_END \
+  }                                                                            \
+ }                                                                             \
+ __finally                                                                     \
+ {                                                                             \
+  _SEH_CALL_FINALLY(_SEHFinally);                                              \
+ }
+
+#define _SEH_LEAVE __leave
+
+#define _SEH_GetExceptionCode() (_SEHExceptionCode)
+#define _SEH_GetExceptionPointers() (_SEHExceptionPointers)
+#define _SEH_AbnormalTermination() (_SEHAbnormalTermination)
+
+/* New syntax */
+
+#define _SEH2_TRY \
+ {                                                                             \
+  void * _SEHPVLocals = &_SEHLocals;                                           \
+  (void)_SEHPVLocals;                                                          \
+                                                                               \
+  __try                                                                        \
+  {
+
+#define _SEH2_EXCEPT(FILTER_) \
+  }                                                                            \
+  __except(_SEH_CALL_FILTER(FILTER_))                                          \
+  {                                                                            \
+   struct _EXCEPTION_POINTERS * _SEHExceptionPointers = GetExceptionPointers();\
+   long _SEHExceptionCode = GetExceptionCode();                                \
+
+#define _SEH2_FINALLY(FINALLY_) \
+  }                                                                            \
+  __finally                                                                    \
+  {                                                                            \
+   _SEH_CALL_FINALLY(FINALLY_)
+
+#define _SEH2_END \
+  }                                                                            \
+ }
+
+#define _SEH2_HANDLE _SEH2_EXCEPT(_SEH_STATIC_FILTER(_SEH_EXECUTE_HANDLER))
+
+#define _SEH2_LEAVE _SEH_LEAVE
+
+#define _SEH2_GetExceptionCode     _SEH_GetExceptionCode
+#define _SEH2_GetExceptionPointers _SEH_GetExceptionPointers
+#define _SEH2_AbnormalTermination  _SEH_AbnormalTermination
+
+#endif
+
+/* EOF */

Added: branches/new_headers/reactos/include/pseh/prettybased.h
--- branches/new_headers/reactos/include/pseh/prettybased.h	2005-05-08 01:38:42 UTC (rev 15099)
+++ branches/new_headers/reactos/include/pseh/prettybased.h	2005-05-08 01:39:14 UTC (rev 15100)
@@ -0,0 +1,299 @@
+/*
+ Copyright (c) 2004 KJK::Hyperion
+ 
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
+ this software and associated documentation files (the "Software"), to deal in
+ the Software without restriction, including without limitation the rights to
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+ of the Software, and to permit persons to whom the Software is furnished to do
+ so, subject to the following conditions:
+ 
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+ 
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+*/
+/*
+Pretty PSEH
+
+Made to be macro compatible with ms seh syntax and to be pretty, having the
+finally block inline etc. Being pretty is not cheap. PPSEH has more
+overhead than PSEH, thou mostly during exception/unwinding. Normal execution
+only add the overhead of one setjmp, and only in the try/finally case.
+PPSEH is probably much less portable than PSEH also.....
+
+ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!ALERT!
+-must always use non-native NLG cause a special version of longjmp (which doesn't
+restore esp) is needed
+
+-compiler must use ebp as stack frame pointer, cause the finally block rely
+on this to access external variables
+
+-all external variables that are used in the except/finally block MUST be volatile
+to prevent variables from being optimized into registers.
+See: http://alphalinux.org/archives/axp-list/1998/February1998/0330.html
+
+-you can't use return within a try/except/finally block
+
+-you can't use __LEAVE within a (for/do/while) loop. it will only leave the loop
+and not the try-block itself
+
+
+USAGE:
+
+__TRY{
+   __LEAVE;
+}
+__EXCEPT(_SEH_STATIC_FILTER(EXCEPTION_EXECUTE_HANDLER)){
+}
+__ENDTRY;
+
+
+__TRY{
+}
+__FINALLY{
+}
+__ENDTRY;
+
+
+_SEH_FILTER(filter){
+   return EXCEPTION_EXECUTE_HANDLER;
+}
+__TRY2{
+}
+__EXCEPT2(filter){
+}
+__FINALLY2{
+}
+__ENDTRY2;
+
+
+
+-Gunnar
+
+*/
+
+
+#ifndef KJK_PPSEH_FRAMEBASED_H_
+#define KJK_PPSEH_FRAMEBASED_H_
+
+#include <pseh/framebased/internal.h>
+#include <pseh/excpt.h>
+#include <malloc.h>
+
+#ifndef offsetof
+# include <stddef.h>
+#endif
+
+/*
+Must always use non-native NLG since we need a special version of longjmp which does
+not restore esp
+*/
+#include <pseh/setjmp.h>
+
+
+typedef struct __SEHFrame
+{
+ _SEHPortableFrame_t SEH_Header;
+ _SEHJmpBuf_t SEH_JmpBuf;
+ _SEHJmpBuf_t* SEH_JmpRetPtr;
+}
+_SEHFrame_t;
+
+/*
+ Note: just define __inline to an empty symbol if your C compiler doesn't
+ support it
+*/
+#ifdef __cplusplus
+# ifndef __inline
+#  define __inline inline
+# endif
+#endif
+
+
+/* FILTER FUNCTIONS */
+/* Declares a filter function's prototype */
+#define _SEH_FILTER(NAME_) \
+ long __stdcall NAME_ \
+ ( \
+  struct _EXCEPTION_POINTERS * _SEHExceptionPointers, \
+  struct __SEHPortableFrame * _SEHPortableFrame \
+ )
+
+
+/* Declares a static filter */
+#define _SEH_STATIC_FILTER(ACTION_) ((_SEHFilter_t)((ACTION_) + 2))
+
+
+static __declspec(noreturn) __inline void __stdcall _SEHCompilerSpecificHandler
+(
+ _SEHPortableFrame_t * frame
+)
+{
+   _SEHFrame_t * myframe;
+   myframe = (_SEHFrame_t *)(((char *)frame) - offsetof(_SEHFrame_t, SEH_Header));
+   _SEHLongJmp(myframe->SEH_JmpBuf, 1);
+}
+
+
+
+void __stdcall _FinallyPretty
+(
+ struct __SEHPortableFrame * frame
+)
+{
+   _SEHFrame_t * myframe;
+   _SEHJmpBuf_t jmpRetBuf;
+   
+   myframe = (_SEHFrame_t *)(((char *)frame) - offsetof(_SEHFrame_t, SEH_Header));   
+    
+   if(_SEHSetJmp(jmpRetBuf) == 0)
+   {
+      myframe->SEH_JmpRetPtr = &jmpRetBuf;
+      _SEHLongJmp_KeepEsp(myframe->SEH_JmpBuf, 2);
+   }
+}
+
+
+        
+#define ___EXCEPT_DUAL(filter)                                                \
+         } while(0);                                                          \
+                                                                              \
+         _SEHLeave(&_SEHFrame->SEH_Header);                                   \
+      }                                                                       \
+      else                                                                    \
+      {                                                                       \
+         _SEHHandlers.SH_Filter = (filter);                                   \
+         _SEHHandlers.SH_Finally = _FinallyPretty;                            \
+                                                                              \
+         if(_loop == 2 || (_ret = _SEHSetJmp(_SEHFrame->SEH_JmpBuf)))         \
+         {                                                                    \
+            if (_ret == 1)                                                    \
+            {                                                                 \
+               _SEHLeave(&_SEHFrame->SEH_Header);                             \
+               do                                                             \
[truncated at 1000 lines; 178 more skipped]