diff --git a/library/std/src/sys/pal/unix/thread.rs b/library/std/src/sys/pal/unix/thread.rs index 8c9167ee9eb28..aee108a60cfed 100644 --- a/library/std/src/sys/pal/unix/thread.rs +++ b/library/std/src/sys/pal/unix/thread.rs @@ -806,6 +806,8 @@ pub mod guard { #[cfg(target_os = "netbsd")] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { let mut ret = None; + // We do not need pthread_attr_init/pthread_attr_destroy + // instead we use `pthread_getattr_np` to initialise the thread's attribute let mut attr: libc::pthread_attr_t = crate::mem::zeroed(); let e = libc::pthread_getattr_np(libc::pthread_self(), &mut attr); if e == 0 { @@ -816,7 +818,9 @@ pub mod guard { // on netbsd, we need to take in account the guard size to push up // the stack's address from the bottom. assert_eq!(libc::pthread_attr_getguardsize(&attr, &mut guardsize), 0); - stackaddr = stackaddr.add(guardsize); + // Only hppa arch seems to support stack growing up to higher address + // (__MACHINE_STACK_GROWS_UP) + stackaddr = stackaddr.sub(guardsize); ret = Some(stackaddr); } ret