@@ -208,7 +208,7 @@ cfg_if::cfg_if! {
208
208
target_os = "watchos" ,
209
209
) ) ] {
210
210
// macOS uses the Mach-O file format and uses DYLD-specific APIs to
211
- // load a list of native libraries that are part of the appplication .
211
+ // load a list of native libraries that are part of the application .
212
212
213
213
use mystd:: os:: unix:: prelude:: * ;
214
214
use mystd:: ffi:: { OsStr , CStr } ;
@@ -372,28 +372,32 @@ cfg_if::cfg_if! {
372
372
fn native_libraries( ) -> Vec <Library > {
373
373
let mut ret = Vec :: new( ) ;
374
374
unsafe {
375
- libc:: dl_iterate_phdr( Some ( callback) , & mut ret as * mut _ as * mut _) ;
375
+ libc:: dl_iterate_phdr( Some ( callback) , & mut ret as * mut Vec <_> as * mut _) ;
376
376
}
377
377
return ret;
378
378
}
379
379
380
+ // `info` should be a valid pointers.
381
+ // `vec` should be a valid pointer to a `std::Vec`.
380
382
unsafe extern "C" fn callback(
381
383
info: * mut libc:: dl_phdr_info,
382
384
_size: libc:: size_t,
383
385
vec: * mut libc:: c_void,
384
386
) -> libc:: c_int {
387
+ let info = & * info;
385
388
let libs = & mut * ( vec as * mut Vec <Library >) ;
386
- let name = if ( * info) . dlpi_name. is_null( ) || * ( * info) . dlpi_name == 0 {
389
+ let is_main_prog = info. dlpi_name. is_null( ) || * info. dlpi_name == 0 ;
390
+ let name = if is_main_prog {
387
391
if libs. is_empty( ) {
388
392
mystd:: env:: current_exe( ) . map( |e| e. into( ) ) . unwrap_or_default( )
389
393
} else {
390
394
OsString :: new( )
391
395
}
392
396
} else {
393
- let bytes = CStr :: from_ptr( ( * info) . dlpi_name) . to_bytes( ) ;
397
+ let bytes = CStr :: from_ptr( info. dlpi_name) . to_bytes( ) ;
394
398
OsStr :: from_bytes( bytes) . to_owned( )
395
399
} ;
396
- let headers = core:: slice:: from_raw_parts( ( * info) . dlpi_phdr, ( * info) . dlpi_phnum as usize ) ;
400
+ let headers = core:: slice:: from_raw_parts( info. dlpi_phdr, info. dlpi_phnum as usize ) ;
397
401
libs. push( Library {
398
402
name,
399
403
segments: headers
@@ -403,7 +407,7 @@ cfg_if::cfg_if! {
403
407
stated_virtual_memory_address: ( * header) . p_vaddr as usize ,
404
408
} )
405
409
. collect( ) ,
406
- bias: ( * info) . dlpi_addr as usize ,
410
+ bias: info. dlpi_addr as usize ,
407
411
} ) ;
408
412
0
409
413
}
0 commit comments