mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-01 15:31:04 +00:00
finish support for traps
This commit is contained in:
parent
ebeea0c71c
commit
de046491d2
@ -87,10 +87,21 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
|
|||||||
TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull {
|
TrapCode::IndirectCallToNull => RuntimeError::IndirectCallToNull {
|
||||||
table: TableIndex::new(0),
|
table: TableIndex::new(0),
|
||||||
},
|
},
|
||||||
TrapCode::HeapOutOfBounds => RuntimeError::OutOfBoundsAccess {
|
TrapCode::HeapOutOfBounds => {
|
||||||
memory: MemoryIndex::new(0),
|
let addr =
|
||||||
addr: 0,
|
(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 {
|
TrapCode::TableOutOfBounds => RuntimeError::TableOutOfBounds {
|
||||||
table: TableIndex::new(0),
|
table: TableIndex::new(0),
|
||||||
},
|
},
|
||||||
@ -99,11 +110,17 @@ pub fn call_protected<T>(handler_data: &HandlerData, f: impl FnOnce() -> T) -> R
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Ok(SIGSEGV) | Ok(SIGBUS) => {
|
Ok(SIGSEGV) | Ok(SIGBUS) => {
|
||||||
// I'm too lazy right now to actually check if the address is within one of the memories,
|
let addr = (faulting_addr as usize) - (handler_data.buffer_ptr as usize);
|
||||||
// so just say that it's a memory-out-of-bounds access for now
|
if addr <= handler_data.buffer_size {
|
||||||
RuntimeError::OutOfBoundsAccess {
|
// in the memory
|
||||||
memory: MemoryIndex::new(0),
|
RuntimeError::OutOfBoundsAccess {
|
||||||
addr: 0,
|
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,
|
Ok(SIGFPE) => RuntimeError::IllegalArithmeticOperation,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user