mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-15 01:41:21 +00:00
longjmp turns out to work on Windows. Remove custom unwinding code.
This commit is contained in:
@ -209,14 +209,12 @@ fn main() {
|
|||||||
cc::Build::new()
|
cc::Build::new()
|
||||||
.cpp(true)
|
.cpp(true)
|
||||||
.file("cpp/object_loader.cpp")
|
.file("cpp/object_loader.cpp")
|
||||||
.file("cpp/unwinding.s")
|
|
||||||
.compile("llvm-backend");
|
.compile("llvm-backend");
|
||||||
|
|
||||||
println!("cargo:rustc-link-lib=static=llvm-backend");
|
println!("cargo:rustc-link-lib=static=llvm-backend");
|
||||||
println!("cargo:rerun-if-changed=build.rs");
|
println!("cargo:rerun-if-changed=build.rs");
|
||||||
println!("cargo:rerun-if-changed=cpp/object_loader.cpp");
|
println!("cargo:rerun-if-changed=cpp/object_loader.cpp");
|
||||||
println!("cargo:rerun-if-changed=cpp/object_loader.hh");
|
println!("cargo:rerun-if-changed=cpp/object_loader.hh");
|
||||||
println!("cargo:rerun-if-changed=cpp/unwinding.s");
|
|
||||||
|
|
||||||
// Enable "nightly" cfg if the current compiler is nightly.
|
// Enable "nightly" cfg if the current compiler is nightly.
|
||||||
if rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly {
|
if rustc_version::version_meta().unwrap().channel == rustc_version::Channel::Nightly {
|
||||||
|
@ -1,15 +1,27 @@
|
|||||||
#include "object_loader.hh"
|
#include "object_loader.hh"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
extern "C" void __register_frame(uint8_t *);
|
extern "C" void __register_frame(uint8_t *);
|
||||||
extern "C" void __deregister_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 {
|
struct UnwindPoint {
|
||||||
UnwindPoint *prev;
|
UnwindPoint *prev;
|
||||||
uint8_t *stack;
|
jmp_buf stack;
|
||||||
std::function<void()> *f;
|
std::function<void()> *f;
|
||||||
std::unique_ptr<std::exception> exception;
|
std::unique_ptr<std::exception> exception;
|
||||||
};
|
};
|
||||||
@ -27,7 +39,7 @@ void catch_unwind(std::function<void()>&& f) {
|
|||||||
current.f = &f;
|
current.f = &f;
|
||||||
unwind_state = ¤t;
|
unwind_state = ¤t;
|
||||||
|
|
||||||
unwinding_setjmp(¤t.stack, unwind_payload, (void *) ¤t);
|
unwinding_setjmp(current.stack, unwind_payload, (void *) ¤t);
|
||||||
if(current.exception) {
|
if(current.exception) {
|
||||||
throw *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