https://git.reactos.org/?p=reactos.git;a=commitdiff;h=478317abcb5dbddc90e2d…
commit 478317abcb5dbddc90e2dbb27b7bb1e94c429442
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Thu Nov 28 12:25:46 2024 +0200
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Tue Jan 14 13:34:24 2025 +0200
[PSEH] Fix SEH compatibility macros for dummy PSEH
This is used with Clang, which does have native SEH, but it's broken and can cause
the compiler to crash. Previously some code was not handling this and instead used native
SEH for clang. Fix this by always using _SEH2_* macros instead of relying on __USE_PSEH2__
to be defined.
Try to improve things
---
sdk/include/psdk/rpc.h | 4 ----
sdk/include/reactos/wine/exception.h | 7 ++-----
sdk/include/vcruntime/excpt.h | 2 +-
sdk/lib/pseh/CMakeLists.txt | 1 -
sdk/lib/pseh/include/pseh/pseh2.h | 10 ++++++++++
5 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/sdk/include/psdk/rpc.h b/sdk/include/psdk/rpc.h
index b35c35fcad1..257823505d9 100644
--- a/sdk/include/psdk/rpc.h
+++ b/sdk/include/psdk/rpc.h
@@ -5,10 +5,6 @@
#endif /* _INC_WINDOWS */
#endif
-#if defined(__USE_PSEH2__) && !defined(RC_INVOKED)
-#include <pseh/pseh2.h>
-#endif
-
#ifndef __RPC_H__
#define __RPC_H__
diff --git a/sdk/include/reactos/wine/exception.h b/sdk/include/reactos/wine/exception.h
index f9333e8ff2a..8d0b3ea46c0 100644
--- a/sdk/include/reactos/wine/exception.h
+++ b/sdk/include/reactos/wine/exception.h
@@ -3,10 +3,7 @@
#include <setjmp.h>
#include <intrin.h>
-#ifdef __USE_PSEH2__
-# include <pseh/pseh2.h>
-# include <pseh/excpt.h>
-#endif
+#include <excpt.h>
#ifdef __cplusplus
extern "C" {
@@ -63,7 +60,7 @@ typedef struct _WINE_EXCEPTION_REGISTRATION_RECORD
#define __EXCEPT(func) _SEH2_EXCEPT(func(_SEH2_GetExceptionInformation()))
#define __EXCEPT_CTX(func, ctx) _SEH2_EXCEPT((func)(GetExceptionInformation(), ctx))
#define __EXCEPT_PAGE_FAULT _SEH2_EXCEPT(_SEH2_GetExceptionCode() ==
STATUS_ACCESS_VIOLATION)
-#define __EXCEPT_ALL _SEH2_EXCEPT(_SEH_EXECUTE_HANDLER)
+#define __EXCEPT_ALL _SEH2_EXCEPT(1)
#define __ENDTRY _SEH2_END
#define __FINALLY(func) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination()); }
#define __FINALLY_CTX(func, ctx) _SEH2_FINALLY { func(!_SEH2_AbnormalTermination(), ctx);
}; _SEH2_END
diff --git a/sdk/include/vcruntime/excpt.h b/sdk/include/vcruntime/excpt.h
index 8bd6e90cc46..faf5f2fe405 100644
--- a/sdk/include/vcruntime/excpt.h
+++ b/sdk/include/vcruntime/excpt.h
@@ -74,7 +74,7 @@ typedef enum _EXCEPTION_DISPOSITION
#endif
-#if defined(_MSC_VER) || (defined(__clang__) && defined(__SEH__))
+#if (defined(_MSC_VER) || (defined(__clang__) && defined(__SEH__))) &&
!defined(_exception_code)
unsigned long __cdecl _exception_code(void);
void *__cdecl _exception_info(void);
int __cdecl _abnormal_termination(void);
diff --git a/sdk/lib/pseh/CMakeLists.txt b/sdk/lib/pseh/CMakeLists.txt
index b2d23bb3588..e36a3f5fd87 100644
--- a/sdk/lib/pseh/CMakeLists.txt
+++ b/sdk/lib/pseh/CMakeLists.txt
@@ -57,5 +57,4 @@ target_include_directories(pseh INTERFACE include)
# Make it clear that we are using PSEH2
if ((CMAKE_C_COMPILER_ID STREQUAL "GNU") OR
((CMAKE_C_COMPILER_ID STREQUAL "Clang") AND (NOT (ARCH STREQUAL
"amd64"))))
- target_compile_definitions(pseh INTERFACE __USE_PSEH2__)
endif()
diff --git a/sdk/lib/pseh/include/pseh/pseh2.h b/sdk/lib/pseh/include/pseh/pseh2.h
index 523d9ddd161..a6d0ab5a3a2 100644
--- a/sdk/lib/pseh/include/pseh/pseh2.h
+++ b/sdk/lib/pseh/include/pseh/pseh2.h
@@ -23,6 +23,8 @@
#ifndef KJK_PSEH2_H_
#define KJK_PSEH2_H_
+#define __USE_PSEH2__
+
#if defined(_USE_NATIVE_SEH) || (defined(_MSC_VER) && !(defined(__clang__)
&& defined(_M_AMD64)))
#define _SEH2_TRY __try
@@ -86,6 +88,14 @@ _Pragma("GCC diagnostic pop")
#define _SEH2_LEAVE goto __seh2_scope_end__;
#define _SEH2_VOLATILE volatile
+#define __try _SEH2_TRY
+#define __except _SEH2_EXCEPT
+#define __finally _SEH2_FINALLY
+#define __endtry _SEH2_END
+#define __leave _SEH2_LEAVE
+#define _exception_code() 0
+#define _exception_info() ((void*)0)
+
#elif defined(_USE_PSEH3)
#include "pseh3.h"