Skip to content

Commit

Permalink
miri: Use strict provenance
Browse files Browse the repository at this point in the history
Currently the tests succeed by using strict provenance. Let's try to use
that so we can possibly catch more memory errors.
  • Loading branch information
sysheap committed Jan 5, 2025
1 parent bdbc217 commit bf8786a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ system-test: build
cargo nextest run --release --manifest-path system-tests/Cargo.toml --target x86_64-unknown-linux-gnu

miri: build-cargo
MIRIFLAGS="-Zmiri-env-forward=RUST_BACKTRACE" RUST_BACKTRACE=1 cargo miri test --target riscv64gc-unknown-linux-gnu
MIRIFLAGS="-Zmiri-env-forward=RUST_BACKTRACE -Zmiri-strict-provenance" RUST_BACKTRACE=1 cargo miri test --target riscv64gc-unknown-linux-gnu

fetch-deps:
cargo fetch
Expand Down
16 changes: 10 additions & 6 deletions kernel/src/klibc/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,30 @@ mod tests {
};
}

fn mmio<T>(value: *mut T) -> MMIO<T> {
MMIO { addr: value }
}

#[test_case]
fn print_works() {
let value = get_test_data();
let mut value = get_test_data();

unsafe {
QEMU_UART.disarm();
}

crate::println!("value at {:p}", &value);

let mmio = MMIO::<mmio_a>::new(&value as *const _ as usize);
let mmio = mmio(&mut value);

crate::println!("{:?}", mmio);
}

#[test_case]
fn offsets() {
let value = get_test_data();
let mut value = get_test_data();

let mmio = MMIO::<mmio_a>::new(&value as *const _ as usize);
let mmio = mmio(&mut value);

check_offset!(value, mmio, a1);
check_offset!(value, mmio, a2);
Expand All @@ -208,7 +212,7 @@ mod tests {
let value = UnsafeCell::new(get_test_data());
let ptr = value.get();

let mmio = MMIO::<mmio_a>::new(ptr as usize);
let mmio = mmio(ptr);

mmio.a1().write(0);
mmio.a2().write(1);
Expand Down Expand Up @@ -239,7 +243,7 @@ mod tests {
let mut value = UnsafeCell::new(42);
let ptr = value.get();

let mut mmio = MMIO::<i32>::new(ptr as usize);
let mut mmio = mmio(ptr);

assert_eq!(mmio.addr as *const i32, ptr);

Expand Down

0 comments on commit bf8786a

Please sign in to comment.