mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-12 08:31:21 +00:00
longjmp turns out to work on Windows. Remove custom unwinding code.
This commit is contained in:
@ -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 = ¤t;
|
||||
|
||||
unwinding_setjmp(¤t.stack, unwind_payload, (void *) ¤t);
|
||||
unwinding_setjmp(current.stack, unwind_payload, (void *) ¤t);
|
||||
if(current.exception) {
|
||||
throw *current.exception;
|
||||
}
|
||||
|
@ -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
|
Reference in New Issue
Block a user