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