| 1 | From: Jakub Jirutka <[email protected]>
|
| 2 | Date: Sat, 15 Jul 2023 21:29:34 +0200
|
| 3 | Subject: [PATCH] Detect stack overflow in remaining_stack()
|
| 4 |
|
| 5 | See https://github.com/rust-lang/stacker/pull/51
|
| 6 |
|
| 7 | |
| 8 | |
| 9 | @@ -89,7 +89,12 @@
|
| 10 | /// to determine whether a stack switch should be made or not.
|
| 11 | pub fn remaining_stack() -> Option<usize> {
|
| 12 | let current_ptr = current_stack_ptr();
|
| 13 | - get_stack_limit().map(|limit| current_ptr - limit)
|
| 14 | + get_stack_limit().map(|limit| {
|
| 15 | + if current_ptr < limit {
|
| 16 | + panic!("stack overflow!");
|
| 17 | + }
|
| 18 | + current_ptr - limit
|
| 19 | + })
|
| 20 | }
|
| 21 |
|
| 22 | psm_stack_information! (
|