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.
This commit is contained in:
LemonBoy 2020-03-23 23:26:34 +01:00
parent d6739b1397
commit c3f93be00c
2 changed files with 6 additions and 0 deletions

View File

@ -184,6 +184,7 @@ pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
pub 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;
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) c_int;
pub extern "c" fn pthread_attr_setstack(attr: *pthread_attr_t, stackaddr: *c_void, stacksize: usize) c_int;
pub extern "c" fn pthread_attr_setguardsize(attr: *pthread_attr_t, guardsize: usize) c_int;
pub extern "c" fn pthread_attr_destroy(attr: *pthread_attr_t) c_int;
pub extern "c" fn pthread_self() pthread_t;
pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*c_void) c_int;

View File

@ -381,6 +381,11 @@ pub const Thread = struct {
mmap_slice.ptr + guard_end_offset,
stack_end_offset - guard_end_offset,
) == 0);
// Even though pthread's man pages state that the guard size is
// ignored when the stack address is explicitly given, on some
// plaforms such as NetBSD we still have to zero it to prevent
// random crashes in pthread_join calls
assert(c.pthread_attr_setguardsize(&attr, 0) == 0);
const err = c.pthread_create(&thread_ptr.data.handle, &attr, MainFuncs.posixThreadMain, @intToPtr(*c_void, arg));
switch (err) {