@@ -201,28 +201,17 @@ pub mod guard {
201
201
current ( ) . map ( |s| s as * mut libc:: c_void )
202
202
}
203
203
204
- #[ cfg( target_os = "freebsd" ) ]
204
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" ,
205
+ target_os = "linux" , target_os = "netbsd" ) ) ]
205
206
unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
206
207
let mut ret = None ;
207
208
let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
208
209
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 {
226
215
let mut stackaddr = :: ptr:: null_mut ( ) ;
227
216
let mut stacksize = 0 ;
228
217
assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
@@ -304,33 +293,18 @@ pub mod guard {
304
293
} )
305
294
}
306
295
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" ) ) ]
329
298
pub unsafe fn current ( ) -> Option < usize > {
330
299
let mut ret = None ;
331
300
let mut attr: libc:: pthread_attr_t = :: mem:: zeroed ( ) ;
332
301
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 {
334
308
let mut guardsize = 0 ;
335
309
assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
336
310
if guardsize == 0 {
@@ -341,7 +315,9 @@ pub mod guard {
341
315
assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr,
342
316
& mut size) , 0 ) ;
343
317
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" ) {
345
321
Some ( stackaddr as usize )
346
322
} else {
347
323
Some ( stackaddr as usize + guardsize as usize )
0 commit comments