public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] Structured Exception Handling support for Windows
@ 2023-11-13  8:58 Julian Waters
  0 siblings, 0 replies; only message in thread
From: Julian Waters @ 2023-11-13  8:58 UTC (permalink / raw)
  To: gcc

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

gcc's assembler has had support for Windows style Structured Exception
Handling for a while now, it would be useful if gcc itself had support for
catching hardware faults on Windows through this mechanism as well (For
example, the Java HotSpot VM will simply not work on Windows without
support for Structured Exception Handling). What would a good syntax for
this be? I was thinking about a regular try catch block modified with a gcc
attribute, perhaps gnu::win32, that only accepts exceptions of type
std::system_error, with all the exception information stored in the
std::system_error object, wrangled somehow from the low level exception
information. Maybe if catch (...) is passed instead of catch
(std::system_error), the block behaves as a finally block?

The changes that would need to be made to gcc would be to pass
__C_specific_handler to the .seh_handler assembler directive for a
particular method with a Structured try catch block inside it, with the
parameter @except if it is an exception handler, or @unwind if it is a
termination handler, and emit custom scope information to .seh_handlerdata,
consisting of (in proper order):

- An address specifying the scope start
- An address specifying scope end
- Address of a dispatcher assembly stub if the scope is an exception
handler (see below), or a finally block if it is of type UNW_INFO_UHANDLER
- Address of the except block, or 0 if of type UNW_INFO_UHANDLER

The dispatcher stub is compiler created, but if it were written in C++,
it's signature would be:

DWORD dispatcher(PEXCEPTION_POINTERS pointers, LPVOID frame);

This stub is responsible for calling the filter that is passed to the
except block, which can return either EXCEPTION_CONTINUE_SEARCH,
EXCEPTION_CONTINUE_EXECUTION, or EXCEPTION_EXECUTE_HANDLER. This is likely
where all the exception handling code would be compiled from the compiler.

There are a little more technical details involved, I'd be happy to share
if asked.

Thoughts?

best regards,
Julian

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

only message in thread, other threads:[~2023-11-13  8:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13  8:58 [RFC] Structured Exception Handling support for Windows 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).