[llvm-dev] Windows: How to catch C++ exceptions in runtime-compiled code?

Igor Minin via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 10 07:07:59 PDT 2016

Hi, Timur. I may be wrong, but it seems that I faced similar problem before.

The problem is that Windows checks memory region of exception handler forMEM_EXECUTE_OPTION_EXECUTE_DISPATCH_ENABLE flag, that is not set by default and can't be set easily.

Before Windows passes control to your handler it does the following checks:

KiUserExceptionDispatcher ->RtlDispatchException -> RtlIsValidHandler (FAIL)

So you need to enable this flag for your memory-generated code. As far as I know it is impossible if permanent DEP is enabled. So you can either run your process without DEP (not an option in the most cases), or use another way to deal with exceptions. One of the possible workarounds is VEH. You can look through OpenJDK as an example.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160610/78fb4a26/attachment-0001.html>

More information about the llvm-dev mailing list