11use super :: mystd:: borrow:: ToOwned ;
22use super :: mystd:: ffi:: { CStr , OsStr } ;
33use super :: mystd:: os:: unix:: prelude:: * ;
4+ use super :: { mmap, xcoff} ;
45use super :: { Library , LibrarySegment , Vec } ;
56
7+ const EXE_IMAGE_BASE : u64 = 0x100000000 ;
8+
69pub ( super ) fn native_libraries ( ) -> Vec < Library > {
710 let mut ret = Vec :: new ( ) ;
811 unsafe {
@@ -26,17 +29,25 @@ pub(super) fn native_libraries() -> Vec<Library> {
2629 loop {
2730 let text_base = ( * current) . ldinfo_textorg as usize ;
2831 if text_base != 0 {
29- let text_size = ( * current) . ldinfo_textsize as usize ;
3032 let bytes = CStr :: from_ptr ( & ( * current) . ldinfo_filename [ 0 ] ) . to_bytes ( ) ;
31- let name = OsStr :: from_bytes ( bytes) . to_owned ( ) ;
32- ret. push ( Library {
33- name,
34- segments : vec ! [ LibrarySegment {
35- stated_virtual_memory_address: text_base,
36- len: text_size,
37- } ] ,
38- bias : 0 ,
39- } ) ;
33+ let mut name = OsStr :: from_bytes ( bytes) . to_owned ( ) ;
34+ if text_base == EXE_IMAGE_BASE as usize {
35+ if let Ok ( exe) = std:: env:: current_exe ( ) {
36+ name = exe. into_os_string ( ) ;
37+ }
38+ }
39+ if let Some ( map) = mmap ( name. as_ref ( ) ) {
40+ if let Some ( image) = xcoff:: get_text_image ( & map) {
41+ ret. push ( Library {
42+ name,
43+ segments : vec ! [ LibrarySegment {
44+ stated_virtual_memory_address: image. base as usize ,
45+ len: image. size,
46+ } ] ,
47+ bias : ( text_base + image. offset ) . wrapping_sub ( image. base as usize ) ,
48+ } ) ;
49+ }
50+ } ;
4051 }
4152 if ( * current) . ldinfo_next == 0 {
4253 break ;
0 commit comments