Custom SEH handler with /SAFESEH

Viewed 1871

I am currently trying to create a compiler in C++, which generates machine code at run time. However, I am currently trying to enable safe exception handling (compiling with /SAFESEH). My custom exception handler is working in the debug mode, but when I run the same code in release mode, my process is just terminated.

I am quite certain the problem is that I fail to register my custom exception handler as such, because when I compile my code with /SAFESEH:NO, everything works fine even in release mode.

My custom exception handler is written in my other C++-code, and I have tried to register it as an exception handler by adding a .asm-file to my project with the content:

.386
.model flat
_MyExceptionHandler@16 proto
.safeseh _MyExceptionHandler@16
end

as described here. The asm-file was then assembled with the /safeseh option (among others).

My handler function currently has the following declaration:

extern "C" EXCEPTION_DISPOSITION __stdcall MyExceptionHandler(struct
_EXCEPTION_RECORD *ExceptionRecord, void * EstablisherFrame, struct 
_CONTEXT *ContextRecord, void * DispatcherContext);

What would the correct way to register this function as an exception handler be?

Thanks for any suggestions!

3 Answers
Related