diff options
Diffstat (limited to 'shell/src')
| -rw-r--r-- | shell/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/shell/src/lib.rs b/shell/src/lib.rs index a32d259..175a2c7 100644 --- a/shell/src/lib.rs +++ b/shell/src/lib.rs | |||
| @@ -740,6 +740,7 @@ write `{} <path> TIL <marker>`", | |||
| 740 | "kill" => cmd_kill(&parsed), | 740 | "kill" => cmd_kill(&parsed), |
| 741 | "demo" => cmd_demo(&parsed), | 741 | "demo" => cmd_demo(&parsed), |
| 742 | "fault" => cmd_fault(), | 742 | "fault" => cmd_fault(), |
| 743 | "corrupt" => cmd_corrupt(), | ||
| 743 | "crashlog" => cmd_crashlog(), | 744 | "crashlog" => cmd_crashlog(), |
| 744 | "stall" => cmd_stall(&parsed), | 745 | "stall" => cmd_stall(&parsed), |
| 745 | _ => term_err(&alloc::format!("unknown command: {}", cmd)), | 746 | _ => term_err(&alloc::format!("unknown command: {}", cmd)), |
| @@ -839,6 +840,21 @@ fn cmd_fault() { | |||
| 839 | } | 840 | } |
| 840 | } | 841 | } |
| 841 | 842 | ||
| 843 | /// Deliberately clobber a live heap block's back-pointer, then free it — | ||
| 844 | /// test hook that proves the allocator's corruption guard fires with a | ||
| 845 | /// readable report (instead of a #GP inside `__rust_dealloc`). The | ||
| 846 | /// system stops; the log must show `!!! heap corruption in dealloc`. | ||
| 847 | fn cmd_corrupt() { | ||
| 848 | term_println("corrupt: clobbering a live block's back-pointer..."); | ||
| 849 | let s = String::from("hello heap guard"); | ||
| 850 | let ptr = s.as_ptr() as usize; | ||
| 851 | unsafe { | ||
| 852 | *((ptr - 8) as *mut usize) = 0xdeed_beef_deed_beefusize; | ||
| 853 | } | ||
| 854 | drop(s); | ||
| 855 | term_println("corrupt: guard did NOT fire (unexpected)"); | ||
| 856 | } | ||
| 857 | |||
| 842 | /// Debug hook: run the crash-log FAT write from the *shell* context (not | 858 | /// Debug hook: run the crash-log FAT write from the *shell* context (not |
| 843 | /// the fault ISR) to compare behaviour. | 859 | /// the fault ISR) to compare behaviour. |
| 844 | fn cmd_crashlog() { | 860 | fn cmd_crashlog() { |
