diff --git a/lib/clif-backend/src/call/recovery.rs b/lib/clif-backend/src/call/recovery.rs index abeb8c5ca..e875fa8f1 100644 --- a/lib/clif-backend/src/call/recovery.rs +++ b/lib/clif-backend/src/call/recovery.rs @@ -36,24 +36,24 @@ unsafe impl Sync for HandlerData {} pub struct HandlerData { pub trap_data: TrapSink, - buffer_ptr: *const c_void, - buffer_size: usize, + exec_buffer_ptr: *const c_void, + exec_buffer_size: usize, } impl HandlerData { - pub fn new(trap_data: TrapSink, buffer_ptr: *const c_void, buffer_size: usize) -> Self { + pub fn new(trap_data: TrapSink, exec_buffer_ptr: *const c_void, exec_buffer_size: usize) -> Self { Self { trap_data, - buffer_ptr, - buffer_size, + exec_buffer_ptr, + exec_buffer_size, } } pub fn lookup(&self, ip: *const c_void) -> Option { let ip = ip as usize; - let buffer_ptr = self.buffer_ptr as usize; + let buffer_ptr = self.exec_buffer_ptr as usize; - if buffer_ptr <= ip && ip < buffer_ptr + self.buffer_size { + if buffer_ptr <= ip && ip < buffer_ptr + self.exec_buffer_size { let offset = ip - buffer_ptr; self.trap_data.lookup(offset) } else { @@ -90,18 +90,9 @@ pub fn call_protected(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R table: TableIndex::new(0), }, TrapCode::HeapOutOfBounds => { - let addr = - (faulting_addr as usize) - (handler_data.buffer_ptr as usize); - if addr <= handler_data.buffer_size { - // in the memory - RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: addr as u32, - } - } else { - // if there's an invalid access outside of the memory, including guard pages - // just kill the process. - panic!("invalid memory access, way out of bounds") + RuntimeError::OutOfBoundsAccess { + memory: MemoryIndex::new(0), + addr: 0, } } TrapCode::TableOutOfBounds => RuntimeError::TableOutOfBounds { @@ -112,17 +103,9 @@ pub fn call_protected(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R }, }, Ok(SIGSEGV) | Ok(SIGBUS) => { - let addr = (faulting_addr as usize) - (handler_data.buffer_ptr as usize); - if addr <= handler_data.buffer_size { - // in the memory - RuntimeError::OutOfBoundsAccess { - memory: MemoryIndex::new(0), - addr: addr as u32, - } - } else { - // if there's an invalid access outside of the memory, including guard pages - // just kill the process. - panic!("invalid memory access, way out of bounds") + RuntimeError::OutOfBoundsAccess { + memory: MemoryIndex::new(0), + addr: 0, } } Ok(SIGFPE) => RuntimeError::IllegalArithmeticOperation, diff --git a/lib/emscripten/src/lib.rs b/lib/emscripten/src/lib.rs index 6463bba0d..8a8ed4183 100644 --- a/lib/emscripten/src/lib.rs +++ b/lib/emscripten/src/lib.rs @@ -95,7 +95,7 @@ pub struct EmscriptenData<'a> { pub memset: Func<'a, (u32, u32, u32), u32>, pub stack_alloc: Func<'a, u32, u32>, - pub jumps: Vec>, + pub jumps: Vec>, } impl<'a> EmscriptenData<'a> { @@ -144,6 +144,8 @@ pub fn run_emscripten_instance( instance.call("___emscripten_environ_constructor", &[])?; } + println!("running emscripten instance"); + let main_func = instance.dyn_func("_main")?; let num_params = main_func.signature().params().len(); let _result = match num_params { diff --git a/lib/emscripten/tests/emtests/_common.rs b/lib/emscripten/tests/emtests/_common.rs index 161f7887e..8d3e00296 100644 --- a/lib/emscripten/tests/emtests/_common.rs +++ b/lib/emscripten/tests/emtests/_common.rs @@ -30,14 +30,14 @@ macro_rules! assert_emscripten_output { $args, ).expect("run_emscripten_instance finishes"); - let output = capturer.end().unwrap().0; - let expected_output = include_str!($expected); + let output = capturer.end().unwrap().0; + let expected_output = include_str!($expected); - assert!( - output.contains(expected_output), - "Output: `{}` does not contain expected output: `{}`", - output, - expected_output - ); + assert!( + output.contains(expected_output), + "Output: `{}` does not contain expected output: `{}`", + output, + expected_output + ); }}; } diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index 476c60929..a06da5f04 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -113,7 +113,7 @@ impl Instance { .func_assoc .get(*func_index) .expect("broken invariant, incorrect func index"); - let signature = SigRegistry.lookup_signature(sig_index); + let signature = &self.module.info.signatures[sig_index]; if signature.params() != Args::types() || signature.returns() != Rets::types() { Err(ResolveError::Signature {