diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-08-31 11:39:55 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-08-31 11:39:55 +0200 |
| commit | 6d6739ccea802354cdba614190d1e87ab8ed0072 (patch) | |
| tree | 45ed795f5ff61af9a4fbbc9c335e2c5c7340f635 /src | |
| parent | d2511e66fbf2be2d633a7a97687a2f102d10ffe7 (diff) | |
| download | box64-6d6739ccea802354cdba614190d1e87ab8ed0072.tar.gz box64-6d6739ccea802354cdba614190d1e87ab8ed0072.zip | |
[BOX32] More 32bits wrapped functions
Diffstat (limited to 'src')
| -rwxr-xr-x | src/include/myalign32.h | 7 | ||||
| -rw-r--r-- | src/include/signals.h | 23 | ||||
| -rw-r--r-- | src/libtools/signal32.c | 79 | ||||
| -rw-r--r-- | src/wrapped32/generated/functions_list.txt | 11 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrappedlibctypes32.h | 5 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.c | 11 | ||||
| -rw-r--r-- | src/wrapped32/generated/wrapper32.h | 6 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc.c | 124 | ||||
| -rwxr-xr-x | src/wrapped32/wrappedlibc_private.h | 45 |
9 files changed, 252 insertions, 59 deletions
diff --git a/src/include/myalign32.h b/src/include/myalign32.h index 7e9c3a6c..2638bf5d 100755 --- a/src/include/myalign32.h +++ b/src/include/myalign32.h @@ -439,5 +439,12 @@ struct i386_addrinfo ptr_t ai_next; // struct addrinfo * } __attribute__((packed)); +struct i386_hostent { + ptr_t h_name; // char * + ptr_t h_aliases; // char ** + int h_addrtype; + int h_length; + ptr_t h_addr_list;// char ** +} __attribute__((packed)); #endif//__MY_ALIGN32__H_ \ No newline at end of file diff --git a/src/include/signals.h b/src/include/signals.h index deda21f7..71d6dafc 100644 --- a/src/include/signals.h +++ b/src/include/signals.h @@ -24,6 +24,29 @@ typedef struct x64_sigaction_restorer_s { sigset_t sa_mask; } x64_sigaction_restorer_t; +#ifdef BOX32 +typedef struct i386_sigaction_s { + union { + ptr_t _sa_handler; // sighandler_t + ptr_t _sa_sigaction; //void (*_sa_sigaction)(int, siginfo_t *, void *); + } _u; + sigset_t sa_mask; + uint32_t sa_flags; + ptr_t sa_restorer; //void (*sa_restorer)(void); +} i386_sigaction_t; + +typedef struct i386_sigaction_restorer_s { + union { + ptr_t _sa_handler; //sighandler_t + ptr_t _sa_sigaction; //void (*_sa_sigaction)(int, siginfo_t *, void *); + } _u; + uint32_t sa_flags; + ptr_t sa_restorer; //void (*sa_restorer)(void); + sigset_t sa_mask; +} i386_sigaction_restorer_t; + +#endif + sighandler_t my_signal(x64emu_t* emu, int signum, sighandler_t handler); sighandler_t my___sysv_signal(x64emu_t* emu, int signum, sighandler_t handler); sighandler_t my_sysv_signal(x64emu_t* emu, int signum, sighandler_t handler); diff --git a/src/libtools/signal32.c b/src/libtools/signal32.c index 54d68143..266128e2 100644 --- a/src/libtools/signal32.c +++ b/src/libtools/signal32.c @@ -738,6 +738,85 @@ void my_sigactionhandler_oldcode_32(int32_t sig, int simple, siginfo_t* info, vo relockMutex(Locks); } +void my32_sigactionhandler(int32_t sig, siginfo_t* info, void * ucntx) +{ + #ifdef DYNAREC + ucontext_t *p = (ucontext_t *)ucntx; + #ifdef ARM64 + void * pc = (void*)p->uc_mcontext.pc; + #elif defined(LA64) + void * pc = (void*)p->uc_mcontext.__pc; + #elif defined(RV64) + void * pc = (void*)p->uc_mcontext.__gregs[0]; + #else + #error Unsupported architecture + #endif + dynablock_t* db = FindDynablockFromNativeAddress(pc); + #else + void* db = NULL; + #endif + + my_sigactionhandler_oldcode_32(sig, 0, info, ucntx, NULL, db); +} + + +EXPORT int my32_sigaction(x64emu_t* emu, int signum, const i386_sigaction_t *act, i386_sigaction_t *oldact) +{ + printf_log(LOG_DEBUG, "Sigaction(signum=%d, act=%p(f=%p, flags=0x%x), old=%p)\n", signum, act, act?from_ptrv(act->_u._sa_handler):NULL, act?act->sa_flags:0, oldact); + if(signum<0 || signum>MAX_SIGNAL) { + errno = EINVAL; + return -1; + } + + if(signum==SIGSEGV && emu->context->no_sigsegv) + return 0; + + if(signum==SIGILL && emu->context->no_sigill) + return 0; + struct sigaction newact = {0}; + struct sigaction old = {0}; + uintptr_t old_handler = my_context->signals[signum]; + if(act) { + newact.sa_mask = act->sa_mask; + newact.sa_flags = act->sa_flags&~0x04000000; // No sa_restorer... + if(act->sa_flags&0x04) { + my_context->signals[signum] = (uintptr_t)act->_u._sa_sigaction; + my_context->is_sigaction[signum] = 1; + if(act->_u._sa_handler!=0 && act->_u._sa_handler!=(ptr_t)1) { + newact.sa_sigaction = my32_sigactionhandler; + } else + newact.sa_sigaction = from_ptrv(act->_u._sa_sigaction); + } else { + my_context->signals[signum] = (uintptr_t)act->_u._sa_handler; + my_context->is_sigaction[signum] = 0; + if(act->_u._sa_handler!=0 && act->_u._sa_handler!=(ptr_t)1) { + newact.sa_flags|=0x04; + newact.sa_sigaction = my32_sigactionhandler; + } else + newact.sa_handler = from_ptrv(act->_u._sa_handler); + } + my_context->restorer[signum] = (act->sa_flags&0x04000000)?(uintptr_t)act->sa_restorer:0; + my_context->onstack[signum] = (act->sa_flags&SA_ONSTACK)?1:0; + } + int ret = 0; + if(signum!=SIGSEGV && signum!=SIGBUS && signum!=SIGILL && signum!=SIGABRT) + ret = sigaction(signum, act?&newact:NULL, oldact?&old:NULL); + if(oldact) { + oldact->sa_flags = old.sa_flags; + oldact->sa_mask = old.sa_mask; + if(old.sa_flags & 0x04) + oldact->_u._sa_sigaction = to_ptrv(old.sa_sigaction); //TODO should wrap... + else + oldact->_u._sa_handler = to_ptrv(old.sa_handler); //TODO should wrap... + if(oldact->_u._sa_sigaction == to_ptrv(my32_sigactionhandler) && old_handler) + oldact->_u._sa_sigaction = to_ptr(old_handler); + oldact->sa_restorer = 0; // no handling for now... + } + return ret; +} +EXPORT int my32___sigaction(x64emu_t* emu, int signum, const i386_sigaction_t *act, i386_sigaction_t *oldact) +__attribute__((alias("my32_sigaction"))); + EXPORT int my32_getcontext(x64emu_t* emu, void* ucp) { // printf_log(LOG_NONE, "Warning: call to partially implemented getcontext\n"); diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt index 23e13945..a5cee043 100644 --- a/src/wrapped32/generated/functions_list.txt +++ b/src/wrapped32/generated/functions_list.txt @@ -37,6 +37,7 @@ #() aFa -> aFa #() tFp -> tFp #() LFrL_ -> LFB +#() pFrL_ -> pFB #() vFEv -> vFEv #() vFEp -> vFEp #() iFEv -> iFEv @@ -89,6 +90,7 @@ #() iFHBp_ -> iFHB #() fFpBp_ -> fFpB #() dFpBp_ -> dFpB +#() pFrL_p -> pFBp #() iFuBLL_ -> iFuB #() iFprLL_ -> iFpB #() iFrLL_BLL_ -> iFBB @@ -164,6 +166,8 @@ #() iFiiiN -> iFiiiN #() iFiiII -> iFiiII #() iFiuui -> iFiuui +#() iFipup -> iFipup +#() iFuupi -> iFuupi #() iFhpiL -> iFhpiL #() lFipLi -> lFipLi #() LFpLLh -> LFpLLh @@ -179,6 +183,7 @@ #() iFEpppp -> iFEpppp #() iFiiipu -> iFiiipu #() iFiLLLL -> iFiLLLL +#() iFpppup -> iFpppup #() iFEBh_ppp -> iFEBppp #() iFEpippp -> iFEpippp #() iFEpuppp -> iFEpuppp @@ -195,6 +200,7 @@ #() iFEvpV -> iFEpV #() UFsvvs -> UFss #() iFEhvpV -> iFEhpV +#() iFEpvvpV -> iFEppV #() iFEpuvvppp -> iFEpuppp wrappedcrashhandler: wrappedldlinux: @@ -220,12 +226,16 @@ wrappedlibc: - __ctype_tolower_loc - __errno_location - pFL: +- pFp: + - gethostbyname - vFip: - vFpi: - vFpu: - iFip: - getrlimit - setrlimit +- iFpi: + - backtrace - iFpp: - alphasort64 - iFpV: @@ -258,6 +268,7 @@ wrappedlibc: - iFpppp: - getaddrinfo - iFhvpV: +- iFpvvpV: - iFpippp: - iFpLppp: - iFpLiipV: diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h index 002b0f01..0a032fe6 100644 --- a/src/wrapped32/generated/wrappedlibctypes32.h +++ b/src/wrapped32/generated/wrappedlibctypes32.h @@ -23,10 +23,12 @@ typedef uint32_t (*uFV_t)(...); typedef uintptr_t (*LFL_t)(uintptr_t); typedef void* (*pFv_t)(void); typedef void* (*pFL_t)(uintptr_t); +typedef void* (*pFp_t)(void*); typedef void (*vFip_t)(int32_t, void*); typedef void (*vFpi_t)(void*, int32_t); typedef void (*vFpu_t)(void*, uint32_t); typedef int32_t (*iFip_t)(int32_t, void*); +typedef int32_t (*iFpi_t)(void*, int32_t); typedef int32_t (*iFpp_t)(void*, void*); typedef int32_t (*iFpV_t)(void*, ...); typedef int32_t (*iFhp_t)(uintptr_t, void*); @@ -52,6 +54,7 @@ typedef int32_t (*iFLLLL_t)(uintptr_t, uintptr_t, uintptr_t, uintptr_t); typedef int32_t (*iFppiV_t)(void*, void*, int32_t, ...); typedef int32_t (*iFpppp_t)(void*, void*, void*, void*); typedef int32_t (*iFhvpV_t)(uintptr_t, void, void*, ...); +typedef int32_t (*iFpvvpV_t)(void*, void, void, void*, ...); typedef int32_t (*iFpippp_t)(void*, int32_t, void*, void*, void*); typedef int32_t (*iFpLppp_t)(void*, uintptr_t, void*, void*, void*); typedef int32_t (*iFpLiipV_t)(void*, uintptr_t, int32_t, int32_t, void*, ...); @@ -64,8 +67,10 @@ typedef int32_t (*iFpuvvppp_t)(void*, uint32_t, void, void, void*, void*, void*) GO(__ctype_b_loc, pFv_t) \ GO(__ctype_tolower_loc, pFv_t) \ GO(__errno_location, pFv_t) \ + GO(gethostbyname, pFp_t) \ GO(getrlimit, iFip_t) \ GO(setrlimit, iFip_t) \ + GO(backtrace, iFpi_t) \ GO(alphasort64, iFpp_t) \ GO(statvfs64, iFhp_t) \ GO(signal, pFip_t) \ diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c index 3a41d9e2..50c13938 100644 --- a/src/wrapped32/generated/wrapper32.c +++ b/src/wrapped32/generated/wrapper32.c @@ -111,6 +111,7 @@ typedef uintptr_t (*hFv_t)(void); typedef void* (*aFa_t)(void*); typedef char* (*tFp_t)(void*); typedef uintptr_t (*LFrL__t)(struct_L_t*); +typedef void* (*pFrL__t)(struct_L_t*); typedef void (*vFEv_t)(x64emu_t*); typedef void (*vFEp_t)(x64emu_t*, void*); typedef int32_t (*iFEv_t)(x64emu_t*); @@ -163,6 +164,7 @@ typedef char* (*tFpL_t)(void*, uintptr_t); typedef int32_t (*iFHBp__t)(uintptr_t, struct_p_t*); typedef float (*fFpBp__t)(void*, struct_p_t*); typedef double (*dFpBp__t)(void*, struct_p_t*); +typedef void* (*pFrL_p_t)(struct_L_t*, void*); typedef int32_t (*iFuBLL__t)(uint32_t, struct_LL_t*); typedef int32_t (*iFprLL__t)(void*, struct_LL_t*); typedef int32_t (*iFrLL_BLL__t)(struct_LL_t*, struct_LL_t*); @@ -238,6 +240,8 @@ typedef int32_t (*iFEhpV_t)(x64emu_t*, uintptr_t, void*, void*); typedef int32_t (*iFiiiN_t)(int32_t, int32_t, int32_t, ...); typedef int32_t (*iFiiII_t)(int32_t, int32_t, int64_t, int64_t); typedef int32_t (*iFiuui_t)(int32_t, uint32_t, uint32_t, int32_t); +typedef int32_t (*iFipup_t)(int32_t, void*, uint32_t, void*); +typedef int32_t (*iFuupi_t)(uint32_t, uint32_t, void*, int32_t); typedef int32_t (*iFhpiL_t)(uintptr_t, void*, int32_t, uintptr_t); typedef intptr_t (*lFipLi_t)(int32_t, void*, uintptr_t, int32_t); typedef uintptr_t (*LFpLLh_t)(void*, uintptr_t, uintptr_t, uintptr_t); @@ -253,6 +257,7 @@ typedef int32_t (*iFEpppi_t)(x64emu_t*, void*, void*, void*, int32_t); typedef int32_t (*iFEpppp_t)(x64emu_t*, void*, void*, void*, void*); typedef int32_t (*iFiiipu_t)(int32_t, int32_t, int32_t, void*, uint32_t); typedef int32_t (*iFiLLLL_t)(int32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t); +typedef int32_t (*iFpppup_t)(void*, void*, void*, uint32_t, void*); typedef int32_t (*iFEBh_ppp_t)(x64emu_t*, struct_h_t*, void*, void*, void*); typedef int32_t (*iFEpippp_t)(x64emu_t*, void*, int32_t, void*, void*, void*); typedef int32_t (*iFEpuppp_t)(x64emu_t*, void*, uint32_t, void*, void*, void*); @@ -315,6 +320,7 @@ void hFv_32(x64emu_t *emu, uintptr_t fcn) { hFv_t fn = (hFv_t)fcn; R_EAX = to_ha void aFa_32(x64emu_t *emu, uintptr_t fcn) { aFa_t fn = (aFa_t)fcn; R_EAX = to_locale(fn(from_locale(from_ptri(ptr_t, R_ESP + 4)))); } void tFp_32(x64emu_t *emu, uintptr_t fcn) { tFp_t fn = (tFp_t)fcn; R_EAX = to_cstring(fn(from_ptriv(R_ESP + 4))); } void LFrL__32(x64emu_t *emu, uintptr_t fcn) { LFrL__t fn = (LFrL__t)fcn; struct_L_t arg_4; from_struct_L(&arg_4, *(ptr_t*)(from_ptr((R_ESP + 4)))); R_EAX = to_ulong(fn(*(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL)); } +void pFrL__32(x64emu_t *emu, uintptr_t fcn) { pFrL__t fn = (pFrL__t)fcn; struct_L_t arg_4; from_struct_L(&arg_4, *(ptr_t*)(from_ptr((R_ESP + 4)))); R_EAX = to_ptrv(fn(*(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL)); } void vFEv_32(x64emu_t *emu, uintptr_t fcn) { vFEv_t fn = (vFEv_t)fcn; fn(emu); } void vFEp_32(x64emu_t *emu, uintptr_t fcn) { vFEp_t fn = (vFEp_t)fcn; fn(emu, from_ptriv(R_ESP + 4)); } void iFEv_32(x64emu_t *emu, uintptr_t fcn) { iFEv_t fn = (iFEv_t)fcn; R_EAX = fn(emu); } @@ -367,6 +373,7 @@ void tFpL_32(x64emu_t *emu, uintptr_t fcn) { tFpL_t fn = (tFpL_t)fcn; R_EAX = to void iFHBp__32(x64emu_t *emu, uintptr_t fcn) { iFHBp__t fn = (iFHBp__t)fcn; struct_p_t arg_8; R_EAX = fn(from_hash_d(from_ptri(ptr_t, R_ESP + 4)), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void fFpBp__32(x64emu_t *emu, uintptr_t fcn) { fFpBp__t fn = (fFpBp__t)fcn; struct_p_t arg_8; float fl = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); fpu_do_push(emu); ST0val = fl; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void dFpBp__32(x64emu_t *emu, uintptr_t fcn) { dFpBp__t fn = (dFpBp__t)fcn; struct_p_t arg_8; double db = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); fpu_do_push(emu); ST0val = db; if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } +void pFrL_p_32(x64emu_t *emu, uintptr_t fcn) { pFrL_p_t fn = (pFrL_p_t)fcn; struct_L_t arg_4; from_struct_L(&arg_4, *(ptr_t*)(from_ptr((R_ESP + 4)))); R_EAX = to_ptrv(fn(*(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL, from_ptriv(R_ESP + 8))); } void iFuBLL__32(x64emu_t *emu, uintptr_t fcn) { iFuBLL__t fn = (iFuBLL__t)fcn; struct_LL_t arg_8; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_LL(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } void iFprLL__32(x64emu_t *emu, uintptr_t fcn) { iFprLL__t fn = (iFprLL__t)fcn; struct_LL_t arg_8; from_struct_LL(&arg_8, *(ptr_t*)(from_ptr((R_ESP + 8)))); R_EAX = fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); } void iFrLL_BLL__32(x64emu_t *emu, uintptr_t fcn) { iFrLL_BLL__t fn = (iFrLL_BLL__t)fcn; struct_LL_t arg_4; from_struct_LL(&arg_4, *(ptr_t*)(from_ptr((R_ESP + 4)))); struct_LL_t arg_8; R_EAX = fn(*(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL, *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL); if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_LL(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } @@ -442,6 +449,8 @@ void iFEhpV_32(x64emu_t *emu, uintptr_t fcn) { iFEhpV_t fn = (iFEhpV_t)fcn; R_EA void iFiiiN_32(x64emu_t *emu, uintptr_t fcn) { iFiiiN_t fn = (iFiiiN_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); } void iFiiII_32(x64emu_t *emu, uintptr_t fcn) { iFiiII_t fn = (iFiiII_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int64_t, R_ESP + 12), from_ptri(int64_t, R_ESP + 20)); } void iFiuui_32(x64emu_t *emu, uintptr_t fcn) { iFiuui_t fn = (iFiuui_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); } +void iFipup_32(x64emu_t *emu, uintptr_t fcn) { iFipup_t fn = (iFipup_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptriv(R_ESP + 16)); } +void iFuupi_32(x64emu_t *emu, uintptr_t fcn) { iFuupi_t fn = (iFuupi_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); } void iFhpiL_32(x64emu_t *emu, uintptr_t fcn) { iFhpiL_t fn = (iFhpiL_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12), to_ulong(from_ptri(ulong_t, R_ESP + 16))); } void lFipLi_32(x64emu_t *emu, uintptr_t fcn) { lFipLi_t fn = (lFipLi_t)fcn; R_EAX = to_long(fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), to_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ptri(int32_t, R_ESP + 16))); } void LFpLLh_32(x64emu_t *emu, uintptr_t fcn) { LFpLLh_t fn = (LFpLLh_t)fcn; R_EAX = to_ulong(fn(from_ptriv(R_ESP + 4), to_ulong(from_ptri(ulong_t, R_ESP + 8)), to_ulong(from_ptri(ulong_t, R_ESP + 12)), from_hash(from_ptri(ptr_t, R_ESP + 16)))); } @@ -457,6 +466,7 @@ void iFEpppi_32(x64emu_t *emu, uintptr_t fcn) { iFEpppi_t fn = (iFEpppi_t)fcn; R void iFEpppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpppp_t fn = (iFEpppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); } void iFiiipu_32(x64emu_t *emu, uintptr_t fcn) { iFiiipu_t fn = (iFiiipu_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptriv(R_ESP + 16), from_ptri(uint32_t, R_ESP + 20)); } void iFiLLLL_32(x64emu_t *emu, uintptr_t fcn) { iFiLLLL_t fn = (iFiLLLL_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), to_ulong(from_ptri(ulong_t, R_ESP + 8)), to_ulong(from_ptri(ulong_t, R_ESP + 12)), to_ulong(from_ptri(ulong_t, R_ESP + 16)), to_ulong(from_ptri(ulong_t, R_ESP + 20))); } +void iFpppup_32(x64emu_t *emu, uintptr_t fcn) { iFpppup_t fn = (iFpppup_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptriv(R_ESP + 20)); } void iFEBh_ppp_32(x64emu_t *emu, uintptr_t fcn) { iFEBh_ppp_t fn = (iFEBh_ppp_t)fcn; struct_h_t arg_4; R_EAX = fn(emu, *(ptr_t*)(from_ptr((R_ESP + 4))) ? &arg_4 : NULL, from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); if (*(ptr_t*)(from_ptr((R_ESP + 4)))) to_struct_h(*(ptr_t*)(from_ptr((R_ESP + 4))), &arg_4); } void iFEpippp_32(x64emu_t *emu, uintptr_t fcn) { iFEpippp_t fn = (iFEpippp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } void iFEpuppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpuppp_t fn = (iFEpuppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16), from_ptriv(R_ESP + 20)); } @@ -483,6 +493,7 @@ void KFKp_32(x64emu_t *emu, uintptr_t fcn) { KFKp_t fn = (KFKp_t)fcn; double db void iFEvpV_32(x64emu_t *emu, uintptr_t fcn) { iFEpV_t fn = (iFEpV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); } void UFsvvs_32(x64emu_t *emu, uintptr_t fcn) { UFss_t fn = (UFss_t)fcn; ui64_t r; r.u = (uint64_t)fn(from_ptrv(R_ESP + 4), from_ptrv(R_ESP + 12)); R_EAX = r.d[0]; R_EDX = r.d[1]; } void iFEhvpV_32(x64emu_t *emu, uintptr_t fcn) { iFEhpV_t fn = (iFEhpV_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 12), from_ptrv(R_ESP + 16)); } +void iFEpvvpV_32(x64emu_t *emu, uintptr_t fcn) { iFEppV_t fn = (iFEppV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 16), from_ptrv(R_ESP + 20)); } void iFEpuvvppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpuppp_t fn = (iFEpuppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 20), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28)); } int isRetX87Wrapper32(wrapper_t fun) { diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h index 2688f112..ede84357 100644 --- a/src/wrapped32/generated/wrapper32.h +++ b/src/wrapped32/generated/wrapper32.h @@ -77,6 +77,7 @@ void hFv_32(x64emu_t *emu, uintptr_t fnc); void aFa_32(x64emu_t *emu, uintptr_t fnc); void tFp_32(x64emu_t *emu, uintptr_t fnc); void LFrL__32(x64emu_t *emu, uintptr_t fnc); +void pFrL__32(x64emu_t *emu, uintptr_t fnc); void vFEv_32(x64emu_t *emu, uintptr_t fnc); void vFEp_32(x64emu_t *emu, uintptr_t fnc); void iFEv_32(x64emu_t *emu, uintptr_t fnc); @@ -129,6 +130,7 @@ void tFpL_32(x64emu_t *emu, uintptr_t fnc); void iFHBp__32(x64emu_t *emu, uintptr_t fnc); void fFpBp__32(x64emu_t *emu, uintptr_t fnc); void dFpBp__32(x64emu_t *emu, uintptr_t fnc); +void pFrL_p_32(x64emu_t *emu, uintptr_t fnc); void iFuBLL__32(x64emu_t *emu, uintptr_t fnc); void iFprLL__32(x64emu_t *emu, uintptr_t fnc); void iFrLL_BLL__32(x64emu_t *emu, uintptr_t fnc); @@ -204,6 +206,8 @@ void iFEhpV_32(x64emu_t *emu, uintptr_t fnc); void iFiiiN_32(x64emu_t *emu, uintptr_t fnc); void iFiiII_32(x64emu_t *emu, uintptr_t fnc); void iFiuui_32(x64emu_t *emu, uintptr_t fnc); +void iFipup_32(x64emu_t *emu, uintptr_t fnc); +void iFuupi_32(x64emu_t *emu, uintptr_t fnc); void iFhpiL_32(x64emu_t *emu, uintptr_t fnc); void lFipLi_32(x64emu_t *emu, uintptr_t fnc); void LFpLLh_32(x64emu_t *emu, uintptr_t fnc); @@ -219,6 +223,7 @@ void iFEpppi_32(x64emu_t *emu, uintptr_t fnc); void iFEpppp_32(x64emu_t *emu, uintptr_t fnc); void iFiiipu_32(x64emu_t *emu, uintptr_t fnc); void iFiLLLL_32(x64emu_t *emu, uintptr_t fnc); +void iFpppup_32(x64emu_t *emu, uintptr_t fnc); void iFEBh_ppp_32(x64emu_t *emu, uintptr_t fnc); void iFEpippp_32(x64emu_t *emu, uintptr_t fnc); void iFEpuppp_32(x64emu_t *emu, uintptr_t fnc); @@ -245,5 +250,6 @@ void KFKp_32(x64emu_t *emu, uintptr_t fnc); void iFEvpV_32(x64emu_t *emu, uintptr_t fnc); void UFsvvs_32(x64emu_t *emu, uintptr_t fnc); void iFEhvpV_32(x64emu_t *emu, uintptr_t fnc); +void iFEpvvpV_32(x64emu_t *emu, uintptr_t fnc); void iFEpuvvppp_32(x64emu_t *emu, uintptr_t fnc); #endif // __WRAPPER32_H_ diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c index a32780e7..604d4a6c 100755 --- a/src/wrapped32/wrappedlibc.c +++ b/src/wrapped32/wrappedlibc.c @@ -153,7 +153,6 @@ typedef void* (*pFu_t)(uint32_t); //#include "wrappercallback.h" -#if 0 // utility functions #define SUPER() \ GO(0) \ @@ -173,6 +172,7 @@ GO(13) \ GO(14) \ GO(15) +#if 0 // compare #define GO(A) \ static uintptr_t my32_compare_fct_##A = 0; \ @@ -363,13 +363,13 @@ static void* findcompare_dirFct(void* fct) printf_log(LOG_NONE, "Warning, no more slot for libc compare_dir callback\n"); return NULL; } - +#endif // filter64 #define GO(A) \ -static uintptr_t my32_filter64_fct_##A = 0; \ -static int my32_filter64_##A(const struct dirent64* a) \ -{ \ - return (int)RunFunction(my_context, my32_filter64_fct_##A, 1, a); \ +static uintptr_t my32_filter64_fct_##A = 0; \ +static int my32_filter64_##A(const struct dirent64* a) \ +{ \ + return (int)RunFunctionFmt(my32_filter64_fct_##A, "p", a); \ } SUPER() #undef GO @@ -389,10 +389,10 @@ static void* findfilter64Fct(void* fct) } // compare64 #define GO(A) \ -static uintptr_t my32_compare64_fct_##A = 0; \ -static int my32_compare64_##A(const struct dirent64* a, const struct dirent64* b) \ -{ \ - return (int)RunFunction(my_context, my32_compare64_fct_##A, 2, a, b); \ +static uintptr_t my32_compare64_fct_##A = 0; \ +static int my32_compare64_##A(const struct dirent64* a, const struct dirent64* b) \ +{ \ + return (int)RunFunctionFmt(my32_compare64_fct_##A, "pp", a, b); \ } SUPER() #undef GO @@ -410,6 +410,7 @@ static void* findcompare64Fct(void* fct) printf_log(LOG_NONE, "Warning, no more slot for libc compare64 callback\n"); return NULL; } +#if 0 // on_exit #define GO(A) \ static uintptr_t my32_on_exit_fct_##A = 0; \ @@ -433,8 +434,8 @@ static void* findon_exitFct(void* fct) printf_log(LOG_NONE, "Warning, no more slot for libc on_exit callback\n"); return NULL; } -#undef SUPER #endif +#undef SUPER EXPORT int my32_statvfs64(x64emu_t* emu, void* f, void* r) { @@ -817,20 +818,15 @@ EXPORT int my32___snprintf_chk(x64emu_t* emu, void* buff, size_t s, int f1, int return vsnprintf(buff, s, fmt, VARARGS_32); } -#if 0 EXPORT int my32_sprintf(x64emu_t* emu, void* buff, void * fmt, void * b) { - #ifndef NOALIGN // need to align on arm myStackAlign32((const char*)fmt, b, emu->scratch); PREPARE_VALIST_32; - void* f = vsprintf; - return ((iFppp_t)f)(buff, fmt, VARARGS_32); - #else - return vsprintf((char*)buff, (char*)fmt, b); - #endif + return vsprintf(buff, fmt, VARARGS_32); } EXPORT int my32___sprintf_chk(x64emu_t* emu, void* buff, void * fmt, void * b) __attribute__((alias("my32_sprintf"))); +#if 0 EXPORT int my32_asprintf(x64emu_t* emu, void** buff, void * fmt, void * b) { #ifndef NOALIGN // need to align on arm @@ -1232,31 +1228,16 @@ EXPORT int my32___xstat64(x64emu_t* emu, int v, void* path, void* buf) UnalignStat64_32(&st, buf); return r; } -#if 0 + EXPORT int my32___lxstat(x64emu_t* emu, int v, void* name, void* buf) { - if (v == 1) - { - static iFipp_t f = NULL; - if(!f) { - library_t* lib = my_lib; - if(!lib) - { - errno = EINVAL; - return -1; - } - f = (iFipp_t)dlsym(lib->priv.w.lib, "__lxstat"); - } - - return f(v, name, buf); - } struct stat64 st; int r = lstat64((const char*)name, &st); if (r) return r; r = FillStatFromStat64(v, &st, buf); return r; } -#endif + EXPORT int my32___lxstat64(x64emu_t* emu, int v, void* name, void* buf) { struct stat64 st; @@ -1859,12 +1840,12 @@ EXPORT int32_t my32_glob64(x64emu_t *emu, void* pat, int32_t flags, void* errfnc return glob64(pat, flags, findgloberrFct(errfnc), pglob); } #endif - +#endif EXPORT int my32_scandir64(x64emu_t *emu, void* dir, void* namelist, void* sel, void* comp) { return scandir64(dir, namelist, findfilter64Fct(sel), findcompare64Fct(comp)); } - +#if 0 EXPORT int my32_scandir(x64emu_t *emu, void* dir, void* namelist, void* sel, void* comp) { static iFpppp_t f = NULL; @@ -2353,6 +2334,37 @@ EXPORT void my32_freeaddrinfo(x64emu_t* emu, void* a) { box_free(a); } +EXPORT void* my32_gethostbyname(x64emu_t* emu, const char* a) +{ + static struct i386_hostent ret = {0}; + static ptr_t strings[128] = {0}; + struct hostent* h = gethostbyname(a); + if(!h) return NULL; + // convert... + ret.h_name = to_cstring(h->h_name); + ret.h_addrtype = h->h_addrtype; + ret.h_length = h->h_length; + ptr_t s = to_ptrv(&strings); + int idx = 0; + ret.h_aliases = h->h_aliases?s:0; + if(h->h_aliases) { + char* p = *h->h_aliases; + while(p) { + strings[idx++] = to_cstring(p++); + } + strings[idx++] = 0; + } + ret.h_addr_list = h->h_addr_list?to_ptrv(&strings[idx]):0; + if(h->h_addr_list) { + void* p = *h->h_addr_list; + while(p) + strings[idx++] = to_ptrv(p++); + strings[idx++] = 0; + } + // done + return &ret; +} + EXPORT int my32_alphasort64(x64emu_t* emu, ptr_t* d1_, ptr_t* d2_) { const struct dirent64* d1 = NULL; @@ -2387,6 +2399,44 @@ EXPORT void* my32___ctype_tolower_loc(x64emu_t* emu) return &emu->tolower; } +// Backtrace stuff: TODO in 32bits + +//#include "elfs/elfdwarf_private.h" +EXPORT int my32_backtrace(x64emu_t* emu, void** buffer, int size) +{ + if (!size) return 0; + #if 0 + dwarf_unwind_t *unwind = init_dwarf_unwind_registers(emu); + int idx = 0; + char success = 0; + uintptr_t addr = *(uintptr_t*)R_RSP; + buffer[0] = (void*)addr; + while (++idx < size) { + uintptr_t ret_addr = get_parent_registers(unwind, FindElfAddress(my_context, addr), addr, &success); + if (ret_addr == my_context->exit_bridge) { + // TODO: do something to be able to get the function name + buffer[idx] = (void*)ret_addr; + success = 2; + // See elfdwarf_private.c for the register mapping + unwind->regs[7] = unwind->regs[6]; // mov rsp, rbp + unwind->regs[6] = *(uint64_t*)unwind->regs[7]; // pop rbp + unwind->regs[7] += 8; + ret_addr = *(uint64_t*)unwind->regs[7]; // ret + unwind->regs[7] += 8; + if (++idx < size) buffer[idx] = (void*)ret_addr; + } else if (!success) break; + else buffer[idx] = (void*)ret_addr; + addr = ret_addr; + } + free_dwarf_unwind_registers(&unwind); + return idx; + #else + uintptr_t addr = from_ptr(*(ptr_t*)from_ptrv(R_ESP)); + buffer[0] = (void*)addr; + return 1; + #endif +} + EXPORT struct __processor_model { unsigned int __cpu_vendor; diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h index cdfd36dc..5c356f2e 100755 --- a/src/wrapped32/wrappedlibc_private.h +++ b/src/wrapped32/wrappedlibc_private.h @@ -7,9 +7,10 @@ // struct utimbuf is: LL // struct timespec is: LL // struct tm is: iiiiiiiiilt +// time_t is: L // a64l -//GO(abort, vFv) +GO(abort, vFv) //GO(abs, iFi) //GOW(accept, iFipp) //GOM(accept4, iFEippi) //%% glibc 2.10+ @@ -87,7 +88,7 @@ GOM(alphasort64, iFEpp) // authnone_create // authunix_create // authunix_create_default -//GOW(backtrace, iFpi) //TODO: probably a my_backtrace version, that use emulated stack instead +GOWM(backtrace, iFEpi) //GO(__backtrace, iFpi) //GO(__backtrace_symbols, pFpi) //GOW(backtrace_symbols, pFpi) @@ -128,7 +129,7 @@ GOW(chdir, iFp) //DATA(__check_rhosts_file, 4) // chflags // __chk_fail -//GOW(chmod, iFpu) +GOW(chmod, iFpu) GOW(chown, iFpuu) //GO(chroot, iFp) //GOW(clearenv, iFv) @@ -166,8 +167,8 @@ GOW(__connect, iFipu) //GO(creat64, iFpu) // create_module // Weak //GO(ctermid, pFp) -//GO(ctime, pFp) -//GO(ctime_r, pFpp) +GO(ctime, pFrL_) +GO(ctime_r, pFrL_p) //DATAM(__ctype_b, 4) GOM(__ctype_b_loc, pFEv) //GOW(__ctype_get_mb_cur_max, LFv) @@ -391,7 +392,7 @@ GOM(freeaddrinfo, vFEp) GOW(freelocale, vFA) GO(__freelocale, vFA) //GO(fremovexattr, iFip) -//GO(freopen, pFppp) +GO(freopen, hFppH) GO(freopen64, hFppH) // frexp // Weak // frexpf // Weak @@ -488,7 +489,7 @@ GOW(getgroups, iFiu) // __getgroups_chk //GO(gethostbyaddr, pFpui) //GO(gethostbyaddr_r, iFpuippupp) -//GO(gethostbyname, pFp) +GOM(gethostbyname, pFEp) //GO(gethostbyname2, pFpi) //GO(gethostbyname2_r, iFpippupp) //GO(gethostbyname_r, iFpppupp) @@ -969,7 +970,7 @@ GO(killpg, iFii) // l64a GO(labs, iFi) // lchmod -//GOW(lchown, iFpuu) +GOW(lchown, iFpuu) // lckpwdf // Weak // lcong48 // lcong48_r // Weak @@ -1016,7 +1017,7 @@ GO2(__libc_sigaction, iFEipp, my32_sigaction) //%% // __libc_system // __libc_thread_freeres //GO(__libc_valloc, pFL) -//GOW(link, iFpp) +GOW(link, iFpp) //GO(linkat, iFipipi) GOW(listen, iFii) //GO(listxattr, iFppu) @@ -1044,7 +1045,7 @@ GOW(lseek, iFiii) GOW(lseek64, IFiIi) //GO(lsetxattr, iFpppui) //GO(lutimes, iFpp) -//GOM(__lxstat, iFEipp) //%% +GOM(__lxstat, iFEipp) //%% GOM(__lxstat64, iFEipp) //%% //GO(madvise, iFpLi) GOM(makecontext, iFEppiV) //%% @@ -1100,7 +1101,7 @@ GO(__memset_chk, pFpiLL) GOW(mkdir, iFpu) //GO(mkdirat, iFipu) //GO(mkdtemp, pFp) -//GO(mkfifo, iFpu) +GO(mkfifo, iFpu) //GO(mkfifoat, iFipu) //GO(mkostemp, iFpi) //GO(mkostemp64, iFpi) @@ -1119,7 +1120,7 @@ GOW(mkdir, iFpu) // monstartup // Weak // __monstartup //DATA(__morecore, 4) -//GOW(mount, iFpppup) +GOW(mount, iFpppup) // mprobe //GOM(mprotect, iFEpLi) //%% // mrand48 @@ -1423,7 +1424,7 @@ GO(rewind, vFh) // scalbnf // Weak // scalbnl // Weak //GOM(scandir, iFEpppp) //%% -//GOM(scandir64, iFEpppp) //%% +GOM(scandir64, iFEpppp) //%% //GO2(scanf, iFpp, vscanf) //GO(__sched_cpualloc, pFu) //TODO: check, return cpu_set_t* : should this be aligned/changed? //GO(__sched_cpucount, iFup) @@ -1528,7 +1529,7 @@ GOW(setvbuf, iFhpiL) //GOW(shmdt, iFp) GOW(shmget, iFuui) GOW(shutdown, iFii) -//GOWM(sigaction, iFEipp) //%% +GOWM(sigaction, iFEipp) //%% //GOWM(__sigaction, iFEipp) //%% GO(sigaddset, iFpi) // __sigaddset @@ -1578,7 +1579,7 @@ GOW(socket, iFiii) //GOW(socketpair, iFiiip) //GO(splice, iFipipuu) //GOM(sprintf, iFEppV) //%% -//GOM(__sprintf_chk, iFEpvvpV) //%% +GOM(__sprintf_chk, iFEpvvpV) //%% // sprofil // Weak GOW(srand, vFu) GO(srand48, vFi) @@ -1612,10 +1613,10 @@ GOW(strcasecmp, iFpp) //GO(__strcasecmp, iFpp) // __strcasecmp_l // strcasecmp_l // Weak -//GOW(strcasestr, pFpp) -//GO(__strcasestr, pFpp) -//GO(strcat, pFpp) -//GO(__strcat_chk, pFppL) +GOW(strcasestr, pFpp) +GO(__strcasestr, pFpp) +GO(strcat, pFpp) +GO(__strcat_chk, pFppL) GO(strchr, pFpi) //GOW(strchrnul, pFpi) GO(strcmp, iFpp) @@ -1755,7 +1756,7 @@ GOM(swapcontext, iFEpp) //%% //GOM(swprintf, iFEpupV) //%% //GOM(__swprintf_chk, iFEpuiupV) //%% //GO2(swscanf, iFppV, vswscanf) // swscanf va_list is only pointer, no realign to do -//GOW(symlink, iFpp) +GOW(symlink, iFpp) //GO(symlinkat, iFpip) GO(sync, vFv) GO(syncfs, iFi) @@ -1914,7 +1915,7 @@ GOM(__vsnprintf_chk, iFEpuvvppp) //%% //GOW(__wait, iFp) //GOW(wait3, iFpip) //GOW(wait4, iFipip) -//GOW(waitid, iFiipi) +GOW(waitid, iFuupi) // might need to wrap "p", it's a siginfo_t * //GOW(waitpid, lFlpi) //GOW(__waitpid, lFlpi) //GO(warn, vFppppppppp) @@ -2103,7 +2104,7 @@ GOW(write, lFipL) // xdr_void // xdr_wrapstring // xencrypt -//GO(__xmknod, iFipup) +GO(__xmknod, iFipup) //GO(__xmknodat, iFiipip) //GO(__xpg_basename, pFp) // __xpg_sigpause // Weak |