Skip to content

Commit

Permalink
Print iterator stages
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Jan 21, 2024
1 parent 327826f commit c23694b
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,15 @@ typedef struct {

static int iter_phdr_cb(struct dl_phdr_info* info, size_t size, void* data)
{
printf("LWJGL: iter_phdr_cb enter\n");
UNUSED_PARAM(size);
int l = -1;
iter_phdr_data* d = (iter_phdr_data*)data;
void* lib = NULL;

/* get loaded object's handle if not requesting info about process itself */
if(d->pLib != NULL) {
printf("LWJGL: pLib != null...\n");
/* unable to relate info->dlpi_addr directly to our dlopen handle, let's
* do what we do on macOS above, re-dlopen the already loaded lib (just
* increases ref count) and compare handles */
Expand All @@ -271,19 +273,23 @@ static int iter_phdr_cb(struct dl_phdr_info* info, size_t size, void* data)
/* compare handles and get name if found; if d->pLib == NULL this will
enter info on first iterated object, which is the process itself */
if(lib == (void*)d->pLib) {
printf("LWJGL: lib == d->pLib...\n");
l = dl_strlen_strcpy(d->sOut, info->dlpi_name, d->bufSize);

/* if dlpi_name is empty, lookup name via dladdr(proc_load_addr, ...) */
if(l == 0 && d->pLib == NULL) {
printf("LWJGL: starting dladdr() name lookup...\n");
/* dlpi_addr is the reloc base (0 if PIE), find real virtual load addr */
void* vladdr = (void*)info->dlpi_addr;
int i = 0;
printf("LWJGL: dlpi_phnum=%ld\n", (long)(info->dlpi_phnum));
for(; i < info->dlpi_phnum; ++i) {
if(info->dlpi_phdr[i].p_type == PT_LOAD) {
vladdr = (void*)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr);
break;
}
}
printf("LWJGL: Found! Exiting...\n");
Dl_info di;
if(dladdr(vladdr, &di) != 0)
l = dl_strlen_strcpy(d->sOut, di.dli_fname, d->bufSize);
Expand Down

0 comments on commit c23694b

Please sign in to comment.