HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //lib/go/src/runtime/testdata/testwinlib/main.c
#include <stdio.h>
#include <windows.h>
#include "testwinlib.h"

int exceptionCount;
int continueCount;
int unhandledCount;

LONG WINAPI customExceptionHandlder(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
    if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
    {
        exceptionCount++;
        // prepare context to resume execution
        CONTEXT *c = ExceptionInfo->ContextRecord;
#ifdef _AMD64_
        c->Rip = *(DWORD64 *)c->Rsp;
        c->Rsp += 8;
#elif defined(_X86_)
        c->Eip = *(DWORD *)c->Esp;
        c->Esp += 4;
#else
        c->Pc = c->Lr;
#endif
#ifdef _ARM64_
        // TODO: remove when windows/arm64 supports SEH stack unwinding.
        return EXCEPTION_CONTINUE_EXECUTION;
#endif
    }
    return EXCEPTION_CONTINUE_SEARCH;
}
LONG WINAPI customContinueHandlder(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
    if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
    {
        continueCount++;
    }
    return EXCEPTION_CONTINUE_SEARCH;
}

LONG WINAPI unhandledExceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo) {
    if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT)
    {
        unhandledCount++;
        return EXCEPTION_CONTINUE_EXECUTION;
    }
    return EXCEPTION_CONTINUE_SEARCH;
}

void throwFromC()
{
    DebugBreak();
}
int main()
{
    // simulate a "lazily" attached debugger, by calling some go code before attaching the exception/continue handler
    Dummy();
    exceptionCount = 0;
    continueCount = 0;
    void *exceptionHandlerHandle = AddVectoredExceptionHandler(0, customExceptionHandlder);
    if (NULL == exceptionHandlerHandle)
    {
        printf("cannot add vectored exception handler\n");
        fflush(stdout);
        return 2;
    }
    void *continueHandlerHandle = AddVectoredContinueHandler(0, customContinueHandlder);
    if (NULL == continueHandlerHandle)
    {
        printf("cannot add vectored continue handler\n");
        fflush(stdout);
        return 2;
    }
    void *prevUnhandledHandler = SetUnhandledExceptionFilter(unhandledExceptionHandler);
    CallMeBack(throwFromC);
    RemoveVectoredContinueHandler(continueHandlerHandle);
    RemoveVectoredExceptionHandler(exceptionHandlerHandle);
    if (prevUnhandledHandler != NULL)
    {
        SetUnhandledExceptionFilter(prevUnhandledHandler);
    }
    printf("exceptionCount: %d\ncontinueCount: %d\nunhandledCount: %d\n", exceptionCount, continueCount, unhandledCount);
    fflush(stdout);
    return 0;
}