public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* .seh_endproc having stack semantics
@ 2023-06-13 17:13 Julian Waters
  0 siblings, 0 replies; only message in thread
From: Julian Waters @ 2023-06-13 17:13 UTC (permalink / raw)
  To: binutils

[-- Attachment #1: Type: text/plain, Size: 1426 bytes --]

Hi all,

I have on my end, an almost working version of a Structured Exception
Handler that mimics the VC compiler:

#define WIN32_TRY \
        asm ("1:" "\n" \
             "\t" ".seh_handler __C_specific_handler, @except" "\n" \
    "\t" ".seh_handlerdata" "\n" \
    "\t" ".long 1" "\n" \
    "\t" ".rva 1b, 2f, 3f, 4f" "\n" \
    "\t" ".seh_code");

#define WIN32_EXCEPT(code, ...) \
        asm ("nop" "\n" \
             "\t" "2: nop" "\n" \
             "\t" "jmp 5f" "\n" \
             "\t" "3:" "\n" \
             "\t" "push rbp" "\n" \
             "\t" "mov rbp, rsp" "\n"); \
        volatile long filter = code; \
        asm ("\t" "mov eax, DWORD PTR -8[rbp]" "\n" \
             "\t" "pop rbp" "\n" \
             "\t" "ret" "\n" \
             "\t" "4:"); \
        __VA_ARGS__ \
asm ("5:");

However, it has a major flaw: It replaces the structured handler for the
function it is in, which means it can only be used once in any given
function, and wrecks any regular C++ exception handling that is also in the
same function. I believe this can be helped by allowing .seh_endproc to
have stack semantics, so an .seh_proc .seh_endproc pair can be nested
inside another, allowing the assembly programmer to create disposable
functions with labels for exception handlers, while right now doing so will
result in unmatched pair errors. Is there a way I could PR a change for
this somehow?

best regards.
Julian

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-13 17:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-13 17:13 .seh_endproc having stack semantics Julian Waters

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).