@@ -164,6 +164,7 @@ impl Drop for Thread {
164164}
165165
166166#[ cfg( all( not( all( target_os = "linux" , not( target_env = "musl" ) ) ) ,
167+ not( target_os = "freebsd" ) ,
167168 not( target_os = "macos" ) ,
168169 not( target_os = "bitrig" ) ,
169170 not( all( target_os = "netbsd" , not( target_vendor = "rumprun" ) ) ) ,
@@ -177,6 +178,7 @@ pub mod guard {
177178
178179
179180#[ cfg( any( all( target_os = "linux" , not( target_env = "musl" ) ) ,
181+ target_os = "freebsd" ,
180182 target_os = "macos" ,
181183 target_os = "bitrig" ,
182184 all( target_os = "netbsd" , not( target_vendor = "rumprun" ) ) ,
@@ -199,12 +201,17 @@ pub mod guard {
199201 current ( ) . map ( |s| s as * mut libc:: c_void )
200202 }
201203
202- #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
204+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
205+ target_os = "linux" , target_os = "netbsd" ) ) ]
203206 unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
204207 let mut ret = None ;
205208 let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
206209 assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
207- if libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
210+ #[ cfg( target_os = "freebsd" ) ]
211+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
212+ #[ cfg( not( target_os = "freebsd" ) ) ]
213+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
214+ if e == 0 {
208215 let mut stackaddr = :: ptr:: null_mut ( ) ;
209216 let mut stacksize = 0 ;
210217 assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
@@ -248,7 +255,11 @@ pub mod guard {
248255 panic ! ( "failed to allocate a guard page" ) ;
249256 }
250257
251- let offset = if cfg ! ( target_os = "linux" ) { 2 } else { 1 } ;
258+ let offset = if cfg ! ( any( target_os = "linux" , target_os = "freebsd" ) ) {
259+ 2
260+ } else {
261+ 1
262+ } ;
252263
253264 Some ( stackaddr as usize + offset * psize)
254265 }
@@ -282,12 +293,17 @@ pub mod guard {
282293 } )
283294 }
284295
285- #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
296+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
297+ target_os = "linux" , target_os = "netbsd" ) ) ]
286298 pub unsafe fn current ( ) -> Option < usize > {
287299 let mut ret = None ;
288300 let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
289301 assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
290- if libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
302+ #[ cfg( target_os = "freebsd" ) ]
303+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
304+ #[ cfg( not( target_os = "freebsd" ) ) ]
305+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
306+ if e == 0 {
291307 let mut guardsize = 0 ;
292308 assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
293309 if guardsize == 0 {
@@ -298,7 +314,9 @@ pub mod guard {
298314 assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
299315 & mut size) , 0 ) ;
300316
301- ret = if cfg ! ( target_os = "netbsd" ) {
317+ ret = if cfg ! ( target_os = "freebsd" ) {
318+ Some ( stackaddr as usize - guardsize as usize )
319+ } else if cfg ! ( target_os = "netbsd" ) {
302320 Some ( stackaddr as usize )
303321 } else {
304322 Some ( stackaddr as usize + guardsize as usize )
0 commit comments