authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-23 23:26:34+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-23 23:26:34+01:00
logc3f93be00cd516a561b32df4c68b5ed01e851645
tree6fdc2ef671460c9e7e3449dcd724604bb7367264
parentd6739b1397b32dae936432d9da17e740477898eb

std: Tell pthread the guard page size is zero

On NetBSD this is needed to avoid crashes in pthread_join as the default value for the guard page size is not ignored even though a custom stack address is specified.

2 files changed, 6 insertions(+), 0 deletions(-)

lib/std/c.zig+1
......@@ -184,6 +184,7 @@ pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
184184pub extern "c" fn pthread_create(noalias newthread: *pthread_t, noalias attr: ?*const pthread_attr_t, start_routine: extern fn (?*c_void) ?*c_void, noalias arg: ?*c_void) c_int;
185185pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
186186pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
187pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
187188pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
188189pub extern "c" fn pthread_self() pthread_t;
189190pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;
lib/std/thread.zig+5
......@@ -381,6 +381,11 @@ pub const Thread = struct {
381381 mmap_slice.ptr + guard_end_offset,
382382 stack_end_offset - guard_end_offset,
383383 ) == 0);
384 // Even though pthread's man pages state that the guard size is
385 // ignored when the stack address is explicitly given, on some
386 // plaforms such as NetBSD we still have to zero it to prevent
387 // random crashes in pthread_join calls
388 assert(c.pthread_attr_setguardsize(&attr, 0) == 0);
384389
385390 const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
386391 switch (err) {