Skip to content

Commit 88f67c4

Browse files
committed
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.
1 parent 1581ef8 commit 88f67c4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ psm_stack_manipulation! {
137137
fn _grow<F: FnOnce()>(stack_size: usize, callback: F) {
138138
// Calculate a number of pages we want to allocate for the new stack.
139139
// For maximum portability we want to produce a stack that is aligned to a page and has
140-
// a size that’s a multiple of page size. Furthermore we want to allocate an extra page
140+
// a size that’s a multiple of page size. Furthermore we want to allocate two extras pages
141141
// for the stack guard. To achieve that we do our calculations in number of pages and
142142
// convert to bytes last.
143143
// FIXME: consider caching the page size.
144144
let page_size = unsafe { libc::sysconf(libc::_SC_PAGE_SIZE) } as usize;
145145
let requested_pages = stack_size
146146
.checked_add(page_size - 1)
147147
.expect("unreasonably large stack requested") / page_size;
148-
let stack_pages = std::cmp::max(1, requested_pages) + 1;
148+
let stack_pages = std::cmp::max(1, requested_pages) + 2;
149149
let stack_bytes = stack_pages.checked_mul(page_size)
150150
.expect("unreasonably large stack requesteed");
151151

0 commit comments

Comments
 (0)