Skip to content

Commit

Permalink
shell: test_page_fault asm
Browse files Browse the repository at this point in the history
Rewrote the test_page_fault function in asm, because rust
used to optimize it out since it is extremely UB.

Fixes sunriseos#223

I went and checked in GDB, and @roblabla was right, the match branch
was never taken, but instead we ended up in weird places.

Now it seems to be working... well, crashing ... well, doing what we expect.
  • Loading branch information
Orycterope committed Mar 14, 2019
1 parent 1d4a9ac commit 88cd8e8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,13 @@ fn test_divide_by_zero() {

/// Test function ensuring pagefaults kills only the current process.
fn test_page_fault() {
let ptr: *const u8 = core::ptr::null();
let _res = unsafe { *ptr };
// dereference the null pointer.
// doing this in rust is so UB, it's optimized out, so we do it in asm.
unsafe {
asm!("
mov al, [0]
" ::: "eax" : "volatile", "intel")
}
}

/// Meme for KFS1
Expand Down

0 comments on commit 88cd8e8

Please sign in to comment.