diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-08-26 17:45:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-26 17:45:13 +0200 |
| commit | b5105a1e57bba3305d5dce93ab4d2f7faab6b34a (patch) | |
| tree | ab26b700d3c48f2c8e32a1084ae7c2e7a8448b06 /src/elfs/elfloader.c | |
| parent | 9beb745765e9c99bad6410094a97bf0bf9ebc1eb (diff) | |
| download | box64-b5105a1e57bba3305d5dce93ab4d2f7faab6b34a.tar.gz box64-b5105a1e57bba3305d5dce93ab4d2f7faab6b34a.zip | |
Added preliminary Box32 support (#1760)
* Improve the ReserveHigMemory helper function * [BOX32] Added some wrapping infrastructure * [BOX32] More wrapped 32bits lib infrastructure * [BOX32] Added callback and tls 32bits handling * [BOX32] Added more 32bits, around wrappers and elfs * [BOX32] Added the 32bits version of myalign * [BOX32] More wrapped libs and 32bits fixes and imrpovments * [BOX32] Added some 32bits tests * [BOX32] Try to enable some Box32 build and test on the CI * [BOX32] Disable Box32 testing on CI platform that use qemu * [BOX32] Another attempt to disable Box32 testing on CI platform that use qemu * [BOX32] Small fix for another attempt to disable Box32 testing on CI platform that use qemu * [BOX32] Yet another fix for another attempt to disable Box32 testing on CI platform that use qemu * [BOX32] Fixed a typo in CI script * [BOX32] Better scratch alighnment and enabled more tests * [BOX32] Added (partial) wrapped 32bits librt * [BOX32] Added mention of Box32 in README * [BOX32] Added phtread handling, and numerous fixes to 32bits handling. [ARM64_DYNAREC] Fixed access to segment with negative offset * [BOX32] Added system libs and cpp testing, plus some more fixes * [BOX32] Fix previous commit * [BOX32] Better stack adjustment for 32bits processes * [BOX32] Added getenv wrapped 32bits function and friends * [BOX32] Don't look for box86 for a Box32 build * [BOX32] Don't do 32bits cppThreads test for now on CI * [BOX32] Enabled a few more 32bits tests * [BOX32] For ld_lib_path for both CppThreads tests * [BOX32] [ANDROID] Some Fixes for Android Build * [BOX32] Still need to disable cppThread_32bits test on CI for some reason * [BOX32] [ANDROID] Don't show PreInit Array Warning (#1751) * [BOX32] [ANDROID] One More Fix for Android Build That I forgotten to … (#1752) * [BOX32] [ANDROID] One More Fix for Android Build That I forgotten to push before * [BOX32] [ANDROID] Try to Create __libc_init * [BOX32] [ANDROID] Try to disable NEEDED_LIBS for now (libdl is not wrapped) * [BOX32] Updated generated files * [BOX32] Added 32bits context functions * [BOX32] Added 32bits signal handling * [BOX32] Added some missing 32bits elfloader functions * [BOX32] Fix build on x86_64 machine * [BOX32] Better fix for x86_64 build * [BOX32] Actually added missing libs, and re-enabled cppThreads_32bits test * [BOX32] Added wrapped 32bits libdl * [BOX32] Try to re-enabled Box32 test on CI for ARM64 builds * [BOX32] fine-tuning Box32 test on CI for ARM64 builds * [BOX32] More fine-tuning to Box32 test on CI for ARM64 builds * [BOX32] Enabled Box32 test on CI for LA64 and RV64 builds too * [BOX32] re-Disabled Box32 test on CI for LA64 and RV64 builds, not working for now * [BOX32] Temporarily disabled cppThreads_32bits test on CI --------- Co-authored-by: KreitinnSoftware <pablopro5051@gmail.com> Co-authored-by: KreitinnSoftware <80591934+KreitinnSoftware@users.noreply.github.com>
Diffstat (limited to 'src/elfs/elfloader.c')
| -rw-r--r-- | src/elfs/elfloader.c | 101 |
1 files changed, 75 insertions, 26 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 248c4282..d251abaa 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -875,7 +875,12 @@ int RelocateElf(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind, e return box64_is32bits?RelocateElf32(maplib, local_maplib, bindnow, deepbind, head):RelocateElf64(maplib, local_maplib, bindnow, deepbind, head); } -int RelocateElfPlt32(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind, elfheader_t* head) { /* TODO */ return -1; } +int RelocateElfPlt32(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind, elfheader_t* head) +#ifndef BOX32 +{ return -1; } +#else + ; +#endif int RelocateElfPlt64(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind, elfheader_t* head) { int need_resolver = 0; @@ -953,7 +958,12 @@ uintptr_t GetLastByte(elfheader_t* h) #endif void checkHookedSymbols(elfheader_t* h); // in mallochook.c -void AddSymbols32(lib_t *maplib, elfheader_t* h) { /* TODO */ } +void AddSymbols32(lib_t *maplib, elfheader_t* h) +#ifndef BOX32 +{ } +#else + ; +#endif void AddSymbols(lib_t *maplib, elfheader_t* h) { if(box64_is32bits) { @@ -1121,15 +1131,10 @@ void startMallocHook(); #else void startMallocHook() {} #endif -void RunElfInit32(elfheader_t* h, x64emu_t *emu) { /* TODO*/ } void RunElfInit(elfheader_t* h, x64emu_t *emu) { if(!h || h->init_done) return; - if(box64_is32bits) { - RunElfInit32(h, emu); - return; - } // reset Segs Cache memset(emu->segs_serial, 0, sizeof(emu->segs_serial)); uintptr_t p = h->initentry + h->delta; @@ -1157,11 +1162,24 @@ void RunElfInit(elfheader_t* h, x64emu_t *emu) 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 - Elf64_Addr *addr = (Elf64_Addr*)(h->initarray + h->delta); - 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), (void*)addr[i]); - RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv); + #ifdef BOX32 + if(box64_is32bits) { + Elf32_Addr *addr = (Elf32_Addr*)(h->initarray + h->delta); + 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); + } + } + } else + #endif + { + Elf64_Addr *addr = (Elf64_Addr*)(h->initarray + h->delta); + 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), (void*)addr[i]); + RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 3, my_context->argc, my_context->argv, my_context->envv); + } } } @@ -1191,15 +1209,10 @@ void RunDeferredElfInit(x64emu_t *emu) box_free(List); } -void RunElfFini32(elfheader_t* h, x64emu_t *emu) { /* TODO */ } void RunElfFini(elfheader_t* h, x64emu_t *emu) { if(!h || h->fini_done || !h->init_done) return; - if(box64_is32bits) { - RunElfFini32(h, emu); - return; - } h->fini_done = 1; // Call the registered cxa_atexit functions CallCleanup(emu, h); @@ -1208,10 +1221,21 @@ void RunElfFini(elfheader_t* h, x64emu_t *emu) printf_log(LOG_DEBUG, "Android does not support Fini for %s\n", ElfName(h)); #else // first check fini array - Elf64_Addr *addr = (Elf64_Addr*)(h->finiarray + h->delta); - for (int i=h->finiarray_sz-1; i>=0; --i) { - printf_dump(LOG_DEBUG, "Calling Fini[%d] for %s @%p\n", i, ElfName(h), (void*)addr[i]); - RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 0); + #ifdef BOX32 + if(box64_is32bits) { + Elf32_Addr *addr = (Elf32_Addr*)(h->finiarray + h->delta); + for (int i=h->finiarray_sz-1; i>=0; --i) { + printf_dump(LOG_DEBUG, "Calling Fini[%d] for %s @%p\n", i, ElfName(h), from_ptrv(addr[i])); + RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 0); + } + } else + #endif + { + Elf64_Addr *addr = (Elf64_Addr*)(h->finiarray + h->delta); + for (int i=h->finiarray_sz-1; i>=0; --i) { + printf_dump(LOG_DEBUG, "Calling Fini[%d] for %s @%p\n", i, ElfName(h), (void*)addr[i]); + RunFunctionWithEmu(emu, 0, (uintptr_t)addr[i], 0); + } } // then the "old-style" fini if(h->finientry) { @@ -1499,7 +1523,12 @@ EXPORT int my_dl_iterate_phdr(x64emu_t *emu, void* F, void *data) { return ret; } -void ResetSpecialCaseMainElf32(elfheader_t* h) { /* TODO */ } +void ResetSpecialCaseMainElf32(elfheader_t* h) +#ifndef BOX32 +{ } +#else + ; +#endif void ResetSpecialCaseMainElf(elfheader_t* h) { if(box64_is32bits) { @@ -1620,7 +1649,12 @@ static Elf64_Sym* ElfLocateSymbol(elfheader_t* head, uintptr_t *offs, uintptr_t return sym; } -void* ElfGetLocalSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { /* TOODO */ return NULL; } +void* ElfGetLocalSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +#ifndef BOX32 +{ return NULL; } +#else + ; +#endif void* ElfGetLocalSymbolStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { Elf64_Sym* sym = ElfLocateSymbol(head, offs, end, symname, ver, vername, local, veropt); @@ -1636,7 +1670,12 @@ void* ElfGetLocalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *e return box64_is32bits?ElfGetLocalSymbolStartEnd32(head, offs, end, symname, ver, vername, local, veropt):ElfGetLocalSymbolStartEnd64(head, offs, end, symname, ver, vername, local, veropt); } -void* ElfGetGlobalSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { /*T ODO */ return NULL; } +void* ElfGetGlobalSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +#ifndef BOX32 +{ return NULL; } +#else + ; +#endif void* ElfGetGlobalSymbolStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { Elf64_Sym* sym = ElfLocateSymbol(head, offs, end, symname, ver, vername, local, veropt); @@ -1652,7 +1691,12 @@ void* ElfGetGlobalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t * return box64_is32bits?ElfGetGlobalSymbolStartEnd32(head, offs, end, symname, ver, vername, local, veropt):ElfGetGlobalSymbolStartEnd64(head, offs, end, symname, ver, vername, local, veropt); } -void* ElfGetWeakSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { /* TODO */ return NULL; } +void* ElfGetWeakSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +#ifndef BOX32 +{ return NULL; } +#else + ; +#endif void* ElfGetWeakSymbolStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) { Elf64_Sym* sym = ElfLocateSymbol(head, offs, end, symname, ver, vername, local, veropt); @@ -1668,7 +1712,12 @@ void* ElfGetWeakSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *en return box64_is32bits?ElfGetWeakSymbolStartEnd32(head, offs, end, symname, ver, vername, local, veropt):ElfGetWeakSymbolStartEnd64(head, offs, end, symname, ver, vername, local, veropt); } -int ElfGetSymTabStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname) { /* TODO */ return 0; } +int ElfGetSymTabStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname) +#ifndef BOX32 +{ return 0; } +#else + ; +#endif int ElfGetSymTabStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname) { Elf64_Sym* sym = ElfSymTabLookup64(head, symname); |