diff --git a/README.md b/README.md index bb1c08bdb3..ad84a2cf8b 100755 --- a/README.md +++ b/README.md @@ -53,11 +53,11 @@ Compilation instructions can be found [here](COMPILE.md) Usage ---- -There are a few environment variables avaiable to control the behaviour of Box86. +There are a few environment variables to control the behaviour of Box86. See [here](USAGE.md) for all environment variables and what they do. -Note that now the Dynarec of Box86 uses a mechanism with Memory Protection and a SegFault signal handler to handle JIT code. That means if you want to use GDB to debug a running program that use JIT'd code (like mono/Unity3D), you will still have many "normal" segfaults triggering. I suggest you use something like `handle SIGSEGV nostop` in GDB to not stop at each segfault, and maybe put a breakpoint inside `my_memprotectionhandler` in `signals.c` if you want to trap SegFaults. +Note: Box86's Dynarec uses a mechanism with Memory Protection and a SegFault signal handler to handle JIT code. In simpler terms, if you want to use GDB to debug a running program that use JIT'd code (like mono/Unity3D), you will still have many "normal" segfaults triggering. It is suggested to use something like `handle SIGSEGV nostop` in GDB to not stop at each segfault, and maybe put a breakpoint inside `my_memprotectionhandler` in `signals.c` if you want to trap SegFaults. ---- @@ -73,7 +73,7 @@ Notes about 64-bit platforms Because Box86 works by directly translating function calls from x86 to host system, the host system (the one Box86 is running on) needs to have 32-bit libraries. Box86 doesn't include any 32-bit <-> 64-bit translation. So basically, to run Box86 on, for example, an ARM64 platform, you will need to build Box86 for ARM 32-bit, and also need to have a chroot with 32-bit libraries. -Also note that, even if, on day, there is a Box86_64, this one will only be able to run x86_64 binaries on 64-bit platforms. You will still need Box86 (and see 32-bit chroot) to run x86 binaries (in fact, the same is the case on actual x86_64 Linux). +Also note that, even if, on day, there is a Box86_64, this one will only be able to run x86_64 binaries on 64-bit platforms. You will still need Box86 (and a 32-bit chroot) to run x86 binaries (in fact, the same is the case on actual x86_64 Linux). ---- diff --git a/src/box86context.c b/src/box86context.c index a175583669..565786b399 100755 --- a/src/box86context.c +++ b/src/box86context.c @@ -129,11 +129,11 @@ int getrand(int maxval) { if(maxval<1024) { return ((random()&0x7fff)*maxval)/0x7fff; - } else { + } uint64_t r = random(); r = (r*maxval) / RAND_MAX; return r; - } + } void free_tlsdatasize(void* p) diff --git a/src/custommem.c b/src/custommem.c index adfacb333b..f8dbe02c49 100644 --- a/src/custommem.c +++ b/src/custommem.c @@ -235,13 +235,13 @@ void* customRealloc(void* p, size_t size) p_blocks[i].maxfree = getMaxFreeBlock(p_blocks[i].block, p_blocks[i].size); pthread_mutex_unlock(&mutex_blocks); return p; - } else { + } pthread_mutex_unlock(&mutex_blocks); void* newp = customMalloc(size); memcpy(newp, p, sizeBlock(sub)); customFree(p); return newp; - } + } } pthread_mutex_unlock(&mutex_blocks); diff --git a/src/tools/fileutils.c b/src/tools/fileutils.c index fb6675fd64..478e08198b 100755 --- a/src/tools/fileutils.c +++ b/src/tools/fileutils.c @@ -28,10 +28,9 @@ int FileExist(const char* filename, int flags) if(flags&IS_FILE) { if(!S_ISREG(sb.st_mode)) return 0; - } else { - if(!S_ISDIR(sb.st_mode)) + } else if(!S_ISDIR(sb.st_mode)) return 0; - } + if(flags&IS_EXECUTABLE) { if((sb.st_mode&S_IXUSR)!=S_IXUSR) return 0; // nope diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index c72d0b40ff..b5eb492f0f 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -473,9 +473,9 @@ void EXPORT my___cxa_finalize(x86emu_t* emu, void* p) if(!p) { // p is null, call (and remove) all Cleanup functions CallAllCleanup(emu); - } else { - CallCleanup(emu, p); + return; } + CallCleanup(emu, p); } int EXPORT my_atexit(x86emu_t* emu, void *p) { @@ -2280,12 +2280,11 @@ EXPORT void my___explicit_bzero_chk(x86emu_t* emu, void* dst, uint32_t len, uint EXPORT void* my_realpath(x86emu_t* emu, void* path, void* resolved_path) { - char* ret; + if(isProcSelf(path, "exe")) { - ret = realpath(emu->context->fullpath, resolved_path); - } else - ret = realpath(path, resolved_path); - return ret; + return realpath(emu->context->fullpath, resolved_path); + } + return realpath(path, resolved_path); } EXPORT void* my_mmap(x86emu_t* emu, void *addr, unsigned long length, int prot, int flags, int fd, int offset) diff --git a/src/wrapped/wrappedxml2.c b/src/wrapped/wrappedxml2.c index a4af979a2f..5fcb7ed963 100755 --- a/src/wrapped/wrappedxml2.c +++ b/src/wrapped/wrappedxml2.c @@ -74,9 +74,10 @@ EXPORT uintptr_t my_xmlMemStrdup = 0; void my_wrap_xmlFree(void* p) { - if(my_xmlFree) + if(my_xmlFree){ RunFunction(my_context, my_xmlFree, 1, p); - else + return; + } free(p); } void* my_wrap_xmlMalloc(size_t s)