Edenia
Edenia

Reputation: 2518

The easiest way to allow SEH of an ASM code calling C

I wrote a function in pure ASM and compiled it with my project with MinGW-w64 GCC. I want to implement a custom structured exception handling to this code and trap any potential exceptions raised (this can be achieved with WinAPI's AddVectoredExceptionHandler as well as setjmp / longjmp).

The problem is that SEH would not work for a naked asm function. If I compile a really small C sample with --save-temps I can see a lot of compiler unwinding metadata and it's just way too complicated for me to even begin understanding what is going on.

Is there any trick that would let me take advantage of the custom exception handling in my ASM function that is called from a C application? All my hopes were destroyed when I tried this:

uint64_t call_asm_func_from_c (int param) {
    __asm__ __volatile__ (
        "call my_asm_function\n"  // Call the external assembly function (it calls a C function by address)
    );
}

hoping that this may work, but here me are.

Upvotes: 3

Views: 45

Answers (0)

Related Questions