@@ -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,6 +201,22 @@ pub mod guard {
199201 current ( ) . map ( |s| s as * mut libc:: c_void )
200202 }
201203
204+ #[ cfg( target_os = "freebsd" ) ]
205+ unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
206+ let mut ret = None ;
207+ let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
208+ assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
209+ if libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
210+ let mut stackaddr = :: ptr:: null_mut ( ) ;
211+ let mut stacksize = 0 ;
212+ assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
213+ & mut stacksize) , 0 ) ;
214+ ret = Some ( stackaddr) ;
215+ }
216+ assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
217+ ret
218+ }
219+
202220 #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
203221 unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
204222 let mut ret = None ;
@@ -248,7 +266,11 @@ pub mod guard {
248266 panic ! ( "failed to allocate a guard page" ) ;
249267 }
250268
251- let offset = if cfg ! ( target_os = "linux" ) { 2 } else { 1 } ;
269+ let offset = if cfg ! ( any( target_os = "linux" , target_os = "freebsd" ) ) {
270+ 2
271+ } else {
272+ 1
273+ } ;
252274
253275 Some ( stackaddr as usize + offset * psize)
254276 }
@@ -282,6 +304,27 @@ pub mod guard {
282304 } )
283305 }
284306
307+ #[ cfg( target_os = "freebsd" ) ]
308+ pub unsafe fn current ( ) -> Option < usize > {
309+ let mut ret = None ;
310+ let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
311+ assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
312+ if libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) == 0 {
313+ let mut guardsize = 0 ;
314+ assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
315+ if guardsize == 0 {
316+ panic ! ( "there is no guard page" ) ;
317+ }
318+ let mut stackaddr = :: ptr:: null_mut ( ) ;
319+ let mut size = 0 ;
320+ assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
321+ & mut size) , 0 ) ;
322+ ret = Some ( stackaddr as usize - guardsize as usize ) ;
323+ }
324+ assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
325+ ret
326+ }
327+
285328 #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
286329 pub unsafe fn current ( ) -> Option < usize > {
287330 let mut ret = None ;
0 commit comments