Skip to content

Commit

Permalink
finish support for traps
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlansneff committed Jan 21, 2019
1 parent ebeea0c commit de04649
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lib/clif-backend/src/call/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,21 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull {
table: TableIndex::new(0),
},
TrapCode::HeapOutOfBounds => RuntimeError::OutOfBoundsAccess {
memory: MemoryIndex::new(0),
addr: 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::TableOutOfBounds => RuntimeError::TableOutOfBounds {
table: TableIndex::new(0),
},
Expand All @@ -99,11 +110,17 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
},
},
Ok(SIGSEGV) | Ok(SIGBUS) => {
// I'm too lazy right now to actually check if the address is within one of the memories,
// so just say that it's a memory-out-of-bounds access for now
RuntimeError::OutOfBoundsAccess {
memory: MemoryIndex::new(0),
addr: 0,
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(SIGFPE) => RuntimeError::IllegalArithmeticOperation,
Expand Down

0 comments on commit de04649

Please sign in to comment.