mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-12 22:05:33 +00:00
Disable memory bound checking for kernel loader.
This commit is contained in:
parent
accb80bca2
commit
620a6ddd85
@ -39,12 +39,25 @@ impl Token {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum MemoryBoundCheckMode {
|
||||
Default,
|
||||
Enable,
|
||||
Disable,
|
||||
}
|
||||
|
||||
impl Default for MemoryBoundCheckMode {
|
||||
fn default() -> MemoryBoundCheckMode {
|
||||
MemoryBoundCheckMode::Default
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration data for the compiler
|
||||
#[derive(Default)]
|
||||
pub struct CompilerConfig {
|
||||
/// Symbol information generated from emscripten; used for more detailed debug messages
|
||||
pub symbol_map: Option<HashMap<u32, String>>,
|
||||
pub enforce_memory_bound_check: bool,
|
||||
pub memory_bound_check_mode: MemoryBoundCheckMode,
|
||||
pub enforce_stack_check: bool,
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use smallvec::SmallVec;
|
||||
use std::ptr::NonNull;
|
||||
use std::{any::Any, collections::HashMap, sync::Arc};
|
||||
use wasmer_runtime_core::{
|
||||
backend::{Backend, RunnableModule, CompilerConfig},
|
||||
backend::{Backend, RunnableModule, CompilerConfig, MemoryBoundCheckMode},
|
||||
codegen::*,
|
||||
memory::MemoryType,
|
||||
module::ModuleInfo,
|
||||
@ -290,7 +290,7 @@ pub struct CodegenError {
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
struct CodegenConfig {
|
||||
enforce_memory_bound_check: bool,
|
||||
memory_bound_check_mode: MemoryBoundCheckMode,
|
||||
enforce_stack_check: bool,
|
||||
}
|
||||
|
||||
@ -475,7 +475,7 @@ impl ModuleCodeGenerator<X64FunctionCode, X64ExecutionContext, CodegenError>
|
||||
|
||||
fn feed_compiler_config(&mut self, config: &CompilerConfig) -> Result<(), CodegenError> {
|
||||
self.config = Some(Arc::new(CodegenConfig {
|
||||
enforce_memory_bound_check: config.enforce_memory_bound_check,
|
||||
memory_bound_check_mode: config.memory_bound_check_mode,
|
||||
enforce_stack_check: config.enforce_stack_check,
|
||||
}));
|
||||
Ok(())
|
||||
@ -1243,13 +1243,13 @@ impl X64FunctionCode {
|
||||
&module_info.imported_memories[import_mem_index].1
|
||||
}
|
||||
};
|
||||
let need_check = if config.enforce_memory_bound_check {
|
||||
true
|
||||
} else {
|
||||
match mem_desc.memory_type() {
|
||||
let need_check = match config.memory_bound_check_mode {
|
||||
MemoryBoundCheckMode::Default => match mem_desc.memory_type() {
|
||||
MemoryType::Dynamic => true,
|
||||
MemoryType::Static | MemoryType::SharedStatic => false,
|
||||
}
|
||||
},
|
||||
MemoryBoundCheckMode::Enable => true,
|
||||
MemoryBoundCheckMode::Disable => false,
|
||||
};
|
||||
|
||||
if need_check {
|
||||
|
@ -10,7 +10,7 @@ use wasmer_runtime::{
|
||||
};
|
||||
use wasmer_runtime_core::{
|
||||
self,
|
||||
backend::{Compiler, CompilerConfig},
|
||||
backend::{Compiler, CompilerConfig, MemoryBoundCheckMode},
|
||||
loader::{self, Loader, Instance as LoadedInstance, LocalLoader},
|
||||
};
|
||||
use wasmer_singlepass_backend::SinglePassCompiler;
|
||||
@ -50,7 +50,7 @@ fn handle_client(mut stream: UnixStream) {
|
||||
&wasm_binary[..],
|
||||
CompilerConfig {
|
||||
symbol_map: None,
|
||||
enforce_memory_bound_check: true,
|
||||
memory_bound_check_mode: MemoryBoundCheckMode::Disable,
|
||||
enforce_stack_check: true,
|
||||
},
|
||||
&SinglePassCompiler::new(),
|
||||
|
@ -22,7 +22,7 @@ use wasmer_runtime::{
|
||||
};
|
||||
use wasmer_runtime_core::{
|
||||
self,
|
||||
backend::{Compiler, CompilerConfig},
|
||||
backend::{Compiler, CompilerConfig, MemoryBoundCheckMode},
|
||||
loader::{self, Loader, Instance as LoadedInstance, LocalLoader},
|
||||
};
|
||||
#[cfg(feature = "backend:singlepass")]
|
||||
@ -298,7 +298,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||
&wasm_binary[..],
|
||||
CompilerConfig {
|
||||
symbol_map: em_symbol_map,
|
||||
enforce_memory_bound_check: true,
|
||||
memory_bound_check_mode: MemoryBoundCheckMode::Disable,
|
||||
enforce_stack_check: true,
|
||||
},
|
||||
&*compiler,
|
||||
@ -368,7 +368,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
|
||||
.map(|arg| arg.as_str())
|
||||
.map(|x| Value::I32(x.parse().unwrap()))
|
||||
.collect();
|
||||
let index = instance.resolve_local_func("main").unwrap();
|
||||
let index = instance.resolve_func("_start").unwrap();
|
||||
let mut ins: Box<LoadedInstance<Error = String>> = match loader {
|
||||
LoaderName::Local => Box::new(instance.load(LocalLoader).unwrap()),
|
||||
LoaderName::Kernel => Box::new(instance.load(::kwasm_loader::KernelLoader).unwrap()),
|
||||
|
Loading…
Reference in New Issue
Block a user