From 88f67c4c0b7531ed0ae5063f28953a96de541583 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Marie?= Date: Sat, 9 May 2020 09:43:45 +0200 Subject: [PATCH] allocate 2 pages more than requested for guard pages as there is two guard pages used (one on top, and another on bottom), two additionnals guard pages needs to be allocated. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4c51fac..827b0c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,7 +137,7 @@ psm_stack_manipulation! { fn _grow(stack_size: usize, callback: F) { // Calculate a number of pages we want to allocate for the new stack. // For maximum portability we want to produce a stack that is aligned to a page and has - // a size that’s a multiple of page size. Furthermore we want to allocate an extra page + // a size that’s a multiple of page size. Furthermore we want to allocate two extras pages // for the stack guard. To achieve that we do our calculations in number of pages and // convert to bytes last. // FIXME: consider caching the page size. @@ -145,7 +145,7 @@ psm_stack_manipulation! { let requested_pages = stack_size .checked_add(page_size - 1) .expect("unreasonably large stack requested") / page_size; - let stack_pages = std::cmp::max(1, requested_pages) + 1; + let stack_pages = std::cmp::max(1, requested_pages) + 2; let stack_bytes = stack_pages.checked_mul(page_size) .expect("unreasonably large stack requesteed");