@@ -319,21 +319,27 @@ mod imp {
319
319
) ) ]
320
320
unsafe fn get_stack_start ( ) -> Option < * mut libc:: c_void > {
321
321
let mut ret = None ;
322
- let mut attr: libc:: pthread_attr_t = crate :: mem:: zeroed ( ) ;
322
+ let mut attr: mem:: MaybeUninit < libc:: pthread_attr_t > = mem:: MaybeUninit :: uninit ( ) ;
323
+ if !cfg ! ( target_os = "freebsd" ) {
324
+ attr = mem:: MaybeUninit :: zeroed ( ) ;
325
+ }
323
326
#[ cfg( target_os = "freebsd" ) ]
324
- assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
327
+ assert_eq ! ( libc:: pthread_attr_init( attr. as_mut_ptr ( ) ) , 0 ) ;
325
328
#[ cfg( target_os = "freebsd" ) ]
326
- let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
329
+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , attr. as_mut_ptr ( ) ) ;
327
330
#[ cfg( not( target_os = "freebsd" ) ) ]
328
- let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
331
+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , attr. as_mut_ptr ( ) ) ;
329
332
if e == 0 {
330
333
let mut stackaddr = crate :: ptr:: null_mut ( ) ;
331
334
let mut stacksize = 0 ;
332
- assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackaddr, & mut stacksize) , 0 ) ;
335
+ assert_eq ! (
336
+ libc:: pthread_attr_getstack( attr. as_ptr( ) , & mut stackaddr, & mut stacksize) ,
337
+ 0
338
+ ) ;
333
339
ret = Some ( stackaddr) ;
334
340
}
335
341
if e == 0 || cfg ! ( target_os = "freebsd" ) {
336
- assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
342
+ assert_eq ! ( libc:: pthread_attr_destroy( attr. as_mut_ptr ( ) ) , 0 ) ;
337
343
}
338
344
ret
339
345
}
@@ -509,16 +515,20 @@ mod imp {
509
515
// FIXME: I am probably not unsafe.
510
516
unsafe fn current_guard ( ) -> Option < Range < usize > > {
511
517
let mut ret = None ;
512
- let mut attr: libc:: pthread_attr_t = crate :: mem:: zeroed ( ) ;
518
+
519
+ let mut attr: mem:: MaybeUninit < libc:: pthread_attr_t > = mem:: MaybeUninit :: uninit ( ) ;
520
+ if !cfg ! ( target_os = "freebsd" ) {
521
+ attr = mem:: MaybeUninit :: zeroed ( ) ;
522
+ }
513
523
#[ cfg( target_os = "freebsd" ) ]
514
- assert_eq ! ( libc:: pthread_attr_init( & mut attr) , 0 ) ;
524
+ assert_eq ! ( libc:: pthread_attr_init( attr. as_mut_ptr ( ) ) , 0 ) ;
515
525
#[ cfg( target_os = "freebsd" ) ]
516
- let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , & mut attr) ;
526
+ let e = libc:: pthread_attr_get_np ( libc:: pthread_self ( ) , attr. as_mut_ptr ( ) ) ;
517
527
#[ cfg( not( target_os = "freebsd" ) ) ]
518
- let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , & mut attr) ;
528
+ let e = libc:: pthread_getattr_np ( libc:: pthread_self ( ) , attr. as_mut_ptr ( ) ) ;
519
529
if e == 0 {
520
530
let mut guardsize = 0 ;
521
- assert_eq ! ( libc:: pthread_attr_getguardsize( & attr, & mut guardsize) , 0 ) ;
531
+ assert_eq ! ( libc:: pthread_attr_getguardsize( attr. as_ptr ( ) , & mut guardsize) , 0 ) ;
522
532
if guardsize == 0 {
523
533
if cfg ! ( all( target_os = "linux" , target_env = "musl" ) ) {
524
534
// musl versions before 1.1.19 always reported guard
@@ -531,7 +541,7 @@ mod imp {
531
541
}
532
542
let mut stackptr = crate :: ptr:: null_mut :: < libc:: c_void > ( ) ;
533
543
let mut size = 0 ;
534
- assert_eq ! ( libc:: pthread_attr_getstack( & attr, & mut stackptr, & mut size) , 0 ) ;
544
+ assert_eq ! ( libc:: pthread_attr_getstack( attr. as_ptr ( ) , & mut stackptr, & mut size) , 0 ) ;
535
545
536
546
let stackaddr = stackptr. addr ( ) ;
537
547
ret = if cfg ! ( any( target_os = "freebsd" , target_os = "netbsd" , target_os = "hurd" ) ) {
@@ -552,7 +562,7 @@ mod imp {
552
562
} ;
553
563
}
554
564
if e == 0 || cfg ! ( target_os = "freebsd" ) {
555
- assert_eq ! ( libc:: pthread_attr_destroy( & mut attr) , 0 ) ;
565
+ assert_eq ! ( libc:: pthread_attr_destroy( attr. as_mut_ptr ( ) ) , 0 ) ;
556
566
}
557
567
ret
558
568
}
0 commit comments