mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-25 14:41:32 +00:00
Run clang-format and cargo fmt
This commit is contained in:
@ -7,91 +7,92 @@ extern "C" void __deregister_frame(uint8_t *);
|
|||||||
|
|
||||||
struct MemoryManager : llvm::RuntimeDyld::MemoryManager {
|
struct MemoryManager : llvm::RuntimeDyld::MemoryManager {
|
||||||
public:
|
public:
|
||||||
MemoryManager(callbacks_t callbacks) : callbacks(callbacks) {}
|
MemoryManager(callbacks_t callbacks) : callbacks(callbacks) {}
|
||||||
|
|
||||||
uint8_t * get_stack_map_ptr() const {
|
uint8_t *get_stack_map_ptr() const { return stack_map_ptr; }
|
||||||
return stack_map_ptr;
|
|
||||||
|
size_t get_stack_map_size() const { return stack_map_size; }
|
||||||
|
|
||||||
|
uint8_t *get_code_ptr() const { return (uint8_t *)code_start_ptr; }
|
||||||
|
|
||||||
|
size_t get_code_size() const { return code_size; }
|
||||||
|
|
||||||
|
virtual ~MemoryManager() override {
|
||||||
|
deregisterEHFrames();
|
||||||
|
// Deallocate all of the allocated memory.
|
||||||
|
callbacks.dealloc_memory(code_section.base, code_section.size);
|
||||||
|
callbacks.dealloc_memory(read_section.base, read_section.size);
|
||||||
|
callbacks.dealloc_memory(readwrite_section.base, readwrite_section.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual uint8_t *allocateCodeSection(uintptr_t size, unsigned alignment,
|
||||||
|
unsigned section_id,
|
||||||
|
llvm::StringRef section_name) override {
|
||||||
|
return allocate_bump(code_section, code_bump_ptr, size, alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual uint8_t *allocateDataSection(uintptr_t size, unsigned alignment,
|
||||||
|
unsigned section_id,
|
||||||
|
llvm::StringRef section_name,
|
||||||
|
bool read_only) override {
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
if (section_name.equals(llvm::StringRef("__llvm_stackmaps")) ||
|
||||||
size_t get_stack_map_size() const {
|
section_name.equals(llvm::StringRef(".llvm_stackmaps"))) {
|
||||||
return stack_map_size;
|
stack_map_ptr = ret;
|
||||||
|
stack_map_size = size;
|
||||||
}
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
uint8_t * get_code_ptr() const {
|
virtual void reserveAllocationSpace(uintptr_t code_size, uint32_t code_align,
|
||||||
return (uint8_t *) code_start_ptr;
|
uintptr_t read_data_size,
|
||||||
}
|
uint32_t read_data_align,
|
||||||
|
uintptr_t read_write_data_size,
|
||||||
|
uint32_t read_write_data_align) override {
|
||||||
|
auto aligner = [](uintptr_t ptr, size_t align) {
|
||||||
|
if (ptr == 0) {
|
||||||
|
return align;
|
||||||
|
}
|
||||||
|
return (ptr + align - 1) & ~(align - 1);
|
||||||
|
};
|
||||||
|
|
||||||
size_t get_code_size() const {
|
uint8_t *code_ptr_out = nullptr;
|
||||||
return code_size;
|
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);
|
||||||
|
assert(code_result == RESULT_OK);
|
||||||
|
code_section = Section{code_ptr_out, code_size_out};
|
||||||
|
code_bump_ptr = (uintptr_t)code_ptr_out;
|
||||||
|
code_start_ptr = (uintptr_t)code_ptr_out;
|
||||||
|
this->code_size = code_size;
|
||||||
|
|
||||||
virtual ~MemoryManager() override {
|
uint8_t *read_ptr_out = nullptr;
|
||||||
deregisterEHFrames();
|
size_t read_size_out = 0;
|
||||||
// Deallocate all of the allocated memory.
|
auto read_result = callbacks.alloc_memory(aligner(read_data_size, 4096),
|
||||||
callbacks.dealloc_memory(code_section.base, code_section.size);
|
PROTECT_READ_WRITE, &read_ptr_out,
|
||||||
callbacks.dealloc_memory(read_section.base, read_section.size);
|
&read_size_out);
|
||||||
callbacks.dealloc_memory(readwrite_section.base, readwrite_section.size);
|
assert(read_result == RESULT_OK);
|
||||||
}
|
read_section = Section{read_ptr_out, read_size_out};
|
||||||
|
read_bump_ptr = (uintptr_t)read_ptr_out;
|
||||||
|
|
||||||
virtual uint8_t* allocateCodeSection(uintptr_t size, unsigned alignment, unsigned section_id, llvm::StringRef section_name) override {
|
uint8_t *readwrite_ptr_out = nullptr;
|
||||||
return allocate_bump(code_section, code_bump_ptr, size, alignment);
|
size_t readwrite_size_out = 0;
|
||||||
}
|
auto readwrite_result = callbacks.alloc_memory(
|
||||||
|
aligner(read_write_data_size, 4096), PROTECT_READ_WRITE,
|
||||||
virtual uint8_t* allocateDataSection(uintptr_t size, unsigned alignment, unsigned section_id, llvm::StringRef section_name, bool read_only) override {
|
&readwrite_ptr_out, &readwrite_size_out);
|
||||||
// Allocate from the read-only section or the read-write section, depending on if this allocation
|
assert(readwrite_result == RESULT_OK);
|
||||||
// should be read-only or not.
|
readwrite_section = Section{readwrite_ptr_out, readwrite_size_out};
|
||||||
uint8_t *ret;
|
readwrite_bump_ptr = (uintptr_t)readwrite_ptr_out;
|
||||||
if (read_only) {
|
}
|
||||||
ret = allocate_bump(read_section, read_bump_ptr, size, alignment);
|
|
||||||
} else {
|
|
||||||
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"))) {
|
|
||||||
stack_map_ptr = ret;
|
|
||||||
stack_map_size = size;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void 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
|
|
||||||
) override {
|
|
||||||
auto aligner = [](uintptr_t ptr, size_t align) {
|
|
||||||
if (ptr == 0) {
|
|
||||||
return align;
|
|
||||||
}
|
|
||||||
return (ptr + align - 1) & ~(align - 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t *code_ptr_out = nullptr;
|
|
||||||
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);
|
|
||||||
assert(code_result == RESULT_OK);
|
|
||||||
code_section = Section { code_ptr_out, code_size_out };
|
|
||||||
code_bump_ptr = (uintptr_t)code_ptr_out;
|
|
||||||
code_start_ptr = (uintptr_t)code_ptr_out;
|
|
||||||
this->code_size = code_size;
|
|
||||||
|
|
||||||
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);
|
|
||||||
assert(read_result == RESULT_OK);
|
|
||||||
read_section = Section { read_ptr_out, read_size_out };
|
|
||||||
read_bump_ptr = (uintptr_t)read_ptr_out;
|
|
||||||
|
|
||||||
uint8_t *readwrite_ptr_out = nullptr;
|
|
||||||
size_t readwrite_size_out = 0;
|
|
||||||
auto readwrite_result = callbacks.alloc_memory(aligner(read_write_data_size, 4096), PROTECT_READ_WRITE, &readwrite_ptr_out, &readwrite_size_out);
|
|
||||||
assert(readwrite_result == RESULT_OK);
|
|
||||||
readwrite_section = Section { readwrite_ptr_out, readwrite_size_out };
|
|
||||||
readwrite_bump_ptr = (uintptr_t)readwrite_ptr_out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Turn on the `reserveAllocationSpace` callback. */
|
/* Turn on the `reserveAllocationSpace` callback. */
|
||||||
virtual bool needsToReserveAllocationSpace() override { return true; }
|
virtual bool needsToReserveAllocationSpace() override { return true; }
|
||||||
@ -164,18 +165,18 @@ private:
|
|||||||
return (uint8_t *)ret_ptr;
|
return (uint8_t *)ret_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Section code_section, read_section, readwrite_section;
|
Section code_section, read_section, readwrite_section;
|
||||||
uintptr_t code_start_ptr;
|
uintptr_t code_start_ptr;
|
||||||
size_t code_size;
|
size_t code_size;
|
||||||
uintptr_t code_bump_ptr, read_bump_ptr, readwrite_bump_ptr;
|
uintptr_t code_bump_ptr, read_bump_ptr, readwrite_bump_ptr;
|
||||||
uint8_t* eh_frame_ptr;
|
uint8_t *eh_frame_ptr;
|
||||||
size_t eh_frame_size;
|
size_t eh_frame_size;
|
||||||
bool eh_frames_registered = false;
|
bool eh_frames_registered = false;
|
||||||
|
|
||||||
callbacks_t callbacks;
|
callbacks_t callbacks;
|
||||||
|
|
||||||
uint8_t *stack_map_ptr = nullptr;
|
uint8_t *stack_map_ptr = nullptr;
|
||||||
size_t stack_map_size = 0;
|
size_t stack_map_size = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SymbolLookup : llvm::JITSymbolResolver {
|
struct SymbolLookup : llvm::JITSymbolResolver {
|
||||||
@ -235,32 +236,31 @@ WasmModule::WasmModule(const uint8_t *object_start, size_t object_size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void* WasmModule::get_func(llvm::StringRef name) const {
|
void *WasmModule::get_func(llvm::StringRef name) const {
|
||||||
auto symbol = runtime_dyld->getSymbol(name);
|
auto symbol = runtime_dyld->getSymbol(name);
|
||||||
return (void*)symbol.getAddress();
|
return (void *)symbol.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * WasmModule::get_stack_map_ptr() const {
|
uint8_t *WasmModule::get_stack_map_ptr() const {
|
||||||
llvm::RuntimeDyld::MemoryManager& mm = *memory_manager;
|
llvm::RuntimeDyld::MemoryManager &mm = *memory_manager;
|
||||||
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
||||||
return local_mm->get_stack_map_ptr();
|
return local_mm->get_stack_map_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t WasmModule::get_stack_map_size() const {
|
size_t WasmModule::get_stack_map_size() const {
|
||||||
llvm::RuntimeDyld::MemoryManager& mm = *memory_manager;
|
llvm::RuntimeDyld::MemoryManager &mm = *memory_manager;
|
||||||
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
||||||
return local_mm->get_stack_map_size();
|
return local_mm->get_stack_map_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t *WasmModule::get_code_ptr() const {
|
||||||
uint8_t * WasmModule::get_code_ptr() const {
|
llvm::RuntimeDyld::MemoryManager &mm = *memory_manager;
|
||||||
llvm::RuntimeDyld::MemoryManager& mm = *memory_manager;
|
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
||||||
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
return local_mm->get_code_ptr();
|
||||||
return local_mm->get_code_ptr();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t WasmModule::get_code_size() const {
|
size_t WasmModule::get_code_size() const {
|
||||||
llvm::RuntimeDyld::MemoryManager& mm = *memory_manager;
|
llvm::RuntimeDyld::MemoryManager &mm = *memory_manager;
|
||||||
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
MemoryManager *local_mm = dynamic_cast<MemoryManager *>(&mm);
|
||||||
return local_mm->get_code_size();
|
return local_mm->get_code_size();
|
||||||
}
|
}
|
||||||
|
@ -83,25 +83,23 @@ public:
|
|||||||
uintptr_t callback;
|
uintptr_t callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WasmModule
|
struct WasmModule {
|
||||||
{
|
public:
|
||||||
public:
|
WasmModule(const uint8_t *object_start, size_t object_size,
|
||||||
WasmModule(
|
callbacks_t callbacks);
|
||||||
const uint8_t *object_start,
|
|
||||||
size_t object_size,
|
|
||||||
callbacks_t callbacks);
|
|
||||||
|
|
||||||
void *get_func(llvm::StringRef name) const;
|
void *get_func(llvm::StringRef name) const;
|
||||||
uint8_t *get_stack_map_ptr() const;
|
uint8_t *get_stack_map_ptr() const;
|
||||||
size_t get_stack_map_size() const;
|
size_t get_stack_map_size() const;
|
||||||
uint8_t *get_code_ptr() const;
|
uint8_t *get_code_ptr() const;
|
||||||
size_t get_code_size() const;
|
size_t get_code_size() const;
|
||||||
|
|
||||||
bool _init_failed = false;
|
bool _init_failed = false;
|
||||||
private:
|
|
||||||
std::unique_ptr<llvm::RuntimeDyld::MemoryManager> memory_manager;
|
private:
|
||||||
std::unique_ptr<llvm::object::ObjectFile> object_file;
|
std::unique_ptr<llvm::RuntimeDyld::MemoryManager> memory_manager;
|
||||||
std::unique_ptr<llvm::RuntimeDyld> runtime_dyld;
|
std::unique_ptr<llvm::object::ObjectFile> object_file;
|
||||||
|
std::unique_ptr<llvm::RuntimeDyld> runtime_dyld;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WasmTrap : UncatchableException {
|
struct WasmTrap : UncatchableException {
|
||||||
@ -225,18 +223,18 @@ void *get_func_symbol(WasmModule *module, const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *llvm_backend_get_stack_map_ptr(const WasmModule *module) {
|
const uint8_t *llvm_backend_get_stack_map_ptr(const WasmModule *module) {
|
||||||
return module->get_stack_map_ptr();
|
return module->get_stack_map_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t llvm_backend_get_stack_map_size(const WasmModule *module) {
|
size_t llvm_backend_get_stack_map_size(const WasmModule *module) {
|
||||||
return module->get_stack_map_size();
|
return module->get_stack_map_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *llvm_backend_get_code_ptr(const WasmModule *module) {
|
const uint8_t *llvm_backend_get_code_ptr(const WasmModule *module) {
|
||||||
return module->get_code_ptr();
|
return module->get_code_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t llvm_backend_get_code_size(const WasmModule *module) {
|
size_t llvm_backend_get_code_size(const WasmModule *module) {
|
||||||
return module->get_code_size();
|
return module->get_code_size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@
|
|||||||
use crate::emitter_x64::*;
|
use crate::emitter_x64::*;
|
||||||
use crate::machine::*;
|
use crate::machine::*;
|
||||||
use crate::protect_unix;
|
use crate::protect_unix;
|
||||||
use dynasmrt::{
|
use dynasmrt::{x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi};
|
||||||
x64::Assembler, AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi,
|
|
||||||
};
|
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
use std::{
|
use std::{
|
||||||
|
Reference in New Issue
Block a user