From cfbbab3fb9925bba7288c21488744c2c98669f08 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Sat, 26 Apr 2025 02:17:46 +0300 Subject: [PATCH] stacker: make remaining stack computation more resilient Sounds like it is plausible for the stack pointer to end up past the computed stack limit depending on the implementation of stack growing and the exact timing at which the stack limit is determined. Supersedes #51 Co-authored-by: Jude Nelson Co-authored-by: Reagan Bohan --- Cargo.toml | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ef48a05..ccb231d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "stacker" -version = "0.1.20" +version = "0.1.21" edition = "2021" rust-version = "1.63" authors = ["Alex Crichton ", "Simonas Kazlauskas "] diff --git a/src/lib.rs b/src/lib.rs index ea58ee9..ee5803c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -91,7 +91,7 @@ pub fn grow R>(stack_size: usize, callback: F) -> R { /// to determine whether a stack switch should be made or not. pub fn remaining_stack() -> Option { let current_ptr = current_stack_ptr(); - get_stack_limit().map(|limit| current_ptr - limit) + get_stack_limit().map(|limit| current_ptr.saturating_sub(limit)) } psm_stack_information!(