@@ -201,28 +201,17 @@ pub mod guard {
201201 current ( ) . map ( |s| s as * mut libc:: c_void )
202202 }
203203
204- #[ cfg( target_os = "freebsd" ) ]
204+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
205+ target_os = "linux" , target_os = "netbsd" ) ) ]
205206 unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
206207 let mut ret = None ;
207208 let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
208209 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-
220- #[ cfg( any( target_os = "linux" , target_os = "android" , target_os = "netbsd" ) ) ]
221- unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
222- let mut ret = None ;
223- let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
224- assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
225- 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 {
226215 let mut stackaddr = :: ptr:: null_mut ( ) ;
227216 let mut stacksize = 0 ;
228217 assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
@@ -304,33 +293,18 @@ pub mod guard {
304293 } )
305294 }
306295
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-
328- #[ 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" ) ) ]
329298 pub unsafe fn current ( ) -> Option < usize > {
330299 let mut ret = None ;
331300 let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
332301 assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
333- 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 {
307+ //if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 {
334308 let mut guardsize = 0 ;
335309 assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
336310 if guardsize == 0 {
@@ -341,7 +315,9 @@ pub mod guard {
341315 assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
342316 & mut size) , 0 ) ;
343317
344- ret = if cfg ! ( target_os = "netbsd" ) {
318+ ret = if cfg ! ( target_os = "freebsd" ) {
319+ Some ( stackaddr as usize - guardsize as usize )
320+ } else if cfg ! ( target_os = "netbsd" ) {
345321 Some ( stackaddr as usize )
346322 } else {
347323 Some ( stackaddr as usize + guardsize as usize )
0 commit comments