Skip to content

Commit 1f1e189

Browse files
committed
Merge pull request #20920 from piyo/issue-20853
Give mmap a page-aligned stack start address Reviewed-by: Aatch
2 parents a1a34a3 + 0568464 commit 1f1e189

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/libstd/sys/unix/thread.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,19 @@ pub mod guard {
9393

9494
PAGE_SIZE = psize as uint;
9595

96-
let stackaddr = get_stack_start();
96+
let mut stackaddr = get_stack_start();
97+
98+
// Ensure stackaddr is page aligned! A parent process might
99+
// have reset RLIMIT_STACK to be non-page aligned. The
100+
// pthread_attr_getstack() reports the usable stack area
101+
// stackaddr < stackaddr + stacksize, so if stackaddr is not
102+
// page-aligned, calculate the fix such that stackaddr <
103+
// new_page_aligned_stackaddr < stackaddr + stacksize
104+
let remainder = (stackaddr as usize) % (PAGE_SIZE as usize);
105+
if remainder != 0 {
106+
stackaddr = ((stackaddr as usize) + (PAGE_SIZE as usize) - remainder)
107+
as *mut libc::c_void;
108+
}
97109

98110
// Rellocate the last page of the stack.
99111
// This ensures SIGBUS will be raised on

0 commit comments

Comments
 (0)