@@ -803,12 +803,30 @@ pub mod guard {
803
803
Some ( stack_ptr. with_addr ( stackaddr) )
804
804
}
805
805
806
+ #[ cfg( target_os = "netbsd" ) ]
807
+ unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
808
+ let mut ret = None ;
809
+ let mut attr: libc:: pthread_attr_t = crate :: mem:: zeroed ( ) ;
810
+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
811
+ if e == 0 {
812
+ let mut stackaddr = crate :: ptr:: null_mut ( ) ;
813
+ let mut stacksize = 0 ;
814
+ let mut guardsize = 0 ;
815
+ assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr, & mut stacksize) , 0 ) ;
816
+ // on netbsd, we need to take in account the guard size to push up
817
+ // the stack's address from the bottom.
818
+ assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
819
+ stackaddr = stackaddr. add ( guardsize) ;
820
+ ret = Some ( stackaddr) ;
821
+ }
822
+ ret
823
+ }
824
+
806
825
#[ cfg( any(
807
826
target_os = "android" ,
808
827
target_os = "freebsd" ,
809
828
target_os = "hurd" ,
810
829
target_os = "linux" ,
811
- target_os = "netbsd" ,
812
830
target_os = "l4re"
813
831
) ) ]
814
832
unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
@@ -911,9 +929,10 @@ pub mod guard {
911
929
}
912
930
} ) * page_size;
913
931
Some ( guard)
914
- } else if cfg ! ( target_os = "openbsd" ) {
932
+ } else if cfg ! ( any ( target_os = "openbsd" , target_os = "netbsd" ) ) {
915
933
// OpenBSD stack already includes a guard page, and stack is
916
934
// immutable.
935
+ // NetBSD stack includes the guard page.
917
936
//
918
937
// We'll just note where we expect rlimit to start
919
938
// faulting, so our handler can report "stack overflow", and
0 commit comments