Consider the following code:

extern "C" void exceptions() {
    asm ("\t" "1:" "\n"
         "\t" ".seh_handler __C_specific_handler, @except" "\n"
         "\t" ".seh_handlerdata" "\n"
         "\t" ".long 1" "\n"
         "\t" ".rva 1b, 2f, 3f, 4f" "\n"
         "\t" ".seh_code");

    {
        // std::printf("Guarded\n");
        RaiseException(EXCEPTION_BREAKPOINT, 0, 0, nullptr);
    }

    asm ("nop" "\n"
         "\t" "2: nop" "\n"
         "\t" "jmp 5f" "\n"
         "\t" "3:" "\n"
         "\t" "push rbp" "\n"
         "\t" "mov rbp, rsp" "\n");

    {
        const volatile long filter = EXCEPTION_EXECUTE_HANDLER;
    }

    asm ("mov eax, DWORD PTR -8[rbp]" "\n"
         "\t" "pop rbp" "\n"
         "\t" "ret" "\n"
         "\t" "4:");

    {
        std::printf("Exception\n");
    }

    asm ("5:");

    std::printf("Intermission\n");

    asm ("\t" "1:" "\n"
         "\t" ".seh_handler __C_specific_handler, @except" "\n"
         "\t" ".seh_handlerdata" "\n"
         "\t" ".long 2" "\n"
         "\t" ".rva 1b, 2f, 3f, 4f" "\n"
         "\t" ".seh_code");

    {
        // std::printf("Guarded\n");
        RaiseException(EXCEPTION_BREAKPOINT, 0, 0, nullptr);
    }

    asm ("nop" "\n"
         "\t" "2: nop" "\n"
         "\t" "jmp 5f" "\n"
         "\t" "3:" "\n"
         "\t" "push rbp" "\n"
         "\t" "mov rbp, rsp" "\n");

    {
        const volatile long filter = EXCEPTION_EXECUTE_HANDLER;
    }

    asm ("mov eax, DWORD PTR -8[rbp]" "\n"
         "\t" "pop rbp" "\n"
         "\t" "ret" "\n"
         "\t" "4:");

    {
        std::printf("Exception\n");
    }

    asm ("5:");
}

The expected output would be:

Exception
Intermission
Exception

But the actual output is:

Exception
Intermission

Given that a function only has one __C_specific_handler, and multiple
Structured Exception try blocks are handled with multiple scope tables, or
.seh_handlerdata as gcc calls them, the fault must lie with
.seh_handlerdata. Is there only allowed to be one .seh_handlerdata emitting
.xdata information about the try and except blocks per function? Because if
so, this should be considered a defect and fixed either upstream or locally
within MinGW, because Windows can and does use multiple scope tables for
each try block per function all the time

best regards,
Julian

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to