diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-10-13 14:46:21 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-10-13 14:46:21 +0200 |
| commit | 103ec5d72ae868c0a094935c2a9ace93f7b3f908 (patch) | |
| tree | ff64f920cd7e04f4930ae7a60b09fadf66ddcb74 /src | |
| parent | 9139ec3e5c669bc90ac393cbe978011cf63102bd (diff) | |
| download | box64-103ec5d72ae868c0a094935c2a9ace93f7b3f908.tar.gz box64-103ec5d72ae868c0a094935c2a9ace93f7b3f908.zip | |
[BOX32] Added some posix_file_action wrapped function, and fixed posix_spawn/exec function argument handling
Diffstat (limited to 'src')
| -rw-r--r-- | src/wrapped32/generated/functions_list.txt | 9 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrappedlibctypes32.h | 7 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.c | 4 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.h | 2 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc.c | 82 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc_private.h | 10 |
6 files changed, 96 insertions, 18 deletions
diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt index 554e0d8b..4e35a471 100644 --- a/src/wrapped32/generated/functions_list.txt +++ b/src/wrapped32/generated/functions_list.txt @@ -705,6 +705,7 @@ #() iFEiiN -> iFEiiN #() iFEipp -> iFEipp #() iFEipV -> iFEipV +#() iFEpii -> iFEpii #() iFEpip -> iFEpip #() iFEpui -> iFEpui #() iFEpuu -> iFEpuu @@ -1146,6 +1147,7 @@ #() iFEuppLp -> iFEuppLp #() iFEpiuuu -> iFEpiuuu #() iFEpiLpp -> iFEpiLpp +#() iFEpipOi -> iFEpipOi #() iFEpuuup -> iFEpuuup #() iFEplluu -> iFEplluu #() iFEpLlpp -> iFEpLlpp @@ -1595,6 +1597,8 @@ wrappedlibc: - __close_nocancel - iFL: - iFp: + - posix_spawn_file_actions_destroy + - posix_spawn_file_actions_init - sysinfo - iFO: - uFp: @@ -1644,6 +1648,7 @@ wrappedlibc: - setrlimit - iFpi: - backtrace + - posix_spawn_file_actions_addclose - iFpL: - iFpp: - alphasort64 @@ -1677,6 +1682,8 @@ wrappedlibc: - iFiip: - iFiiN: - iFipp: +- iFpii: + - posix_spawn_file_actions_adddup2 - iFpLi: - iFppp: - vswscanf @@ -1728,6 +1735,8 @@ wrappedlibc: - getpwuid_r - iFpvvpV: - iFpiLpp: +- iFpipOi: + - posix_spawn_file_actions_addopen - iFpppLp: - getgrnam_r - getpwnam_r diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h index 28395822..7ab82cf9 100644 --- a/src/wrapped32/generated/wrappedlibctypes32.h +++ b/src/wrapped32/generated/wrappedlibctypes32.h @@ -59,6 +59,7 @@ typedef int32_t (*iFvpV_t)(void, void*, ...); typedef int32_t (*iFiip_t)(int32_t, int32_t, void*); typedef int32_t (*iFiiN_t)(int32_t, int32_t, ...); typedef int32_t (*iFipp_t)(int32_t, void*, void*); +typedef int32_t (*iFpii_t)(void*, int32_t, int32_t); typedef int32_t (*iFpLi_t)(void*, uintptr_t, int32_t); typedef int32_t (*iFppp_t)(void*, void*, void*); typedef int32_t (*iFppV_t)(void*, void*, ...); @@ -93,6 +94,7 @@ typedef int32_t (*iFiippi_t)(int32_t, int32_t, void*, void*, int32_t); typedef int32_t (*iFuppLp_t)(uint32_t, void*, void*, uintptr_t, void*); typedef int32_t (*iFpvvpV_t)(void*, void, void, void*, ...); typedef int32_t (*iFpiLpp_t)(void*, int32_t, uintptr_t, void*, void*); +typedef int32_t (*iFpipOi_t)(void*, int32_t, void*, int32_t, int32_t); typedef int32_t (*iFpppLp_t)(void*, void*, void*, uintptr_t, void*); typedef void* (*pFpLLiN_t)(void*, uintptr_t, uintptr_t, int32_t, ...); typedef void* (*pFppLLp_t)(void*, void*, uintptr_t, uintptr_t, void*); @@ -109,6 +111,8 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void #define SUPER() ADDED_FUNCTIONS() \ GO(freeaddrinfo, vFp_t) \ GO(__close_nocancel, iFi_t) \ + GO(posix_spawn_file_actions_destroy, iFp_t) \ + GO(posix_spawn_file_actions_init, iFp_t) \ GO(sysinfo, iFp_t) \ GO(getwc, uFS_t) \ GO(__sysconf, lFi_t) \ @@ -135,6 +139,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(getrlimit, iFup_t) \ GO(setrlimit, iFup_t) \ GO(backtrace, iFpi_t) \ + GO(posix_spawn_file_actions_addclose, iFpi_t) \ GO(alphasort64, iFpp_t) \ GO(execvp, iFpp_t) \ GO(statvfs, iFpp_t) \ @@ -149,6 +154,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(localtime_r, pFpp_t) \ GO(vsyslog, vFipp_t) \ GO(_ITM_addUserCommitAction, vFpup_t) \ + GO(posix_spawn_file_actions_adddup2, iFpii_t) \ GO(vswscanf, iFppp_t) \ GO(swscanf, iFppV_t) \ GO(fscanf, iFSpV_t) \ @@ -166,6 +172,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(getaddrinfo, iFpppp_t) \ GO(getgrgid_r, iFuppLp_t) \ GO(getpwuid_r, iFuppLp_t) \ + GO(posix_spawn_file_actions_addopen, iFpipOi_t) \ GO(getgrnam_r, iFpppLp_t) \ GO(getpwnam_r, iFpppLp_t) \ GO(gethostbyname_r, iFpppupp_t) \ diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c index 1392307c..b3b8d5b1 100644 --- a/src/wrapped32/generated/wrapper32.c +++ b/src/wrapped32/generated/wrapper32.c @@ -795,6 +795,7 @@ typedef int32_t (*iFEiip_t)(x64emu_t*, int32_t, int32_t, void*); typedef int32_t (*iFEiiN_t)(x64emu_t*, int32_t, int32_t, ...); typedef int32_t (*iFEipp_t)(x64emu_t*, int32_t, void*, void*); typedef int32_t (*iFEipV_t)(x64emu_t*, int32_t, void*, void*); +typedef int32_t (*iFEpii_t)(x64emu_t*, void*, int32_t, int32_t); typedef int32_t (*iFEpip_t)(x64emu_t*, void*, int32_t, void*); typedef int32_t (*iFEpui_t)(x64emu_t*, void*, uint32_t, int32_t); typedef int32_t (*iFEpuu_t)(x64emu_t*, void*, uint32_t, uint32_t); @@ -1236,6 +1237,7 @@ typedef int32_t (*iFEiippi_t)(x64emu_t*, int32_t, int32_t, void*, void*, int32_t typedef int32_t (*iFEuppLp_t)(x64emu_t*, uint32_t, void*, void*, uintptr_t, void*); typedef int32_t (*iFEpiuuu_t)(x64emu_t*, void*, int32_t, uint32_t, uint32_t, uint32_t); typedef int32_t (*iFEpiLpp_t)(x64emu_t*, void*, int32_t, uintptr_t, void*, void*); +typedef int32_t (*iFEpipOi_t)(x64emu_t*, void*, int32_t, void*, int32_t, int32_t); typedef int32_t (*iFEpuuup_t)(x64emu_t*, void*, uint32_t, uint32_t, uint32_t, void*); typedef int32_t (*iFEplluu_t)(x64emu_t*, void*, intptr_t, intptr_t, uint32_t, uint32_t); typedef int32_t (*iFEpLlpp_t)(x64emu_t*, void*, uintptr_t, intptr_t, void*, void*); @@ -2293,6 +2295,7 @@ void iFEiip_32(x64emu_t *emu, uintptr_t fcn) { iFEiip_t fn = (iFEiip_t)fcn; R_EA void iFEiiN_32(x64emu_t *emu, uintptr_t fcn) { iFEiiN_t fn = (iFEiiN_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } void iFEipp_32(x64emu_t *emu, uintptr_t fcn) { iFEipp_t fn = (iFEipp_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } void iFEipV_32(x64emu_t *emu, uintptr_t fcn) { iFEipV_t fn = (iFEipV_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); } +void iFEpii_32(x64emu_t *emu, uintptr_t fcn) { iFEpii_t fn = (iFEpii_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } void iFEpip_32(x64emu_t *emu, uintptr_t fcn) { iFEpip_t fn = (iFEpip_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } void iFEpui_32(x64emu_t *emu, uintptr_t fcn) { iFEpui_t fn = (iFEpui_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } void iFEpuu_32(x64emu_t *emu, uintptr_t fcn) { iFEpuu_t fn = (iFEpuu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } @@ -2734,6 +2737,7 @@ void iFEiippi_32(x64emu_t *emu, uintptr_t fcn) { iFEiippi_t fn = (iFEiippi_t)fcn void iFEuppLp_32(x64emu_t *emu, uintptr_t fcn) { iFEuppLp_t fn = (iFEuppLp_t)fcn; R_EAX = fn(emu, from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ulong(from_ptri(ulong_t, R_ESP + 16)), from_ptriv(R_ESP + 20)); } void iFEpiuuu_32(x64emu_t *emu, uintptr_t fcn) { iFEpiuuu_t fn = (iFEpiuuu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); } void iFEpiLpp_32(x64emu_t *emu, uintptr_t fcn) { iFEpiLpp_t fn = (iFEpiLpp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } +void iFEpipOi_32(x64emu_t *emu, uintptr_t fcn) { iFEpipOi_t fn = (iFEpipOi_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), of_convert32(from_ptri(int32_t, R_ESP + 16)), from_ptri(int32_t, R_ESP + 20)); } void iFEpuuup_32(x64emu_t *emu, uintptr_t fcn) { iFEpuuup_t fn = (iFEpuuup_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); } void iFEplluu_32(x64emu_t *emu, uintptr_t fcn) { iFEplluu_t fn = (iFEplluu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_long(from_ptri(long_t, R_ESP + 8)), from_long(from_ptri(long_t, R_ESP + 12)), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); } void iFEpLlpp_32(x64emu_t *emu, uintptr_t fcn) { iFEpLlpp_t fn = (iFEpLlpp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_long(from_ptri(long_t, R_ESP + 12)), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h index 9d547f20..450a2b7d 100644 --- a/src/wrapped32/generated/wrapper32.h +++ b/src/wrapped32/generated/wrapper32.h @@ -746,6 +746,7 @@ void iFEiip_32(x64emu_t *emu, uintptr_t fnc); void iFEiiN_32(x64emu_t *emu, uintptr_t fnc); void iFEipp_32(x64emu_t *emu, uintptr_t fnc); void iFEipV_32(x64emu_t *emu, uintptr_t fnc); +void iFEpii_32(x64emu_t *emu, uintptr_t fnc); void iFEpip_32(x64emu_t *emu, uintptr_t fnc); void iFEpui_32(x64emu_t *emu, uintptr_t fnc); void iFEpuu_32(x64emu_t *emu, uintptr_t fnc); @@ -1187,6 +1188,7 @@ void iFEiippi_32(x64emu_t *emu, uintptr_t fnc); void iFEuppLp_32(x64emu_t *emu, uintptr_t fnc); void iFEpiuuu_32(x64emu_t *emu, uintptr_t fnc); void iFEpiLpp_32(x64emu_t *emu, uintptr_t fnc); +void iFEpipOi_32(x64emu_t *emu, uintptr_t fnc); void iFEpuuup_32(x64emu_t *emu, uintptr_t fnc); void iFEplluu_32(x64emu_t *emu, uintptr_t fnc); void iFEpLlpp_32(x64emu_t *emu, uintptr_t fnc); diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c index 609a660a..cc1f42e3 100755 --- a/src/wrapped32/wrappedlibc.c +++ b/src/wrapped32/wrappedlibc.c @@ -1649,7 +1649,7 @@ EXPORT int32_t my32_execv(x64emu_t* emu, const char* path, ptr_t argv[]) while(argv[n]) ++n; char** newargv = (char**)calloc(n+1, sizeof(char*)); for(int i=0; i<=n; ++i) - newargv[i+1] = from_ptrv(argv[i]); + newargv[i] = from_ptrv(argv[i]); return execv(path, (void*)newargv); } @@ -1692,7 +1692,7 @@ EXPORT int32_t my32_execve(x64emu_t* emu, const char* path, ptr_t argv[], ptr_t while(argv[n]) ++n; const char** newargv = (const char**)calloc(n+1, sizeof(char*)); for(int i=0; i<=n; ++i) - newargv[i+1] = from_ptrv(argv[i]); + newargv[i] = from_ptrv(argv[i]); if(!strcmp(path + strlen(path) - strlen("/uname"), "/uname") && newargv[1] && (!strcmp(newargv[1], "-m") || !strcmp(newargv[1], "-p") || !strcmp(newargv[1], "-i")) @@ -1738,7 +1738,7 @@ EXPORT int32_t my32_execvp(x64emu_t* emu, const char* path, ptr_t argv[]) while(argv[n]) ++n; char** newargv = (char**)calloc(n+1, sizeof(char*)); for(int i=0; i<=n; ++i) - newargv[i+1] = from_ptrv(argv[i]); + newargv[i] = from_ptrv(argv[i]); return execv(fullpath, (void*)newargv); } // execvp should use PATH to search for the program first @@ -1750,16 +1750,74 @@ typedef struct int __pad[16]; } posix_spawn_file_actions_32_t; +void convert_file_action_to_32(void* d, void* s) +{ + posix_spawn_file_actions_32_t* dst = d; + posix_spawn_file_actions_t* src = s; + dst->__allocated = src->__allocated; + dst->__used = src->__used; + dst->__actions = to_ptrv(src->__actions); +} +void convert_file_action_to_64(void* d, void* s) +{ + posix_spawn_file_actions_t* dst = d; + posix_spawn_file_actions_32_t* src = s; + dst->__actions = from_ptrv(src->__actions); + dst->__used = src->__used; + dst->__allocated = src->__allocated; +} + +EXPORT int my32_posix_spawn_file_actions_init(x64emu_t* emu, posix_spawn_file_actions_32_t* action) +{ + posix_spawn_file_actions_t action_l; + int ret = posix_spawn_file_actions_init(&action_l); + convert_file_action_to_32(action, &action_l); + return ret; +} +EXPORT int my32_posix_spawn_file_actions_addopen(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides, const char* path, int oflag, int modes) +{ + posix_spawn_file_actions_t action_l = {0}; + convert_file_action_to_64(&action_l, action); + int ret = posix_spawn_file_actions_addopen(&action_l, fides, path, oflag, modes); + convert_file_action_to_32(action, &action_l); + return ret; +} + +EXPORT int my32_posix_spawn_file_actions_addclose(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides) +{ + posix_spawn_file_actions_t action_l = {0}; + convert_file_action_to_64(&action_l, action); + int ret = posix_spawn_file_actions_addclose(&action_l, fides); + convert_file_action_to_32(action, &action_l); + return ret; +} + +EXPORT int my32_posix_spawn_file_actions_adddup2(x64emu_t* emu, posix_spawn_file_actions_32_t* action, int fides, int newfides) +{ + posix_spawn_file_actions_t action_l = {0}; + convert_file_action_to_64(&action_l, action); + int ret = posix_spawn_file_actions_adddup2(&action_l, fides, newfides); + convert_file_action_to_32(action, &action_l); + return ret; +} + +EXPORT int my32_posix_spawn_file_actions_destroy(x64emu_t* emu, posix_spawn_file_actions_32_t* action) +{ + posix_spawn_file_actions_t action_l; + convert_file_action_to_64(&action_l, action); + int ret = posix_spawn_file_actions_destroy(&action_l); + convert_file_action_to_32(action, &action_l); // just in case? + return ret; +} + EXPORT int32_t my32_posix_spawn(x64emu_t* emu, pid_t* pid, const char* fullpath, - const posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[]) + posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[]) { posix_spawn_file_actions_t actions_l = {0}; posix_spawn_file_actions_t *actions = NULL; if(actions_s) { actions = &actions_l; - actions->__allocated = actions_s->__allocated; - actions->__used = actions_s->__used; - actions->__actions = from_ptrv(actions_s->__actions); + convert_file_action_to_64(actions, actions_s); } // use fullpath... int self = isProcSelf(fullpath, "exe"); @@ -1797,20 +1855,18 @@ EXPORT int32_t my32_posix_spawn(x64emu_t* emu, pid_t* pid, const char* fullpath, while(argv[n]) ++n; char** newargv = (char**)calloc(n+1, sizeof(char*)); for(int i=0; i<=n; ++i) - newargv[i+1] = from_ptrv(argv[i]); + newargv[i] = from_ptrv(argv[i]); return posix_spawn(pid, fullpath, actions, attrp, newargv, newenvp); } EXPORT int32_t my32_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path, - const posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[]) + posix_spawn_file_actions_32_t *actions_s, const posix_spawnattr_t* attrp, ptr_t const argv[], ptr_t const envp[]) { posix_spawn_file_actions_t actions_l = {0}; posix_spawn_file_actions_t *actions = NULL; if(actions_s) { actions = &actions_l; - actions->__allocated = actions_s->__allocated; - actions->__used = actions_s->__used; - actions->__actions = from_ptrv(actions_s->__actions); + convert_file_action_to_64(actions, actions_s); } // need to use BOX32_PATH / PATH here... char* fullpath = ResolveFile(path, &my_context->box64_path); @@ -1851,7 +1907,7 @@ EXPORT int32_t my32_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path, while(argv[n]) ++n; char** newargv = (char**)calloc(n+1, sizeof(char*)); for(int i=0; i<=n; ++i) - newargv[i+1] = from_ptrv(argv[i]); + newargv[i] = from_ptrv(argv[i]); return posix_spawnp(pid, path, actions, attrp, newargv, newenvp); } diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h index 0d72a3e3..ea2b8c5d 100755 --- a/src/wrapped32/wrappedlibc_private.h +++ b/src/wrapped32/wrappedlibc_private.h @@ -1263,11 +1263,11 @@ GOM(posix_spawn, iFEpppppp) // posix_spawnattr_setschedpolicy // posix_spawnattr_setsigdefault // posix_spawnattr_setsigmask -// posix_spawn_file_actions_addclose -//GO(posix_spawn_file_actions_adddup2, iFpii) -//GO(posix_spawn_file_actions_addopen, iFpipii) -//GO(posix_spawn_file_actions_destroy, iFp) -//GO(posix_spawn_file_actions_init, iFp) +GOM(posix_spawn_file_actions_addclose, iFEpi) +GOM(posix_spawn_file_actions_adddup2, iFEpii) +GOM(posix_spawn_file_actions_addopen, iFEpipOi) +GOM(posix_spawn_file_actions_destroy, iFEp) +GOM(posix_spawn_file_actions_init, iFEp) GOM(posix_spawnp, iFEpppppp) //%% GO(ppoll, iFpurLL_p) GOW(prctl, iFiLLLL) |