cranelift-interpreter: Add trap on misaligned memory accesses (#5921)

* Add checks to `InterpreterState::checked_{load,store}` to trap on misaligned memory accesses
where `aligned` memory flag is set.

* Alter `stack_{load,store}` instructions to now rely on `MemFlags::new()` instead of
`MemFlags::trusted` since `InterpreterState::checked_{load,store}` is only able to
deduce type alignment and not stack slot alignment.
This commit is contained in:
Jan-Justin van Tonder
2023-03-07 01:06:19 +01:00
committed by GitHub
parent 3c9fc3ec8c
commit a2beacd288
3 changed files with 69 additions and 2 deletions

View File

@@ -142,6 +142,10 @@ pub enum MemoryError {
OutOfBoundsLoad { addr: Address, load_size: usize },
#[error("Store of {store_size} bytes is larger than available size at address {addr:?}")]
OutOfBoundsStore { addr: Address, store_size: usize },
#[error("Load of {load_size} bytes is misaligned at address {addr:?}")]
MisalignedLoad { addr: Address, load_size: usize },
#[error("Store of {store_size} bytes is misaligned at address {addr:?}")]
MisalignedStore { addr: Address, store_size: usize },
}
/// This dummy state allows interpretation over an immutable mapping of values in a single frame.