Skip to content

Commit

Permalink
win32.c: add an seh handler for win64
Browse files Browse the repository at this point in the history
  • Loading branch information
tgingold committed Apr 9, 2024
1 parent 99ab16c commit f2d18bc
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/grt/config/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
static int run_env_en;
static jmp_buf run_env;

static EXCEPTION_DISPOSITION
ghdl_SEH_handler (struct _EXCEPTION_RECORD* ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT* ContextRecord,
void *DispatcherContext);

struct exception_registration
{
struct exception_registration *prev;
Expand Down Expand Up @@ -158,6 +152,28 @@ __ghdl_maybe_return_via_longjump (int val)
longjmp (run_env, val);
}

#ifdef __x86_64__
int __run_seh(int (*func)(void));

asm ("\n\
.def __run_seh\n\
.scl 2\n\
.type 32\n\
.endef\n\
.seh_proc __run_seh\n\
.seh_handler ghdl_SEH_handler,@except\n\
__run_seh:\n\
subq $40, %rsp\n\
.seh_stackalloc 40\n\
.seh_endprologue\n\
call %rcx\n\
nop\n\
addq $40, %rsp\n\
ret\n\
.seh_endproc\n\
");
#endif

int
__ghdl_run_through_longjump (int (*func)(void))
{
Expand All @@ -181,8 +197,13 @@ __ghdl_run_through_longjump (int (*func)(void))

run_env_en = 1;
res = setjmp (run_env);
if (res == 0)
if (res == 0) {
#ifdef __x86_64__
res = __run_seh(func);
#else
res = (*func)();
#endif
}
run_env_en = 0;

#ifdef __i386__
Expand Down

0 comments on commit f2d18bc

Please sign in to comment.