Skip to content

Give mmap a page-aligned stack start address #20920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/libstd/sys/unix/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,19 @@ pub mod guard {

PAGE_SIZE = psize as uint;

let stackaddr = get_stack_start();
let mut stackaddr = get_stack_start();

// Ensure stackaddr is page aligned! A parent process might
// have reset RLIMIT_STACK to be non-page aligned. The
// pthread_attr_getstack() reports the usable stack area
// stackaddr < stackaddr + stacksize, so if stackaddr is not
// page-aligned, calculate the fix such that stackaddr <
// new_page_aligned_stackaddr < stackaddr + stacksize
let remainder = (stackaddr as usize) % (PAGE_SIZE as usize);
if remainder != 0 {
stackaddr = ((stackaddr as usize) + (PAGE_SIZE as usize) - remainder)
as *mut libc::c_void;
}

// Rellocate the last page of the stack.
// This ensures SIGBUS will be raised on
Expand Down