在 2025-12-26 20:53, Pali Rohár 写道:
On Friday 26 December 2025 00:13:25 Pali Rohár wrote:For non-i386 builds use asm .seh_handler directive for registering the SEH handler. This directive register SEH handler for the whole function and therefore function has to be marked as noinline. Use exactly same SEH handler as it used for i386 builds, function API is same across platforms.This asm .seh_handler directive requires support for compiler, assembler and linker. So check for SEH_INLINE_ASM macro in the same way as it is in the mingw-w64-crt/crt/crtexe.c file. --- mingw-w64-libraries/winpthreads/src/thread.c | 28 ++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c index e2f9806ad579..ed2e8d07d84a 100644 --- a/mingw-w64-libraries/winpthreads/src/thread.c +++ b/mingw-w64-libraries/winpthreads/src/thread.c @@ -86,7 +86,16 @@ SetThreadName_VEH (PEXCEPTION_POINTERS ExceptionInfo) return EXCEPTION_CONTINUE_SEARCH; }-#if !defined(_MSC_VER) && defined(__i386__)+#if defined(__SEH__) && (!defined(__clang__) || __clang_major__ >= 7) +#define SEH_INLINE_ASM +#ifdef __arm__ +#define ASM_EXCEPT "%%except" +#else +#define ASM_EXCEPT "@except" +#endif +#endif + +#if !defined(_MSC_VER) && (defined(__i386__) || defined(SEH_INLINE_ASM)) static EXCEPTION_DISPOSITION __cdecl SetThreadName_SEH (EXCEPTION_RECORD *ExceptionRecord, PVOID EstablisherFrame, CONTEXT *ContextRecord, PVOID DispatcherContext) { @@ -110,6 +119,9 @@ typedef struct _THREADNAME_INFO DWORD dwFlags; /* reserved for future use, must be zero */ } THREADNAME_INFO;+#if !defined(_MSC_VER) && !defined(__i386__) && defined(SEH_INLINE_ASM)+WINPTHREADS_ATTRIBUTE((noinline)) /* required for asm .seh_handler directive */ +#endif static void SetThreadName (DWORD dwThreadID, LPCSTR szThreadName) { @@ -152,8 +164,20 @@ SetThreadName (DWORD dwThreadID, LPCSTR szThreadName) __writefsdword (0, (DWORD) &exception_record); /* register our SEH handler */ RaiseException (EXCEPTION_SET_THREAD_NAME, 0, infosize, (ULONG_PTR *) &info); __writefsdword (0, (DWORD) exception_record.Next); /* unregister our SEH handler */ +#elif defined(SEH_INLINE_ASM) + /* On other platforms is SEH handler registered at compile time. + Assembler directive .seh_handler statically register SEH handler for + the whole current function. It does not matter at which line is this + directive called. It always applies for the whole function, so also + for code before the directive itself. As this function does not do + anything other, we can register our SEH handler for the whole function. + Function has to be marked as noinline to ensure that SEH handler + would not be registered for parent caller function too. + */ + asm volatile (".seh_handler %p0, " ASM_EXCEPT :: "i" (SetThreadName_SEH));Here %p0 does not work with clang. I propose to use %c0 which seems to be supported also by clang.
`%c0` should be acceptable. There are some grammar errors in this piece of comment which I have to fix, but the changes in code look good.
This series of patches depend on some previous changes of VEH, so I have pushed both, with VEH changes reordered to the end.
-- Best regards, LIU Hao
OpenPGP_signature.asc
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
