https://git.reactos.org/?p=reactos.git;a=commitdiff;h=53f498c96849edf7d9105c8e0943fc426792b8c4

commit 53f498c96849edf7d9105c8e0943fc426792b8c4
Author:     Timo Kreuzer <timo.kreu...@reactos.org>
AuthorDate: Sat Nov 16 21:48:13 2024 +0200
Commit:     Timo Kreuzer <timo.kreu...@reactos.org>
CommitDate: Wed Nov 27 10:50:03 2024 +0200

    [SDK][PSEH] Improve PSEH a bit
    
    Add PSEH include dir globally, include pseh2.h from excpt.h and add 
compatibility macros to reduce hacks in 3rd-perty code.
---
 CMakeLists.txt                                  |  5 +++--
 base/setup/lib/CMakeLists.txt                   |  1 -
 modules/rostests/apitests/compiler/ms/seh/seh.h |  3 ---
 sdk/include/vcruntime/excpt.h                   | 13 +++++++++----
 sdk/lib/pseh/i386/pseh3.c                       |  5 +++--
 sdk/lib/pseh/include/pseh/pseh2.h               | 11 ++++++++++-
 sdk/lib/pseh/include/pseh/pseh2_64.h            | 11 +++++++++++
 7 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 787f8e920ec..13916a9362a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -324,7 +324,8 @@ Enable this if the module uses typeid or dynamic_cast. You 
will probably need to
         sdk/include/ddk
         sdk/include/ndk
         sdk/include/reactos
-        sdk/include/reactos/libs)
+        sdk/include/reactos/libs
+        sdk/lib/pseh/include)
 
     if(ARCH STREQUAL "arm")
         include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/arm)
@@ -341,7 +342,7 @@ Enable this if the module uses typeid or dynamic_cast. You 
will probably need to
     add_subdirectory(sdk/include/asm)
 
     if(ARCH MATCHES "64$")
-        include(sdk/cmake/baseaddress64.cmake)  
+        include(sdk/cmake/baseaddress64.cmake)
     elseif(NO_ROSSYM)
         include(sdk/cmake/baseaddress_dwarf.cmake)
     elseif(MSVC)
diff --git a/base/setup/lib/CMakeLists.txt b/base/setup/lib/CMakeLists.txt
index 34b43018c23..836c9ef5967 100644
--- a/base/setup/lib/CMakeLists.txt
+++ b/base/setup/lib/CMakeLists.txt
@@ -5,7 +5,6 @@ if(_WINKD_)
 endif()
 
 include_directories(spapisup utils)
-include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/pseh/include)
 
 list(APPEND SOURCE
     spapisup/fileqsup.c
diff --git a/modules/rostests/apitests/compiler/ms/seh/seh.h 
b/modules/rostests/apitests/compiler/ms/seh/seh.h
index 35370152d24..0dc184001b4 100644
--- a/modules/rostests/apitests/compiler/ms/seh/seh.h
+++ b/modules/rostests/apitests/compiler/ms/seh/seh.h
@@ -23,9 +23,6 @@
 #define leave   _SEH2_LEAVE
 #define endtry  _SEH2_END
 #define abnormal_termination _abnormal_termination
-#define GetExceptionInformation() _SEH2_GetExceptionInformation()
-#define GetExceptionCode() _SEH2_GetExceptionCode()
-#define AbnormalTermination() _SEH2_AbnormalTermination()
 #define gcc_volatile volatile
 
 #endif
diff --git a/sdk/include/vcruntime/excpt.h b/sdk/include/vcruntime/excpt.h
index 798b19180f1..8bd6e90cc46 100644
--- a/sdk/include/vcruntime/excpt.h
+++ b/sdk/include/vcruntime/excpt.h
@@ -8,6 +8,10 @@
 
 #include <vcruntime.h>
 
+#if !defined(RC_INVOKED)
+#include <pseh/pseh2.h>
+#endif
+
 #pragma pack(push,_CRT_PACKING)
 
 #ifdef __cplusplus
@@ -71,16 +75,17 @@ typedef enum _EXCEPTION_DISPOSITION
 #endif
 
 #if defined(_MSC_VER) || (defined(__clang__) && defined(__SEH__))
+  unsigned long __cdecl _exception_code(void);
+  void *__cdecl _exception_info(void);
+  int __cdecl _abnormal_termination(void);
+#endif
+
 #define GetExceptionCode _exception_code
 #define exception_code _exception_code
 #define GetExceptionInformation (struct _EXCEPTION_POINTERS *)_exception_info
 #define exception_info (struct _EXCEPTION_POINTERS *)_exception_info
 #define AbnormalTermination _abnormal_termination
 #define abnormal_termination _abnormal_termination
-  unsigned long __cdecl _exception_code(void);
-  void *__cdecl _exception_info(void);
-  int __cdecl _abnormal_termination(void);
-#endif
 
 #define EXCEPTION_EXECUTE_HANDLER 1
 #define EXCEPTION_CONTINUE_SEARCH 0
diff --git a/sdk/lib/pseh/i386/pseh3.c b/sdk/lib/pseh/i386/pseh3.c
index ed7e0f43ad9..35db77d58b0 100644
--- a/sdk/lib/pseh/i386/pseh3.c
+++ b/sdk/lib/pseh/i386/pseh3.c
@@ -30,12 +30,13 @@
  *                   |-----------|
  */
 
+/* We need the full structure with all non-volatile */
+#define _SEH3$_FRAME_ALL_NONVOLATILES 1
+
 #include <stdarg.h>
 #include <windef.h>
 #include <winnt.h>
 
-/* We need the full structure with all non-volatile */
-#define _SEH3$_FRAME_ALL_NONVOLATILES 1
 #include "pseh3.h"
 #include "pseh3_asmdef.h"
 
diff --git a/sdk/lib/pseh/include/pseh/pseh2.h 
b/sdk/lib/pseh/include/pseh/pseh2.h
index 407557f2152..523d9ddd161 100644
--- a/sdk/lib/pseh/include/pseh/pseh2.h
+++ b/sdk/lib/pseh/include/pseh/pseh2.h
@@ -25,7 +25,6 @@
 
 #if defined(_USE_NATIVE_SEH) || (defined(_MSC_VER) && !(defined(__clang__) && 
defined(_M_AMD64)))
 
-#include <excpt.h>
 #define _SEH2_TRY __try
 #define _SEH2_FINALLY __finally
 #define _SEH2_EXCEPT(...) __except(__VA_ARGS__)
@@ -37,6 +36,8 @@
 #define _SEH2_LEAVE __leave
 #define _SEH2_VOLATILE
 
+#define __endtry
+
 #elif defined(__GNUC__) && !defined(__clang__) && defined(_M_AMD64)
 
 #include "pseh2_64.h"
@@ -101,6 +102,14 @@ _Pragma("GCC diagnostic pop")
 #define _SEH2_YIELD(x) x
 #define _SEH2_VOLATILE volatile
 
+#ifndef __try // Conflict with GCC's STL
+#define __try _SEH3_TRY
+#define __except _SEH3_EXCEPT
+#define __finally _SEH3_FINALLY
+#define __endtry _SEH3_END
+#define __leave _SEH3_LEAVE
+#endif
+
 #elif defined(__GNUC__)
 
 struct _EXCEPTION_RECORD;
diff --git a/sdk/lib/pseh/include/pseh/pseh2_64.h 
b/sdk/lib/pseh/include/pseh/pseh2_64.h
index 29af396a714..7d9414ddd2b 100644
--- a/sdk/lib/pseh/include/pseh/pseh2_64.h
+++ b/sdk/lib/pseh/include/pseh/pseh2_64.h
@@ -173,3 +173,14 @@ __seh2$$begin_except__: __MINGW_ATTRIB_UNUSED;
 #define _SEH2_LEAVE goto __seh2$$leave_scope__
 #define _SEH2_YIELD(__stmt) __stmt
 #define _SEH2_VOLATILE volatile
+
+#ifndef __try // Conflict with GCC's STL
+#define __try _SEH2_TRY
+#define __except _SEH2_EXCEPT
+#define __finally _SEH2_FINALLY
+#define __endtry _SEH2_END
+#define __leave goto __seh2$$leave_scope__
+#define _exception_info() __seh2$$exception_ptr__
+#define _exception_code() __seh2$$exception_code__
+#define _abnormal_termination() __seh2$$abnormal_termination__
+#endif

Reply via email to