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

Reply via email to