about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorClifford Caoile <piyo@users.sf.net>2015-01-11 12:52:50 +0900
committerClifford Caoile <piyo@users.sf.net>2015-01-11 12:56:04 +0900
commit0568464d365266d583e3562835fcdb2be4cc7860 (patch)
treee175ff83b9b15d47acf28bf835d8e4aad19120fb /src/libstd/sys
parent431105a70acaf6e0a1d64b6dd3f69563d6694287 (diff)
downloadrust-0568464d365266d583e3562835fcdb2be4cc7860.tar.gz
rust-0568464d365266d583e3562835fcdb2be4cc7860.zip
Give mmap a page-aligned stack start address
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/unix/thread.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs
index 2416b64f98f..ac51b68795f 100644
--- a/src/libstd/sys/unix/thread.rs
+++ b/src/libstd/sys/unix/thread.rs
@@ -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