@@ -81,15 +81,9 @@ static int xdl_iterate_open_or_rewind_maps(FILE **maps) {
8181 return 0 ;
8282}
8383
84- static uintptr_t xdl_iterate_get_pathname_from_maps (struct dl_phdr_info * info , char * buf , size_t buf_len ,
85- FILE * * maps ) {
86- // get base address
87- uintptr_t min_vaddr = xdl_iterate_get_min_vaddr (info );
88- if (UINTPTR_MAX == min_vaddr ) return 0 ; // failed
89- uintptr_t base = (uintptr_t )(info -> dlpi_addr + min_vaddr );
90-
84+ static int xdl_iterate_get_pathname_from_maps (uintptr_t base , char * buf , size_t buf_len , FILE * * maps ) {
9185 // open or rewind maps-file
92- if (0 != xdl_iterate_open_or_rewind_maps (maps )) return 0 ; // failed
86+ if (0 != xdl_iterate_open_or_rewind_maps (maps )) return -1 ; // failed
9387
9488 char line [1024 ];
9589 while (fgets (line , sizeof (line ), * maps )) {
@@ -106,10 +100,10 @@ static uintptr_t xdl_iterate_get_pathname_from_maps(struct dl_phdr_info *info, c
106100
107101 // found it
108102 strlcpy (buf , pathname , buf_len );
109- return ( uintptr_t ) buf ; // OK
103+ return 0 ; // OK
110104 }
111105
112- return 0 ; // failed
106+ return -1 ; // failed
113107}
114108
115109static int xdl_iterate_by_linker_cb (struct dl_phdr_info * info , size_t size , void * arg ) {
@@ -142,11 +136,15 @@ static int xdl_iterate_by_linker_cb(struct dl_phdr_info *info, size_t size, void
142136
143137 // fix dlpi_name (from /proc/self/maps)
144138 if ('/' != info -> dlpi_name [0 ] && '[' != info -> dlpi_name [0 ] && (0 != (flags & XDL_FULL_PATHNAME ))) {
145- char buf [512 ];
146- uintptr_t pathname = xdl_iterate_get_pathname_from_maps (info , buf , sizeof (buf ), maps );
147- if (0 == pathname ) return 0 ; // ignore this ELF
139+ // get base address
140+ uintptr_t min_vaddr = xdl_iterate_get_min_vaddr (info );
141+ if (UINTPTR_MAX == min_vaddr ) return 0 ; // ignore this ELF
142+ uintptr_t base = (uintptr_t )(info -> dlpi_addr + min_vaddr );
143+
144+ char buf [1024 ];
145+ if (0 != xdl_iterate_get_pathname_from_maps (base , buf , sizeof (buf ), maps )) return 0 ; // ignore this ELF
148146
149- info -> dlpi_name = (const char * )pathname ;
147+ info -> dlpi_name = (const char * )buf ;
150148 }
151149
152150 // callback
@@ -245,3 +243,10 @@ int xdl_iterate_phdr_impl(xdl_iterate_phdr_cb_t cb, void *cb_arg, int flags) {
245243 // iterate by dl_iterate_phdr()
246244 return xdl_iterate_by_linker (cb , cb_arg , flags );
247245}
246+
247+ int xdl_iterate_get_full_pathname (uintptr_t base , char * buf , size_t buf_len ) {
248+ FILE * maps = NULL ;
249+ int r = xdl_iterate_get_pathname_from_maps (base , buf , buf_len , & maps );
250+ if (NULL != maps ) fclose (maps );
251+ return r ;
252+ }
0 commit comments