longjmp turns out to work on Windows. Remove custom unwinding code.

This commit is contained in:
losfair
2019-08-08 03:19:19 +08:00
parent 4b1d337ebe
commit b113f5a24b
3 changed files with 16 additions and 33 deletions

View File

@ -1,15 +1,27 @@
#include "object_loader.hh"
#include <iostream>
#include <memory>
#include <setjmp.h>
extern "C" void __register_frame(uint8_t *);
extern "C" void __deregister_frame(uint8_t *);
extern "C" void unwinding_setjmp(uint8_t **stack_out, void (*func)(void *), void *userdata);
[[noreturn]] extern "C" void unwinding_longjmp(uint8_t *stack_in);
void unwinding_setjmp(jmp_buf stack_out, void (*func)(void *), void *userdata) {
if(setjmp(stack_out)) {
} else {
func(userdata);
}
}
[[noreturn]]
void unwinding_longjmp(jmp_buf stack_in) {
longjmp(stack_in, 42);
}
struct UnwindPoint {
UnwindPoint *prev;
uint8_t *stack;
jmp_buf stack;
std::function<void()> *f;
std::unique_ptr<std::exception> exception;
};
@ -27,7 +39,7 @@ void catch_unwind(std::function<void()>&& f) {
current.f = &f;
unwind_state = &current;
unwinding_setjmp(&current.stack, unwind_payload, (void *) &current);
unwinding_setjmp(current.stack, unwind_payload, (void *) &current);
if(current.exception) {
throw *current.exception;
}

View File

@ -1,27 +0,0 @@
# (save_place, func(userdata), userdata)
.globl _unwinding_setjmp
_unwinding_setjmp:
push %r15
push %r14
push %r13
push %r12
push %rbx
push %rbp
sub $8, %rsp # 16-byte alignment
mov %rsp, (%rdi)
mov %rdx, %rdi
callq *%rsi
setjmp_ret:
add $8, %rsp
pop %rbp
pop %rbx
pop %r12
pop %r13
pop %r14
pop %r15
ret
.globl _unwinding_longjmp
_unwinding_longjmp:
mov %rdi, %rsp
jmp setjmp_ret