diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2025-07-03 12:10:44 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2025-07-03 12:10:44 +0200 |
| commit | 5923a9089fc29023cd26ba5303165bf65fa43201 (patch) | |
| tree | e81d8c9b4dd91c82b8abb08b43c966e11a9149cb /src/core.c | |
| parent | e274abf13d898db1b0516089a54ee5dff0997658 (diff) | |
| download | box64-5923a9089fc29023cd26ba5303165bf65fa43201.tar.gz box64-5923a9089fc29023cd26ba5303165bf65fa43201.zip | |
[BOX32] Relaunch box32 to set personality to 32bits
Diffstat (limited to 'src/core.c')
| -rw-r--r-- | src/core.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core.c b/src/core.c index 82eb20cd..3ccbb85e 100644 --- a/src/core.c +++ b/src/core.c @@ -15,6 +15,9 @@ #include <sys/stat.h> #include <stdarg.h> #include <ctype.h> +#ifdef BOX32 +#include <sys/personality.h> +#endif #ifdef DYNAREC #include <sys/types.h> #include <sys/stat.h> @@ -1149,6 +1152,29 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf } #ifdef BOX32 box64_is32bits = FileIsX86ELF(my_context->fullpath); + // try to switch personality, but only if not already tried + if(box64_is32bits) { + int tried = getenv("BOX32_PERSONA32BITS")?1:0; + if(tried) { + unsetenv("BOX32_PERSONA32BITS"); + int p = personality(0xffffffff); + if(p==ADDR_LIMIT_32BIT) printf_log(LOG_INFO, "Personality set to 32bits\n"); + } else { + if(personality(ADDR_LIMIT_32BIT)!=-1) { + int nenv = 0; + while(env[nenv]) nenv++; + // alloc + "LD_PRELOAD" if needd + last NULL ending + char** newenv = (char**)box_calloc(nenv+1+1, sizeof(char*)); + // copy strings + for (int i=0; i<nenv; ++i) + newenv[i] = box_strdup(env[i]); + newenv[nenv] = "BOX32_PERSONA32BITS=1"; + // re-launch... + if(execve(argv[0], (void*)argv, newenv)<0) + printf_log(LOG_NONE, "Failed to relaunch. Error is %d/%s\n", errno, strerror(errno)); + } + } + } if(box64_is32bits) { printf_log(LOG_INFO, "Using Box32 to load 32bits elf\n"); loadProtectionFromMap(); |