From 56e735349d1e2f11c85efba5964184c0beab9d96 Mon Sep 17 00:00:00 2001 From: losfair Date: Wed, 21 Aug 2019 15:23:56 -0700 Subject: [PATCH] Format everything --- lib/llvm-backend/cpp/object_loader.cpp | 95 +++++++++++++------------- lib/llvm-backend/cpp/object_loader.hh | 18 ++--- lib/llvm-backend/src/backend.rs | 2 +- lib/llvm-backend/src/platform/unix.rs | 4 +- lib/llvm-backend/src/stackmap.rs | 6 +- lib/runtime-core/src/state.rs | 7 +- lib/runtime-core/src/tiering.rs | 3 +- src/bin/wasmer.rs | 54 ++++++++------- 8 files changed, 93 insertions(+), 96 deletions(-) diff --git a/lib/llvm-backend/cpp/object_loader.cpp b/lib/llvm-backend/cpp/object_loader.cpp index 49590efda..1e842b97e 100644 --- a/lib/llvm-backend/cpp/object_loader.cpp +++ b/lib/llvm-backend/cpp/object_loader.cpp @@ -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 *f; - std::unique_ptr exception; + UnwindPoint *prev; + jmp_buf stack; + std::function *f; + std::unique_ptr 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&& f) { - UnwindPoint current; - current.prev = unwind_state; - current.f = &f; - unwind_state = ¤t; +void catch_unwind(std::function &&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; - } + 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(); - } + 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 §ion, uintptr_t &bump_ptr, size_t size, - size_t align) { +uint8_t *MemoryManager::allocate_bump(Section §ion, uintptr_t &bump_ptr, + size_t size, size_t align) { auto aligner = [](uintptr_t &ptr, size_t align) { ptr = (ptr + align - 1) & ~(align - 1); }; diff --git a/lib/llvm-backend/cpp/object_loader.hh b/lib/llvm-backend/cpp/object_loader.hh index 319eed232..9bcecbe25 100644 --- a/lib/llvm-backend/cpp/object_loader.hh +++ b/lib/llvm-backend/cpp/object_loader.hh @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include #include +#include +#include +#include #include @@ -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&& f); +void catch_unwind(std::function &&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) { diff --git a/lib/llvm-backend/src/backend.rs b/lib/llvm-backend/src/backend.rs index 901730ae6..cdee5c60d 100644 --- a/lib/llvm-backend/src/backend.rs +++ b/lib/llvm-backend/src/backend.rs @@ -331,7 +331,7 @@ impl LLVMBackend { local_func_id_to_offset, }, LLVMCache { buffer }, - ) + ); } } diff --git a/lib/llvm-backend/src/platform/unix.rs b/lib/llvm-backend/src/platform/unix.rs index b06746d9e..9e77c57d6 100644 --- a/lib/llvm-backend/src/platform/unix.rs +++ b/lib/llvm-backend/src/platform/unix.rs @@ -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 diff --git a/lib/llvm-backend/src/stackmap.rs b/lib/llvm-backend/src/stackmap.rs index f409d719e..27a16aafa 100644 --- a/lib/llvm-backend/src/stackmap.rs +++ b/lib/llvm-backend/src/stackmap.rs @@ -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!( diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index 39cd6b897..b6bbb95f5 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -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(); diff --git a/lib/runtime-core/src/tiering.rs b/lib/runtime-core/src/tiering.rs index 5980ac146..21a9ea2d3 100644 --- a/lib/runtime-core/src/tiering.rs +++ b/lib/runtime-core/src/tiering.rs @@ -210,8 +210,7 @@ pub unsafe fn run_tiering ShellExitOperation>( if let Err(e) = ret { if let Ok(new_image) = e.downcast::() { // 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; } diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index aedb3ecc3..fb213c277 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -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 = 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 Box + 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 = 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 Box + Send> { + Box::new(move || get_compiler_by_backend(backend).unwrap()) + }) + .collect(), + interactive_shell, + )? + }; } #[cfg(not(feature = "managed"))]