mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-13 00:51:20 +00:00
Merge branch 'fix/llvm-trap-windows' into feature/llvm-osr
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#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 *);
|
||||
@ -12,6 +13,54 @@ MemoryManager::~MemoryManager() {
|
||||
callbacks.dealloc_memory(read_section.base, read_section.size);
|
||||
callbacks.dealloc_memory(readwrite_section.base, readwrite_section.size);
|
||||
}
|
||||
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;
|
||||
jmp_buf stack;
|
||||
std::function<void()> *f;
|
||||
std::unique_ptr<std::exception> exception;
|
||||
};
|
||||
|
||||
static thread_local UnwindPoint *unwind_state = nullptr;
|
||||
|
||||
static void unwind_payload(void *_point) {
|
||||
UnwindPoint *point = (UnwindPoint *) _point;
|
||||
(*point->f)();
|
||||
}
|
||||
|
||||
void catch_unwind(std::function<void()>&& f) {
|
||||
UnwindPoint current;
|
||||
current.prev = unwind_state;
|
||||
current.f = &f;
|
||||
unwind_state = ¤t;
|
||||
|
||||
unwinding_setjmp(current.stack, unwind_payload, (void *) ¤t);
|
||||
if(current.exception) {
|
||||
throw *current.exception;
|
||||
}
|
||||
}
|
||||
|
||||
void unsafe_unwind(std::exception *exception) {
|
||||
UnwindPoint *state = unwind_state;
|
||||
if(state) {
|
||||
state->exception.reset(exception);
|
||||
unwinding_longjmp(state->stack);
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *MemoryManager::allocateCodeSection(uintptr_t size, unsigned alignment,
|
||||
unsigned section_id,
|
||||
|
Reference in New Issue
Block a user