문제

Certain kinds of events in 64-bit Windows programs e.g. division by zero, null pointer reference, stack overflow if you detect that with a guard page, are normally handled (in a program that finds it necessary to handle them) with structured or vectored exceptions.

In the context of a JIT compiler, structured exceptions are slightly awkward due to the need to provide unwinding information and conform to the unwinding protocol for all functions, which might not interact well with e.g. a copying garbage collector that moves code blocks, which suggests the use of vectored exceptions.

While vectored exception handlers are normally expected to return, using them for this purpose would involve exiting the handler with longjmp or some equivalent code that resets the stack pointer without doing any unwinding.

Is this legal, or is there some stumbling block I'm overlooking?

The equivalent in Unix seems to be legal, for what that's worth: Longjmp out of signal handler?

도움이 되었습니까?

해결책

Well, it seems to work fine in the test I ran.

#include <setjmp.h>
#include <stdio.h>
#include <windows.h>

jmp_buf jmp;

LONG CALLBACK eh(PEXCEPTION_POINTERS e) {
    longjmp(jmp, 1);
}

void main() {
    AddVectoredExceptionHandler(1, eh);
    for (int i = 0; i != 10; ++i)
        if (!setjmp(jmp))
            *(char*)0 = 0;
        else
            puts("ok");
    getchar();
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top