Commit b21d3535a5

LemonBoy <thatlemon@gmail.com>
2020-03-23 20:12:10
std: Fix parameters for pthread_attr_setstack
The guard page size shouldn't be taken into account, pthread is only interested in the usable area.
1 parent 09a5f17
Changed files (1)
lib
lib/std/thread.zig
@@ -375,7 +375,12 @@ pub const Thread = struct {
             if (c.pthread_attr_init(&attr) != 0) return error.SystemResources;
             defer assert(c.pthread_attr_destroy(&attr) == 0);
 
-            assert(c.pthread_attr_setstack(&attr, mmap_slice.ptr, stack_end_offset) == 0);
+            // Tell pthread where the effective stack start is and its size
+            assert(c.pthread_attr_setstack(
+                &attr,
+                mmap_slice.ptr + guard_end_offset,
+                stack_end_offset - guard_end_offset,
+            ) == 0);
 
             const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
             switch (err) {