Skip to content

Commit

Permalink
[BOX32] Fixed main Elf init not always called
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Sep 30, 2024
1 parent f7e769f commit f7c93b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,12 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
RunElfInit(lib_elf, emu);
}
printf_dump(LOG_DEBUG, "Calling Init for %s @%p\n", ElfName(h), (void*)p);
if(h->initentry)
RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv, my_context->envv);
if(h->initentry) {
if(box64_is32bits)
RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv32, my_context->envv32);
else
RunFunctionWithEmu(emu, 0, p, 3, my_context->argc, my_context->argv, my_context->envv);
}
printf_dump(LOG_DEBUG, "Done Init for %s\n", ElfName(h));
// and check init array now
#ifdef BOX32
Expand All @@ -1179,7 +1183,7 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu)
for (size_t i=0; i<h->initarray_sz; ++i) {
if(addr[i]) {
printf_dump(LOG_DEBUG, "Calling Init[%zu] for %s @%p\n", i, ElfName(h), from_ptrv(addr[i]));
RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv);
RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv32, my_context->envv32);
}
}
} else
Expand Down
8 changes: 8 additions & 0 deletions src/emu/x64run_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ int32_t EXPORT my32___libc_start_main(x64emu_t* emu, int *(main) (int, char * *,
if(emu->error) // any error, don't bother with more
return 0;
emu->quit = 0;
} else {
if(my_context->elfs[0]) {
printf_dump(LOG_DEBUG, "Calling init from main elf\n");
RunElfInit(my_context->elfs[0], emu);
}
}
if(my_context->elfs[0]) {
MarkElfInitDone(my_context->elfs[0]);
}
printf_log(LOG_DEBUG, "Transfert to main(%d, %p, %p)=>%p from __libc_start_main\n", my_context->argc, my_context->argv, my_context->envv, main);
// call main and finish
Expand Down

0 comments on commit f7c93b6

Please sign in to comment.