Skip to content

Commit

Permalink
Merge pull request #309 from heavygabriel/master
Browse files Browse the repository at this point in the history
Simplified code
  • Loading branch information
ptitSeb authored Jan 11, 2021
2 parents 258f7f9 + 088a85c commit 4b020ab
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

----

Expand All @@ -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).

----

Expand Down
4 changes: 2 additions & 2 deletions src/box86context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/custommem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/tools/fileutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/wrapped/wrappedxml2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4b020ab

Please sign in to comment.