Format everything

This commit is contained in:
losfair 2019-08-21 15:23:56 -07:00
parent 53ebcc355a
commit 56e735349d
8 changed files with 93 additions and 96 deletions

View File

@ -6,7 +6,7 @@
extern "C" void __register_frame(uint8_t *);
extern "C" void __deregister_frame(uint8_t *);
MemoryManager::~MemoryManager() {
MemoryManager::~MemoryManager() {
deregisterEHFrames();
// Deallocate all of the allocated memory.
callbacks.dealloc_memory(code_section.base, code_section.size);
@ -14,72 +14,68 @@ MemoryManager::~MemoryManager() {
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)) {
if (setjmp(stack_out)) {
} else {
func(userdata);
}
}
[[noreturn]]
void unwinding_longjmp(jmp_buf stack_in) {
longjmp(stack_in, 42);
}
[[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;
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)();
UnwindPoint *point = (UnwindPoint *)_point;
(*point->f)();
}
void catch_unwind(std::function<void()>&& f) {
UnwindPoint current;
current.prev = unwind_state;
current.f = &f;
unwind_state = &current;
void catch_unwind(std::function<void()> &&f) {
UnwindPoint current;
current.prev = unwind_state;
current.f = &f;
unwind_state = &current;
unwinding_setjmp(current.stack, unwind_payload, (void *) &current);
if(current.exception) {
throw *current.exception;
}
unwinding_setjmp(current.stack, unwind_payload, (void *)&current);
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();
}
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,
llvm::StringRef section_name) {
unsigned section_id,
llvm::StringRef section_name) {
return allocate_bump(code_section, code_bump_ptr, size, alignment);
}
uint8_t *MemoryManager::allocateDataSection(uintptr_t size, unsigned alignment,
unsigned section_id,
llvm::StringRef section_name,
bool read_only) {
unsigned section_id,
llvm::StringRef section_name,
bool read_only) {
// Allocate from the read-only section or the read-write section, depending
// on if this allocation should be read-only or not.
uint8_t *ret;
if (read_only) {
ret = allocate_bump(read_section, read_bump_ptr, size, alignment);
} else {
ret =
allocate_bump(readwrite_section, readwrite_bump_ptr, size, alignment);
ret = allocate_bump(readwrite_section, readwrite_bump_ptr, size, alignment);
}
if (section_name.equals(llvm::StringRef("__llvm_stackmaps")) ||
section_name.equals(llvm::StringRef(".llvm_stackmaps"))) {
@ -89,11 +85,12 @@ uint8_t *MemoryManager::allocateDataSection(uintptr_t size, unsigned alignment,
return ret;
}
void MemoryManager::reserveAllocationSpace(uintptr_t code_size, uint32_t code_align,
uintptr_t read_data_size,
uint32_t read_data_align,
uintptr_t read_write_data_size,
uint32_t read_write_data_align) {
void MemoryManager::reserveAllocationSpace(uintptr_t code_size,
uint32_t code_align,
uintptr_t read_data_size,
uint32_t read_data_align,
uintptr_t read_write_data_size,
uint32_t read_write_data_align) {
auto aligner = [](uintptr_t ptr, size_t align) {
if (ptr == 0) {
return align;
@ -104,7 +101,7 @@ void MemoryManager::reserveAllocationSpace(uintptr_t code_size, uint32_t code_al
size_t code_size_out = 0;
auto code_result =
callbacks.alloc_memory(aligner(code_size, 4096), PROTECT_READ_WRITE,
&code_ptr_out, &code_size_out);
&code_ptr_out, &code_size_out);
assert(code_result == RESULT_OK);
code_section = Section{code_ptr_out, code_size_out};
code_bump_ptr = (uintptr_t)code_ptr_out;
@ -113,9 +110,9 @@ void MemoryManager::reserveAllocationSpace(uintptr_t code_size, uint32_t code_al
uint8_t *read_ptr_out = nullptr;
size_t read_size_out = 0;
auto read_result = callbacks.alloc_memory(aligner(read_data_size, 4096),
PROTECT_READ_WRITE, &read_ptr_out,
&read_size_out);
auto read_result =
callbacks.alloc_memory(aligner(read_data_size, 4096), PROTECT_READ_WRITE,
&read_ptr_out, &read_size_out);
assert(read_result == RESULT_OK);
read_section = Section{read_ptr_out, read_size_out};
read_bump_ptr = (uintptr_t)read_ptr_out;
@ -133,7 +130,7 @@ void MemoryManager::reserveAllocationSpace(uintptr_t code_size, uint32_t code_al
bool MemoryManager::needsToReserveAllocationSpace() { return true; }
void MemoryManager::registerEHFrames(uint8_t *addr, uint64_t LoadAddr,
size_t size) {
size_t size) {
// We don't know yet how to do this on Windows, so we hide this on compilation
// so we can compile and pass spectests on unix systems
#ifndef _WIN32
@ -157,7 +154,7 @@ void MemoryManager::deregisterEHFrames() {
bool MemoryManager::finalizeMemory(std::string *ErrMsg) {
auto code_result =
callbacks.protect_memory(code_section.base, code_section.size,
mem_protect_t::PROTECT_READ_EXECUTE);
mem_protect_t::PROTECT_READ_EXECUTE);
if (code_result != RESULT_OK) {
return false;
}
@ -174,10 +171,10 @@ bool MemoryManager::finalizeMemory(std::string *ErrMsg) {
}
void MemoryManager::notifyObjectLoaded(llvm::RuntimeDyld &RTDyld,
const llvm::object::ObjectFile &Obj) {}
const llvm::object::ObjectFile &Obj) {}
uint8_t *MemoryManager::allocate_bump(Section &section, uintptr_t &bump_ptr, size_t size,
size_t align) {
uint8_t *MemoryManager::allocate_bump(Section &section, uintptr_t &bump_ptr,
size_t size, size_t align) {
auto aligner = [](uintptr_t &ptr, size_t align) {
ptr = (ptr + align - 1) & ~(align - 1);
};

View File

@ -3,10 +3,10 @@
#include <cstddef>
#include <cstdint>
#include <exception>
#include <iostream>
#include <sstream>
#include <setjmp.h>
#include <functional>
#include <iostream>
#include <setjmp.h>
#include <sstream>
#include <llvm/ExecutionEngine/RuntimeDyld.h>
@ -81,7 +81,7 @@ public:
virtual void deregisterEHFrames() override;
virtual bool finalizeMemory(std::string *ErrMsg = nullptr) override;
virtual void notifyObjectLoaded(llvm::RuntimeDyld &RTDyld,
const llvm::object::ObjectFile &Obj) override;
const llvm::object::ObjectFile &Obj) override;
private:
struct Section {
@ -106,12 +106,12 @@ private:
size_t stack_map_size = 0;
};
struct WasmException: std::exception {
struct WasmException : std::exception {
public:
virtual std::string description() const noexcept = 0;
};
void catch_unwind(std::function<void()>&& f);
void catch_unwind(std::function<void()> &&f);
[[noreturn]] void unsafe_unwind(std::exception *exception);
struct UncatchableException : WasmException {
@ -239,7 +239,9 @@ result_t module_load(const uint8_t *mem_ptr, size_t mem_size,
return RESULT_OK;
}
[[noreturn]] void throw_trap(WasmTrap::Type ty) { unsafe_unwind(new WasmTrap(ty)); }
[[noreturn]] void throw_trap(WasmTrap::Type ty) {
unsafe_unwind(new WasmTrap(ty));
}
void module_delete(WasmModule *module) { delete module; }
@ -260,7 +262,7 @@ bool invoke_trampoline(trampoline_t trampoline, void *ctx, void *func,
box_any_t *user_error, void *invoke_env) noexcept {
try {
catch_unwind([trampoline, ctx, func, params, results]() {
trampoline(ctx, func, params, results);
trampoline(ctx, func, params, results);
});
return true;
} catch (const WasmTrap &e) {

View File

@ -331,7 +331,7 @@ impl LLVMBackend {
local_func_id_to_offset,
},
LLVMCache { buffer },
)
);
}
}

View File

@ -4,7 +4,9 @@ use libc::{
c_void, mmap, mprotect, munmap, siginfo_t, MAP_ANON, MAP_PRIVATE, PROT_EXEC, PROT_NONE,
PROT_READ, PROT_WRITE,
};
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGSEGV, SIGILL};
use nix::sys::signal::{
sigaction, SaFlags, SigAction, SigHandler, SigSet, SIGBUS, SIGILL, SIGSEGV,
};
use std::ptr;
/// `__register_frame` and `__deregister_frame` on macos take a single fde as an

View File

@ -232,10 +232,8 @@ impl StackmapEntry {
if loc.offset_or_small_constant >= 0 {
assert!(loc.offset_or_small_constant >= 16); // (saved_rbp, return_address)
assert!(loc.offset_or_small_constant % 8 == 0);
prev_frame_diff.insert(
(loc.offset_or_small_constant as usize - 16) / 8,
Some(mv),
);
prev_frame_diff
.insert((loc.offset_or_small_constant as usize - 16) / 8, Some(mv));
} else {
let stack_offset = ((-loc.offset_or_small_constant) / 4) as usize;
assert!(

View File

@ -726,11 +726,8 @@ pub mod x64 {
assert_eq!(vmctx.internal.memory_bound, memory.len());
}
std::slice::from_raw_parts_mut(
vmctx.internal.memory_base,
vmctx.internal.memory_bound,
)
.copy_from_slice(memory);
std::slice::from_raw_parts_mut(vmctx.internal.memory_base, vmctx.internal.memory_bound)
.copy_from_slice(memory);
}
let globals_len = (*vmctx.module).info.globals.len();

View File

@ -210,8 +210,7 @@ pub unsafe fn run_tiering<F: Fn(InteractiveShellContext) -> ShellExitOperation>(
if let Err(e) = ret {
if let Ok(new_image) = e.downcast::<InstanceImage>() {
// Tier switch event
if !was_sigint_triggered_fault() && opt_state.outcome.lock().unwrap().is_some()
{
if !was_sigint_triggered_fault() && opt_state.outcome.lock().unwrap().is_some() {
resume_image = Some(*new_image);
continue;
}

View File

@ -587,32 +587,34 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
let start_raw: extern "C" fn(&mut wasmer_runtime_core::vm::Ctx) =
unsafe { ::std::mem::transmute(start.get_vm_func()) };
unsafe { run_tiering(
module.info(),
&wasm_binary,
if let Some(ref path) = options.resume {
let mut f = File::open(path).unwrap();
let mut out: Vec<u8> = vec![];
f.read_to_end(&mut out).unwrap();
Some(
wasmer_runtime_core::state::InstanceImage::from_bytes(&out)
.expect("failed to decode image"),
)
} else {
None
},
&import_object,
start_raw,
&mut instance,
options
.optimized_backends
.iter()
.map(|&backend| -> Box<dyn Fn() -> Box<dyn Compiler> + Send> {
Box::new(move || get_compiler_by_backend(backend).unwrap())
})
.collect(),
interactive_shell,
)? };
unsafe {
run_tiering(
module.info(),
&wasm_binary,
if let Some(ref path) = options.resume {
let mut f = File::open(path).unwrap();
let mut out: Vec<u8> = vec![];
f.read_to_end(&mut out).unwrap();
Some(
wasmer_runtime_core::state::InstanceImage::from_bytes(&out)
.expect("failed to decode image"),
)
} else {
None
},
&import_object,
start_raw,
&mut instance,
options
.optimized_backends
.iter()
.map(|&backend| -> Box<dyn Fn() -> Box<dyn Compiler> + Send> {
Box::new(move || get_compiler_by_backend(backend).unwrap())
})
.collect(),
interactive_shell,
)?
};
}
#[cfg(not(feature = "managed"))]