mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 05:08:19 +00:00
Fixed linting issues
This commit is contained in:
1
lib/cache/src/filesystem.rs
vendored
1
lib/cache/src/filesystem.rs
vendored
@@ -3,7 +3,6 @@ use crate::hash::WasmHash;
|
|||||||
use std::fs::{create_dir_all, File};
|
use std::fs::{create_dir_all, File};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use thiserror::Error;
|
|
||||||
use wasmer::{DeserializeError, Module, SerializeError, Store};
|
use wasmer::{DeserializeError, Module, SerializeError, Store};
|
||||||
|
|
||||||
/// Representation of a directory that contains compiled wasm artifacts.
|
/// Representation of a directory that contains compiled wasm artifacts.
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ impl Relocation {
|
|||||||
.checked_add(reloc_addend as u32)
|
.checked_add(reloc_addend as u32)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
(reloc_address, reloc_delta_u32 as u64)
|
(reloc_address, reloc_delta_u32 as u64)
|
||||||
},
|
}
|
||||||
RelocationKind::X86CallPCRel4 | RelocationKind::X86CallPLTRel4 => {
|
RelocationKind::X86CallPCRel4 | RelocationKind::X86CallPLTRel4 => {
|
||||||
let reloc_address = start + self.offset as usize;
|
let reloc_address = start + self.offset as usize;
|
||||||
let reloc_addend = self.addend as isize;
|
let reloc_addend = self.addend as isize;
|
||||||
|
|||||||
@@ -8,19 +8,15 @@ use std::path::Path;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::FunctionType;
|
||||||
use wasm_common::{FunctionType, LocalFunctionIndex, MemoryIndex, SignatureIndex, TableIndex};
|
use wasmer_compiler::CompileError;
|
||||||
use wasmer_compiler::{Compilation, CompileError, FunctionBody, Target};
|
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::{Compiler, CompilerConfig};
|
use wasmer_compiler::{Compiler, CompilerConfig};
|
||||||
use wasmer_engine::{
|
use wasmer_engine::{
|
||||||
CompiledModule as BaseCompiledModule, DeserializeError, Engine, InstantiationError, Resolver,
|
CompiledModule as BaseCompiledModule, DeserializeError, Engine, InstantiationError, Resolver,
|
||||||
SerializeError, Tunables,
|
SerializeError, Tunables,
|
||||||
};
|
};
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{InstanceHandle, SignatureRegistry, VMSharedSignatureIndex, VMTrampoline};
|
||||||
InstanceHandle, MemoryPlan, Module, SignatureRegistry, TablePlan, VMFunctionBody,
|
|
||||||
VMSharedSignatureIndex, VMTrampoline,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// A WebAssembly `Native` Engine.
|
/// A WebAssembly `Native` Engine.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -34,9 +30,11 @@ impl NativeEngine {
|
|||||||
const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254];
|
const MAGIC_HEADER_MH_CIGAM_64: &'static [u8] = &[207, 250, 237, 254];
|
||||||
|
|
||||||
// ELF Magic header for Linux (32 bit)
|
// ELF Magic header for Linux (32 bit)
|
||||||
|
#[allow(dead_code)]
|
||||||
const MAGIC_HEADER_ELF_32: &'static [u8] = &[0x7f, b'E', b'L', b'F', 1];
|
const MAGIC_HEADER_ELF_32: &'static [u8] = &[0x7f, b'E', b'L', b'F', 1];
|
||||||
|
|
||||||
// ELF Magic header for Linux (64 bit)
|
// ELF Magic header for Linux (64 bit)
|
||||||
|
#[allow(dead_code)]
|
||||||
const MAGIC_HEADER_ELF_64: &'static [u8] = &[0x7f, b'E', b'L', b'F', 2];
|
const MAGIC_HEADER_ELF_64: &'static [u8] = &[0x7f, b'E', b'L', b'F', 2];
|
||||||
|
|
||||||
/// Create a new `NativeEngine` with the given config
|
/// Create a new `NativeEngine` with the given config
|
||||||
@@ -172,7 +170,7 @@ impl Engine for NativeEngine {
|
|||||||
resolver: &dyn Resolver,
|
resolver: &dyn Resolver,
|
||||||
) -> Result<InstanceHandle, InstantiationError> {
|
) -> Result<InstanceHandle, InstantiationError> {
|
||||||
let compiled_module = compiled_module.downcast_ref::<NativeModule>().unwrap();
|
let compiled_module = compiled_module.downcast_ref::<NativeModule>().unwrap();
|
||||||
unsafe { compiled_module.instantiate(&self, resolver, Box::new(())) }
|
compiled_module.instantiate(&self, resolver, Box::new(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finish the instantiation of a WebAssembly module
|
/// Finish the instantiation of a WebAssembly module
|
||||||
@@ -182,7 +180,7 @@ impl Engine for NativeEngine {
|
|||||||
handle: &InstanceHandle,
|
handle: &InstanceHandle,
|
||||||
) -> Result<(), InstantiationError> {
|
) -> Result<(), InstantiationError> {
|
||||||
let compiled_module = compiled_module.downcast_ref::<NativeModule>().unwrap();
|
let compiled_module = compiled_module.downcast_ref::<NativeModule>().unwrap();
|
||||||
unsafe { compiled_module.finish_instantiation(&handle) }
|
compiled_module.finish_instantiation(&handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializes a WebAssembly module
|
/// Serializes a WebAssembly module
|
||||||
@@ -218,7 +216,7 @@ impl Engine for NativeEngine {
|
|||||||
let mut file = File::open(&file_ref)?;
|
let mut file = File::open(&file_ref)?;
|
||||||
let mut buffer = [0; 5];
|
let mut buffer = [0; 5];
|
||||||
// read up to 5 bytes
|
// read up to 5 bytes
|
||||||
file.read(&mut buffer)?;
|
file.read_exact(&mut buffer)?;
|
||||||
if !Self::is_deserializable(&buffer) {
|
if !Self::is_deserializable(&buffer) {
|
||||||
return Err(DeserializeError::Incompatible(
|
return Err(DeserializeError::Incompatible(
|
||||||
"The provided bytes are not in any native format Wasmer can understand".to_string(),
|
"The provided bytes are not in any native format Wasmer can understand".to_string(),
|
||||||
|
|||||||
@@ -7,28 +7,25 @@ use faerie::{ArtifactBuilder, Decl, Link};
|
|||||||
use libloading::{Library, Symbol};
|
use libloading::{Library, Symbol};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::ffi::c_void;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
use wasm_common::entity::{BoxedSlice, EntityRef, PrimaryMap};
|
use wasm_common::entity::{BoxedSlice, EntityRef, PrimaryMap};
|
||||||
use wasm_common::{
|
use wasm_common::{
|
||||||
DataInitializer, LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
|
DataInitializer, FunctionIndex, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer,
|
||||||
MemoryIndex, OwnedDataInitializer, SignatureIndex, TableIndex, FunctionIndex,
|
SignatureIndex, TableIndex,
|
||||||
};
|
};
|
||||||
use wasmer_compiler::CompileError;
|
use wasmer_compiler::CompileError;
|
||||||
#[cfg(feature = "compiler")]
|
#[cfg(feature = "compiler")]
|
||||||
use wasmer_compiler::ModuleEnvironment;
|
use wasmer_compiler::ModuleEnvironment;
|
||||||
use wasmer_compiler::{Relocation, RelocationKind, RelocationTarget, Relocations};
|
use wasmer_compiler::RelocationTarget;
|
||||||
use wasmer_engine::{
|
use wasmer_engine::{
|
||||||
resolve_imports, CompiledModule, DeserializeError, Engine, GlobalFrameInfoRegistration,
|
resolve_imports, CompiledModule, DeserializeError, Engine, InstantiationError, Resolver,
|
||||||
InstantiationError, LinkError, Resolver, RuntimeError, SerializableFunctionFrameInfo,
|
RuntimeError, SerializeError,
|
||||||
SerializeError, Tunables,
|
|
||||||
};
|
};
|
||||||
use wasmer_runtime::{
|
use wasmer_runtime::{
|
||||||
InstanceHandle, LinearMemory, Module, SignatureRegistry, Table, VMFunctionBody,
|
InstanceHandle, Module, SignatureRegistry, VMFunctionBody, VMSharedSignatureIndex, VMTrampoline,
|
||||||
VMGlobalDefinition, VMSharedSignatureIndex, VMTrampoline,
|
|
||||||
};
|
};
|
||||||
use wasmer_runtime::{MemoryPlan, TablePlan};
|
use wasmer_runtime::{MemoryPlan, TablePlan};
|
||||||
|
|
||||||
@@ -36,14 +33,13 @@ use wasmer_runtime::{MemoryPlan, TablePlan};
|
|||||||
pub struct NativeModule {
|
pub struct NativeModule {
|
||||||
sharedobject_path: PathBuf,
|
sharedobject_path: PathBuf,
|
||||||
metadata: ModuleMetadata,
|
metadata: ModuleMetadata,
|
||||||
|
#[allow(dead_code)]
|
||||||
library: Library,
|
library: Library,
|
||||||
finished_functions: BoxedSlice<LocalFunctionIndex, *mut [VMFunctionBody]>,
|
finished_functions: BoxedSlice<LocalFunctionIndex, *mut [VMFunctionBody]>,
|
||||||
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, *const VMFunctionBody>,
|
finished_dynamic_function_trampolines: BoxedSlice<FunctionIndex, *const VMFunctionBody>,
|
||||||
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
signatures: BoxedSlice<SignatureIndex, VMSharedSignatureIndex>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handle = *mut c_void;
|
|
||||||
|
|
||||||
fn to_compile_error(err: impl Error) -> CompileError {
|
fn to_compile_error(err: impl Error) -> CompileError {
|
||||||
CompileError::Codegen(format!("{}", err))
|
CompileError::Codegen(format!("{}", err))
|
||||||
}
|
}
|
||||||
@@ -97,8 +93,8 @@ impl NativeModule {
|
|||||||
.collect::<PrimaryMap<SignatureIndex, _>>();
|
.collect::<PrimaryMap<SignatureIndex, _>>();
|
||||||
|
|
||||||
// Compile the dynamic function trampolines
|
// Compile the dynamic function trampolines
|
||||||
let dynamic_function_trampolines = compiler
|
let dynamic_function_trampolines =
|
||||||
.compile_dynamic_function_trampolines(&translation.module)?;
|
compiler.compile_dynamic_function_trampolines(&translation.module)?;
|
||||||
|
|
||||||
let data_initializers = translation
|
let data_initializers = translation
|
||||||
.data_initializers
|
.data_initializers
|
||||||
@@ -228,9 +224,6 @@ impl NativeModule {
|
|||||||
LibCall::NearestF64 => "wasmer_f64_nearest",
|
LibCall::NearestF64 => "wasmer_f64_nearest",
|
||||||
LibCall::RaiseTrap => "wasmer_raise_trap",
|
LibCall::RaiseTrap => "wasmer_raise_trap",
|
||||||
LibCall::Probestack => "wasmer_probestack",
|
LibCall::Probestack => "wasmer_probestack",
|
||||||
libcall => {
|
|
||||||
unimplemented!("The `{:?}` libcall is not yet implemented", libcall)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
obj.link(Link {
|
obj.link(Link {
|
||||||
from: &function_name,
|
from: &function_name,
|
||||||
@@ -239,10 +232,10 @@ impl NativeModule {
|
|||||||
})
|
})
|
||||||
.map_err(to_compile_error)?;
|
.map_err(to_compile_error)?;
|
||||||
}
|
}
|
||||||
RelocationTarget::CustomSection(custom_section) => {
|
RelocationTarget::CustomSection(_custom_section) => {
|
||||||
// do nothing
|
// TODO: Implement custom sections
|
||||||
}
|
}
|
||||||
RelocationTarget::JumpTable(func_index, jt) => {
|
RelocationTarget::JumpTable(_func_index, _jt) => {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -252,12 +245,11 @@ impl NativeModule {
|
|||||||
let file = NamedTempFile::new().map_err(to_compile_error)?;
|
let file = NamedTempFile::new().map_err(to_compile_error)?;
|
||||||
|
|
||||||
// Re-open it.
|
// Re-open it.
|
||||||
let mut file2 = file.reopen().map_err(to_compile_error)?;
|
|
||||||
let (file, filepath) = file.keep().map_err(to_compile_error)?;
|
let (file, filepath) = file.keep().map_err(to_compile_error)?;
|
||||||
obj.write(file).map_err(to_compile_error)?;
|
obj.write(file).map_err(to_compile_error)?;
|
||||||
|
|
||||||
let shared_file = NamedTempFile::new().map_err(to_compile_error)?;
|
let shared_file = NamedTempFile::new().map_err(to_compile_error)?;
|
||||||
let (file, shared_filepath) = shared_file.keep().map_err(to_compile_error)?;
|
let (_file, shared_filepath) = shared_file.keep().map_err(to_compile_error)?;
|
||||||
let output = Command::new("gcc")
|
let output = Command::new("gcc")
|
||||||
.arg(&filepath)
|
.arg(&filepath)
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
@@ -281,12 +273,26 @@ impl NativeModule {
|
|||||||
format!("wasmer_function_{}_{}", metadata.prefix, index.index())
|
format!("wasmer_function_{}_{}", metadata.prefix, index.index())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_function_call_trampoline_name(metadata: &ModuleMetadata, index: SignatureIndex) -> String {
|
fn get_function_call_trampoline_name(
|
||||||
format!("wasmer_trampoline_function_call_{}_{}", metadata.prefix, index.index())
|
metadata: &ModuleMetadata,
|
||||||
|
index: SignatureIndex,
|
||||||
|
) -> String {
|
||||||
|
format!(
|
||||||
|
"wasmer_trampoline_function_call_{}_{}",
|
||||||
|
metadata.prefix,
|
||||||
|
index.index()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_dynamic_function_trampoline_name(metadata: &ModuleMetadata, index: FunctionIndex) -> String {
|
fn get_dynamic_function_trampoline_name(
|
||||||
format!("wasmer_trampoline_dynamic_function_{}_{}", metadata.prefix, index.index())
|
metadata: &ModuleMetadata,
|
||||||
|
index: FunctionIndex,
|
||||||
|
) -> String {
|
||||||
|
format!(
|
||||||
|
"wasmer_trampoline_dynamic_function_{}_{}",
|
||||||
|
metadata.prefix,
|
||||||
|
index.index()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a `NativeModule` from component parts.
|
/// Construct a `NativeModule` from component parts.
|
||||||
@@ -329,9 +335,16 @@ impl NativeModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retrieve dynamic function trampolines (only for imported functions)
|
// Retrieve dynamic function trampolines (only for imported functions)
|
||||||
let mut finished_dynamic_function_trampolines: PrimaryMap<FunctionIndex, *const VMFunctionBody> =
|
let mut finished_dynamic_function_trampolines: PrimaryMap<
|
||||||
PrimaryMap::with_capacity(metadata.module.num_imported_funcs);
|
FunctionIndex,
|
||||||
for func_index in metadata.module.functions.keys().take(metadata.module.num_imported_funcs) {
|
*const VMFunctionBody,
|
||||||
|
> = PrimaryMap::with_capacity(metadata.module.num_imported_funcs);
|
||||||
|
for func_index in metadata
|
||||||
|
.module
|
||||||
|
.functions
|
||||||
|
.keys()
|
||||||
|
.take(metadata.module.num_imported_funcs)
|
||||||
|
{
|
||||||
let function_name = Self::get_dynamic_function_trampoline_name(&metadata, func_index);
|
let function_name = Self::get_dynamic_function_trampoline_name(&metadata, func_index);
|
||||||
unsafe {
|
unsafe {
|
||||||
let trampoline: Symbol<*const VMFunctionBody> = lib
|
let trampoline: Symbol<*const VMFunctionBody> = lib
|
||||||
@@ -404,13 +417,13 @@ impl NativeModule {
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
let mut size = &mut **symbol.deref();
|
let size = &mut **symbol.deref();
|
||||||
let mut readable = &size[..];
|
let mut readable = &size[..];
|
||||||
let metadata_len = leb128::read::unsigned(&mut readable).map_err(|e| {
|
let metadata_len = leb128::read::unsigned(&mut readable).map_err(|_e| {
|
||||||
DeserializeError::CorruptedBinary("Can't read metadata size".to_string())
|
DeserializeError::CorruptedBinary("Can't read metadata size".to_string())
|
||||||
})?;
|
})?;
|
||||||
let metadata_slice: &'static [u8] =
|
let metadata_slice: &'static [u8] =
|
||||||
unsafe { slice::from_raw_parts(&size[10] as *const u8, metadata_len as usize) };
|
slice::from_raw_parts(&size[10] as *const u8, metadata_len as usize);
|
||||||
let metadata: ModuleMetadata = bincode::deserialize(metadata_slice)
|
let metadata: ModuleMetadata = bincode::deserialize(metadata_slice)
|
||||||
.map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;
|
.map_err(|e| DeserializeError::CorruptedBinary(format!("{:?}", e)))?;
|
||||||
let mut engine_inner = engine.inner_mut();
|
let mut engine_inner = engine.inner_mut();
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wasm_common::entity::PrimaryMap;
|
use wasm_common::entity::PrimaryMap;
|
||||||
use wasm_common::{
|
use wasm_common::{Features, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, TableIndex};
|
||||||
Features, LocalFunctionIndex, MemoryIndex, OwnedDataInitializer, SignatureIndex, TableIndex,
|
|
||||||
};
|
|
||||||
use wasmer_compiler::{FunctionBody, JumpTableOffsets, Relocation, SectionBody, SectionIndex};
|
|
||||||
use wasmer_engine::SerializableFunctionFrameInfo;
|
|
||||||
use wasmer_runtime::Module;
|
use wasmer_runtime::Module;
|
||||||
use wasmer_runtime::{MemoryPlan, TablePlan};
|
use wasmer_runtime::{MemoryPlan, TablePlan};
|
||||||
|
|
||||||
|
|||||||
@@ -146,8 +146,7 @@ impl Run {
|
|||||||
}
|
}
|
||||||
#[cfg(feature = "jit")]
|
#[cfg(feature = "jit")]
|
||||||
{
|
{
|
||||||
use wasmer_engine_jit::JITEngine;
|
if wasmer_engine_jit::JITEngine::is_deserializable(&contents) {
|
||||||
if JITEngine::is_deserializable(&contents) {
|
|
||||||
let tunables = Tunables::default();
|
let tunables = Tunables::default();
|
||||||
let engine = JITEngine::headless(tunables);
|
let engine = JITEngine::headless(tunables);
|
||||||
let store = Store::new(Arc::new(engine));
|
let store = Store::new(Arc::new(engine));
|
||||||
|
|||||||
Reference in New Issue
Block a user