diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/library_list.h | 2 | ||||
| -rw-r--r-- | src/libtools/threads.c | 28 | ||||
| -rw-r--r-- | src/wrapped/generated/functions_list.txt | 1 | ||||
| -rw-r--r-- | src/wrapped/generated/wrappedlibctypes.h | 1 | ||||
| -rw-r--r-- | src/wrapped/wrappedldlinux.c | 2 | ||||
| -rw-r--r-- | src/wrapped/wrappedlibc.c | 54 | ||||
| -rw-r--r-- | src/wrapped/wrappedlibc_private.h | 2 |
7 files changed, 76 insertions, 14 deletions
diff --git a/src/library_list.h b/src/library_list.h index 30f8efff..bba625f8 100644 --- a/src/library_list.h +++ b/src/library_list.h @@ -396,4 +396,4 @@ GO("libandroid-support.so", androidsupport) GO("ld-linux-x86-64.so.2", ldlinux) //GO("libunwind.so.8", unwind) -GO("crashhandler.so", crashhandler) +//GO("crashhandler.so", crashhandler) diff --git a/src/libtools/threads.c b/src/libtools/threads.c index afa7a337..142d97b5 100644 --- a/src/libtools/threads.c +++ b/src/libtools/threads.c @@ -284,19 +284,19 @@ EXPORT int my_pthread_attr_destroy(x64emu_t* emu, void* attr) EXPORT int my_pthread_attr_getstack(x64emu_t* emu, void* attr, void** stackaddr, size_t* stacksize) { PTHREAD_ATTR_ALIGN(attr); - int ret = pthread_attr_getstack(PTHREAD_ATTR(attr), stackaddr, stacksize); - // no need to unalign, it's const for attr - if (ret==0) - GetStackSize(emu, (uintptr_t)attr, stackaddr, stacksize); + int ret = 0; + if(!GetStackSize(emu, (uintptr_t)attr, stackaddr, stacksize)) + ret = pthread_attr_getstack(PTHREAD_ATTR(attr), stackaddr, stacksize); +printf_log(LOG_INFO, "pthread_attr_getstack gives (%d) %p 0x%zx\n", ret, *stackaddr, *stacksize); return ret; } EXPORT int my_pthread_attr_setstack(x64emu_t* emu, void* attr, void* stackaddr, size_t stacksize) { - if(!emu->context->stacksizes) { - emu->context->stacksizes = kh_init(threadstack); + if(!my_context->stacksizes) { + my_context->stacksizes = kh_init(threadstack); } - AddStackSize(emu->context->stacksizes, (uintptr_t)attr, stackaddr, stacksize); + AddStackSize(my_context->stacksizes, (uintptr_t)attr, stackaddr, stacksize); //Don't call actual setstack... //return pthread_attr_setstack(attr, stackaddr, stacksize); PTHREAD_ATTR_ALIGN(attr); @@ -356,20 +356,25 @@ EXPORT int my_pthread_attr_getscope(x64emu_t* emu, pthread_attr_t* attr, int* sc PTHREAD_ATTR_ALIGN(attr); return pthread_attr_getscope(PTHREAD_ATTR(attr), scope); } -EXPORT int my_pthread_attr_getstackaddr(x64emu_t* emu, pthread_attr_t* attr, void* addr) +EXPORT int my_pthread_attr_getstackaddr(x64emu_t* emu, pthread_attr_t* attr, void** addr) { (void)emu; size_t size; PTHREAD_ATTR_ALIGN(attr); - return pthread_attr_getstack(PTHREAD_ATTR(attr), addr, &size); - //return pthread_attr_getstackaddr(getAlignedAttr(attr), addr); + int ret = 0; + if(!GetStackSize(emu, (uintptr_t)attr, addr, &size )) + ret = pthread_attr_getstack(PTHREAD_ATTR(attr), addr, &size); +printf_log(LOG_INFO, "pthread_attr_getstackaddr gives %p\n", *addr); + return ret; } EXPORT int my_pthread_attr_getstacksize(x64emu_t* emu, pthread_attr_t* attr, size_t* size) { (void)emu; void* addr; PTHREAD_ATTR_ALIGN(attr); - int ret = pthread_attr_getstack(PTHREAD_ATTR(attr), &addr, size); + int ret = 0; + if(!GetStackSize(emu, (uintptr_t)attr, &addr, size )) + ret = pthread_attr_getstack(PTHREAD_ATTR(attr), &addr, size); if(!*size) *size = 2*1024*1024; //return pthread_attr_getstacksize(getAlignedAttr(attr), size); @@ -470,6 +475,7 @@ EXPORT int my_pthread_getattr_np(x64emu_t* emu, pthread_t thread_id, pthread_att } void* stack = emu->init_stack; size_t sz = emu->size_stack; +printf_log(LOG_INFO, "pthread_getattr_np called for self, stack=%p, sz=%lx\n", stack, sz); if (!sz) { // get default stack size pthread_attr_t attr; diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 80429074..7518a658 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -4449,6 +4449,7 @@ wrappedlibc: - __vfprintf_chk - __vsscanf - execve + - execvpe - iFppV: - __asprintf - __isoc23_sscanf diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h index 206d429f..ea45efda 100644 --- a/src/wrapped/generated/wrappedlibctypes.h +++ b/src/wrapped/generated/wrappedlibctypes.h @@ -219,6 +219,7 @@ typedef int32_t (*iFppipppp_t)(void*, void*, int32_t, void*, void*, void*, void* GO(__vfprintf_chk, iFppp_t) \ GO(__vsscanf, iFppp_t) \ GO(execve, iFppp_t) \ + GO(execvpe, iFppp_t) \ GO(__asprintf, iFppV_t) \ GO(__isoc23_sscanf, iFppV_t) \ GO(__isoc99_fscanf, iFppV_t) \ diff --git a/src/wrapped/wrappedldlinux.c b/src/wrapped/wrappedldlinux.c index 90ec1b23..cd2ee420 100644 --- a/src/wrapped/wrappedldlinux.c +++ b/src/wrapped/wrappedldlinux.c @@ -31,7 +31,7 @@ EXPORT void* my___tls_get_addr(void* p) EXPORT void* my___libc_stack_end; void stSetup(box64context_t* context) { - my___libc_stack_end = context->stack; // is this the end, or should I add stasz? + my___libc_stack_end = context->stack + context->stacksz; } #ifdef STATICBUILD diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 01b5bc69..f341abaf 100644 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -2442,6 +2442,60 @@ EXPORT int32_t my_execvp(x64emu_t* emu, const char* path, char* const argv[]) // fullpath is gone, so the search will only be on PATH, not on BOX64_PATH (is that an issue?) return execvp(path, argv); } +// execvp should use PATH to search for the program first +EXPORT int32_t my_execvpe(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]) +{ + // need to use BOX64_PATH / PATH here... + char* fullpath = ResolveFileSoft(path, &my_context->box64_path); + // use fullpath... + int self = isProcSelf(fullpath, "exe"); + int x64 = FileIsX64ELF(fullpath); + int x86 = my_context->box86path?FileIsX86ELF(fullpath):0; + int script = (my_context->bashpath && FileIsShell(fullpath))?1:0; + printf_log(LOG_DEBUG, "execvpe(\"%s\", %p, %p), IsX86=%d / fullpath=\"%s\"\n", path, argv, envp, x64, fullpath); + // hack to update the environ var if needed + if(envp == my_context->envv && environ) { + envp = environ; + } + if (x64 || x86 || script || self) { + // count argv... + int i=0; + while(argv[i]) ++i; + int toadd = script?2:1; + char** newargv = (char**)alloca((i+toadd+1)*sizeof(char*)); + memset(newargv, 0, (i+toadd+1)*sizeof(char*)); + newargv[0] = x86?emu->context->box86path:emu->context->box64path; + if(script) newargv[1] = emu->context->bashpath; // script needs to be launched with bash + for (int j=0; j<i; ++j) + newargv[j+toadd] = argv[j]; + if(self) newargv[1] = emu->context->fullpath; + //else if(script) newargv[2] = fullpath; + else { + // TODO check if envp is not environ and add the value on a copy + if(strcmp(newargv[toadd], path)) + setenv(x86?"BOX86_ARG0":"BOX64_ARG0", newargv[toadd], 1); + newargv[toadd] = fullpath; + } + + printf_log(LOG_DEBUG, " => execvp(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i); + int ret; + ret = execvpe(newargv[0], newargv, envp); + box_free(fullpath); + return ret; + } + if((!strcmp(path + strlen(path) - strlen("/uname"), "/uname") || !strcmp(path, "uname")) + && argv[1] && (!strcmp(argv[1], "-m") || !strcmp(argv[1], "-p") || !strcmp(argv[1], "-i")) + && !argv[2]) { + // uname -m is redirected to box64 -m + path = my_context->box64path; + char *argv2[3] = { my_context->box64path, argv[1], NULL }; + + return execvpe(path, argv2, envp); + } + + // fullpath is gone, so the search will only be on PATH, not on BOX64_PATH (is that an issue?) + return execvpe(path, argv, envp); +} EXPORT int32_t my_execl(x64emu_t* emu, const char* path) { diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index ce9f3976..18eb894c 100644 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -344,7 +344,7 @@ GOM(execlp, iFEpV) // First argument is also part of the variadic GOM(execv, iFEpp) GOM(execve, iFEppp) GOM(execvp, iFEpp) -GOW(execvpe, iFppp) +GOWM(execvpe, iFEppp) GO(_exit, vFi) GOM(exit, vFEi) GOW(_Exit, vFi) |