diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2022-04-24 17:29:22 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2022-04-24 17:29:22 +0200 |
| commit | ab633484cd817ebee22b9432c0ac7ccececc1bd1 (patch) | |
| tree | 8044e1fb8ecc42decc80a003f9d7f4f0de900e3f /src | |
| parent | 5e69a69b8d9f780b823a5ac310cfcf6b1d80664c (diff) | |
| download | box64-ab633484cd817ebee22b9432c0ac7ccececc1bd1.tar.gz box64-ab633484cd817ebee22b9432c0ac7ccececc1bd1.zip | |
Improved BOX64_LOAD_ADDR env. var. to help having reproducible runs
Diffstat (limited to 'src')
| -rwxr-xr-x | src/elfs/elfloader.c | 19 | ||||
| -rwxr-xr-x | src/include/debug.h | 1 | ||||
| -rwxr-xr-x | src/main.c | 8 |
3 files changed, 19 insertions, 9 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index d7ad4c93..941f094b 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -156,12 +156,14 @@ const char* ElfPath(elfheader_t* head) int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin) { uintptr_t offs = 0; - if(mainbin && head->vaddr==0) { - char* load_addr = getenv("BOX64_LOAD_ADDR"); - if(load_addr) - if(sscanf(load_addr, "0x%zx", &offs)!=1) - offs = 0; + if((mainbin && head->vaddr==0) || (!mainbin && !head->vaddr && box64_load_addr)) { + if(box64_load_addr) { + offs = box64_load_addr; + box64_load_addr += head->memsz; + box64_load_addr = (box64_load_addr+0xffffffLL)&~0xffffffLL; + } } + int log_level = box64_load_addr?LOG_INFO:LOG_DEBUG; if(!offs) offs = head->vaddr; if(head->vaddr) { @@ -209,8 +211,7 @@ int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin) } head->multiblock_n = n; // might be less in fact for (int i=0; i<head->multiblock_n; ++i) { - - printf_log(LOG_DEBUG, "Allocating 0x%lx memory @%p for Elf \"%s\"\n", head->multiblock_size[i], (void*)head->multiblock_offs[i], head->name); + printf_log(log_level, "Allocating 0x%lx memory @%p for Elf \"%s\"\n", head->multiblock_size[i], (void*)head->multiblock_offs[i], head->name); void* p = mmap((void*)head->multiblock_offs[i], head->multiblock_size[i] , PROT_READ | PROT_WRITE | PROT_EXEC , MAP_PRIVATE | MAP_ANONYMOUS /*| ((wine_preloaded)?MAP_FIXED:0)*/ @@ -245,7 +246,7 @@ int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin) // vaddr is 0, load everything has a One block if(!offs && box64_wine) offs = (uintptr_t)find47bitBlock(head->memsz); // limit to 47bits... - printf_log(LOG_DEBUG, "Allocating 0x%zx memory @%p for Elf \"%s\"\n", head->memsz, (void*)offs, head->name); + printf_log(log_level, "Allocating 0x%zx memory @%p for Elf \"%s\"\n", head->memsz, (void*)offs, head->name); void* p = mmap((void*)offs, head->memsz , PROT_READ | PROT_WRITE | PROT_EXEC , MAP_PRIVATE | MAP_ANONYMOUS /*| (((offs&&wine_preloaded)?MAP_FIXED:0))*/ @@ -262,7 +263,7 @@ int AllocElfMemory(box64context_t* context, elfheader_t* head, int mainbin) head->memory = p; memset(p, 0, head->memsz); head->delta = (intptr_t)p - (intptr_t)head->vaddr; - printf_log(LOG_DEBUG, "Got %p (delta=%p)\n", p, (void*)head->delta); + printf_log(log_level, "Got %p (delta=%p)\n", p, (void*)head->delta); head->multiblock_n = 1; head->multiblock_size = (uint64_t*)calloc(head->multiblock_n, sizeof(uint64_t)); diff --git a/src/include/debug.h b/src/include/debug.h index 87d03a2d..30ca16da 100755 --- a/src/include/debug.h +++ b/src/include/debug.h @@ -8,6 +8,7 @@ extern int box64_dump; // dump elf or not extern int box64_dynarec_log; extern int box64_dynarec; extern int box64_pagesize; +extern uintptr_t box64_load_addr; #ifdef DYNAREC extern int box64_dynarec_dump; extern int box64_dynarec_trace; diff --git a/src/main.c b/src/main.c index 94d6b3d4..1a123f21 100755 --- a/src/main.c +++ b/src/main.c @@ -39,6 +39,7 @@ int box64_dump = 0; int box64_nobanner = 0; int box64_dynarec_log = LOG_NONE; int box64_pagesize; +uintptr_t box64_load_addr = 0; #ifdef DYNAREC int box64_dynarec = 1; int box64_dynarec_dump = 0; @@ -481,6 +482,13 @@ void LoadLogEnv() #endif #endif // Other BOX64 env. var. + p = getenv("BOX64_LOAD_ADDR"); + if(p) { + if(sscanf(p, "0x%zx", &box64_load_addr)!=1) + box64_load_addr = 0; + if(box64_load_addr) + printf_log(LOG_INFO, "Use a starting load address of %p\n", (void*)box64_load_addr); + } p = getenv("BOX64_DLSYM_ERROR"); if(p) { if(strlen(p)==1) { |