mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-29 08:31:32 +00:00
Enforce runtime memory and stack bound check when using kernel loader.
This commit is contained in:
@ -40,15 +40,12 @@ impl Token {
|
||||
}
|
||||
|
||||
/// 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>>,
|
||||
}
|
||||
|
||||
impl Default for CompilerConfig {
|
||||
fn default() -> CompilerConfig {
|
||||
CompilerConfig { symbol_map: None }
|
||||
}
|
||||
pub enforce_memory_bound_check: bool,
|
||||
pub enforce_stack_check: bool,
|
||||
}
|
||||
|
||||
pub trait Compiler {
|
||||
|
@ -43,6 +43,8 @@ pub trait ModuleCodeGenerator<FCG: FunctionCodeGenerator<E>, RM: RunnableModule,
|
||||
|
||||
/// Adds an import function.
|
||||
fn feed_import_function(&mut self) -> Result<(), E>;
|
||||
|
||||
fn feed_compiler_config(&mut self, config: &CompilerConfig) -> Result<(), E> { Ok(()) }
|
||||
}
|
||||
|
||||
pub struct StreamingCompiler<
|
||||
|
@ -53,6 +53,8 @@ pub fn read_module<
|
||||
middlewares: &mut MiddlewareChain,
|
||||
compiler_config: &CompilerConfig,
|
||||
) -> Result<ModuleInfo, LoadError> {
|
||||
mcg.feed_compiler_config(compiler_config)
|
||||
.map_err(|x| LoadError::Codegen(format!("{:?}", x)))?;
|
||||
let mut info = ModuleInfo {
|
||||
memories: Map::new(),
|
||||
globals: Map::new(),
|
||||
|
@ -65,6 +65,8 @@ pub struct InternalCtx {
|
||||
pub dynamic_sigindices: *const SigId,
|
||||
|
||||
pub intrinsics: *const Intrinsics,
|
||||
|
||||
pub stack_lower_bound: *mut u8,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@ -157,6 +159,8 @@ impl Ctx {
|
||||
dynamic_sigindices: local_backing.dynamic_sigindices.as_ptr(),
|
||||
|
||||
intrinsics: get_intrinsics_for_module(&module.info),
|
||||
|
||||
stack_lower_bound: ::std::ptr::null_mut(),
|
||||
},
|
||||
local_functions: local_backing.local_functions.as_ptr(),
|
||||
|
||||
@ -191,6 +195,8 @@ impl Ctx {
|
||||
dynamic_sigindices: local_backing.dynamic_sigindices.as_ptr(),
|
||||
|
||||
intrinsics: get_intrinsics_for_module(&module.info),
|
||||
|
||||
stack_lower_bound: ::std::ptr::null_mut(),
|
||||
},
|
||||
local_functions: local_backing.local_functions.as_ptr(),
|
||||
|
||||
@ -288,9 +294,13 @@ impl Ctx {
|
||||
8 * (mem::size_of::<usize>() as u8)
|
||||
}
|
||||
|
||||
pub fn offset_local_functions() -> u8 {
|
||||
pub fn offset_stack_lower_bound() -> u8 {
|
||||
9 * (mem::size_of::<usize>() as u8)
|
||||
}
|
||||
|
||||
pub fn offset_local_functions() -> u8 {
|
||||
10 * (mem::size_of::<usize>() as u8)
|
||||
}
|
||||
}
|
||||
|
||||
enum InnerFunc {}
|
||||
@ -489,6 +499,11 @@ mod vm_offset_tests {
|
||||
offset_of!(InternalCtx => intrinsics).get_byte_offset(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ctx::offset_stack_lower_bound() as usize,
|
||||
offset_of!(InternalCtx => stack_lower_bound).get_byte_offset(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Ctx::offset_local_functions() as usize,
|
||||
offset_of!(Ctx => local_functions).get_byte_offset(),
|
||||
|
Reference in New Issue
Block a user