Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix signature index issue #155

Merged
merged 3 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 19 additions & 36 deletions lib/clif-backend/src/call/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,28 @@ 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<TrapData> {
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 {
Expand Down Expand Up @@ -89,42 +93,21 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull {
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")
}
}
TrapCode::HeapOutOfBounds => RuntimeError::OutOfBoundsAccess {
memory: MemoryIndex::new(0),
addr: 0,
},
TrapCode::TableOutOfBounds => RuntimeError::TableOutOfBounds {
table: TableIndex::new(0),
},
_ => RuntimeError::Unknown {
msg: "unknown trap".to_string(),
},
},
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")
}
}
Ok(SIGSEGV) | Ok(SIGBUS) => RuntimeError::OutOfBoundsAccess {
memory: MemoryIndex::new(0),
addr: 0,
},
Ok(SIGFPE) => RuntimeError::IllegalArithmeticOperation,
_ => unimplemented!(),
}
Expand Down
4 changes: 3 additions & 1 deletion lib/emscripten/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnsafeCell<[u8; 27]>>,
pub jumps: Vec<UnsafeCell<[u32; 27]>>,
}

impl<'a> EmscriptenData<'a> {
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions lib/emscripten/tests/emtests/_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

assert!(
output.contains(expected_output),
"Output: `{}` does not contain expected output: `{}`",
output,
expected_output
);
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
);
syrusakbary marked this conversation as resolved.
Show resolved Hide resolved
}};
}
2 changes: 1 addition & 1 deletion lib/runtime-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️


if signature.params() != Args::types() || signature.returns() != Rets::types() {
Err(ResolveError::Signature {
Expand Down