在 2026-1-13 19:18, Luca Bacci 写道:
No don't use those macros. The x86-32 variant changes ESP which can break code. You should register SEH handlers by hand.Hello,I see that mingw-w64 provides helper macros for frame-based SEH (excpt.h). I have some questions: * How should I use them? * Are the macros supported on all architectures? * Are there limitations I should be aware of?
For x86-32:
Define a local variable `EXCEPTION_REGISTRATION_RECORD record`, set
`record.Next` field to `(EXCEPTION_REGISTRATION_RECORD*) __readfsdword(0)`,
set `record.Handler` to your handler, then call
`__writefsdword(0, (DWORD) &record)` to install it. Before the function
returns, it's necessary to call `__writefsdword(0, (DWORD) record.Next)`
to uninstall the handler.
The handler may be `__cdecl` or `__stdcall`. The definition of
`EXCEPTION_REGISTRATION_RECORD` uses `__stdcall`.
For x86-64:
Add `__asm__ (".seh_handler <your-handler>, @except, @unwind")` in your
function. A handler may be an exception handler, or an unwind handler,
or both. An exception handler is called only when an exception is raised.
An unwind handler is called only when the stack is unwound.
C code must be compiled with `-funwind-tables` or `-fexceptions`.
For ARM64:
Add `__asm__ (".seh_handler <your-handler>, @except")` in your function.
Unlike x86-64, a handler is both an exception handler and an unwind handler;
the `@unwind` flag is ignored.
To determine whether an exception is being raised or the stack is being
unwound in the exception handler, test
`ExceptionRecord->ExceptionFlags & EXCEPTION_UNWINDING`.
C code must be compiled with `-funwind-tables` or `-fexceptions`.
--
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
