diff options
Diffstat (limited to 'src/wrapped32')
41 files changed, 8253 insertions, 0 deletions
diff --git a/src/wrapped32/generated/converter32.c b/src/wrapped32/generated/converter32.c new file mode 100644 index 00000000..e098645a --- /dev/null +++ b/src/wrapped32/generated/converter32.c @@ -0,0 +1,61 @@ +// Manually created for now +#include "converter32.h" + +void from_struct_p(struct_p_t *dest, ptr_t s) { + uint8_t* src = (uint8_t*)from_ptrv(s); + dest->p0 = from_ptrv(*(ptr_t*)src); src += 4; +} +void to_struct_p(ptr_t d, const struct_p_t *src) { + if (!src) return; + uint8_t* dest = (uint8_t*)from_ptrv(d); + *(ptr_t*)dest = to_ptrv(src->p0); dest += 4; +} + +void from_struct_L(struct_L_t *dest, ptr_t s) { + uint8_t* src = (uint8_t*)from_ptrv(s); + dest->L0 = from_ulong(*(ulong_t*)src); src += 4; +} +void to_struct_L(ptr_t d, const struct_L_t *src) { + if (!src) return; + uint8_t* dest = (uint8_t*)from_ptrv(d); + *(ulong_t*)dest = to_ulong(src->L0); dest += 4; +} + + +void from_struct_h(struct_h_t *dest, ptr_t s) { + uint8_t* src = (uint8_t*)from_ptrv(s); + dest->h0 = from_hash(*(ulong_t*)src); src += 4; +} +void to_struct_h(ptr_t d, const struct_h_t *src) { + if (!src) return; + uint8_t* dest = (uint8_t*)from_ptrv(d); + *(ulong_t*)dest = to_hash(src->h0); dest += 4; +} + +void from_struct_H(struct_H_t *dest, ptr_t s) { + uint8_t* src = (uint8_t*)from_ptrv(s); + dest->H0 = from_hash_d(*(ulong_t*)src); src += 4; +} +void to_struct_H(ptr_t d, const struct_H_t *src) { + if (!src) return; + uint8_t* dest = (uint8_t*)from_ptrv(d); + *(ulong_t*)dest = to_hash_d(src->H0); dest += 4; +} + +void from_struct_ppppp(struct_ppppp_t *dest, ptr_t s) { + uint8_t* src = (uint8_t*)from_ptrv(s); + dest->p0 = *(void**)src; src += 4; + dest->p1 = *(void**)src; src += 4; + dest->p2 = *(void**)src; src += 4; + dest->p3 = *(void**)src; src += 4; + dest->p4 = *(void**)src; src += 4; +} +void to_struct_ppppp(ptr_t d, const struct_ppppp_t *src) { + if (!src) return; + uint8_t* dest = (uint8_t*)from_ptrv(d); + *(ptr_t*)dest = to_ptrv(src->p0); dest += 4; + *(ptr_t*)dest = to_ptrv(src->p1); dest += 4; + *(ptr_t*)dest = to_ptrv(src->p2); dest += 4; + *(ptr_t*)dest = to_ptrv(src->p3); dest += 4; + *(ptr_t*)dest = to_ptrv(src->p4); dest += 4; +} diff --git a/src/wrapped32/generated/converter32.h b/src/wrapped32/generated/converter32.h new file mode 100644 index 00000000..86dd3e21 --- /dev/null +++ b/src/wrapped32/generated/converter32.h @@ -0,0 +1,37 @@ +// Manually created for now +#ifndef __CONVERTER_H_ +#define __CONVERTER_H_ + +#include "box32.h" + +typedef struct struct_p_s { + void *p0; +} struct_p_t; +void from_struct_p(struct_p_t *dest, ptr_t src); +void to_struct_p(ptr_t dest, const struct_p_t *src); +typedef struct struct_L_s { + unsigned long L0; +} struct_L_t; +void from_struct_L(struct_L_t *dest, ptr_t src); +void to_struct_L(ptr_t dest, const struct_L_t *src); +typedef struct struct_h_s { + uintptr_t h0; +} struct_h_t; +void from_struct_h(struct_h_t *dest, ptr_t src); +void to_struct_h(ptr_t dest, const struct_h_t *src); +typedef struct struct_H_s { + uintptr_t H0; +} struct_H_t; +void from_struct_H(struct_H_t *dest, ptr_t src); +void to_struct_H(ptr_t dest, const struct_H_t *src); +typedef struct struct_ppppp_s { + void* p0; + void* p1; + void* p2; + void* p3; + void* p4; +} struct_ppppp_t; +void from_struct_ppppp(struct_ppppp_t *dest, ptr_t src); +void to_struct_ppppp(ptr_t dest, const struct_ppppp_t *src); + +#endif // __CONVERTER_H_ diff --git a/src/wrapped32/generated/functions_list.txt b/src/wrapped32/generated/functions_list.txt new file mode 100644 index 00000000..28592269 --- /dev/null +++ b/src/wrapped32/generated/functions_list.txt @@ -0,0 +1,365 @@ +#() vFv -> vFv +#() vFi -> vFi +#() vFu -> vFu +#() vFp -> vFp +#() vFA -> vFA +#() iFv -> iFv +#() iFi -> iFi +#() iFI -> iFI +#() iFu -> iFu +#() iFf -> iFf +#() iFd -> iFd +#() iFL -> iFL +#() iFp -> iFp +#() iFh -> iFh +#() iFH -> iFH +#() IFf -> IFf +#() IFd -> IFd +#() uFv -> uFv +#() uFu -> uFu +#() uFU -> uFU +#() UFs -> UFs +#() fFf -> fFf +#() dFv -> dFv +#() dFd -> dFd +#() lFi -> lFi +#() lFp -> lFp +#() LFv -> LFv +#() LFL -> LFL +#() pFu -> pFu +#() pFL -> pFL +#() pFp -> pFp +#() hFv -> hFv +#() aFa -> aFa +#() vFEv -> vFEv +#() vFEp -> vFEp +#() iFEv -> iFEv +#() iFEi -> iFEi +#() iFEL -> iFEL +#() iFEp -> iFEp +#() iFEh -> iFEh +#() iFEO -> iFEO +#() iFii -> iFii +#() iFiI -> iFiI +#() iFiu -> iFiu +#() iFip -> iFip +#() iFuu -> iFuu +#() iFup -> iFup +#() iFli -> iFli +#() iFpi -> iFpi +#() iFpp -> iFpp +#() iFhp -> iFhp +#() iFhh -> iFhh +#() IFII -> IFII +#() uFEu -> uFEu +#() uFEV -> uFEV +#() uFpa -> uFpa +#() UFii -> UFii +#() UFUU -> UFUU +#() UFss -> UFss +#() fFif -> fFif +#() fFfi -> fFfi +#() fFff -> fFff +#() fFfD -> fFfD +#() fFfp -> fFfp +#() dFid -> dFid +#() dFdi -> dFdi +#() dFdd -> dFdd +#() dFdD -> dFdD +#() dFdp -> dFdp +#() LFpp -> LFpp +#() pFEv -> pFEv +#() pFEp -> pFEp +#() pFLL -> pFLL +#() aFia -> aFia +#() iFHBp_ -> iFHB +#() vFEip -> vFEip +#() vFEpi -> vFEpi +#() vFEpu -> vFEpu +#() vFfpp -> vFfpp +#() vFdpp -> vFdpp +#() iFEpi -> iFEpi +#() iFEpL -> iFEpL +#() iFEpp -> iFEpp +#() iFEpV -> iFEpV +#() iFiii -> iFiii +#() iFiiI -> iFiiI +#() iFiiu -> iFiiu +#() iFiiO -> iFiiO +#() iFiII -> iFiII +#() iFiuu -> iFiuu +#() iFiLN -> iFiLN +#() iFipp -> iFipp +#() iFuii -> iFuii +#() iFuip -> iFuip +#() iFuui -> iFuui +#() iFuuu -> iFuuu +#() iFuLp -> iFuLp +#() iFupp -> iFupp +#() iFpiu -> iFpiu +#() iFpip -> iFpip +#() iFpuu -> iFpuu +#() iFppu -> iFppu +#() iFppL -> iFppL +#() iFppp -> iFppp +#() iFpOu -> iFpOu +#() IFiIi -> IFiIi +#() fFfff -> fFfff +#() fFffp -> fFffp +#() dFddd -> dFddd +#() dFddp -> dFddp +#() pFEip -> pFEip +#() pFEpi -> pFEpi +#() pFEpp -> pFEpp +#() pFppL -> pFppL +#() pFpOM -> pFpOM +#() hFEpp -> hFEpp +#() aFipa -> aFipa +#() lFpBp_i -> lFpBi +#() vFEipV -> vFEipV +#() vFEppp -> vFEppp +#() iFEiiN -> iFEiiN +#() iFEipp -> iFEipp +#() iFELup -> iFELup +#() iFEpip -> iFEpip +#() iFEpup -> iFEpup +#() iFEppu -> iFEppu +#() iFEppL -> iFEppL +#() iFEppp -> iFEppp +#() iFiiII -> iFiiII +#() iFiuui -> iFiuui +#() LFpLLh -> LFpLLh +#() pFEppi -> pFEppi +#() pFEppp -> pFEppp +#() pFppuL -> pFppuL +#() pFppLL -> pFppLL +#() iFEppiV -> iFEppiV +#() iFEpppi -> iFEpppi +#() iFiLLLL -> iFiLLLL +#() iFEBh_ppp -> iFEBppp +#() iFEpippppp -> iFEpippppp +#defined(ANDROID) pFv -> pFv +#defined(ANDROID) vFEpppp -> vFEpppp +#defined(HAVE_LD80BITS) DFD -> DFD +#defined(HAVE_LD80BITS) DFDD -> DFDD +#defined(HAVE_LD80BITS) DFDp -> DFDp +#!defined(HAVE_LD80BITS) KFK -> KFK +#!defined(HAVE_LD80BITS) KFKK -> KFKK +#!defined(HAVE_LD80BITS) KFKp -> KFKp +#() iFEvpV -> iFEpV +#() UFsvvs -> UFss +wrappedcrashhandler: +wrappedldlinux: +- pFv: + - ___tls_get_addr +- pFp: + - __tls_get_addr +wrappedlibc: +- vFv: +- vFp: +- iFv: +- iFi: + - __close_nocancel +- iFL: +- iFp: +- iFO: +- uFu: +- uFV: +- LFL: +- pFL: +- vFip: +- vFpi: +- vFpu: +- iFpp: +- iFpV: +- IFII: +- UFUU: +- pFip: + - signal +- hFpp: +- vFipV: +- iFvpV: +- iFiiN: +- iFipp: +- iFppp: +- vFpppp: + - __libc_init +- iFiiII: +- iFppiV: +- iFpippppp: +wrappedlibdl: +- iFp: + - dlclose +- pFv: + - dlerror +- iFpp: + - _dl_find_object + - dladdr +- pFpi: + - dlopen +- pFpp: + - dlsym +- iFpip: + - dlinfo +- pFppi: + - dlmopen +- pFppp: + - dlvsym +- iFpppi: + - dladdr1 +wrappedlibm: +- UFs: + - cacosf + - cacoshf + - casinf + - casinhf + - catanf + - catanhf + - ccosf + - ccoshf + - cexpf + - clogf + - cprojf + - csinf + - csinhf + - csqrtf + - ctanf + - ctanhf +- fFf: + - __acosf_finite + - __acoshf_finite + - __asinf_finite + - __coshf_finite + - __exp2f_finite + - __expf_finite + - __log10f_finite + - __log2f_finite + - __logf_finite + - __sinhf_finite + - __sqrtf_finite +- dFd: + - __acos_finite + - __acosh_finite + - __asin_finite + - __cosh_finite + - __exp2_finite + - __exp_finite + - __log10_finite + - __log2_finite + - __log_finite + - __sinh_finite + - __sqrt_finite +- DFD: + - pow10l +- KFK: + - acoshl + - acosl + - asinhl + - asinl + - atanhl + - cbrtl + - erfcl + - erfl + - ldexpl + - lgammal + - logl + - pow10l + - tgammal +- fFff: + - __atan2f_finite + - __hypotf_finite + - __powf_finite +- dFdd: + - __atan2_finite + - __hypot_finite + - __pow_finite +- KFKK: + - fmodl + - powl +- KFKp: + - frexpl + - lgammal_r +- UFsvvs: + - cpowf +wrappedlibpthread: +- vFv: + - __pthread_initialize +- vFp: + - __pthread_register_cancel + - __pthread_unregister_cancel + - __pthread_unwind_next +- iFp: + - __pthread_mutex_destroy + - __pthread_mutex_lock + - __pthread_mutex_trylock + - __pthread_mutex_unlock + - pthread_attr_destroy + - pthread_attr_init + - pthread_cond_broadcast@GLIBC_2.0 + - pthread_cond_destroy@GLIBC_2.0 + - pthread_cond_signal@GLIBC_2.0 + - pthread_mutex_destroy + - pthread_mutex_lock + - pthread_mutex_trylock + - pthread_mutex_unlock + - pthread_rwlock_rdlock + - pthread_rwlock_unlock + - pthread_rwlock_wrlock +- iFh: + - pthread_detach +- vFpi: + - _pthread_cleanup_pop + - _pthread_cleanup_pop_restore +- iFpi: + - pthread_attr_setdetachstate + - pthread_attr_setinheritsched + - pthread_attr_setschedpolicy + - pthread_attr_setscope + - pthread_kill + - pthread_mutexattr_setkind_np +- iFpL: + - pthread_attr_setguardsize + - pthread_attr_setstacksize +- iFpp: + - __pthread_key_create + - __pthread_mutex_init + - __pthread_once + - pthread_attr_getdetachstate + - pthread_attr_getguardsize + - pthread_attr_getinheritsched + - pthread_attr_getschedparam + - pthread_attr_getschedpolicy + - pthread_attr_getscope + - pthread_attr_getstackaddr + - pthread_attr_getstacksize + - pthread_attr_setschedparam + - pthread_attr_setstackaddr + - pthread_cond_init@GLIBC_2.0 + - pthread_cond_wait + - pthread_cond_wait@GLIBC_2.0 + - pthread_key_create + - pthread_mutex_init + - pthread_mutex_timedlock + - pthread_once + - pthread_setname_np +- vFppp: + - _pthread_cleanup_push + - _pthread_cleanup_push_defer +- iFLup: + - pthread_setaffinity_np +- iFpup: + - pthread_attr_setaffinity_np + - pthread_getaffinity_np +- iFppu: + - pthread_getname_np +- iFppL: + - pthread_attr_setstack +- iFppp: + - __pthread_atfork + - pthread_atfork + - pthread_attr_getstack + - pthread_cond_timedwait + - pthread_cond_timedwait@GLIBC_2.0 +- iFhppp: + - pthread_create +wrappedlibrt: diff --git a/src/wrapped32/generated/wrappedcrashhandlerdefs32.h b/src/wrapped32/generated/wrappedcrashhandlerdefs32.h new file mode 100644 index 00000000..83e132a1 --- /dev/null +++ b/src/wrapped32/generated/wrappedcrashhandlerdefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedcrashhandlerDEFS32_H_ +#define __wrappedcrashhandlerDEFS32_H_ + + +#endif // __wrappedcrashhandlerDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedcrashhandlertypes32.h b/src/wrapped32/generated/wrappedcrashhandlertypes32.h new file mode 100644 index 00000000..5b75966f --- /dev/null +++ b/src/wrapped32/generated/wrappedcrashhandlertypes32.h @@ -0,0 +1,17 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedcrashhandlerTYPES32_H_ +#define __wrappedcrashhandlerTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + + +#define SUPER() ADDED_FUNCTIONS() + +#endif // __wrappedcrashhandlerTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedcrashhandlerundefs32.h b/src/wrapped32/generated/wrappedcrashhandlerundefs32.h new file mode 100644 index 00000000..d70f6207 --- /dev/null +++ b/src/wrapped32/generated/wrappedcrashhandlerundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedcrashhandlerUNDEFS32_H_ +#define __wrappedcrashhandlerUNDEFS32_H_ + + +#endif // __wrappedcrashhandlerUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedldlinuxdefs32.h b/src/wrapped32/generated/wrappedldlinuxdefs32.h new file mode 100644 index 00000000..24962643 --- /dev/null +++ b/src/wrapped32/generated/wrappedldlinuxdefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedldlinuxDEFS32_H_ +#define __wrappedldlinuxDEFS32_H_ + + +#endif // __wrappedldlinuxDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedldlinuxtypes32.h b/src/wrapped32/generated/wrappedldlinuxtypes32.h new file mode 100644 index 00000000..e010f126 --- /dev/null +++ b/src/wrapped32/generated/wrappedldlinuxtypes32.h @@ -0,0 +1,21 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedldlinuxTYPES32_H_ +#define __wrappedldlinuxTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + +typedef void* (*pFv_t)(void); +typedef void* (*pFp_t)(void*); + +#define SUPER() ADDED_FUNCTIONS() \ + GO(___tls_get_addr, pFv_t) \ + GO(__tls_get_addr, pFp_t) + +#endif // __wrappedldlinuxTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedldlinuxundefs32.h b/src/wrapped32/generated/wrappedldlinuxundefs32.h new file mode 100644 index 00000000..0ab4c7e3 --- /dev/null +++ b/src/wrapped32/generated/wrappedldlinuxundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedldlinuxUNDEFS32_H_ +#define __wrappedldlinuxUNDEFS32_H_ + + +#endif // __wrappedldlinuxUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibcdefs32.h b/src/wrapped32/generated/wrappedlibcdefs32.h new file mode 100644 index 00000000..bcd18301 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibcdefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibcDEFS32_H_ +#define __wrappedlibcDEFS32_H_ + + +#endif // __wrappedlibcDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibctypes32.h b/src/wrapped32/generated/wrappedlibctypes32.h new file mode 100644 index 00000000..1b3d5ab3 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibctypes32.h @@ -0,0 +1,49 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibcTYPES32_H_ +#define __wrappedlibcTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + +typedef void (*vFv_t)(void); +typedef void (*vFp_t)(void*); +typedef int32_t (*iFv_t)(void); +typedef int32_t (*iFi_t)(int32_t); +typedef int32_t (*iFL_t)(uintptr_t); +typedef int32_t (*iFp_t)(void*); +typedef int32_t (*iFO_t)(int32_t); +typedef uint32_t (*uFu_t)(uint32_t); +typedef uint32_t (*uFV_t)(...); +typedef uintptr_t (*LFL_t)(uintptr_t); +typedef void* (*pFL_t)(uintptr_t); +typedef void (*vFip_t)(int32_t, void*); +typedef void (*vFpi_t)(void*, int32_t); +typedef void (*vFpu_t)(void*, uint32_t); +typedef int32_t (*iFpp_t)(void*, void*); +typedef int32_t (*iFpV_t)(void*, ...); +typedef int64_t (*IFII_t)(int64_t, int64_t); +typedef uint64_t (*UFUU_t)(uint64_t, uint64_t); +typedef void* (*pFip_t)(int32_t, void*); +typedef uintptr_t (*hFpp_t)(void*, void*); +typedef void (*vFipV_t)(int32_t, void*, ...); +typedef int32_t (*iFvpV_t)(void, void*, ...); +typedef int32_t (*iFiiN_t)(int32_t, int32_t, ...); +typedef int32_t (*iFipp_t)(int32_t, void*, void*); +typedef int32_t (*iFppp_t)(void*, void*, void*); +typedef void (*vFpppp_t)(void*, void*, void*, void*); +typedef int32_t (*iFiiII_t)(int32_t, int32_t, int64_t, int64_t); +typedef int32_t (*iFppiV_t)(void*, void*, int32_t, ...); +typedef int32_t (*iFpippppp_t)(void*, int32_t, void*, void*, void*, void*, void*); + +#define SUPER() ADDED_FUNCTIONS() \ + GO(__close_nocancel, iFi_t) \ + GO(signal, pFip_t) \ + GO(__libc_init, vFpppp_t) + +#endif // __wrappedlibcTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedlibcundefs32.h b/src/wrapped32/generated/wrappedlibcundefs32.h new file mode 100644 index 00000000..13e37512 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibcundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibcUNDEFS32_H_ +#define __wrappedlibcUNDEFS32_H_ + + +#endif // __wrappedlibcUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibdldefs32.h b/src/wrapped32/generated/wrappedlibdldefs32.h new file mode 100644 index 00000000..a817cc31 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibdldefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibdlDEFS32_H_ +#define __wrappedlibdlDEFS32_H_ + + +#endif // __wrappedlibdlDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibdltypes32.h b/src/wrapped32/generated/wrappedlibdltypes32.h new file mode 100644 index 00000000..6368b9a1 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibdltypes32.h @@ -0,0 +1,36 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibdlTYPES32_H_ +#define __wrappedlibdlTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + +typedef int32_t (*iFp_t)(void*); +typedef void* (*pFv_t)(void); +typedef int32_t (*iFpp_t)(void*, void*); +typedef void* (*pFpi_t)(void*, int32_t); +typedef void* (*pFpp_t)(void*, void*); +typedef int32_t (*iFpip_t)(void*, int32_t, void*); +typedef void* (*pFppi_t)(void*, void*, int32_t); +typedef void* (*pFppp_t)(void*, void*, void*); +typedef int32_t (*iFpppi_t)(void*, void*, void*, int32_t); + +#define SUPER() ADDED_FUNCTIONS() \ + GO(dlclose, iFp_t) \ + GO(dlerror, pFv_t) \ + GO(_dl_find_object, iFpp_t) \ + GO(dladdr, iFpp_t) \ + GO(dlopen, pFpi_t) \ + GO(dlsym, pFpp_t) \ + GO(dlinfo, iFpip_t) \ + GO(dlmopen, pFppi_t) \ + GO(dlvsym, pFppp_t) \ + GO(dladdr1, iFpppi_t) + +#endif // __wrappedlibdlTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedlibdlundefs32.h b/src/wrapped32/generated/wrappedlibdlundefs32.h new file mode 100644 index 00000000..1a512d1a --- /dev/null +++ b/src/wrapped32/generated/wrappedlibdlundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibdlUNDEFS32_H_ +#define __wrappedlibdlUNDEFS32_H_ + + +#endif // __wrappedlibdlUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibmdefs32.h b/src/wrapped32/generated/wrappedlibmdefs32.h new file mode 100644 index 00000000..abfcbb76 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibmdefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibmDEFS32_H_ +#define __wrappedlibmDEFS32_H_ + + +#endif // __wrappedlibmDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibmtypes32.h b/src/wrapped32/generated/wrappedlibmtypes32.h new file mode 100644 index 00000000..589a2f45 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibmtypes32.h @@ -0,0 +1,90 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibmTYPES32_H_ +#define __wrappedlibmTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + +typedef uint64_t (*UFs_t)(void*); +typedef float (*fFf_t)(float); +typedef double (*dFd_t)(double); +typedef long double (*DFD_t)(long double); +typedef double (*KFK_t)(double); +typedef float (*fFff_t)(float, float); +typedef double (*dFdd_t)(double, double); +typedef double (*KFKK_t)(double, double); +typedef double (*KFKp_t)(double, void*); +typedef uint64_t (*UFsvvs_t)(void*, void, void, void*); + +#define SUPER() ADDED_FUNCTIONS() \ + GO(cacosf, UFs_t) \ + GO(cacoshf, UFs_t) \ + GO(casinf, UFs_t) \ + GO(casinhf, UFs_t) \ + GO(catanf, UFs_t) \ + GO(catanhf, UFs_t) \ + GO(ccosf, UFs_t) \ + GO(ccoshf, UFs_t) \ + GO(cexpf, UFs_t) \ + GO(clogf, UFs_t) \ + GO(cprojf, UFs_t) \ + GO(csinf, UFs_t) \ + GO(csinhf, UFs_t) \ + GO(csqrtf, UFs_t) \ + GO(ctanf, UFs_t) \ + GO(ctanhf, UFs_t) \ + GO(__acosf_finite, fFf_t) \ + GO(__acoshf_finite, fFf_t) \ + GO(__asinf_finite, fFf_t) \ + GO(__coshf_finite, fFf_t) \ + GO(__exp2f_finite, fFf_t) \ + GO(__expf_finite, fFf_t) \ + GO(__log10f_finite, fFf_t) \ + GO(__log2f_finite, fFf_t) \ + GO(__logf_finite, fFf_t) \ + GO(__sinhf_finite, fFf_t) \ + GO(__sqrtf_finite, fFf_t) \ + GO(__acos_finite, dFd_t) \ + GO(__acosh_finite, dFd_t) \ + GO(__asin_finite, dFd_t) \ + GO(__cosh_finite, dFd_t) \ + GO(__exp2_finite, dFd_t) \ + GO(__exp_finite, dFd_t) \ + GO(__log10_finite, dFd_t) \ + GO(__log2_finite, dFd_t) \ + GO(__log_finite, dFd_t) \ + GO(__sinh_finite, dFd_t) \ + GO(__sqrt_finite, dFd_t) \ + GO(pow10l, DFD_t) \ + GO(acoshl, KFK_t) \ + GO(acosl, KFK_t) \ + GO(asinhl, KFK_t) \ + GO(asinl, KFK_t) \ + GO(atanhl, KFK_t) \ + GO(cbrtl, KFK_t) \ + GO(erfcl, KFK_t) \ + GO(erfl, KFK_t) \ + GO(ldexpl, KFK_t) \ + GO(lgammal, KFK_t) \ + GO(logl, KFK_t) \ + GO(pow10l, KFK_t) \ + GO(tgammal, KFK_t) \ + GO(__atan2f_finite, fFff_t) \ + GO(__hypotf_finite, fFff_t) \ + GO(__powf_finite, fFff_t) \ + GO(__atan2_finite, dFdd_t) \ + GO(__hypot_finite, dFdd_t) \ + GO(__pow_finite, dFdd_t) \ + GO(fmodl, KFKK_t) \ + GO(powl, KFKK_t) \ + GO(frexpl, KFKp_t) \ + GO(lgammal_r, KFKp_t) \ + GO(cpowf, UFsvvs_t) + +#endif // __wrappedlibmTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedlibmundefs32.h b/src/wrapped32/generated/wrappedlibmundefs32.h new file mode 100644 index 00000000..f9a4b404 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibmundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibmUNDEFS32_H_ +#define __wrappedlibmUNDEFS32_H_ + + +#endif // __wrappedlibmUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibpthreaddefs32.h b/src/wrapped32/generated/wrappedlibpthreaddefs32.h new file mode 100644 index 00000000..4192688c --- /dev/null +++ b/src/wrapped32/generated/wrappedlibpthreaddefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibpthreadDEFS32_H_ +#define __wrappedlibpthreadDEFS32_H_ + + +#endif // __wrappedlibpthreadDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibpthreadtypes32.h b/src/wrapped32/generated/wrappedlibpthreadtypes32.h new file mode 100644 index 00000000..74b615de --- /dev/null +++ b/src/wrapped32/generated/wrappedlibpthreadtypes32.h @@ -0,0 +1,97 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibpthreadTYPES32_H_ +#define __wrappedlibpthreadTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + +typedef void (*vFv_t)(void); +typedef void (*vFp_t)(void*); +typedef int32_t (*iFp_t)(void*); +typedef int32_t (*iFh_t)(uintptr_t); +typedef void (*vFpi_t)(void*, int32_t); +typedef int32_t (*iFpi_t)(void*, int32_t); +typedef int32_t (*iFpL_t)(void*, uintptr_t); +typedef int32_t (*iFpp_t)(void*, void*); +typedef void (*vFppp_t)(void*, void*, void*); +typedef int32_t (*iFLup_t)(uintptr_t, uint32_t, void*); +typedef int32_t (*iFpup_t)(void*, uint32_t, void*); +typedef int32_t (*iFppu_t)(void*, void*, uint32_t); +typedef int32_t (*iFppL_t)(void*, void*, uintptr_t); +typedef int32_t (*iFppp_t)(void*, void*, void*); +typedef int32_t (*iFhppp_t)(uintptr_t, void*, void*, void*); + +#define SUPER() ADDED_FUNCTIONS() \ + GO(__pthread_initialize, vFv_t) \ + GO(__pthread_register_cancel, vFp_t) \ + GO(__pthread_unregister_cancel, vFp_t) \ + GO(__pthread_unwind_next, vFp_t) \ + GO(__pthread_mutex_destroy, iFp_t) \ + GO(__pthread_mutex_lock, iFp_t) \ + GO(__pthread_mutex_trylock, iFp_t) \ + GO(__pthread_mutex_unlock, iFp_t) \ + GO(pthread_attr_destroy, iFp_t) \ + GO(pthread_attr_init, iFp_t) \ + GO(pthread_cond_broadcast@GLIBC_2.0, iFp_t) \ + GO(pthread_cond_destroy@GLIBC_2.0, iFp_t) \ + GO(pthread_cond_signal@GLIBC_2.0, iFp_t) \ + GO(pthread_mutex_destroy, iFp_t) \ + GO(pthread_mutex_lock, iFp_t) \ + GO(pthread_mutex_trylock, iFp_t) \ + GO(pthread_mutex_unlock, iFp_t) \ + GO(pthread_rwlock_rdlock, iFp_t) \ + GO(pthread_rwlock_unlock, iFp_t) \ + GO(pthread_rwlock_wrlock, iFp_t) \ + GO(pthread_detach, iFh_t) \ + GO(_pthread_cleanup_pop, vFpi_t) \ + GO(_pthread_cleanup_pop_restore, vFpi_t) \ + GO(pthread_attr_setdetachstate, iFpi_t) \ + GO(pthread_attr_setinheritsched, iFpi_t) \ + GO(pthread_attr_setschedpolicy, iFpi_t) \ + GO(pthread_attr_setscope, iFpi_t) \ + GO(pthread_kill, iFpi_t) \ + GO(pthread_mutexattr_setkind_np, iFpi_t) \ + GO(pthread_attr_setguardsize, iFpL_t) \ + GO(pthread_attr_setstacksize, iFpL_t) \ + GO(__pthread_key_create, iFpp_t) \ + GO(__pthread_mutex_init, iFpp_t) \ + GO(__pthread_once, iFpp_t) \ + GO(pthread_attr_getdetachstate, iFpp_t) \ + GO(pthread_attr_getguardsize, iFpp_t) \ + GO(pthread_attr_getinheritsched, iFpp_t) \ + GO(pthread_attr_getschedparam, iFpp_t) \ + GO(pthread_attr_getschedpolicy, iFpp_t) \ + GO(pthread_attr_getscope, iFpp_t) \ + GO(pthread_attr_getstackaddr, iFpp_t) \ + GO(pthread_attr_getstacksize, iFpp_t) \ + GO(pthread_attr_setschedparam, iFpp_t) \ + GO(pthread_attr_setstackaddr, iFpp_t) \ + GO(pthread_cond_init@GLIBC_2.0, iFpp_t) \ + GO(pthread_cond_wait, iFpp_t) \ + GO(pthread_cond_wait@GLIBC_2.0, iFpp_t) \ + GO(pthread_key_create, iFpp_t) \ + GO(pthread_mutex_init, iFpp_t) \ + GO(pthread_mutex_timedlock, iFpp_t) \ + GO(pthread_once, iFpp_t) \ + GO(pthread_setname_np, iFpp_t) \ + GO(_pthread_cleanup_push, vFppp_t) \ + GO(_pthread_cleanup_push_defer, vFppp_t) \ + GO(pthread_setaffinity_np, iFLup_t) \ + GO(pthread_attr_setaffinity_np, iFpup_t) \ + GO(pthread_getaffinity_np, iFpup_t) \ + GO(pthread_getname_np, iFppu_t) \ + GO(pthread_attr_setstack, iFppL_t) \ + GO(__pthread_atfork, iFppp_t) \ + GO(pthread_atfork, iFppp_t) \ + GO(pthread_attr_getstack, iFppp_t) \ + GO(pthread_cond_timedwait, iFppp_t) \ + GO(pthread_cond_timedwait@GLIBC_2.0, iFppp_t) \ + GO(pthread_create, iFhppp_t) + +#endif // __wrappedlibpthreadTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedlibpthreadundefs32.h b/src/wrapped32/generated/wrappedlibpthreadundefs32.h new file mode 100644 index 00000000..687cec63 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibpthreadundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibpthreadUNDEFS32_H_ +#define __wrappedlibpthreadUNDEFS32_H_ + + +#endif // __wrappedlibpthreadUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibrtdefs32.h b/src/wrapped32/generated/wrappedlibrtdefs32.h new file mode 100644 index 00000000..5c2c26cb --- /dev/null +++ b/src/wrapped32/generated/wrappedlibrtdefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibrtDEFS32_H_ +#define __wrappedlibrtDEFS32_H_ + + +#endif // __wrappedlibrtDEFS32_H_ diff --git a/src/wrapped32/generated/wrappedlibrttypes32.h b/src/wrapped32/generated/wrappedlibrttypes32.h new file mode 100644 index 00000000..41bb06d3 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibrttypes32.h @@ -0,0 +1,17 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibrtTYPES32_H_ +#define __wrappedlibrtTYPES32_H_ + +#ifndef LIBNAME +#error You should only #include this file inside a wrapped*.c file +#endif +#ifndef ADDED_FUNCTIONS +#define ADDED_FUNCTIONS() +#endif + + +#define SUPER() ADDED_FUNCTIONS() + +#endif // __wrappedlibrtTYPES32_H_ diff --git a/src/wrapped32/generated/wrappedlibrtundefs32.h b/src/wrapped32/generated/wrappedlibrtundefs32.h new file mode 100644 index 00000000..13b52f67 --- /dev/null +++ b/src/wrapped32/generated/wrappedlibrtundefs32.h @@ -0,0 +1,8 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __wrappedlibrtUNDEFS32_H_ +#define __wrappedlibrtUNDEFS32_H_ + + +#endif // __wrappedlibrtUNDEFS32_H_ diff --git a/src/wrapped32/generated/wrapper32.c b/src/wrapped32/generated/wrapper32.c new file mode 100644 index 00000000..1d8c2890 --- /dev/null +++ b/src/wrapped32/generated/wrapper32.c @@ -0,0 +1,423 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +#include "wrapper32.h" +#include "emu/x64emu_private.h" +#include "emu/x87emu_private.h" +#include "regs.h" +#include "x64emu.h" +#include "box32.h" +#include "converter32.h" + +typedef union ui64_s { + int64_t i; + uint64_t u; + uint32_t d[2]; +} ui64_t; + +typedef struct _2uint_struct_s { + uint32_t a; + uint32_t b; +} _2uint_struct_t; + +extern void* my__IO_2_1_stderr_; +extern void* my__IO_2_1_stdin_ ; +extern void* my__IO_2_1_stdout_; + +static void* io_convert(void* v) +{ + if(!v) + return v; + if(v==my__IO_2_1_stderr_) + return stderr; + if(v==my__IO_2_1_stdin_) + return stdin; + if(v==my__IO_2_1_stdout_) + return stdout; + return v; +} + +typedef struct my_GValue_s +{ + int g_type; + union { + int v_int; + int64_t v_int64; + uint64_t v_uint64; + float v_float; + double v_double; + void* v_pointer; + } data[2]; +} my_GValue_t; + +static void alignGValue(my_GValue_t* v, void* value) +{ + v->g_type = *(int*)value; + memcpy(v->data, value+4, 2*sizeof(double)); +} +static void unalignGValue(void* value, my_GValue_t* v) +{ + *(int*)value = v->g_type; + memcpy(value+4, v->data, 2*sizeof(double)); +} + +void* VulkanFromx86(void* src, void** save); +void VulkanTox86(void* src, void* save); + +#define ST0val ST0.d + +int of_convert32(int); + +typedef void (*vFv_t)(void); +typedef void (*vFi_t)(int32_t); +typedef void (*vFu_t)(uint32_t); +typedef void (*vFp_t)(void*); +typedef void (*vFA_t)(void*); +typedef int32_t (*iFv_t)(void); +typedef int32_t (*iFi_t)(int32_t); +typedef int32_t (*iFI_t)(int64_t); +typedef int32_t (*iFu_t)(uint32_t); +typedef int32_t (*iFf_t)(float); +typedef int32_t (*iFd_t)(double); +typedef int32_t (*iFL_t)(uintptr_t); +typedef int32_t (*iFp_t)(void*); +typedef int32_t (*iFh_t)(uintptr_t); +typedef int32_t (*iFH_t)(uintptr_t); +typedef int64_t (*IFf_t)(float); +typedef int64_t (*IFd_t)(double); +typedef uint32_t (*uFv_t)(void); +typedef uint32_t (*uFu_t)(uint32_t); +typedef uint32_t (*uFU_t)(uint64_t); +typedef uint64_t (*UFs_t)(void*); +typedef float (*fFf_t)(float); +typedef double (*dFv_t)(void); +typedef double (*dFd_t)(double); +typedef intptr_t (*lFi_t)(int32_t); +typedef intptr_t (*lFp_t)(void*); +typedef uintptr_t (*LFv_t)(void); +typedef uintptr_t (*LFL_t)(uintptr_t); +typedef void* (*pFu_t)(uint32_t); +typedef void* (*pFL_t)(uintptr_t); +typedef void* (*pFp_t)(void*); +typedef uintptr_t (*hFv_t)(void); +typedef void* (*aFa_t)(void*); +typedef void (*vFEv_t)(x64emu_t*); +typedef void (*vFEp_t)(x64emu_t*, void*); +typedef int32_t (*iFEv_t)(x64emu_t*); +typedef int32_t (*iFEi_t)(x64emu_t*, int32_t); +typedef int32_t (*iFEL_t)(x64emu_t*, uintptr_t); +typedef int32_t (*iFEp_t)(x64emu_t*, void*); +typedef int32_t (*iFEh_t)(x64emu_t*, uintptr_t); +typedef int32_t (*iFEO_t)(x64emu_t*, int32_t); +typedef int32_t (*iFii_t)(int32_t, int32_t); +typedef int32_t (*iFiI_t)(int32_t, int64_t); +typedef int32_t (*iFiu_t)(int32_t, uint32_t); +typedef int32_t (*iFip_t)(int32_t, void*); +typedef int32_t (*iFuu_t)(uint32_t, uint32_t); +typedef int32_t (*iFup_t)(uint32_t, void*); +typedef int32_t (*iFli_t)(intptr_t, int32_t); +typedef int32_t (*iFpi_t)(void*, int32_t); +typedef int32_t (*iFpp_t)(void*, void*); +typedef int32_t (*iFhp_t)(uintptr_t, void*); +typedef int32_t (*iFhh_t)(uintptr_t, uintptr_t); +typedef int64_t (*IFII_t)(int64_t, int64_t); +typedef uint32_t (*uFEu_t)(x64emu_t*, uint32_t); +typedef uint32_t (*uFEV_t)(x64emu_t*, void*); +typedef uint32_t (*uFpa_t)(void*, void*); +typedef uint64_t (*UFii_t)(int32_t, int32_t); +typedef uint64_t (*UFUU_t)(uint64_t, uint64_t); +typedef uint64_t (*UFss_t)(void*, void*); +typedef float (*fFif_t)(int32_t, float); +typedef float (*fFfi_t)(float, int32_t); +typedef float (*fFff_t)(float, float); +typedef float (*fFfD_t)(float, long double); +typedef float (*fFfp_t)(float, void*); +typedef double (*dFid_t)(int32_t, double); +typedef double (*dFdi_t)(double, int32_t); +typedef double (*dFdd_t)(double, double); +typedef double (*dFdD_t)(double, long double); +typedef double (*dFdp_t)(double, void*); +typedef uintptr_t (*LFpp_t)(void*, void*); +typedef void* (*pFEv_t)(x64emu_t*); +typedef void* (*pFEp_t)(x64emu_t*, void*); +typedef void* (*pFLL_t)(uintptr_t, uintptr_t); +typedef void* (*aFia_t)(int32_t, void*); +typedef int32_t (*iFHBp__t)(uintptr_t, struct_p_t*); +typedef void (*vFEip_t)(x64emu_t*, int32_t, void*); +typedef void (*vFEpi_t)(x64emu_t*, void*, int32_t); +typedef void (*vFEpu_t)(x64emu_t*, void*, uint32_t); +typedef void (*vFfpp_t)(float, void*, void*); +typedef void (*vFdpp_t)(double, void*, void*); +typedef int32_t (*iFEpi_t)(x64emu_t*, void*, int32_t); +typedef int32_t (*iFEpL_t)(x64emu_t*, void*, uintptr_t); +typedef int32_t (*iFEpp_t)(x64emu_t*, void*, void*); +typedef int32_t (*iFEpV_t)(x64emu_t*, void*, void*); +typedef int32_t (*iFiii_t)(int32_t, int32_t, int32_t); +typedef int32_t (*iFiiI_t)(int32_t, int32_t, int64_t); +typedef int32_t (*iFiiu_t)(int32_t, int32_t, uint32_t); +typedef int32_t (*iFiiO_t)(int32_t, int32_t, int32_t); +typedef int32_t (*iFiII_t)(int32_t, int64_t, int64_t); +typedef int32_t (*iFiuu_t)(int32_t, uint32_t, uint32_t); +typedef int32_t (*iFiLN_t)(int32_t, uintptr_t, ...); +typedef int32_t (*iFipp_t)(int32_t, void*, void*); +typedef int32_t (*iFuii_t)(uint32_t, int32_t, int32_t); +typedef int32_t (*iFuip_t)(uint32_t, int32_t, void*); +typedef int32_t (*iFuui_t)(uint32_t, uint32_t, int32_t); +typedef int32_t (*iFuuu_t)(uint32_t, uint32_t, uint32_t); +typedef int32_t (*iFuLp_t)(uint32_t, uintptr_t, void*); +typedef int32_t (*iFupp_t)(uint32_t, void*, void*); +typedef int32_t (*iFpiu_t)(void*, int32_t, uint32_t); +typedef int32_t (*iFpip_t)(void*, int32_t, void*); +typedef int32_t (*iFpuu_t)(void*, uint32_t, uint32_t); +typedef int32_t (*iFppu_t)(void*, void*, uint32_t); +typedef int32_t (*iFppL_t)(void*, void*, uintptr_t); +typedef int32_t (*iFppp_t)(void*, void*, void*); +typedef int32_t (*iFpOu_t)(void*, int32_t, uint32_t); +typedef int64_t (*IFiIi_t)(int32_t, int64_t, int32_t); +typedef float (*fFfff_t)(float, float, float); +typedef float (*fFffp_t)(float, float, void*); +typedef double (*dFddd_t)(double, double, double); +typedef double (*dFddp_t)(double, double, void*); +typedef void* (*pFEip_t)(x64emu_t*, int32_t, void*); +typedef void* (*pFEpi_t)(x64emu_t*, void*, int32_t); +typedef void* (*pFEpp_t)(x64emu_t*, void*, void*); +typedef void* (*pFppL_t)(void*, void*, uintptr_t); +typedef void* (*pFpOM_t)(void*, int32_t, ...); +typedef uintptr_t (*hFEpp_t)(x64emu_t*, void*, void*); +typedef void* (*aFipa_t)(int32_t, void*, void*); +typedef intptr_t (*lFpBp_i_t)(void*, struct_p_t*, int32_t); +typedef void (*vFEipV_t)(x64emu_t*, int32_t, void*, void*); +typedef void (*vFEppp_t)(x64emu_t*, void*, void*, 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 (*iFELup_t)(x64emu_t*, uintptr_t, uint32_t, void*); +typedef int32_t (*iFEpip_t)(x64emu_t*, void*, int32_t, void*); +typedef int32_t (*iFEpup_t)(x64emu_t*, void*, uint32_t, void*); +typedef int32_t (*iFEppu_t)(x64emu_t*, void*, void*, uint32_t); +typedef int32_t (*iFEppL_t)(x64emu_t*, void*, void*, uintptr_t); +typedef int32_t (*iFEppp_t)(x64emu_t*, void*, void*, void*); +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 uintptr_t (*LFpLLh_t)(void*, uintptr_t, uintptr_t, uintptr_t); +typedef void* (*pFEppi_t)(x64emu_t*, void*, void*, int32_t); +typedef void* (*pFEppp_t)(x64emu_t*, void*, void*, void*); +typedef void* (*pFppuL_t)(void*, void*, uint32_t, uintptr_t); +typedef void* (*pFppLL_t)(void*, void*, uintptr_t, uintptr_t); +typedef int32_t (*iFEppiV_t)(x64emu_t*, void*, void*, int32_t, void*); +typedef int32_t (*iFEpppi_t)(x64emu_t*, void*, void*, void*, int32_t); +typedef int32_t (*iFiLLLL_t)(int32_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t); +typedef int32_t (*iFEBh_ppp_t)(x64emu_t*, struct_h_t*, void*, void*, void*); +typedef int32_t (*iFEpippppp_t)(x64emu_t*, void*, int32_t, void*, void*, void*, void*, void*); + +#if defined(ANDROID) +typedef void* (*pFv_t)(void); +typedef void (*vFEpppp_t)(x64emu_t*, void*, void*, void*, void*); +#endif + +#if defined(HAVE_LD80BITS) +typedef long double (*DFD_t)(long double); +typedef long double (*DFDD_t)(long double, long double); +typedef long double (*DFDp_t)(long double, void*); +#endif + +#if !defined(HAVE_LD80BITS) +typedef double (*KFK_t)(double); +typedef double (*KFKK_t)(double, double); +typedef double (*KFKp_t)(double, void*); +#endif + +void vFv_32(x64emu_t *emu, uintptr_t fcn) { vFv_t fn = (vFv_t)fcn; fn(); } +void vFi_32(x64emu_t *emu, uintptr_t fcn) { vFi_t fn = (vFi_t)fcn; fn(from_ptri(int32_t, R_ESP + 4)); } +void vFu_32(x64emu_t *emu, uintptr_t fcn) { vFu_t fn = (vFu_t)fcn; fn(from_ptri(uint32_t, R_ESP + 4)); } +void vFp_32(x64emu_t *emu, uintptr_t fcn) { vFp_t fn = (vFp_t)fcn; fn(from_ptriv(R_ESP + 4)); } +void vFA_32(x64emu_t *emu, uintptr_t fcn) { vFA_t fn = (vFA_t)fcn; fn(from_locale_d(from_ptri(ptr_t, R_ESP + 4))); } +void iFv_32(x64emu_t *emu, uintptr_t fcn) { iFv_t fn = (iFv_t)fcn; R_EAX = fn(); } +void iFi_32(x64emu_t *emu, uintptr_t fcn) { iFi_t fn = (iFi_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4)); } +void iFI_32(x64emu_t *emu, uintptr_t fcn) { iFI_t fn = (iFI_t)fcn; R_EAX = fn(from_ptri(int64_t, R_ESP + 4)); } +void iFu_32(x64emu_t *emu, uintptr_t fcn) { iFu_t fn = (iFu_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4)); } +void iFf_32(x64emu_t *emu, uintptr_t fcn) { iFf_t fn = (iFf_t)fcn; R_EAX = fn(from_ptri(float, R_ESP + 4)); } +void iFd_32(x64emu_t *emu, uintptr_t fcn) { iFd_t fn = (iFd_t)fcn; R_EAX = fn(from_ptri(double, R_ESP + 4)); } +void iFL_32(x64emu_t *emu, uintptr_t fcn) { iFL_t fn = (iFL_t)fcn; R_EAX = fn(to_ulong(from_ptri(ulong_t, R_ESP + 4))); } +void iFp_32(x64emu_t *emu, uintptr_t fcn) { iFp_t fn = (iFp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4)); } +void iFh_32(x64emu_t *emu, uintptr_t fcn) { iFh_t fn = (iFh_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4))); } +void iFH_32(x64emu_t *emu, uintptr_t fcn) { iFH_t fn = (iFH_t)fcn; R_EAX = fn(from_hash_d(from_ptri(ptr_t, R_ESP + 4))); } +void IFf_32(x64emu_t *emu, uintptr_t fcn) { IFf_t fn = (IFf_t)fcn; ui64_t r; r.i = fn(from_ptri(float, R_ESP + 4)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void IFd_32(x64emu_t *emu, uintptr_t fcn) { IFd_t fn = (IFd_t)fcn; ui64_t r; r.i = fn(from_ptri(double, R_ESP + 4)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void uFv_32(x64emu_t *emu, uintptr_t fcn) { uFv_t fn = (uFv_t)fcn; R_EAX = (uint32_t)fn(); } +void uFu_32(x64emu_t *emu, uintptr_t fcn) { uFu_t fn = (uFu_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint32_t, R_ESP + 4)); } +void uFU_32(x64emu_t *emu, uintptr_t fcn) { uFU_t fn = (uFU_t)fcn; R_EAX = (uint32_t)fn(from_ptri(uint64_t, R_ESP + 4)); } +void UFs_32(x64emu_t *emu, uintptr_t fcn) { UFs_t fn = (UFs_t)fcn; ui64_t r; r.u = (uint64_t)fn(from_ptrv(R_ESP + 4)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void fFf_32(x64emu_t *emu, uintptr_t fcn) { fFf_t fn = (fFf_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4)); fpu_do_push(emu); ST0val = fl; } +void dFv_32(x64emu_t *emu, uintptr_t fcn) { dFv_t fn = (dFv_t)fcn; double db = fn(); fpu_do_push(emu); ST0val = db; } +void dFd_32(x64emu_t *emu, uintptr_t fcn) { dFd_t fn = (dFd_t)fcn; double db = fn(from_ptri(double, R_ESP + 4)); fpu_do_push(emu); ST0val = db; } +void lFi_32(x64emu_t *emu, uintptr_t fcn) { lFi_t fn = (lFi_t)fcn; R_EAX = to_long(fn(from_ptri(int32_t, R_ESP + 4))); } +void lFp_32(x64emu_t *emu, uintptr_t fcn) { lFp_t fn = (lFp_t)fcn; R_EAX = to_long(fn(from_ptriv(R_ESP + 4))); } +void LFv_32(x64emu_t *emu, uintptr_t fcn) { LFv_t fn = (LFv_t)fcn; R_EAX = to_ulong(fn()); } +void LFL_32(x64emu_t *emu, uintptr_t fcn) { LFL_t fn = (LFL_t)fcn; R_EAX = to_ulong(fn(to_ulong(from_ptri(ulong_t, R_ESP + 4)))); } +void pFu_32(x64emu_t *emu, uintptr_t fcn) { pFu_t fn = (pFu_t)fcn; R_EAX = to_ptrv(fn(from_ptri(uint32_t, R_ESP + 4))); } +void pFL_32(x64emu_t *emu, uintptr_t fcn) { pFL_t fn = (pFL_t)fcn; R_EAX = to_ptrv(fn(to_ulong(from_ptri(ulong_t, R_ESP + 4)))); } +void pFp_32(x64emu_t *emu, uintptr_t fcn) { pFp_t fn = (pFp_t)fcn; R_EAX = to_ptrv(fn(from_ptriv(R_ESP + 4))); } +void hFv_32(x64emu_t *emu, uintptr_t fcn) { hFv_t fn = (hFv_t)fcn; R_EAX = to_hash(fn()); } +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 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); } +void iFEi_32(x64emu_t *emu, uintptr_t fcn) { iFEi_t fn = (iFEi_t)fcn; R_EAX = fn(emu, from_ptri(int32_t, R_ESP + 4)); } +void iFEL_32(x64emu_t *emu, uintptr_t fcn) { iFEL_t fn = (iFEL_t)fcn; R_EAX = fn(emu, to_ulong(from_ptri(ulong_t, R_ESP + 4))); } +void iFEp_32(x64emu_t *emu, uintptr_t fcn) { iFEp_t fn = (iFEp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4)); } +void iFEh_32(x64emu_t *emu, uintptr_t fcn) { iFEh_t fn = (iFEh_t)fcn; R_EAX = fn(emu, from_hash(from_ptri(ptr_t, R_ESP + 4))); } +void iFEO_32(x64emu_t *emu, uintptr_t fcn) { iFEO_t fn = (iFEO_t)fcn; R_EAX = fn(emu, of_convert32(from_ptri(int32_t, R_ESP + 4))); } +void iFii_32(x64emu_t *emu, uintptr_t fcn) { iFii_t fn = (iFii_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); } +void iFiI_32(x64emu_t *emu, uintptr_t fcn) { iFiI_t fn = (iFiI_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int64_t, R_ESP + 8)); } +void iFiu_32(x64emu_t *emu, uintptr_t fcn) { iFiu_t fn = (iFiu_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8)); } +void iFip_32(x64emu_t *emu, uintptr_t fcn) { iFip_t fn = (iFip_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8)); } +void iFuu_32(x64emu_t *emu, uintptr_t fcn) { iFuu_t fn = (iFuu_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8)); } +void iFup_32(x64emu_t *emu, uintptr_t fcn) { iFup_t fn = (iFup_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8)); } +void iFli_32(x64emu_t *emu, uintptr_t fcn) { iFli_t fn = (iFli_t)fcn; R_EAX = fn(to_long(from_ptri(long_t, R_ESP + 4)), from_ptri(int32_t, R_ESP + 8)); } +void iFpi_32(x64emu_t *emu, uintptr_t fcn) { iFpi_t fn = (iFpi_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); } +void iFpp_32(x64emu_t *emu, uintptr_t fcn) { iFpp_t fn = (iFpp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8)); } +void iFhp_32(x64emu_t *emu, uintptr_t fcn) { iFhp_t fn = (iFhp_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_ptriv(R_ESP + 8)); } +void iFhh_32(x64emu_t *emu, uintptr_t fcn) { iFhh_t fn = (iFhh_t)fcn; R_EAX = fn(from_hash(from_ptri(ptr_t, R_ESP + 4)), from_hash(from_ptri(ptr_t, R_ESP + 8))); } +void IFII_32(x64emu_t *emu, uintptr_t fcn) { IFII_t fn = (IFII_t)fcn; ui64_t r; r.i = fn(from_ptri(int64_t, R_ESP + 4), from_ptri(int64_t, R_ESP + 12)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void uFEu_32(x64emu_t *emu, uintptr_t fcn) { uFEu_t fn = (uFEu_t)fcn; R_EAX = (uint32_t)fn(emu, from_ptri(uint32_t, R_ESP + 4)); } +void uFEV_32(x64emu_t *emu, uintptr_t fcn) { uFEV_t fn = (uFEV_t)fcn; R_EAX = (uint32_t)fn(emu, from_ptrv(R_ESP + 4)); } +void uFpa_32(x64emu_t *emu, uintptr_t fcn) { uFpa_t fn = (uFpa_t)fcn; R_EAX = (uint32_t)fn(from_ptriv(R_ESP + 4), from_locale(from_ptri(ptr_t, R_ESP + 8))); } +void UFii_32(x64emu_t *emu, uintptr_t fcn) { UFii_t fn = (UFii_t)fcn; ui64_t r; r.u = (uint64_t)fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void UFUU_32(x64emu_t *emu, uintptr_t fcn) { UFUU_t fn = (UFUU_t)fcn; ui64_t r; r.u = (uint64_t)fn(from_ptri(uint64_t, R_ESP + 4), from_ptri(uint64_t, R_ESP + 12)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void UFss_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 + 4)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void fFif_32(x64emu_t *emu, uintptr_t fcn) { fFif_t fn = (fFif_t)fcn; float fl = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(float, R_ESP + 8)); fpu_do_push(emu); ST0val = fl; } +void fFfi_32(x64emu_t *emu, uintptr_t fcn) { fFfi_t fn = (fFfi_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); fpu_do_push(emu); ST0val = fl; } +void fFff_32(x64emu_t *emu, uintptr_t fcn) { fFff_t fn = (fFff_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), from_ptri(float, R_ESP + 8)); fpu_do_push(emu); ST0val = fl; } +void fFfD_32(x64emu_t *emu, uintptr_t fcn) { fFfD_t fn = (fFfD_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), LD2localLD(from_ptrv(R_ESP + 8))); fpu_do_push(emu); ST0val = fl; } +void fFfp_32(x64emu_t *emu, uintptr_t fcn) { fFfp_t fn = (fFfp_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), from_ptriv(R_ESP + 8)); fpu_do_push(emu); ST0val = fl; } +void dFid_32(x64emu_t *emu, uintptr_t fcn) { dFid_t fn = (dFid_t)fcn; double db = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(double, R_ESP + 8)); fpu_do_push(emu); ST0val = db; } +void dFdi_32(x64emu_t *emu, uintptr_t fcn) { dFdi_t fn = (dFdi_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), from_ptri(int32_t, R_ESP + 12)); fpu_do_push(emu); ST0val = db; } +void dFdd_32(x64emu_t *emu, uintptr_t fcn) { dFdd_t fn = (dFdd_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), from_ptri(double, R_ESP + 12)); fpu_do_push(emu); ST0val = db; } +void dFdD_32(x64emu_t *emu, uintptr_t fcn) { dFdD_t fn = (dFdD_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), LD2localLD(from_ptrv(R_ESP + 12))); fpu_do_push(emu); ST0val = db; } +void dFdp_32(x64emu_t *emu, uintptr_t fcn) { dFdp_t fn = (dFdp_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), from_ptriv(R_ESP + 12)); fpu_do_push(emu); ST0val = db; } +void LFpp_32(x64emu_t *emu, uintptr_t fcn) { LFpp_t fn = (LFpp_t)fcn; R_EAX = to_ulong(fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8))); } +void pFEv_32(x64emu_t *emu, uintptr_t fcn) { pFEv_t fn = (pFEv_t)fcn; R_EAX = to_ptrv(fn(emu)); } +void pFEp_32(x64emu_t *emu, uintptr_t fcn) { pFEp_t fn = (pFEp_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4))); } +void pFLL_32(x64emu_t *emu, uintptr_t fcn) { pFLL_t fn = (pFLL_t)fcn; R_EAX = to_ptrv(fn(to_ulong(from_ptri(ulong_t, R_ESP + 4)), to_ulong(from_ptri(ulong_t, R_ESP + 8)))); } +void aFia_32(x64emu_t *emu, uintptr_t fcn) { aFia_t fn = (aFia_t)fcn; R_EAX = to_locale(fn(from_ptri(int32_t, R_ESP + 4), from_locale(from_ptri(ptr_t, R_ESP + 8)))); } +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 vFEip_32(x64emu_t *emu, uintptr_t fcn) { vFEip_t fn = (vFEip_t)fcn; fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8)); } +void vFEpi_32(x64emu_t *emu, uintptr_t fcn) { vFEpi_t fn = (vFEpi_t)fcn; fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); } +void vFEpu_32(x64emu_t *emu, uintptr_t fcn) { vFEpu_t fn = (vFEpu_t)fcn; fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8)); } +void vFfpp_32(x64emu_t *emu, uintptr_t fcn) { vFfpp_t fn = (vFfpp_t)fcn; fn(from_ptri(float, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +void vFdpp_32(x64emu_t *emu, uintptr_t fcn) { vFdpp_t fn = (vFdpp_t)fcn; fn(from_ptri(double, R_ESP + 4), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); } +void iFEpi_32(x64emu_t *emu, uintptr_t fcn) { iFEpi_t fn = (iFEpi_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8)); } +void iFEpL_32(x64emu_t *emu, uintptr_t fcn) { iFEpL_t fn = (iFEpL_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), to_ulong(from_ptri(ulong_t, R_ESP + 8))); } +void iFEpp_32(x64emu_t *emu, uintptr_t fcn) { iFEpp_t fn = (iFEpp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8)); } +void iFEpV_32(x64emu_t *emu, uintptr_t fcn) { iFEpV_t fn = (iFEpV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptrv(R_ESP + 8)); } +void iFiii_32(x64emu_t *emu, uintptr_t fcn) { iFiii_t fn = (iFiii_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)); } +void iFiiI_32(x64emu_t *emu, uintptr_t fcn) { iFiiI_t fn = (iFiiI_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)); } +void iFiiu_32(x64emu_t *emu, uintptr_t fcn) { iFiiu_t fn = (iFiiu_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFiiO_32(x64emu_t *emu, uintptr_t fcn) { iFiiO_t fn = (iFiiO_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), of_convert32(from_ptri(int32_t, R_ESP + 12))); } +void iFiII_32(x64emu_t *emu, uintptr_t fcn) { iFiII_t fn = (iFiII_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int64_t, R_ESP + 8), from_ptri(int64_t, R_ESP + 16)); } +void iFiuu_32(x64emu_t *emu, uintptr_t fcn) { iFiuu_t fn = (iFiuu_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)); } +void iFiLN_32(x64emu_t *emu, uintptr_t fcn) { iFiLN_t fn = (iFiLN_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), to_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12)); } +void iFipp_32(x64emu_t *emu, uintptr_t fcn) { iFipp_t fn = (iFipp_t)fcn; R_EAX = fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFuii_32(x64emu_t *emu, uintptr_t fcn) { iFuii_t fn = (iFuii_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } +void iFuip_32(x64emu_t *emu, uintptr_t fcn) { iFuip_t fn = (iFuip_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFuui_32(x64emu_t *emu, uintptr_t fcn) { iFuui_t fn = (iFuui_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12)); } +void iFuuu_32(x64emu_t *emu, uintptr_t fcn) { iFuuu_t fn = (iFuuu_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFuLp_32(x64emu_t *emu, uintptr_t fcn) { iFuLp_t fn = (iFuLp_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), to_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptriv(R_ESP + 12)); } +void iFupp_32(x64emu_t *emu, uintptr_t fcn) { iFupp_t fn = (iFupp_t)fcn; R_EAX = fn(from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFpiu_32(x64emu_t *emu, uintptr_t fcn) { iFpiu_t fn = (iFpiu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFpip_32(x64emu_t *emu, uintptr_t fcn) { iFpip_t fn = (iFpip_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFpuu_32(x64emu_t *emu, uintptr_t fcn) { iFpuu_t fn = (iFpuu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFppu_32(x64emu_t *emu, uintptr_t fcn) { iFppu_t fn = (iFppu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFppL_32(x64emu_t *emu, uintptr_t fcn) { iFppL_t fn = (iFppL_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), to_ulong(from_ptri(ulong_t, R_ESP + 12))); } +void iFppp_32(x64emu_t *emu, uintptr_t fcn) { iFppp_t fn = (iFppp_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFpOu_32(x64emu_t *emu, uintptr_t fcn) { iFpOu_t fn = (iFpOu_t)fcn; R_EAX = fn(from_ptriv(R_ESP + 4), of_convert32(from_ptri(int32_t, R_ESP + 8)), from_ptri(uint32_t, R_ESP + 12)); } +void IFiIi_32(x64emu_t *emu, uintptr_t fcn) { IFiIi_t fn = (IFiIi_t)fcn; ui64_t r; r.i = fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int64_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 16)); R_EAX = r.d[0]; R_EDX = r.d[1]; } +void fFfff_32(x64emu_t *emu, uintptr_t fcn) { fFfff_t fn = (fFfff_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), from_ptri(float, R_ESP + 8), from_ptri(float, R_ESP + 12)); fpu_do_push(emu); ST0val = fl; } +void fFffp_32(x64emu_t *emu, uintptr_t fcn) { fFffp_t fn = (fFffp_t)fcn; float fl = fn(from_ptri(float, R_ESP + 4), from_ptri(float, R_ESP + 8), from_ptriv(R_ESP + 12)); fpu_do_push(emu); ST0val = fl; } +void dFddd_32(x64emu_t *emu, uintptr_t fcn) { dFddd_t fn = (dFddd_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), from_ptri(double, R_ESP + 12), from_ptri(double, R_ESP + 20)); fpu_do_push(emu); ST0val = db; } +void dFddp_32(x64emu_t *emu, uintptr_t fcn) { dFddp_t fn = (dFddp_t)fcn; double db = fn(from_ptri(double, R_ESP + 4), from_ptri(double, R_ESP + 12), from_ptriv(R_ESP + 20)); fpu_do_push(emu); ST0val = db; } +void pFEip_32(x64emu_t *emu, uintptr_t fcn) { pFEip_t fn = (pFEip_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8))); } +void pFEpi_32(x64emu_t *emu, uintptr_t fcn) { pFEpi_t fn = (pFEpi_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8))); } +void pFEpp_32(x64emu_t *emu, uintptr_t fcn) { pFEpp_t fn = (pFEpp_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8))); } +void pFppL_32(x64emu_t *emu, uintptr_t fcn) { pFppL_t fn = (pFppL_t)fcn; R_EAX = to_ptrv(fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), to_ulong(from_ptri(ulong_t, R_ESP + 12)))); } +void pFpOM_32(x64emu_t *emu, uintptr_t fcn) { pFpOM_t fn = (pFpOM_t)fcn; R_EAX = to_ptrv(fn(from_ptriv(R_ESP + 4), of_convert32(from_ptri(int32_t, R_ESP + 8)), from_ptriv(R_ESP + 12),from_ptriv(R_ESP + 12 + 4))); } +void hFEpp_32(x64emu_t *emu, uintptr_t fcn) { hFEpp_t fn = (hFEpp_t)fcn; R_EAX = to_hash(fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8))); } +void aFipa_32(x64emu_t *emu, uintptr_t fcn) { aFipa_t fn = (aFipa_t)fcn; R_EAX = to_locale(fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_locale(from_ptri(ptr_t, R_ESP + 12)))); } +void lFpBp_i_32(x64emu_t *emu, uintptr_t fcn) { lFpBp_i_t fn = (lFpBp_i_t)fcn; struct_p_t arg_8; R_EAX = to_long(fn(from_ptriv(R_ESP + 4), *(ptr_t*)(from_ptr((R_ESP + 8))) ? &arg_8 : NULL, from_ptri(int32_t, R_ESP + 12))); if (*(ptr_t*)(from_ptr((R_ESP + 8)))) to_struct_p(*(ptr_t*)(from_ptr((R_ESP + 8))), &arg_8); } +void vFEipV_32(x64emu_t *emu, uintptr_t fcn) { vFEipV_t fn = (vFEipV_t)fcn; fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptrv(R_ESP + 12)); } +void vFEppp_32(x64emu_t *emu, uintptr_t fcn) { vFEppp_t fn = (vFEppp_t)fcn; fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +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 iFELup_32(x64emu_t *emu, uintptr_t fcn) { iFELup_t fn = (iFELup_t)fcn; R_EAX = fn(emu, to_ulong(from_ptri(ulong_t, R_ESP + 4)), from_ptri(uint32_t, R_ESP + 8), from_ptriv(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 iFEpup_32(x64emu_t *emu, uintptr_t fcn) { iFEpup_t fn = (iFEpup_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptri(uint32_t, R_ESP + 8), from_ptriv(R_ESP + 12)); } +void iFEppu_32(x64emu_t *emu, uintptr_t fcn) { iFEppu_t fn = (iFEppu_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12)); } +void iFEppL_32(x64emu_t *emu, uintptr_t fcn) { iFEppL_t fn = (iFEppL_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), to_ulong(from_ptri(ulong_t, R_ESP + 12))); } +void iFEppp_32(x64emu_t *emu, uintptr_t fcn) { iFEppp_t fn = (iFEppp_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12)); } +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 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)))); } +void pFEppi_32(x64emu_t *emu, uintptr_t fcn) { pFEppi_t fn = (pFEppi_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); } +void pFEppp_32(x64emu_t *emu, uintptr_t fcn) { pFEppp_t fn = (pFEppp_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12))); } +void pFppuL_32(x64emu_t *emu, uintptr_t fcn) { pFppuL_t fn = (pFppuL_t)fcn; R_EAX = to_ptrv(fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), to_ulong(from_ptri(ulong_t, R_ESP + 16)))); } +void pFppLL_32(x64emu_t *emu, uintptr_t fcn) { pFppLL_t fn = (pFppLL_t)fcn; R_EAX = to_ptrv(fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), to_ulong(from_ptri(ulong_t, R_ESP + 12)), to_ulong(from_ptri(ulong_t, R_ESP + 16)))); } +void iFEppiV_32(x64emu_t *emu, uintptr_t fcn) { iFEppiV_t fn = (iFEppiV_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptrv(R_ESP + 16)); } +void iFEpppi_32(x64emu_t *emu, uintptr_t fcn) { iFEpppi_t fn = (iFEpppi_t)fcn; R_EAX = fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(int32_t, R_ESP + 16)); } +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 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 iFEpippppp_32(x64emu_t *emu, uintptr_t fcn) { iFEpippppp_t fn = (iFEpippppp_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), from_ptriv(R_ESP + 24), from_ptriv(R_ESP + 28)); } + +#if defined(ANDROID) +void pFv_32(x64emu_t *emu, uintptr_t fcn) { pFv_t fn = (pFv_t)fcn; R_EAX = to_ptrv(fn()); } +void vFEpppp_32(x64emu_t *emu, uintptr_t fcn) { vFEpppp_t fn = (vFEpppp_t)fcn; fn(emu, from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptriv(R_ESP + 16)); } +#endif + +#if defined(HAVE_LD80BITS) +void DFD_32(x64emu_t *emu, uintptr_t fcn) { DFD_t fn = (DFD_t)fcn; long double ld = fn(LD2localLD(from_ptrv(R_ESP + 4))); fpu_do_push(emu); ST0val = ld; } +void DFDD_32(x64emu_t *emu, uintptr_t fcn) { DFDD_t fn = (DFDD_t)fcn; long double ld = fn(LD2localLD(from_ptrv(R_ESP + 4)), LD2localLD(from_ptrv(R_ESP + 16))); fpu_do_push(emu); ST0val = ld; } +void DFDp_32(x64emu_t *emu, uintptr_t fcn) { DFDp_t fn = (DFDp_t)fcn; long double ld = fn(LD2localLD(from_ptrv(R_ESP + 4)), from_ptriv(R_ESP + 16)); fpu_do_push(emu); ST0val = ld; } +#endif + +#if !defined(HAVE_LD80BITS) +void KFK_32(x64emu_t *emu, uintptr_t fcn) { KFK_t fn = (KFK_t)fcn; double db = fn(FromLD(from_ptrv(R_ESP + 4))); fpu_do_push(emu); ST0val = db; } +void KFKK_32(x64emu_t *emu, uintptr_t fcn) { KFKK_t fn = (KFKK_t)fcn; double db = fn(FromLD(from_ptrv(R_ESP + 4)), FromLD(from_ptrv(R_ESP + 16))); fpu_do_push(emu); ST0val = db; } +void KFKp_32(x64emu_t *emu, uintptr_t fcn) { KFKp_t fn = (KFKp_t)fcn; double db = fn(FromLD(from_ptrv(R_ESP + 4)), from_ptriv(R_ESP + 16)); fpu_do_push(emu); ST0val = db; } +#endif + +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]; } + +int isRetX87Wrapper32(wrapper_t fun) { + if (fun == &fFf_32) return 1; + if (fun == &dFv_32) return 1; + if (fun == &dFd_32) return 1; + if (fun == &fFif_32) return 1; + if (fun == &fFfi_32) return 1; + if (fun == &fFff_32) return 1; + if (fun == &fFfD_32) return 1; + if (fun == &fFfp_32) return 1; + if (fun == &dFid_32) return 1; + if (fun == &dFdi_32) return 1; + if (fun == &dFdd_32) return 1; + if (fun == &dFdD_32) return 1; + if (fun == &dFdp_32) return 1; + if (fun == &fFfff_32) return 1; + if (fun == &fFffp_32) return 1; + if (fun == &dFddd_32) return 1; + if (fun == &dFddp_32) return 1; +#if defined(HAVE_LD80BITS) + if (fun == &DFD_32) return 1; + if (fun == &DFDD_32) return 1; + if (fun == &DFDp_32) return 1; +#endif +#if !defined(HAVE_LD80BITS) + if (fun == &KFK_32) return 1; + if (fun == &KFKK_32) return 1; + if (fun == &KFKp_32) return 1; +#endif + return 0; +} diff --git a/src/wrapped32/generated/wrapper32.h b/src/wrapped32/generated/wrapper32.h new file mode 100644 index 00000000..3496a5ea --- /dev/null +++ b/src/wrapped32/generated/wrapper32.h @@ -0,0 +1,200 @@ +/****************************************************************** + * File automatically generated by rebuild_wrappers_32.py (v0.0.1.1) * + ******************************************************************/ +#ifndef __WRAPPER32_H_ +#define __WRAPPER32_H_ +#include <stdint.h> +#include <string.h> + +typedef struct x64emu_s x64emu_t; + +// the generic wrapper pointer functions +typedef void (*wrapper_t)(x64emu_t* emu, uintptr_t fnc); + +// list of defined wrappers +// E = current x64emu struct +// v = void +// C = unsigned byte c = char +// W = unsigned short w = short +// u = uint32, i = int32 +// U = uint64, I = int64 +// L = unsigned long, l = signed long (long is an int with the size of a pointer) +// p = pointer +// h = hash (32<->64bits) +// H = hash (32<->64bits) that will be deleted from hashmaps +// a = locale +// A = locale that will be deleted from hashmaps +// f = float, d = double, D = long double, K = fake long double +// V = vaargs, s = address on the stack (doesn't move forward the pointer) +// O = libc O_ flags bitfield +// o = stdout +// S = _IO_2_1_stdXXX_ pointer (or FILE*) +// 2 = struct of 2 uint +// N = ... automatically sending 1 arg +// M = ... automatically sending 2 args +// P = Vulkan struct pointer +// s..._ = pointer to read-only structure +// B..._ = pointer to write-only structure +// b..._ = pointer to read-write structure + +void vFv_32(x64emu_t *emu, uintptr_t fnc); +void vFi_32(x64emu_t *emu, uintptr_t fnc); +void vFu_32(x64emu_t *emu, uintptr_t fnc); +void vFp_32(x64emu_t *emu, uintptr_t fnc); +void vFA_32(x64emu_t *emu, uintptr_t fnc); +void iFv_32(x64emu_t *emu, uintptr_t fnc); +void iFi_32(x64emu_t *emu, uintptr_t fnc); +void iFI_32(x64emu_t *emu, uintptr_t fnc); +void iFu_32(x64emu_t *emu, uintptr_t fnc); +void iFf_32(x64emu_t *emu, uintptr_t fnc); +void iFd_32(x64emu_t *emu, uintptr_t fnc); +void iFL_32(x64emu_t *emu, uintptr_t fnc); +void iFp_32(x64emu_t *emu, uintptr_t fnc); +void iFh_32(x64emu_t *emu, uintptr_t fnc); +void iFH_32(x64emu_t *emu, uintptr_t fnc); +void IFf_32(x64emu_t *emu, uintptr_t fnc); +void IFd_32(x64emu_t *emu, uintptr_t fnc); +void uFv_32(x64emu_t *emu, uintptr_t fnc); +void uFu_32(x64emu_t *emu, uintptr_t fnc); +void uFU_32(x64emu_t *emu, uintptr_t fnc); +void UFs_32(x64emu_t *emu, uintptr_t fnc); +void fFf_32(x64emu_t *emu, uintptr_t fnc); +void dFv_32(x64emu_t *emu, uintptr_t fnc); +void dFd_32(x64emu_t *emu, uintptr_t fnc); +void lFi_32(x64emu_t *emu, uintptr_t fnc); +void lFp_32(x64emu_t *emu, uintptr_t fnc); +void LFv_32(x64emu_t *emu, uintptr_t fnc); +void LFL_32(x64emu_t *emu, uintptr_t fnc); +void pFu_32(x64emu_t *emu, uintptr_t fnc); +void pFL_32(x64emu_t *emu, uintptr_t fnc); +void pFp_32(x64emu_t *emu, uintptr_t fnc); +void hFv_32(x64emu_t *emu, uintptr_t fnc); +void aFa_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); +void iFEi_32(x64emu_t *emu, uintptr_t fnc); +void iFEL_32(x64emu_t *emu, uintptr_t fnc); +void iFEp_32(x64emu_t *emu, uintptr_t fnc); +void iFEh_32(x64emu_t *emu, uintptr_t fnc); +void iFEO_32(x64emu_t *emu, uintptr_t fnc); +void iFii_32(x64emu_t *emu, uintptr_t fnc); +void iFiI_32(x64emu_t *emu, uintptr_t fnc); +void iFiu_32(x64emu_t *emu, uintptr_t fnc); +void iFip_32(x64emu_t *emu, uintptr_t fnc); +void iFuu_32(x64emu_t *emu, uintptr_t fnc); +void iFup_32(x64emu_t *emu, uintptr_t fnc); +void iFli_32(x64emu_t *emu, uintptr_t fnc); +void iFpi_32(x64emu_t *emu, uintptr_t fnc); +void iFpp_32(x64emu_t *emu, uintptr_t fnc); +void iFhp_32(x64emu_t *emu, uintptr_t fnc); +void iFhh_32(x64emu_t *emu, uintptr_t fnc); +void IFII_32(x64emu_t *emu, uintptr_t fnc); +void uFEu_32(x64emu_t *emu, uintptr_t fnc); +void uFEV_32(x64emu_t *emu, uintptr_t fnc); +void uFpa_32(x64emu_t *emu, uintptr_t fnc); +void UFii_32(x64emu_t *emu, uintptr_t fnc); +void UFUU_32(x64emu_t *emu, uintptr_t fnc); +void UFss_32(x64emu_t *emu, uintptr_t fnc); +void fFif_32(x64emu_t *emu, uintptr_t fnc); +void fFfi_32(x64emu_t *emu, uintptr_t fnc); +void fFff_32(x64emu_t *emu, uintptr_t fnc); +void fFfD_32(x64emu_t *emu, uintptr_t fnc); +void fFfp_32(x64emu_t *emu, uintptr_t fnc); +void dFid_32(x64emu_t *emu, uintptr_t fnc); +void dFdi_32(x64emu_t *emu, uintptr_t fnc); +void dFdd_32(x64emu_t *emu, uintptr_t fnc); +void dFdD_32(x64emu_t *emu, uintptr_t fnc); +void dFdp_32(x64emu_t *emu, uintptr_t fnc); +void LFpp_32(x64emu_t *emu, uintptr_t fnc); +void pFEv_32(x64emu_t *emu, uintptr_t fnc); +void pFEp_32(x64emu_t *emu, uintptr_t fnc); +void pFLL_32(x64emu_t *emu, uintptr_t fnc); +void aFia_32(x64emu_t *emu, uintptr_t fnc); +void iFHBp__32(x64emu_t *emu, uintptr_t fnc); +void vFEip_32(x64emu_t *emu, uintptr_t fnc); +void vFEpi_32(x64emu_t *emu, uintptr_t fnc); +void vFEpu_32(x64emu_t *emu, uintptr_t fnc); +void vFfpp_32(x64emu_t *emu, uintptr_t fnc); +void vFdpp_32(x64emu_t *emu, uintptr_t fnc); +void iFEpi_32(x64emu_t *emu, uintptr_t fnc); +void iFEpL_32(x64emu_t *emu, uintptr_t fnc); +void iFEpp_32(x64emu_t *emu, uintptr_t fnc); +void iFEpV_32(x64emu_t *emu, uintptr_t fnc); +void iFiii_32(x64emu_t *emu, uintptr_t fnc); +void iFiiI_32(x64emu_t *emu, uintptr_t fnc); +void iFiiu_32(x64emu_t *emu, uintptr_t fnc); +void iFiiO_32(x64emu_t *emu, uintptr_t fnc); +void iFiII_32(x64emu_t *emu, uintptr_t fnc); +void iFiuu_32(x64emu_t *emu, uintptr_t fnc); +void iFiLN_32(x64emu_t *emu, uintptr_t fnc); +void iFipp_32(x64emu_t *emu, uintptr_t fnc); +void iFuii_32(x64emu_t *emu, uintptr_t fnc); +void iFuip_32(x64emu_t *emu, uintptr_t fnc); +void iFuui_32(x64emu_t *emu, uintptr_t fnc); +void iFuuu_32(x64emu_t *emu, uintptr_t fnc); +void iFuLp_32(x64emu_t *emu, uintptr_t fnc); +void iFupp_32(x64emu_t *emu, uintptr_t fnc); +void iFpiu_32(x64emu_t *emu, uintptr_t fnc); +void iFpip_32(x64emu_t *emu, uintptr_t fnc); +void iFpuu_32(x64emu_t *emu, uintptr_t fnc); +void iFppu_32(x64emu_t *emu, uintptr_t fnc); +void iFppL_32(x64emu_t *emu, uintptr_t fnc); +void iFppp_32(x64emu_t *emu, uintptr_t fnc); +void iFpOu_32(x64emu_t *emu, uintptr_t fnc); +void IFiIi_32(x64emu_t *emu, uintptr_t fnc); +void fFfff_32(x64emu_t *emu, uintptr_t fnc); +void fFffp_32(x64emu_t *emu, uintptr_t fnc); +void dFddd_32(x64emu_t *emu, uintptr_t fnc); +void dFddp_32(x64emu_t *emu, uintptr_t fnc); +void pFEip_32(x64emu_t *emu, uintptr_t fnc); +void pFEpi_32(x64emu_t *emu, uintptr_t fnc); +void pFEpp_32(x64emu_t *emu, uintptr_t fnc); +void pFppL_32(x64emu_t *emu, uintptr_t fnc); +void pFpOM_32(x64emu_t *emu, uintptr_t fnc); +void hFEpp_32(x64emu_t *emu, uintptr_t fnc); +void aFipa_32(x64emu_t *emu, uintptr_t fnc); +void lFpBp_i_32(x64emu_t *emu, uintptr_t fnc); +void vFEipV_32(x64emu_t *emu, uintptr_t fnc); +void vFEppp_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 iFELup_32(x64emu_t *emu, uintptr_t fnc); +void iFEpip_32(x64emu_t *emu, uintptr_t fnc); +void iFEpup_32(x64emu_t *emu, uintptr_t fnc); +void iFEppu_32(x64emu_t *emu, uintptr_t fnc); +void iFEppL_32(x64emu_t *emu, uintptr_t fnc); +void iFEppp_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 LFpLLh_32(x64emu_t *emu, uintptr_t fnc); +void pFEppi_32(x64emu_t *emu, uintptr_t fnc); +void pFEppp_32(x64emu_t *emu, uintptr_t fnc); +void pFppuL_32(x64emu_t *emu, uintptr_t fnc); +void pFppLL_32(x64emu_t *emu, uintptr_t fnc); +void iFEppiV_32(x64emu_t *emu, uintptr_t fnc); +void iFEpppi_32(x64emu_t *emu, uintptr_t fnc); +void iFiLLLL_32(x64emu_t *emu, uintptr_t fnc); +void iFEBh_ppp_32(x64emu_t *emu, uintptr_t fnc); +void iFEpippppp_32(x64emu_t *emu, uintptr_t fnc); + +#if defined(ANDROID) +void pFv_32(x64emu_t *emu, uintptr_t fnc); +void vFEpppp_32(x64emu_t *emu, uintptr_t fnc); +#endif + +#if defined(HAVE_LD80BITS) +void DFD_32(x64emu_t *emu, uintptr_t fnc); +void DFDD_32(x64emu_t *emu, uintptr_t fnc); +void DFDp_32(x64emu_t *emu, uintptr_t fnc); +#endif + +#if !defined(HAVE_LD80BITS) +void KFK_32(x64emu_t *emu, uintptr_t fnc); +void KFKK_32(x64emu_t *emu, uintptr_t fnc); +void KFKp_32(x64emu_t *emu, uintptr_t fnc); +#endif + +void iFEvpV_32(x64emu_t *emu, uintptr_t fnc); +void UFsvvs_32(x64emu_t *emu, uintptr_t fnc); +#endif // __WRAPPER32_H_ diff --git a/src/wrapped32/wrappedcrashhandler.c b/src/wrapped32/wrappedcrashhandler.c new file mode 100755 index 00000000..ed9b3b1e --- /dev/null +++ b/src/wrapped32/wrappedcrashhandler.c @@ -0,0 +1,32 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "x64emu.h" +#include "emu/x64emu_private.h" +#include "callback.h" +#include "librarian.h" +#include "box32context.h" +#include "emu/x64emu_private.h" + +static const char* crashhandlerName = "crashhandler.so"; +#define LIBNAME crashhandler + +#define PRE_INIT \ + if(!box64_steam) \ + return -1; \ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);\ + else + + +#include "wrappedlib_init32.h" + diff --git a/src/wrapped32/wrappedcrashhandler_private.h b/src/wrapped32/wrappedcrashhandler_private.h new file mode 100755 index 00000000..52ed57d6 --- /dev/null +++ b/src/wrapped32/wrappedcrashhandler_private.h @@ -0,0 +1,49 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) +#error Meh.... +#endif + +//GO(Breakpad_SetSteamID, +//DATAB(__bss_start, +//GO(CreateInterface, +//DATAB(_edata, +//DATAB(_end, +//GO(_fini, +//GO(_init, +//GO(SteamRealPath, +//GO(__wrap_access, +//GO(__wrap_chmod, +//GO(__wrap_chown, +//GO(__wrap_dlmopen, +//GO(__wrap_dlopen, +//GO(__wrap_fopen, +//GO(__wrap_fopen64, +//GO(__wrap_freopen, +//GO(__wrap_lchown, +//GO(__wrap_link, +//GO(__wrap_lstat, +//GO(__wrap_lstat64, +//GO(__wrap___lxstat, +//GO(__wrap___lxstat64, +//GO(__wrap_mkdir, +//GO(__wrap_mkfifo, +//GO(__wrap_mknod, +//GO(__wrap_mount, +//GO(__wrap_open, +//GO(__wrap_open64, +//GO(__wrap_opendir, +//GO(__wrap_rename, +//GO(__wrap_rmdir, +//GO(__wrap_scandir, +//GO(__wrap_scandir64, +//GO(__wrap_stat, +//GO(__wrap_stat64, +//GO(__wrap_statfs, +//GO(__wrap_statfs64, +//GO(__wrap_statvfs, +//GO(__wrap_statvfs64, +//GO(__wrap_symlink, +//GO(__wrap_unlink, +//GO(__wrap_utime, +//GO(__wrap_utimes, +//GO(__wrap___xstat, +//GO(__wrap___xstat64, diff --git a/src/wrapped32/wrappedldlinux.c b/src/wrapped32/wrappedldlinux.c new file mode 100755 index 00000000..f0c8bf89 --- /dev/null +++ b/src/wrapped32/wrappedldlinux.c @@ -0,0 +1,58 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "x64emu.h" +#include "emu/x64emu_private.h" +#include "elfloader.h" +#include "box32context.h" + +typedef struct my32_tls_s { + int i; + uint32_t o; +} my32_tls_t; + +EXPORT void* my32___tls_get_addr(x64emu_t* emu, void* p) +{ + my32_tls_t *t = (my32_tls_t*)p; + return GetDTatOffset(emu->context, t->i, t->o); +} + +EXPORT void* my32____tls_get_addr(x64emu_t* emu) +{ + // the GNU version (with 3 '_') use register for the parameter! + my32_tls_t *t = (my32_tls_t*)from_ptrv(R_EAX); + return GetDTatOffset(emu->context, t->i, t->o); +} + +EXPORT ptr_t my32___libc_stack_end; +static void stSetup32(box64context_t* context) +{ + my32___libc_stack_end = to_ptrv(context->stack); // is this the end, or should I add stasz? +} + +// don't try to load the actual ld-linux (because name is variable), just use box64 itself, as it's linked to ld-linux +static const char* ldlinuxName = "ld-linux.so.3"; +#define LIBNAME ldlinux + +// fake (ignored) _r_data structure +EXPORT void* my32__r_debug[5]; + +#define PRE_INIT\ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ + else + +#define CUSTOM_INIT \ + stSetup32(box64); \ + +#include "wrappedlib_init32.h" + diff --git a/src/wrapped32/wrappedldlinux_private.h b/src/wrapped32/wrappedldlinux_private.h new file mode 100755 index 00000000..cfff7731 --- /dev/null +++ b/src/wrapped32/wrappedldlinux_private.h @@ -0,0 +1,25 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) +#error meh! +#endif + +// _dl_allocate_tls +// _dl_allocate_tls_init +// _dl_argv //type B +// _dl_cache_libcmp +// _dl_deallocate_tls +// _dl_debug_state +// _dl_get_tls_static_info +// _dl_make_stack_executable +// _dl_mcount +// _dl_rtld_di_serinfo +// _dl_tls_setup +DATA(__libc_enable_secure, 4) +DATA(__libc_stack_end, 4) +DATA(__pointer_chk_guard, 4) +DATAM(_r_debug, 20) //type B +DATA(_rtld_global, 4) +DATA(_rtld_global_ro, 4) +DATA(__stack_chk_guard, 4) +// defini dans glibc/sysdeps/i386/dl-tls.h +GOM(___tls_get_addr, pFEv) //the parameter tls_index is in a register (EAX?) +GOM(__tls_get_addr, pFEp) //same, but the parameter is in the stack diff --git a/src/wrapped32/wrappedlib_init32.h b/src/wrapped32/wrappedlib_init32.h new file mode 100644 index 00000000..65736fa2 --- /dev/null +++ b/src/wrapped32/wrappedlib_init32.h @@ -0,0 +1,325 @@ +#ifndef LIBNAME +#error Meh +#endif + +#include "debug.h" +#include "librarian/library_inner.h" + +#define FUNC3(M,N) wrapped##M##N +#define FUNC2(M,N) FUNC3(M,N) +#define FUNC(N) FUNC2(LIBNAME,N) +#define QUOTE(M) #M +#define PRIVATE2(P) QUOTE(wrapped##P##_private.h) +#define PRIVATE(P) PRIVATE2(P) +#define MAPNAME3(N,M) N##M +#define MAPNAME2(N,M) MAPNAME3(N,M) +#define MAPNAME(N) MAPNAME2(LIBNAME,N) + +// prepare the maps +#define _DOIT(P,Q) QUOTE(generated/wrapped##P##Q.h) +#define DOIT(P,Q) _DOIT(P,Q) +#include DOIT(LIBNAME,defs32) + +// regular symbol mapped to itself +#define GO(N, W) +// regular symbol mapped to itself, but weak +#define GOW(N, W) +// symbol mapped to my32_symbol +#define GOM(N, W) +// symbol mapped to my32_symbol, but weak +#define GOWM(N, W) +// regular symbol mapped to itself, that returns a structure +#define GOS(N, W) +// symbol mapped to another one +#define GO2(N, W, O) +// weak symbol mapped to another one +#define GOW2(N, W, O) +// data +#define DATA(N, S) +// data, Weak (type V) +#define DATAV(N, S) +// data, Uninitialized (type B) +#define DATAB(N, S) +// data, "my32_" type +#define DATAM(N, S) + +// #define the 4 maps first +#undef GO +#undef GOW +#ifdef STATICBUILD +#define GO(N, W) {#N, W##_32, 0, &N}, +#define GOW(N, W) {#N, W##_32, 1, &N}, +#else +#define GO(N, W) {#N, W##_32, 0}, +#define GOW(N, W) {#N, W##_32, 1}, +#endif +static const map_onesymbol_t MAPNAME(symbolmap)[] = { + #include PRIVATE(LIBNAME) +}; +#undef GO +#undef GOW +#undef GOM +#undef GOWM +#define GO(N, W) +#define GOW(N, W) +#ifdef STATICBUILD +#define GOM(N, W) {#N, W##_32, 0, &my32_##N}, +#define GOWM(N, W) {#N, W##_32, 1, &my32_##N}, +#else +#define GOM(N, W) {#N, W##_32, 0}, +#define GOWM(N, W) {#N, W##_32, 1}, +#endif +static const map_onesymbol_t MAPNAME(mysymbolmap)[] = { + #include PRIVATE(LIBNAME) +}; +#undef GOM +#undef GOWM +#undef GOS +#define GOM(N, W) +#define GOWM(N, W) +#ifdef STATICBUILD +#define GOS(N, W) {#N, W##_32, 0, &my32_##N}, +#else +#define GOS(N, W) {#N, W##_32, 0}, +#endif +static const map_onesymbol_t MAPNAME(stsymbolmap)[] = { + #include PRIVATE(LIBNAME) +}; +#undef GOS +#define GOS(N, W) +#undef GO2 +#undef GOW2 +#ifdef STATICBUILD +#define GO2(N, W, O) {#N, W##_32, 0, #O, &O}, +#define GOW2(N, W, O) {#N, W##_32, 1, #O, &O}, +#else +#define GO2(N, W, O) {#N, W##_32, 0, #O}, +#define GOW2(N, W, O) {#N, W##_32, 1, #O}, +#endif +static const map_onesymbol2_t MAPNAME(symbol2map)[] = { + #include PRIVATE(LIBNAME) +}; +#undef GO2 +#define GO2(N, W, O) +#undef GOW2 +#define GOW2(N, W, O) +#undef DATA +#undef DATAV +#undef DATAB +#ifdef STATICBUILD +#define DATA(N, S) {#N, S, 0, (void*)&N}, +#define DATAV(N, S) {#N, S, 1, (void*)&N}, +#define DATAB(N, S) {#N, S, 0, (void*)&N}, +#else +#define DATA(N, S) {#N, S, 0}, +#define DATAV(N, S) {#N, S, 1}, +#define DATAB(N, S) {#N, S, 0}, +#endif +static const map_onedata_t MAPNAME(datamap)[] = { + #include PRIVATE(LIBNAME) +}; +#undef DATA +#undef DATAV +#undef DATAB +#define DATA(N, S) +#define DATAV(N, S) +#define DATAB(N, S) +#undef DATAM +#ifdef STATICBUILD +#define DATAM(N, S) {#N, S, 0, &my32_##N}, +#else +#define DATAM(N, S) {#N, S, 0}, +#endif +static const map_onedata_t MAPNAME(mydatamap)[] = { + #include PRIVATE(LIBNAME) +}; + +#undef GO +#undef GOW +#undef GOM +#undef GOWM +#undef GO2 +#undef GOS +#undef DATA +#undef DATAV +#undef DATAB +#undef DATAM + +#include DOIT(LIBNAME,undefs32) +#undef DOIT +#undef _DOIT + +#if !defined(ALTNAME) && defined(ALTNAME2) +#error Please define ALTNAME before defining ALTNAME2 +#endif + +#define COUNT_NARGS(...) COUNT_NARGS_AUX(__VA_ARGS__, 5, 4, 3, 2, 1, 0) +#define COUNT_NARGS_AUX(_1, _2, _3, _4, _5, n, ...) COUNT_NARGS_AUX##n(This should not appear, too many libraries) +#define COUNT_NARGS_AUX1(v1, v2) 1 +#define COUNT_NARGS_AUX2(v1, v2) 2 +#define COUNT_NARGS_AUX3(v1, v2) 3 +#define COUNT_NARGS_AUX4(v1, v2) 4 +#define COUNT_NARGS_AUX5(v1, v2) 5 + +int FUNC(_init32)(library_t* lib, box64context_t* box64) +{ + (void)box64; + + // Init first + free(lib->path); lib->path=NULL; +#ifdef PRE_INIT + PRE_INIT +#endif + { +#ifndef STATICBUILD + lib->w.lib = dlopen(MAPNAME(Name), RTLD_LAZY | RTLD_GLOBAL); + if(!lib->w.lib) { +#ifdef ALTNAME + lib->w.lib = dlopen(ALTNAME, RTLD_LAZY | RTLD_GLOBAL); + if(!lib->w.lib) { +#ifdef ALTNAME2 + lib->w.lib = dlopen(ALTNAME2, RTLD_LAZY | RTLD_GLOBAL); + if(!lib->w.lib) +#endif +#endif + return -1; +#ifdef ALTNAME +#ifdef ALTNAME2 + else lib->path = box_strdup(ALTNAME2); +#endif + } else lib->path = box_strdup(ALTNAME); +#endif + } else lib->path = box_strdup(MAPNAME(Name)); +#else + lib->path = box_strdup(MAPNAME(Name)); +#endif + } + WrappedLib_CommonInit(lib); + + khint_t k; + int ret; + int cnt; + + // populates maps... +#ifdef STATICBUILD +#define DOIT(mapname) \ + cnt = sizeof(MAPNAME(mapname))/sizeof(map_onesymbol_t); \ + for (int i = 0; i < cnt; ++i) { \ + if (MAPNAME(mapname)[i].weak) { \ + k = kh_put(symbolmap, lib->w.w##mapname, MAPNAME(mapname)[i].name, &ret); \ + kh_value(lib->w.w##mapname, k).w = MAPNAME(mapname)[i].w; \ + kh_value(lib->w.w##mapname, k).resolved = 0; \ + kh_value(lib->w.w##mapname, k).addr = (uintptr_t)MAPNAME(mapname)[i].addr; \ + } else { \ + k = kh_put(symbolmap, lib->w.mapname, MAPNAME(mapname)[i].name, &ret); \ + kh_value(lib->w.mapname, k).w = MAPNAME(mapname)[i].w; \ + kh_value(lib->w.mapname, k).resolved = 0; \ + kh_value(lib->w.mapname, k).addr = (uintptr_t)MAPNAME(mapname)[i].addr; \ + } \ + if (strchr(MAPNAME(mapname)[i].name, '@')) \ + AddDictionnary(box64->versym, MAPNAME(mapname)[i].name); \ + } +#else +#define DOIT(mapname) \ + cnt = sizeof(MAPNAME(mapname))/sizeof(map_onesymbol_t); \ + for (int i = 0; i < cnt; ++i) { \ + if (MAPNAME(mapname)[i].weak) { \ + k = kh_put(symbolmap, lib->w.w##mapname, MAPNAME(mapname)[i].name, &ret); \ + kh_value(lib->w.w##mapname, k).w = MAPNAME(mapname)[i].w; \ + kh_value(lib->w.w##mapname, k).resolved = 0; \ + } else { \ + k = kh_put(symbolmap, lib->w.mapname, MAPNAME(mapname)[i].name, &ret); \ + kh_value(lib->w.mapname, k).w = MAPNAME(mapname)[i].w; \ + kh_value(lib->w.mapname, k).resolved = 0; \ + } \ + if (strchr(MAPNAME(mapname)[i].name, '@')) \ + AddDictionnary(box64->versym, MAPNAME(mapname)[i].name); \ + } +#endif + DOIT(symbolmap) + DOIT(mysymbolmap) +#undef DOIT + cnt = sizeof(MAPNAME(stsymbolmap))/sizeof(map_onesymbol_t); + for (int i=0; i<cnt; ++i) { + k = kh_put(symbolmap, lib->w.stsymbolmap, MAPNAME(stsymbolmap)[i].name, &ret); + kh_value(lib->w.stsymbolmap, k).w = MAPNAME(stsymbolmap)[i].w; + #ifdef STATICBUILD + kh_value(lib->w.stsymbolmap, k).resolved = 1; + kh_value(lib->w.stsymbolmap, k).addr = (uintptr_t)MAPNAME(stsymbolmap)[i].addr; + #else + kh_value(lib->w.stsymbolmap, k).resolved = 0; + #endif + if(strchr(MAPNAME(stsymbolmap)[i].name, '@')) + AddDictionnary(box64->versym, MAPNAME(stsymbolmap)[i].name); + } + cnt = sizeof(MAPNAME(symbol2map))/sizeof(map_onesymbol2_t); + for (int i=0; i<cnt; ++i) { + k = kh_put(symbol2map, lib->w.symbol2map, MAPNAME(symbol2map)[i].name, &ret); + kh_value(lib->w.symbol2map, k).name = MAPNAME(symbol2map)[i].name2; + kh_value(lib->w.symbol2map, k).w = MAPNAME(symbol2map)[i].w; + kh_value(lib->w.symbol2map, k).weak = MAPNAME(symbol2map)[i].weak; + #ifdef STATICBUILD + kh_value(lib->w.symbol2map, k).resolved = 1; + kh_value(lib->w.symbol2map, k).addr = (uintptr_t)MAPNAME(symbol2map)[i].addr; + #else + kh_value(lib->w.symbol2map, k).resolved = 0; + #endif + if(strchr(MAPNAME(symbol2map)[i].name, '@')) + AddDictionnary(box64->versym, MAPNAME(symbol2map)[i].name); + } + cnt = sizeof(MAPNAME(datamap))/sizeof(map_onedata_t); + for (int i=0; i<cnt; ++i) { + if(MAPNAME(datamap)[i].weak) { + k = kh_put(datamap, lib->w.wdatamap, MAPNAME(datamap)[i].name, &ret); + #ifdef STATICBUILD + kh_value(lib->w.wdatamap, k).size = MAPNAME(datamap)[i].sz; + kh_value(lib->w.wdatamap, k).addr = (uintptr_t)MAPNAME(datamap)[i].addr; + #else + kh_value(lib->w.wdatamap, k) = MAPNAME(datamap)[i].sz; + #endif + } else { + k = kh_put(datamap, lib->w.datamap, MAPNAME(datamap)[i].name, &ret); + #ifdef STATICBUILD + kh_value(lib->w.datamap, k).size = MAPNAME(datamap)[i].sz; + kh_value(lib->w.datamap, k).addr = (uintptr_t)MAPNAME(datamap)[i].addr; + #else + kh_value(lib->w.datamap, k) = MAPNAME(datamap)[i].sz; + #endif + } + } + cnt = sizeof(MAPNAME(mydatamap))/sizeof(map_onedata_t); + for (int i=0; i<cnt; ++i) { + k = kh_put(datamap, lib->w.mydatamap, MAPNAME(mydatamap)[i].name, &ret); + #ifdef STATICBUILD + kh_value(lib->w.mydatamap, k).size = MAPNAME(mydatamap)[i].sz; + kh_value(lib->w.mydatamap, k).addr = (uintptr_t)MAPNAME(mydatamap)[i].addr; + #else + kh_value(lib->w.mydatamap, k) = MAPNAME(mydatamap)[i].sz; + #endif + } +#ifdef ALTMY + SETALT(ALTMY); +#endif +#ifdef HAS_MY + getMy(lib); +#endif +#ifdef CUSTOM_INIT + CUSTOM_INIT +#endif +#ifdef NEEDED_LIBS + setNeededLibs(lib, COUNT_NARGS(NEEDED_LIBS), NEEDED_LIBS); +#endif + + return 0; +} + +void FUNC(_fini32)(library_t* lib) +{ +#ifdef HAS_MY + freeMy(); +#endif +#ifdef CUSTOM_FINI + CUSTOM_FINI +#endif + WrappedLib_FinishFini(lib); +} diff --git a/src/wrapped32/wrappedlibc.c b/src/wrapped32/wrappedlibc.c new file mode 100755 index 00000000..952d7f7f --- /dev/null +++ b/src/wrapped32/wrappedlibc.c @@ -0,0 +1,2867 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <stdlib.h> +#include <stdio.h> +#include <stddef.h> +#include <string.h> +#include <wchar.h> +#include <dlfcn.h> +#include <signal.h> +#include <errno.h> +#include <err.h> +#include <stdarg.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/select.h> +#include <unistd.h> +#include <fcntl.h> +#include <glob.h> +#include <ctype.h> +#include <dirent.h> +#include <search.h> +#include <sys/types.h> +#include <poll.h> +#include <sys/epoll.h> +#include <ftw.h> +#include <sys/syscall.h> +#include <sys/socket.h> +#include <sys/utsname.h> +#include <sys/mman.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> +#include <setjmp.h> +#include <sys/vfs.h> +#include <spawn.h> +#include <getopt.h> +#include <pwd.h> +#include <locale.h> + +#include "wrappedlibs.h" + +#include "box64stack.h" +#include "x64emu.h" +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "callback.h" +#include "librarian.h" +#include "librarian/library_private.h" +#include "emu/x64emu_private.h" +#include "box32context.h" +#include "myalign32.h" +#include "signals.h" +#include "fileutils.h" +#include "auxval.h" +#include "elfloader.h" +#include "bridge.h" +#include "globalsymbols.h" +#include "box32.h" + +#ifdef PANDORA +#ifndef __NR_preadv +#define __NR_preadv (__NR_SYSCALL_BASE+361) +#endif +#ifndef __NR_pwritev +#define __NR_pwritev (__NR_SYSCALL_BASE+362) +#endif +#ifndef __NR_accept4 +#define __NR_accept4 (__NR_SYSCALL_BASE+366) +#endif +#ifndef __NR_sendmmsg +#define __NR_sendmmsg (__NR_SYSCALL_BASE+374) +#endif +#ifndef __NR_prlimit64 +#define __NR_prlimit64 (__NR_SYSCALL_BASE+369) +#endif +#ifndef __NR_recvmmsg +#define __NR_recvmmsg (__NR_SYSCALL_BASE+365) +#endif +#elif defined(__arm__) +#ifndef __NR_accept4 +#define __NR_accept4 (__NR_SYSCALL_BASE+366) +#endif +#endif + +// need to undef all read / read64 stuffs! +#undef pread +#undef pwrite +#undef lseek +#undef fseeko +#undef ftello +#undef fseekpos +#undef fsetpos +#undef fgetpos +#undef fopen +#undef statfs +#undef fstatfs +#undef freopen +#undef truncate +#undef ftruncate +#undef tmpfile +#undef lockf +#undef fscanf +#undef scanf +#undef sscanf +#undef vfscanf +#undef vscanf +#undef vsscanf +#undef getc +#undef putc +#undef mkstemp +#undef mkstemps +#undef mkostemp +#undef mkostemps +#undef open +#undef openat +#undef read +#undef write +#undef creat +#undef scandir +#undef mmap +#undef fcntl +#undef stat +#undef __xstat +#undef xstat +#undef scandir +#undef ftw +#undef nftw +#undef glob + +#define LIBNAME libc + +static const char* libcName = +#ifdef ANDROID + "libc.so" +#else + "libc.so.6" +#endif + ; + +static library_t* my_lib = NULL; + +extern int fix_64bit_inodes; +#if 0 +typedef int (*iFL_t)(unsigned long); +typedef void (*vFpp_t)(void*, void*); +typedef void (*vFpp_t)(void*, void*); +typedef void (*vFipp_t)(int32_t, void*, void*); +typedef int32_t (*iFpi_t)(void*, int32_t); +typedef int32_t (*iFpp_t)(void*, void*); +typedef int32_t (*iFpL_t)(void*, size_t); +typedef int32_t (*iFiip_t)(int32_t, int32_t, void*); +typedef int32_t (*iFipp_t)(int32_t, void*, void*); +typedef int32_t (*iFppi_t)(void*, void*, int32_t); +typedef int32_t (*iFpup_t)(void*, uint32_t, void*); +typedef int32_t (*iFpuu_t)(void*, uint32_t, uint32_t); +typedef int32_t (*iFiiII_t)(int, int, int64_t, int64_t); +typedef int32_t (*iFiiiV_t)(int, int, int, ...); +typedef int32_t (*iFippi_t)(int32_t, void*, void*, int32_t); +typedef int32_t (*iFpppp_t)(void*, void*, void*, void*); +typedef int32_t (*iFpipp_t)(void*, int32_t, void*, void*); +typedef int32_t (*iFpLpp_t)(void*, size_t, void*, void*); +typedef int32_t (*iFppii_t)(void*, void*, int32_t, int32_t); +typedef int32_t (*iFipuu_t)(int32_t, void*, uint32_t, uint32_t); +typedef int32_t (*iFipiI_t)(int32_t, void*, int32_t, int64_t); +typedef int32_t (*iFipuup_t)(int32_t, void*, uint32_t, uint32_t, void*); +typedef int32_t (*iFiiV_t)(int32_t, int32_t, ...); +typedef void* (*pFp_t)(void*); +typedef void* (*pFu_t)(uint32_t); +#define SUPER() \ + GO(_ITM_addUserCommitAction, iFpup_t) \ + GO(_IO_file_stat, iFpp_t) + +#endif + +//#include "wrappercallback.h" + +#if 0 +// utility functions +#define SUPER() \ +GO(0) \ +GO(1) \ +GO(2) \ +GO(3) \ +GO(4) \ +GO(5) \ +GO(6) \ +GO(7) \ +GO(8) \ +GO(9) \ +GO(10) \ +GO(11) \ +GO(12) \ +GO(13) \ +GO(14) \ +GO(15) + +// compare +#define GO(A) \ +static uintptr_t my32_compare_fct_##A = 0; \ +static int my32_compare_##A(void* a, void* b) \ +{ \ + return (int)RunFunction(my_context, my32_compare_fct_##A, 2, a, b);\ +} +SUPER() +#undef GO +static void* findcompareFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_compare_fct_##A == (uintptr_t)fct) return my32_compare_##A; + SUPER() + #undef GO + #define GO(A) if(my32_compare_fct_##A == 0) {my32_compare_fct_##A = (uintptr_t)fct; return my32_compare_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc compare callback\n"); + return NULL; +} + +// ftw +#define GO(A) \ +static uintptr_t my32_ftw_fct_##A = 0; \ +static int my32_ftw_##A(void* fpath, void* sb, int flag) \ +{ \ + return (int)RunFunction(my_context, my32_ftw_fct_##A, 3, fpath, sb, flag); \ +} +SUPER() +#undef GO +static void* findftwFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_ftw_fct_##A == (uintptr_t)fct) return my32_ftw_##A; + SUPER() + #undef GO + #define GO(A) if(my32_ftw_fct_##A == 0) {my32_ftw_fct_##A = (uintptr_t)fct; return my32_ftw_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc ftw callback\n"); + return NULL; +} + +// ftw64 +#define GO(A) \ +static uintptr_t my32_ftw64_fct_##A = 0; \ +static int my32_ftw64_##A(void* fpath, void* sb, int flag) \ +{ \ + struct i386_stat64 i386st; \ + UnalignStat64(sb, &i386st); \ + return (int)RunFunction(my_context, my32_ftw64_fct_##A, 3, fpath, &i386st, flag); \ +} +SUPER() +#undef GO +static void* findftw64Fct(void* fct) +{ + if(!fct) return NULL; + #define GO(A) if(my32_ftw64_fct_##A == (uintptr_t)fct) return my32_ftw64_##A; + SUPER() + #undef GO + #define GO(A) if(my32_ftw64_fct_##A == 0) {my32_ftw64_fct_##A = (uintptr_t)fct; return my32_ftw64_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc ftw64 callback\n"); + return NULL; +} + +// nftw +#define GO(A) \ +static uintptr_t my32_nftw_fct_##A = 0; \ +static int my32_nftw_##A(void* fpath, void* sb, int flag, void* ftwbuff) \ +{ \ + return (int)RunFunction(my_context, my32_nftw_fct_##A, 4, fpath, sb, flag, ftwbuff); \ +} +SUPER() +#undef GO +static void* findnftwFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_nftw_fct_##A == (uintptr_t)fct) return my32_nftw_##A; + SUPER() + #undef GO + #define GO(A) if(my32_nftw_fct_##A == 0) {my32_nftw_fct_##A = (uintptr_t)fct; return my32_nftw_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc nftw callback\n"); + return NULL; +} + +// nftw64 +#define GO(A) \ +static uintptr_t my32_nftw64_fct_##A = 0; \ +static int my32_nftw64_##A(void* fpath, void* sb, int flag, void* ftwbuff) \ +{ \ + struct i386_stat64 i386st; \ + UnalignStat64(sb, &i386st); \ + return (int)RunFunction(my_context, my32_nftw64_fct_##A, 4, fpath, &i386st, flag, ftwbuff); \ +} +SUPER() +#undef GO +static void* findnftw64Fct(void* fct) +{ + if(!fct) return NULL; + #define GO(A) if(my32_nftw64_fct_##A == (uintptr_t)fct) return my32_nftw64_##A; + SUPER() + #undef GO + #define GO(A) if(my32_nftw64_fct_##A == 0) {my32_nftw64_fct_##A = (uintptr_t)fct; return my32_nftw64_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc nftw64 callback\n"); + return NULL; +} + +// globerr +#define GO(A) \ +static uintptr_t my32_globerr_fct_##A = 0; \ +static int my32_globerr_##A(void* epath, int eerrno) \ +{ \ + return (int)RunFunction(my_context, my32_globerr_fct_##A, 2, epath, eerrno); \ +} +SUPER() +#undef GO +static void* findgloberrFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_globerr_fct_##A == (uintptr_t)fct) return my32_globerr_##A; + SUPER() + #undef GO + #define GO(A) if(my32_globerr_fct_##A == 0) {my32_globerr_fct_##A = (uintptr_t)fct; return my32_globerr_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc globerr callback\n"); + return NULL; +} +#undef dirent +// filter_dir +#define GO(A) \ +static uintptr_t my32_filter_dir_fct_##A = 0; \ +static int my32_filter_dir_##A(const struct dirent* a) \ +{ \ + return (int)RunFunction(my_context, my32_filter_dir_fct_##A, 1, a); \ +} +SUPER() +#undef GO +static void* findfilter_dirFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_filter_dir_fct_##A == (uintptr_t)fct) return my32_filter_dir_##A; + SUPER() + #undef GO + #define GO(A) if(my32_filter_dir_fct_##A == 0) {my32_filter_dir_fct_##A = (uintptr_t)fct; return my32_filter_dir_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc filter_dir callback\n"); + return NULL; +} +// compare_dir +#define GO(A) \ +static uintptr_t my32_compare_dir_fct_##A = 0; \ +static int my32_compare_dir_##A(const struct dirent* a, const struct dirent* b) \ +{ \ + return (int)RunFunction(my_context, my32_compare_dir_fct_##A, 2, a, b); \ +} +SUPER() +#undef GO +static void* findcompare_dirFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_compare_dir_fct_##A == (uintptr_t)fct) return my32_compare_dir_##A; + SUPER() + #undef GO + #define GO(A) if(my32_compare_dir_fct_##A == 0) {my32_compare_dir_fct_##A = (uintptr_t)fct; return my32_compare_dir_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc compare_dir callback\n"); + return NULL; +} + +// 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); \ +} +SUPER() +#undef GO +static void* findfilter64Fct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_filter64_fct_##A == (uintptr_t)fct) return my32_filter64_##A; + SUPER() + #undef GO + #define GO(A) if(my32_filter64_fct_##A == 0) {my32_filter64_fct_##A = (uintptr_t)fct; return my32_filter64_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc filter64 callback\n"); + return NULL; +} +// 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); \ +} +SUPER() +#undef GO +static void* findcompare64Fct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_compare64_fct_##A == (uintptr_t)fct) return my32_compare64_##A; + SUPER() + #undef GO + #define GO(A) if(my32_compare64_fct_##A == 0) {my32_compare64_fct_##A = (uintptr_t)fct; return my32_compare64_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc compare64 callback\n"); + return NULL; +} +// on_exit +#define GO(A) \ +static uintptr_t my32_on_exit_fct_##A = 0; \ +static void my32_on_exit_##A(int a, const void* b) \ +{ \ + RunFunction(my_context, my32_on_exit_fct_##A, 2, a, b); \ +} +SUPER() +#undef GO +static void* findon_exitFct(void* fct) +{ + if(!fct) return NULL; + void* p; + if((p = GetNativeFnc((uintptr_t)fct))) return p; + #define GO(A) if(my32_on_exit_fct_##A == (uintptr_t)fct) return my32_on_exit_##A; + SUPER() + #undef GO + #define GO(A) if(my32_on_exit_fct_##A == 0) {my32_on_exit_fct_##A = (uintptr_t)fct; return my32_on_exit_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libc on_exit callback\n"); + return NULL; +} +#undef SUPER +#endif + +// some my32_XXX declare and defines +int32_t my32___libc_start_main(x64emu_t* emu, int *(main) (int, char * *, char * *), + int argc, char * * ubp_av, void (*init) (void), void (*fini) (void), + void (*rtld_fini) (void), void (* stack_end)); // implemented in x64run_private.c +EXPORT void my32___libc_init_first(x64emu_t* emu, int argc, char* arg0, char** b) +{ + // do nothing specific for now + return; +} +uint32_t my32_syscall(x64emu_t *emu); // implemented in x64syscall.c +void EXPORT my32___stack_chk_fail(x64emu_t* emu) +{ + char buff[200]; + #ifdef HAVE_TRACE + sprintf(buff, "%p: Stack is corrupted, aborting (prev IP=%p)\n", (void*)emu->old_ip, (void*)emu->prev2_ip); + #else + sprintf(buff, "%p: Stack is corrupted, aborting\n", (void*)emu->old_ip); + #endif + StopEmu(emu, buff, 1); +} +void EXPORT my32___gmon_start__(x64emu_t *emu) +{ + printf_log(LOG_DEBUG, "__gmon_start__ called (dummy call)\n"); +} +int EXPORT my32___cxa_atexit(x64emu_t* emu, void* p, void* a, void* d) +{ + AddCleanup1Arg(emu, p, a,FindElfAddress(my_context, (uintptr_t)d)); + return 0; +} +void EXPORT my32___cxa_finalize(x64emu_t* emu, void* p) +{ + if(!p) { + // p is null, call (and remove) all Cleanup functions + CallAllCleanup(emu); + return; + } + CallCleanup(emu, p); +} +int EXPORT my32_atexit(x64emu_t* emu, void *p) +{ + AddCleanup(emu, p); + return 0; +} + + +int my32_getcontext(x64emu_t* emu, void* ucp); +int my32_setcontext(x64emu_t* emu, void* ucp); +int my32_makecontext(x64emu_t* emu, void* ucp, void* fnc, int32_t argc, void* argv); +int my32_swapcontext(x64emu_t* emu, void* ucp1, void* ucp2); + +// All signal and context functions defined in signals.c + +// All fts function defined in myfts.c + +// getauxval implemented in auxval.c + + +// this one is defined in elfloader.c +int my32_dl_iterate_phdr(x64emu_t *emu, void* F, void *data); + +pid_t EXPORT my32_fork(x64emu_t* emu) +{ +/* #if 1 + emu->quit = 1; + emu->fork = 1; + return 0; + #else + return 0; + #endif*/ + // execute atforks prepare functions, in reverse order + for (int i=my_context->atfork_sz-1; i>=0; --i) + if(my_context->atforks[i].prepare) + RunFunctionWithEmu(emu, 0, my_context->atforks[i].prepare, 0); + int type = emu->type; + pid_t v; + v = fork(); + if(type == EMUTYPE_MAIN) + thread_set_emu(emu); + if(v<0) { + printf_log(LOG_NONE, "BOX32: Warning, fork errored... (%d)\n", v); + // error... + } else if(v>0) { + // execute atforks parent functions + for (int i=0; i<my_context->atfork_sz; --i) + if(my_context->atforks[i].parent) + RunFunctionWithEmu(emu, 0, my_context->atforks[i].parent, 0); + + } else /*if(v==0)*/ { + // execute atforks child functions + for (int i=0; i<my_context->atfork_sz; --i) + if(my_context->atforks[i].child) + RunFunctionWithEmu(emu, 0, my_context->atforks[i].child, 0); + } + return v; +} +pid_t EXPORT my32___fork(x64emu_t* emu) __attribute__((alias("my32_fork"))); +pid_t EXPORT my32_vfork(x64emu_t* emu) +{ + #if 1 + emu->quit = 1; + emu->fork = 1; // use regular fork... + return 0; + #else + return 0; + #endif +} + +int EXPORT my32_uname(struct utsname *buf) +{ + //TODO: check sizeof(struct utsname) == 390 + int ret = uname(buf); + strcpy(buf->machine, "x86_64"); + return ret; +} + +// X86_O_RDONLY 0x00 +#define X86_O_WRONLY 0x01 // octal 01 +#define X86_O_RDWR 0x02 // octal 02 +#define X86_O_CREAT 0x40 // octal 0100 +#define X86_O_EXCL 0x80 // octal 0200 +#define X86_O_NOCTTY 0x100 // octal 0400 +#define X86_O_TRUNC 0x200 // octal 01000 +#define X86_O_APPEND 0x400 // octal 02000 +#define X86_O_NONBLOCK 0x800 // octal 04000 +#define X86_O_SYNC 0x101000 // octal 04010000 +#define X86_O_DSYNC 0x1000 // octal 010000 +#define X86_O_RSYNC O_SYNC +#define X86_FASYNC 020000 +#define X86_O_DIRECT 040000 +#define X86_O_LARGEFILE 0100000 +#define X86_O_DIRECTORY 0200000 +#define X86_O_NOFOLLOW 0400000 +#define X86_O_NOATIME 01000000 +#define X86_O_CLOEXEC 02000000 +#define X86_O_PATH 010000000 +#define X86_O_TMPFILE 020200000 + +#ifndef O_TMPFILE +#define O_TMPFILE (020000000 | O_DIRECTORY) +#endif +#ifndef O_PATH +#define O_PATH 010000000 +#endif + +#define SUPER() \ + GO(O_WRONLY) \ + GO(O_RDWR) \ + GO(O_CREAT) \ + GO(O_EXCL) \ + GO(O_NOCTTY) \ + GO(O_TRUNC) \ + GO(O_APPEND) \ + GO(O_NONBLOCK) \ + GO(O_SYNC) \ + GO(O_DSYNC) \ + GO(O_RSYNC) \ + GO(FASYNC) \ + GO(O_DIRECT) \ + GO(O_LARGEFILE) \ + GO(O_TMPFILE) \ + GO(O_DIRECTORY) \ + GO(O_NOFOLLOW) \ + GO(O_NOATIME) \ + GO(O_CLOEXEC) \ + GO(O_PATH) \ + +// x86->arm +int of_convert32(int a) +{ + if(!a || a==-1) return a; + int b=0; + #define GO(A) if((a&X86_##A)==X86_##A) {a&=~X86_##A; b|=A;} + SUPER(); + #undef GO + if(a) { + printf_log(LOG_NONE, "Warning, of_convert32(...) left over 0x%x, converted 0x%x\n", a, b); + } + return a|b; +} + +// arm->x86 +int of_unconvert32(int a) +{ + if(!a || a==-1) return a; + int b=0; + #define GO(A) if((a&A)==A) {a&=~A; b|=X86_##A;} + SUPER(); + #undef GO + if(a) { + printf_log(LOG_NONE, "Warning, of_unconvert32(...) left over 0x%x, converted 0x%x\n", a, b); + } + return a|b; +} +#undef SUPER + +#if 0 +EXPORT void* my32__ZGTtnaX (size_t a) { printf("warning _ZGTtnaX called\n"); return NULL; } +EXPORT void my32__ZGTtdlPv (void* a) { printf("warning _ZGTtdlPv called\n"); } +EXPORT uint8_t my32__ITM_RU1(const uint8_t * a) { printf("warning _ITM_RU1 called\n"); return 0; } +EXPORT uint32_t my32__ITM_RU4(const uint32_t * a) { printf("warning _ITM_RU4 called\n"); return 0; } +EXPORT uint64_t my32__ITM_RU8(const uint64_t * a) { printf("warning _ITM_RU8 called\n"); return 0; } +EXPORT void my32__ITM_memcpyRtWn(void * a, const void * b, size_t c) {printf("warning _ITM_memcpyRtWn called\n"); } +EXPORT void my32__ITM_memcpyRnWt(void * a, const void * b, size_t c) {printf("warning _ITM_memcpyRtWn called\n"); } +#endif +EXPORT void my32_longjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val); +EXPORT void my32__longjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val) __attribute__((alias("my32_longjmp"))); +EXPORT void my32_siglongjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val) __attribute__((alias("my32_longjmp"))); +EXPORT void my32___longjmp_chk(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val) __attribute__((alias("my32_longjmp"))); + +//EXPORT int32_t my32_setjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p); +//EXPORT int32_t my32__setjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p) __attribute__((alias("my32_setjmp"))); +//EXPORT int32_t my32___sigsetjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p) __attribute__((alias("my32_setjmp"))); +#if 0 +EXPORT void my32_exit(x64emu_t *emu, int32_t status) +{ + R_EAX = (uint32_t)status; + emu->quit = 1; +} +EXPORT void my32__exit(x64emu_t *emu, int32_t status) __attribute__((alias("my32_exit"))); +EXPORT void my32__Exit(x64emu_t *emu, int32_t status) __attribute__((alias("my32_exit"))); +#endif +void myStackAlign32(const char* fmt, uint32_t* st, uint64_t* mystack); // align st into mystack according to fmt (for v(f)printf(...)) +typedef int (*iFpp_t)(void*, void*); +typedef int (*iFppp_t)(void*, void*, void*); +typedef int (*iFpupp_t)(void*, uint32_t, void*, void*); +EXPORT int my32_printf(x64emu_t *emu, void* fmt, void* b) { + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + return vprintf((const char*)fmt, VARARGS_32); +} +EXPORT int my32___printf_chk(x64emu_t *emu, void* fmt, void* b) __attribute__((alias("my32_printf"))); +#if 0 + +EXPORT int my32_vprintf(x64emu_t *emu, void* fmt, void* b) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vprintf; + return ((iFpp_t)f)(fmt, VARARGS_32); + #else + // other platform don't need that + return vprintf(fmt, b); + #endif +} +EXPORT int my32___vprintf_chk(x64emu_t *emu, void* fmt, void* b) __attribute__((alias("my32_vprintf"))); + +EXPORT int my32_vfprintf(x64emu_t *emu, void* F, void* fmt, void* b) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vfprintf; + return ((iFppp_t)f)(F, fmt, VARARGS_32); + #else + // other platform don't need that + return vfprintf(F, fmt, b); + #endif +} +EXPORT int my32___vfprintf_chk(x64emu_t *emu, void* F, void* fmt, void* b) __attribute__((alias("my32_vfprintf"))); +EXPORT int my32__IO_vfprintf(x64emu_t *emu, void* F, void* fmt, void* b) __attribute__((alias("my32_vfprintf"))); + +EXPORT int my32_dprintf(x64emu_t *emu, int fd, void* fmt, void* V) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, V, emu->scratch); + PREPARE_VALIST_32; + void* f = vdprintf; + return ((iFipp_t)f)(fd, fmt, VARARGS_32); + #else + return vdprintf(fd, (const char*)fmt, (va_list)V); + #endif +} +EXPORT int my32___dprintf_chk(x64emu_t *emu, int fd, void* fmt, void* V) __attribute__((alias("my32_dprintf"))); + +EXPORT int my32_fprintf(x64emu_t *emu, void* F, void* fmt, void* V) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, V, emu->scratch); + PREPARE_VALIST_32; + void* f = vfprintf; + return ((iFppp_t)f)(F, fmt, VARARGS_32); + #else + return vfprintf((FILE*)F, (const char*)fmt, (va_list)V); + #endif +} +EXPORT int my32___fprintf_chk(x64emu_t *emu, void* F, void* fmt, void* V) __attribute__((alias("my32_fprintf"))); + +EXPORT int my32_wprintf(x64emu_t *emu, void* fmt, void* V) { + #ifndef NOALIGN + // need to align on arm + myStackAlignW((const char*)fmt, V, emu->scratch); + PREPARE_VALIST_32; + void* f = vwprintf; + return ((iFpp_t)f)(fmt, VARARGS_32); + #else + // other platform don't need that + return vwprintf((const wchar_t*)fmt, (va_list)V); + #endif +} +EXPORT int my32___wprintf_chk(x64emu_t *emu, int flag, void* fmt, void* V) { + #ifndef NOALIGN + // need to align on arm + myStackAlignW((const char*)fmt, V, emu->scratch); + PREPARE_VALIST_32; + void* f = vwprintf; + return ((iFpp_t)f)(fmt, VARARGS_32); + #else + // other platform don't need that + return vwprintf((const wchar_t*)fmt, (va_list)V); + #endif +} +EXPORT int my32_fwprintf(x64emu_t *emu, void* F, void* fmt, void* V) { + #ifndef NOALIGN + // need to align on arm + myStackAlignW((const char*)fmt, V, emu->scratch); + PREPARE_VALIST_32; + void* f = vfwprintf; + return ((iFppp_t)f)(F, fmt, VARARGS_32); + #else + // other platform don't need that + return vfwprintf((FILE*)F, (const wchar_t*)fmt, V); + #endif +} +EXPORT int my32___fwprintf_chk(x64emu_t *emu, void* F, void* fmt, void* V) __attribute__((alias("my32_fwprintf"))); + +EXPORT int my32_vfwprintf(x64emu_t *emu, void* F, void* fmt, void* b) { + #ifndef NOALIGN + myStackAlignW((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vfwprintf; + return ((iFppp_t)f)(F, fmt, VARARGS_32); + #else + return vfwprintf(F, fmt, b); + #endif +} + +EXPORT int my32_vwprintf(x64emu_t *emu, void* fmt, void* b) { + #ifndef NOALIGN + myStackAlignW((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vwprintf; + return ((iFpp_t)f)(fmt, VARARGS_32); + #else + void* f = vwprintf; + return ((iFpp_t)f)(fmt, b); + #endif +} + +EXPORT void *my32_div(void *result, int numerator, int denominator) { + *(div_t *)result = div(numerator, denominator); + return result; +} + +EXPORT int my32_snprintf(x64emu_t* emu, void* buff, size_t s, void * fmt, void * b) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vsnprintf; + return ((iFpLpp_t)f)(buff, s, fmt, VARARGS_32); + #else + return vsnprintf((char*)buff, s, (char*)fmt, b); + #endif +} +EXPORT int my32___snprintf(x64emu_t* emu, void* buff, size_t s, void * fmt, void * b) __attribute__((alias("my32_snprintf"))); + +EXPORT int my32___snprintf_chk(x64emu_t* emu, void* buff, size_t s, int f1, int f2, void * fmt, void * b) { + (void)f1; (void)f2; + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vsnprintf; + return ((iFpLpp_t)f)(buff, s, fmt, VARARGS_32); + #else + return vsnprintf((char*)buff, s, (char*)fmt, b); + #endif +} + + +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 +} +EXPORT int my32___sprintf_chk(x64emu_t* emu, void* buff, void * fmt, void * b) __attribute__((alias("my32_sprintf"))); + +EXPORT int my32_asprintf(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 = vasprintf; + return ((iFppp_t)f)(buff, fmt, VARARGS_32); + #else + return vasprintf((char**)buff, (char*)fmt, b); + #endif +} +EXPORT int my32___asprintf(x64emu_t* emu, void** buff, void * fmt, void * b) __attribute__((alias("my32_asprintf"))); + +EXPORT int my32_vsprintf(x64emu_t* emu, void* buff, void * fmt, uint32_t * b) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vsprintf; + int r = ((iFppp_t)f)(buff, fmt, VARARGS_32); + return r; + #else + void* f = vsprintf; + int r = ((iFppp_t)f)(buff, fmt, b); + return r; + #endif +} +EXPORT int my32___vsprintf_chk(x64emu_t* emu, void* buff, int flags, size_t len, void * fmt, uint32_t * b) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vsprintf; + int r = ((iFppp_t)f)(buff, fmt, VARARGS_32); + return r; + #else + void* f = vsprintf; + int r = ((iFppp_t)f)(buff, fmt, b); + return r; + #endif +} + +#ifdef POWERPCLE +EXPORT int my32_vfscanf(x64emu_t* emu, void* stream, void* fmt, void* b) // probably uneeded to do a GOM, a simple wrap should enough +{ + //myStackAlign32((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32_(b); + void* f = vfscanf; + + return ((iFppp_t)f)(stream, fmt, VARARGS_32_(b)); +} + + + +EXPORT int my32_vsscanf(x64emu_t* emu, void* stream, void* fmt, void* b) +{ + //myStackAlign32((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32_(b); + void* f = vsscanf; + + return ((iFppp_t)f)(stream, fmt, VARARGS_32_(b)); +} + +EXPORT int my32__vsscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vsscanf"))); +EXPORT int my32_sscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vsscanf"))); + +EXPORT int my32__IO_vfscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vfscanf"))); +EXPORT int my32___isoc99_vsscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vsscanf"))); + +EXPORT int my32___isoc99_vfscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vfscanf"))); +EXPORT int my32___isoc99_fscanf(x64emu_t* emu, void* stream, void* fmt, void* b) __attribute__((alias("my32_vfscanf"))); + +EXPORT int my32___isoc99_sscanf(x64emu_t* emu, void* stream, void* fmt, void* b) +{ + void* f = sscanf; + PREPARE_VALIST_32; + + return ((iFppp_t)f)(stream, fmt, VARARGS_32); +} +#endif + +EXPORT int my32_vsnprintf(x64emu_t* emu, void* buff, uint32_t s, void * fmt, void * b, va_list V) { + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vsnprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, VARARGS_32); + return r; + #else + void* f = vsnprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, (uint32_t*)b); + return r; + #endif +} +EXPORT int my32___vsnprintf(x64emu_t* emu, void* buff, uint32_t s, void * fmt, void * b, va_list V) __attribute__((alias("my32_vsnprintf"))); +EXPORT int my32___vsnprintf_chk(x64emu_t* emu, void* buff, uint32_t s, void * fmt, void * b, va_list V) __attribute__((alias("my32_vsnprintf"))); + +EXPORT int my32_vasprintf(x64emu_t* emu, void* strp, void* fmt, void* b, va_list V) +{ + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vasprintf; + int r = ((iFppp_t)f)(strp, fmt, VARARGS_32); + return r; + #else + void* f = vasprintf; + int r = ((iFppp_t)f)(strp, fmt, (uint32_t*)b); + return r; + #endif +} +EXPORT int my32___vasprintf_chk(x64emu_t* emu, void* strp, int flags, void* fmt, void* b, va_list V) +{ + #ifndef NOALIGN + // need to align on arm + myStackAlign32((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vasprintf; + int r = ((iFppp_t)f)(strp, fmt, VARARGS_32); + return r; + #else + void* f = vasprintf; + int r = ((iFppp_t)f)(strp, fmt, (uint32_t*)b); + return r; + #endif +} + +EXPORT int my32___asprintf_chk(x64emu_t* emu, void* result_ptr, int flags, void* fmt, void* b) +{ + #ifndef NOALIGN + myStackAlign32((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vasprintf; + return ((iFppp_t)f)(result_ptr, fmt, VARARGS_32); + #else + return vasprintf((char**)result_ptr, (char*)fmt, b); + #endif +} + +EXPORT int my32_vswprintf(x64emu_t* emu, void* buff, uint32_t s, void * fmt, void * b, va_list V) { + #ifndef NOALIGN + // need to align on arm + myStackAlignW((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vswprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, VARARGS_32); + return r; + #else + void* f = vswprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, (uint32_t*)b); + return r; + #endif +} +EXPORT int my32___vswprintf(x64emu_t* emu, void* buff, uint32_t s, void * fmt, void * b, va_list V) __attribute__((alias("my32_vswprintf"))); +EXPORT int my32___vswprintf_chk(x64emu_t* emu, void* buff, size_t s, int flags, size_t m, void * fmt, void * b, va_list V) { + #ifndef NOALIGN + // need to align on arm + myStackAlignW((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vswprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, VARARGS_32); + return r; + #else + void* f = vswprintf; + int r = ((iFpupp_t)f)(buff, s, fmt, (uint32_t*)b); + return r; + #endif +} + +EXPORT void my32_verr(x64emu_t* emu, int eval, void* fmt, void* b) { + #ifndef NOALIGN + myStackAlignW((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = verr; + ((vFipp_t)f)(eval, fmt, VARARGS_32); + #else + void* f = verr; + ((vFipp_t)f)(eval, fmt, (uint32_t*)b); + #endif +} + +EXPORT void my32_vwarn(x64emu_t* emu, void* fmt, void* b) { + #ifndef NOALIGN + myStackAlignW((const char*)fmt, (uint32_t*)b, emu->scratch); + PREPARE_VALIST_32; + void* f = vwarn; + ((vFpp_t)f)(fmt, VARARGS_32); + #else + void* f = vwarn; + ((vFpp_t)f)(fmt, (uint32_t*)b); + #endif +} + +EXPORT int my32___swprintf_chk(x64emu_t* emu, void* s, uint32_t n, int32_t flag, uint32_t slen, void* fmt, void * b) +{ + #ifndef NOALIGN + myStackAlignW((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vswprintf; + int r = ((iFpupp_t)f)(s, n, fmt, VARARGS_32); + return r; + #else + void* f = vswprintf; + int r = ((iFpupp_t)f)(s, n, fmt, b); + return r; + #endif +} +EXPORT int my32_swprintf(x64emu_t* emu, void* s, uint32_t n, void* fmt, void *b) +{ + #ifndef NOALIGN + myStackAlignW((const char*)fmt, b, emu->scratch); + PREPARE_VALIST_32; + void* f = vswprintf; + int r = ((iFpupp_t)f)(s, n, fmt, VARARGS_32); + return r; + #else + void* f = vswprintf; + int r = ((iFpupp_t)f)(s, n, fmt, b); + return r; + #endif +} + +EXPORT void my32__ITM_addUserCommitAction(x64emu_t* emu, void* cb, uint32_t b, void* c) +{ + // disabled for now... Are all this _ITM_ stuff really mendatory? + #if 0 + // quick and dirty... Should store the callback to be removed later.... + libc_my32_t *my = (libc_my32_t *)emu->context->libclib->priv.w.p2; + x64emu_t *cbemu = AddCallback(emu, (uintptr_t)cb, 1, c, NULL, NULL, NULL); + my->_ITM_addUserCommitAction(libc1ArgCallback, b, cbemu); + // should keep track of cbemu to remove at some point... + #else + printf("warning _ITM_addUserCommitAction called\n"); + #endif +} +#endif +EXPORT void my32__ITM_registerTMCloneTable(x64emu_t* emu, void* p, uint32_t s) {} +EXPORT void my32__ITM_deregisterTMCloneTable(x64emu_t* emu, void* p) {} + + +struct i386_stat { + uint64_t st_dev; + uint32_t __pad1; + uint32_t st_ino; + uint32_t st_mode; + uint32_t st_nlink; + uint32_t st_uid; + uint32_t st_gid; + uint64_t st_rdev; + uint32_t __pad2; + int32_t st_size; + int32_t st_blksize; + int32_t st_blocks; + int32_t st_atime_sec; + uint32_t st_atime_nsec; + int32_t st_mtime_sec; + uint32_t st_mtime_nsec; + int32_t st_ctime_sec; + uint32_t st_ctime_nsec; + uint32_t __unused4; + uint32_t __unused5; +} __attribute__((packed)); + +static int FillStatFromStat64(int vers, const struct stat64 *st64, void *st32) +{ + struct i386_stat *i386st = (struct i386_stat *)st32; + + if (vers != 3) + { + errno = EINVAL; + return -1; + } + + i386st->st_dev = st64->st_dev; + i386st->__pad1 = 0; + if (fix_64bit_inodes) + { + i386st->st_ino = st64->st_ino ^ (st64->st_ino >> 32); + } + else + { + i386st->st_ino = st64->st_ino; + if ((st64->st_ino >> 32) != 0) + { + errno = EOVERFLOW; + return -1; + } + } + i386st->st_mode = st64->st_mode; + i386st->st_nlink = st64->st_nlink; + i386st->st_uid = st64->st_uid; + i386st->st_gid = st64->st_gid; + i386st->st_rdev = st64->st_rdev; + i386st->__pad2 = 0; + i386st->st_size = st64->st_size; + if ((i386st->st_size >> 31) != (int32_t)(st64->st_size >> 32)) + { + errno = EOVERFLOW; + return -1; + } + i386st->st_blksize = st64->st_blksize; + i386st->st_blocks = st64->st_blocks; + if ((i386st->st_blocks >> 31) != (int32_t)(st64->st_blocks >> 32)) + { + errno = EOVERFLOW; + return -1; + } + i386st->st_atime_sec = st64->st_atim.tv_sec; + i386st->st_atime_nsec = st64->st_atim.tv_nsec; + i386st->st_mtime_sec = st64->st_mtim.tv_sec; + i386st->st_mtime_nsec = st64->st_mtim.tv_nsec; + i386st->st_ctime_sec = st64->st_ctim.tv_sec; + i386st->st_ctime_nsec = st64->st_ctim.tv_nsec; + i386st->__unused4 = 0; + i386st->__unused5 = 0; + return 0; +} +#if 0 +#ifdef ANDROID +EXPORT int my32_stat(char* path, void* buf) +{ + struct stat64 st; + int r = stat64(path, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32_fstat(int fd, void* buf) +{ + struct stat64 st; + int r = fstat64(fd, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32_lstat(char* path, void* buf) +{ + struct stat64 st; + int r = lstat64(path, &st); + UnalignStat64(&st, buf); + return r; +} +#endif + +EXPORT int my32___fxstat(x64emu_t *emu, int vers, int fd, void* buf) +{ + if (vers == 1) + { + static iFiip_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) + { + errno = EINVAL; + return -1; + } + f = (iFiip_t)dlsym(lib->priv.w.lib, "__fxstat"); + } + + return f(vers, fd, buf); + } + struct stat64 st; + int r = fstat64(fd, &st); + if (r) return r; + r = FillStatFromStat64(vers, &st, buf); + return r; +} + +EXPORT int my32___fxstat64(x64emu_t *emu, int vers, int fd, void* buf) +{ + struct stat64 st; + int r = fstat64(fd, &st); + //int r = syscall(__NR_stat64, fd, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32_stat64(x64emu_t* emu, void* path, void* buf) +{ + struct stat64 st; + int r = stat64(path, &st); + UnalignStat64(&st, buf); + return r; +} +EXPORT int my32_lstat64(x64emu_t* emu, void* path, void* buf) +{ + struct stat64 st; + int r = lstat64(path, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32___xstat(x64emu_t* emu, int v, void* path, 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, "__xstat"); + } + + return f(v, path, buf); + } + struct stat64 st; + int r = stat64((const char*)path, &st); + if (r) return r; + r = FillStatFromStat64(v, &st, buf); + return r; +} + +EXPORT int my32___xstat64(x64emu_t* emu, int v, void* path, void* buf) +{ + struct stat64 st; + int r = stat64((const char*)path, &st); + UnalignStat64(&st, buf); + return r; +} + +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; +} + +EXPORT int my32___lxstat64(x64emu_t* emu, int v, void* name, void* buf) +{ + struct stat64 st; + int r = lstat64((const char*)name, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32___fxstatat(x64emu_t* emu, int v, int d, void* path, void* buf, int flags) +{ + struct stat64 st; + int r = fstatat64(d, path, &st, flags); + if (r) return r; + r = FillStatFromStat64(v, &st, buf); + return r; +} + +EXPORT int my32___fxstatat64(x64emu_t* emu, int v, int d, void* path, void* buf, int flags) +{ + struct stat64 st; + int r = fstatat64(d, path, &st, flags); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32__IO_file_stat(x64emu_t* emu, void* f, void* buf) +{ + struct stat64 st; + libc_my32_t *my = (libc_my32_t *)emu->context->libclib->priv.w.p2; + int r = my->_IO_file_stat(f, &st); + UnalignStat64(&st, buf); + return r; +} + +EXPORT int my32_fstatfs64(int fd, void* buf) +{ + struct statfs64 st; + int r = fstatfs64(fd, &st); + UnalignStatFS64(&st, buf); + return r; +} + +EXPORT int my32_statfs64(const char* path, void* buf) +{ + struct statfs64 st; + int r = statfs64(path, &st); + UnalignStatFS64(&st, buf); + return r; +} + + +#ifdef ANDROID +typedef int (*__compar_d_fn_t)(const void*, const void*, void*); + +static size_t qsort_r_partition(void* base, size_t size, __compar_d_fn_t compar, void* arg, size_t lo, size_t hi) +{ + void* tmp = malloc(size); + void* pivot = ((char*)base) + lo * size; + size_t i = lo; + for (size_t j = lo; j <= hi; j++) + { + void* base_i = ((char*)base) + i * size; + void* base_j = ((char*)base) + j * size; + if (compar(base_j, pivot, arg) < 0) + { + memcpy(tmp, base_i, size); + memcpy(base_i, base_j, size); + memcpy(base_j, tmp, size); + i++; + } + } + void* base_i = ((char *)base) + i * size; + void* base_hi = ((char *)base) + hi * size; + memcpy(tmp, base_i, size); + memcpy(base_i, base_hi, size); + memcpy(base_hi, tmp, size); + free(tmp); + return i; +} + +static void qsort_r_helper(void* base, size_t size, __compar_d_fn_t compar, void* arg, ssize_t lo, ssize_t hi) +{ + if (lo < hi) + { + size_t p = qsort_r_partition(base, size, compar, arg, lo, hi); + qsort_r_helper(base, size, compar, arg, lo, p - 1); + qsort_r_helper(base, size, compar, arg, p + 1, hi); + } +} + +static void qsort_r(void* base, size_t nmemb, size_t size, __compar_d_fn_t compar, void* arg) +{ + return qsort_r_helper(base, size, compar, arg, 0, nmemb - 1); +} +#endif + +typedef struct compare_r_s { + x64emu_t* emu; + uintptr_t f; + void* data; + int r; +} compare_r_t; + +static int my32_compare_r_cb(void* a, void* b, compare_r_t* arg) +{ + return (int)RunFunctionWithEmu(arg->emu, 0, arg->f, 2+arg->r, a, b, arg->data); +} +EXPORT void my32_qsort(x64emu_t* emu, void* base, size_t nmemb, size_t size, void* fnc) +{ + compare_r_t args; + args.emu = emu; args.f = (uintptr_t)fnc; args.r = 0; args.data = NULL; + qsort_r(base, nmemb, size, (__compar_d_fn_t)my32_compare_r_cb, &args); +} +EXPORT void my32_qsort_r(x64emu_t* emu, void* base, size_t nmemb, size_t size, void* fnc, void* data) +{ + compare_r_t args; + args.emu = emu; args.f = (uintptr_t)fnc; args.r = 1; args.data = data; + qsort_r(base, nmemb, size, (__compar_d_fn_t)my32_compare_r_cb, &args); +} + +EXPORT void* my32_bsearch(x64emu_t* emu, void* key, void* base, size_t nmemb, size_t size, void* fnc) +{ + return bsearch(key, base, nmemb, size, findcompareFct(fnc)); +} + +EXPORT void* my32_lsearch(x64emu_t* emu, void* key, void* base, size_t* nmemb, size_t size, void* fnc) +{ + return lsearch(key, base, nmemb, size, findcompareFct(fnc)); +} +EXPORT void* my32_lfind(x64emu_t* emu, void* key, void* base, size_t* nmemb, size_t size, void* fnc) +{ + return lfind(key, base, nmemb, size, findcompareFct(fnc)); +} + + +struct i386_dirent { + uint32_t d_ino; + int32_t d_off; + uint16_t d_reclen; + uint8_t d_type; + char d_name[256]; +}; + +EXPORT void* my32_readdir(x64emu_t* emu, void* dirp) +{ + if (fix_64bit_inodes) + { + struct dirent64 *dp64 = readdir64((DIR *)dirp); + if (!dp64) return NULL; + uint32_t ino32 = dp64->d_ino ^ (dp64->d_ino >> 32); + int32_t off32 = dp64->d_off; + struct i386_dirent *dp32 = (struct i386_dirent *)&(dp64->d_off); + dp32->d_ino = ino32; + dp32->d_off = off32; + dp32->d_reclen -= 8; + return dp32; + } + else + { + static pFp_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) return NULL; + f = (pFp_t)dlsym(lib->priv.w.lib, "readdir"); + } + + return f(dirp); + } +} + +EXPORT int32_t my32_readdir_r(x64emu_t* emu, void* dirp, void* entry, void** result) +{ + struct dirent64 d64, *dp64; + if (fix_64bit_inodes && (sizeof(d64.d_name) > 1)) + { + static iFppp_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) + { + *result = NULL; + return 0; + } + f = (iFppp_t)dlsym(lib->priv.w.lib, "readdir64_r"); + } + + int r = f(dirp, &d64, &dp64); + if (r || !dp64 || !entry) + { + *result = NULL; + return r; + } + + struct i386_dirent *dp32 = (struct i386_dirent *)entry; + int namelen = dp64->d_reclen - offsetof(struct dirent64, d_name); + if (namelen > sizeof(dp32->d_name)) + { + *result = NULL; + return ENAMETOOLONG; + } + + dp32->d_ino = dp64->d_ino ^ (dp64->d_ino >> 32); + dp32->d_off = dp64->d_off; + dp32->d_reclen = namelen + offsetof(struct i386_dirent, d_name); + dp32->d_type = dp64->d_type; + memcpy(dp32->d_name, dp64->d_name, namelen); + *result = dp32; + return 0; + } + else + { + static iFppp_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) + { + *result = NULL; + return 0; + } + f = (iFppp_t)dlsym(lib->priv.w.lib, "readdir_r"); + } + + return f(dirp, entry, result); + } +} +#endif +static int isProcSelf(const char *path, const char* w) +{ + if(strncmp(path, "/proc/", 6)==0) { + char tmp[64]; + // check if self .... + sprintf(tmp, "/proc/self/%s", w); + if(strcmp((const char*)path, tmp)==0) + return 1; + // check if self PID .... + pid_t pid = getpid(); + sprintf(tmp, "/proc/%d/%s", pid, w); + if(strcmp((const char*)path, tmp)==0) + return 1; + } + return 0; +} + +EXPORT int32_t my32_readlink(x64emu_t* emu, void* path, void* buf, uint32_t sz) +{ + if(isProcSelf((const char*)path, "exe")) { + // special case for self... + return strlen(strncpy((char*)buf, emu->context->fullpath, sz)); + } + return readlink((const char*)path, (char*)buf, sz); +} +#ifndef NOALIGN + +void CreateCPUInfoFile(int fd); +int getNCpu(); +static int isCpuTopology(const char* p) { + if(strstr(p, "/sys/devices/system/cpu/cpu")!=p) + return -1; //nope + if( FileExist(p, -1)) + return -1; //no need to fake it + char buf[512]; + const char* p2 = p + strlen("/sys/devices/system/cpu/cpu"); + int n = 0; + while(*p2>='0' && *p2<='9') { + n = n*10+ *p2 - '0'; + ++p2; + } + if(n>=getNCpu()) // filter for non existing cpu + return -1; + snprintf(buf, 512, "/sys/devices/system/cpu/cpu%d/topology/core_id", n); + if(!strcmp(p, buf)) + return n; + return -1; +} +static void CreateCPUTopologyCoreID(int fd, int cpu) +{ + char buf[512]; + snprintf(buf, 512, "%d\n", cpu); + size_t dummy = write(fd, buf, strlen(buf)); + (void)dummy; +} + + +#ifdef ANDROID +static int shm_open(const char *name, int oflag, mode_t mode) { + return -1; +} +static int shm_unlink(const char *name) { + return -1; +} +#endif +#endif +#define TMP_CPUINFO "box32_tmpcpuinfo" +#define TMP_CPUTOPO "box32_tmpcputopo%d" + +#define TMP_MEMMAP "box32_tmpmemmap" +#define TMP_CMDLINE "box32_tmpcmdline" +EXPORT int32_t my32_open(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mode) +{ + if(isProcSelf((const char*) pathname, "cmdline")) { + // special case for self command line... + #if 0 + char tmpcmdline[200] = {0}; + char tmpbuff[100] = {0}; + sprintf(tmpbuff, "%s/cmdlineXXXXXX", getenv("TMP")?getenv("TMP"):"."); + int tmp = mkstemp(tmpbuff); + int dummy; + if(tmp<0) return open(pathname, flags, mode); + dummy = write(tmp, emu->context->fullpath, strlen(emu->context->fullpath)+1); + for (int i=1; i<emu->context->argc; ++i) + dummy = write(tmp, emu->context->argv[i], strlen(emu->context->argv[i])+1); + lseek(tmp, 0, SEEK_SET); + #else + int tmp = shm_open(TMP_CMDLINE, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open(pathname, flags, mode); + shm_unlink(TMP_CMDLINE); // remove the shm file, but it will still exist because it's currently in use + int dummy = write(tmp, emu->context->fullpath, strlen(emu->context->fullpath)+1); + (void)dummy; + for (int i=1; i<emu->context->argc; ++i) + dummy = write(tmp, emu->context->argv[i], strlen(emu->context->argv[i])+1); + lseek(tmp, 0, SEEK_SET); + #endif + return tmp; + } + if(isProcSelf((const char*)pathname, "exe")) { + return open(emu->context->fullpath, flags, mode); + } + #ifndef NOALIGN + if(strcmp((const char*)pathname, "/proc/cpuinfo")==0) { + // special case for cpuinfo + int tmp = shm_open(TMP_CPUINFO, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open(pathname, flags, mode); // error fallback + shm_unlink(TMP_CPUINFO); // remove the shm file, but it will still exist because it's currently in use + CreateCPUInfoFile(tmp); + lseek(tmp, 0, SEEK_SET); + return tmp; + } + if(isCpuTopology((const char*)pathname)!=-1) { + int n = isCpuTopology((const char*)pathname); + char buf[512]; + snprintf(buf, 512, TMP_CPUTOPO, n); + int tmp = shm_open(buf, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open(pathname, flags, mode); // error fallback + shm_unlink(buf); // remove the shm file, but it will still exist because it's currently in use + CreateCPUTopologyCoreID(tmp, n); + lseek(tmp, 0, SEEK_SET); + return tmp; + } + #endif + int ret = open(pathname, flags, mode); + return ret; +} +EXPORT int32_t my32___open(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mode) __attribute__((alias("my32_open"))); + +#ifdef DYNAREC +static int hasDBFromAddress(uintptr_t addr) +{ + int idx = (addr>>DYNAMAP_SHIFT); + return getDB(idx)?1:0; +} +#endif + +EXPORT int32_t my32_read(int fd, void* buf, uint32_t count) +{ + int ret = read(fd, buf, count); +#ifdef DYNAREC + if(ret!=count && ret>0) { + // continue reading... + void* p = buf+ret; + if(hasDBFromAddress((uintptr_t)p)) { + // allow writing the whole block (this happens with HalfLife, libMiles load code directly from .mix and other file like that) + unprotectDB((uintptr_t)p, count-ret, 1); + int l; + do { + l = read(fd, p, count-ret); + if(l>0) { + p+=l; ret+=l; + } + } while(l>0); + } + } +#endif + return ret; +} + +EXPORT int32_t my32_open64(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mode) +{ + if(isProcSelf((const char*)pathname, "cmdline")) { + // special case for self command line... + #if 0 + char tmpcmdline[200] = {0}; + char tmpbuff[100] = {0}; + sprintf(tmpbuff, "%s/cmdlineXXXXXX", getenv("TMP")?getenv("TMP"):"."); + int tmp = mkstemp64(tmpbuff); + int dummy; + if(tmp<0) return open64(pathname, flags, mode); + dummy = write(tmp, emu->context->fullpath, strlen(emu->context->fullpath)+1); + for (int i=1; i<emu->context->argc; ++i) + dummy = write(tmp, emu->context->argv[i], strlen(emu->context->argv[i])+1); + lseek64(tmp, 0, SEEK_SET); + #else + int tmp = shm_open(TMP_CMDLINE, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open64(pathname, flags, mode); + shm_unlink(TMP_CMDLINE); // remove the shm file, but it will still exist because it's currently in use + int dummy = write(tmp, emu->context->fullpath, strlen(emu->context->fullpath)+1); + (void)dummy; + for (int i=1; i<emu->context->argc; ++i) + dummy = write(tmp, emu->context->argv[i], strlen(emu->context->argv[i])+1); + lseek(tmp, 0, SEEK_SET); + #endif + return tmp; + } + if(isProcSelf((const char*)pathname, "exe")) { + return open64(emu->context->fullpath, flags, mode); + } + #ifndef NOALIGN + if(strcmp((const char*)pathname, "/proc/cpuinfo")==0) { + // special case for cpuinfo + int tmp = shm_open(TMP_CPUINFO, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open64(pathname, flags, mode); // error fallback + shm_unlink(TMP_CPUINFO); // remove the shm file, but it will still exist because it's currently in use + CreateCPUInfoFile(tmp); + lseek(tmp, 0, SEEK_SET); + return tmp; + } + if(isCpuTopology((const char*)pathname)!=-1) { + int n = isCpuTopology((const char*)pathname); + char buf[512]; + snprintf(buf, 512, TMP_CPUTOPO, n); + int tmp = shm_open(buf, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return open64(pathname, flags, mode); // error fallback + shm_unlink(buf); // remove the shm file, but it will still exist because it's currently in use + CreateCPUTopologyCoreID(tmp, n); + lseek(tmp, 0, SEEK_SET); + return tmp; + } + #endif + return open64(pathname, flags, mode); +} + +EXPORT FILE* my32_fopen(x64emu_t* emu, const char* path, const char* mode) +{ + if(isProcSelf(path, "maps")) { + // special case for self memory map + int tmp = shm_open(TMP_MEMMAP, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen(path, mode); // error fallback + shm_unlink(TMP_MEMMAP); // remove the shm file, but it will still exist because it's currently in use + CreateMemorymapFile(emu->context, tmp); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode); + } + #ifndef NOALIGN + if(strcmp(path, "/proc/cpuinfo")==0) { + // special case for cpuinfo + int tmp = shm_open(TMP_CPUINFO, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen(path, mode); // error fallback + shm_unlink(TMP_CPUINFO); // remove the shm file, but it will still exist because it's currently in use + CreateCPUInfoFile(tmp); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode); + } + if(isCpuTopology(path)!=-1) { + int n = isCpuTopology(path); + char buf[512]; + snprintf(buf, 512, TMP_CPUTOPO, n); + int tmp = shm_open(buf, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen(path, mode); // error fallback + shm_unlink(buf); // remove the shm file, but it will still exist because it's currently in use + CreateCPUTopologyCoreID(tmp, n); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode);; + } + #endif + if(isProcSelf(path, "exe")) { + return fopen(emu->context->fullpath, mode); + } + return fopen(path, mode); +} + +EXPORT FILE* my32_fopen64(x64emu_t* emu, const char* path, const char* mode) +{ + if(isProcSelf(path, "maps")) { + // special case for self memory map + int tmp = shm_open(TMP_MEMMAP, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen64(path, mode); // error fallback + shm_unlink(TMP_MEMMAP); // remove the shm file, but it will still exist because it's currently in use + CreateMemorymapFile(emu->context, tmp); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode); + } + #ifndef NOALIGN + if(strcmp(path, "/proc/cpuinfo")==0) { + // special case for cpuinfo + int tmp = shm_open(TMP_CPUINFO, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen64(path, mode); // error fallback + shm_unlink(TMP_CPUINFO); // remove the shm file, but it will still exist because it's currently in use + CreateCPUInfoFile(tmp); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode); + } + if(isCpuTopology(path)!=-1) { + int n = isCpuTopology(path); + char buf[512]; + snprintf(buf, 512, TMP_CPUTOPO, n); + int tmp = shm_open(buf, O_RDWR | O_CREAT, S_IRWXU); + if(tmp<0) return fopen(path, mode); // error fallback + shm_unlink(buf); // remove the shm file, but it will still exist because it's currently in use + CreateCPUTopologyCoreID(tmp, n); + lseek(tmp, 0, SEEK_SET); + return fdopen(tmp, mode);; + } + #endif + if(isProcSelf(path, "exe")) { + return fopen64(emu->context->fullpath, mode); + } + return fopen64(path, mode); +} + +#if 0 +EXPORT int my32_mkstemps64(x64emu_t* emu, char* template, int suffixlen) +{ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "mkstemps64"); + if(f) + return ((iFpi_t)f)(template, suffixlen); + // implement own version... + // TODO: check size of template, and if really XXXXXX is there + char* fname = strdup(template); + do { + strcpy(fname, template); + char num[8]; + sprintf(num, "%06d", rand()%999999); + memcpy(fname+strlen(fname)-suffixlen-6, num, 6); + } while(!FileExist(fname, -1)); + int ret = open64(fname, O_EXCL); + free(fname); + return ret; +} + +EXPORT int32_t my32_ftw(x64emu_t* emu, void* pathname, void* B, int32_t nopenfd) +{ + static iFppi_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) return 0; + f = (iFppi_t)dlsym(lib->priv.w.lib, "ftw"); + } + + return f(pathname, findftwFct(B), nopenfd); +} + +EXPORT int32_t my32_nftw(x64emu_t* emu, void* pathname, void* B, int32_t nopenfd, int32_t flags) +{ + static iFppii_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) return 0; + f = (iFppii_t)dlsym(lib->priv.w.lib, "nftw"); + } + + return f(pathname, findnftwFct(B), nopenfd, flags); +} + +EXPORT void* my32_ldiv(x64emu_t* emu, void* p, int32_t num, int32_t den) +{ + *((ldiv_t*)p) = ldiv(num, den); + return p; +} + +#ifndef NOALIGN +EXPORT int my32_epoll_create(x64emu_t* emu, int size) +{ + return epoll_create(size); +} +EXPORT int my32_epoll_create1(x64emu_t* emu, int flags) +{ + return epoll_create1(flags); +} +EXPORT int32_t my32_epoll_ctl(x64emu_t* emu, int32_t epfd, int32_t op, int32_t fd, void* event) +{ + struct epoll_event _event[1] = {0}; + if(event && (op!=EPOLL_CTL_DEL)) + AlignEpollEvent(_event, event, 1); + return epoll_ctl(epfd, op, fd, event?_event:event); +} +EXPORT int32_t my32_epoll_wait(x64emu_t* emu, int32_t epfd, void* events, int32_t maxevents, int32_t timeout) +{ + struct epoll_event _events[maxevents]; + //AlignEpollEvent(_events, events, maxevents); + int32_t ret = epoll_wait(epfd, events?_events:NULL, maxevents, timeout); + if(ret>0) + UnalignEpollEvent(events, _events, ret); + return ret; +} +#endif + +EXPORT int32_t my32_glob(x64emu_t *emu, void* pat, int32_t flags, void* errfnc, void* pglob) +{ + static iFpipp_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) return 0; + f = (iFpipp_t)dlsym(lib->priv.w.lib, "glob"); + } + + return f(pat, flags, findgloberrFct(errfnc), pglob); +} + +#ifndef ANDROID +EXPORT int32_t my32_glob64(x64emu_t *emu, void* pat, int32_t flags, void* errfnc, void* pglob) +{ + return glob64(pat, flags, findgloberrFct(errfnc), pglob); +} +#endif + +EXPORT int my32_scandir64(x64emu_t *emu, void* dir, void* namelist, void* sel, void* comp) +{ + return scandir64(dir, namelist, findfilter64Fct(sel), findcompare64Fct(comp)); +} + +EXPORT int my32_scandir(x64emu_t *emu, void* dir, void* namelist, void* sel, void* comp) +{ + static iFpppp_t f = NULL; + if(!f) { + library_t* lib = my_lib; + if(!lib) return 0; + f = (iFpppp_t)dlsym(lib->priv.w.lib, "scandir"); + } + + return f(dir, namelist, findfilter_dirFct(sel), findcompare_dirFct(comp)); +} + +EXPORT int my32_ftw64(x64emu_t* emu, void* filename, void* func, int descriptors) +{ + return ftw64(filename, findftw64Fct(func), descriptors); +} + +EXPORT int32_t my32_nftw64(x64emu_t* emu, void* pathname, void* B, int32_t nopenfd, int32_t flags) +{ + return nftw64(pathname, findnftw64Fct(B), nopenfd, flags); +} + +EXPORT int32_t my32_execv(x64emu_t* emu, const char* path, char* const argv[]) +{ + int self = isProcSelf(path, "exe"); + int x86 = FileIsX86ELF(path); + int x64 = my_context->box64path?FileIsX64ELF(path):0; + printf_log(LOG_DEBUG, "execv(\"%s\", %p) is x86=%d\n", path, argv, x86); + if (x86 || x64 || self) { + int skip_first = 0; + if(strlen(path)>=strlen("wine-preloader") && strcmp(path+strlen(path)-strlen("wine-preloader"), "wine-preloader")==0) + skip_first++; + // count argv... + int n=skip_first; + while(argv[n]) ++n; + const char** newargv = (const char**)calloc(n+2, sizeof(char*)); + newargv[0] = x64?emu->context->box64path:emu->context->box64path; + memcpy(newargv+1, argv+skip_first, sizeof(char*)*(n+1)); + if(self) newargv[1] = emu->context->fullpath; + printf_log(LOG_DEBUG, " => execv(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box64path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); + int ret = execv(newargv[0], (char* const*)newargv); + free(newargv); + return ret; + } + return execv(path, argv); +} +#endif +EXPORT int32_t my32_execve(x64emu_t* emu, const char* path, char* const argv[], char* const envp[]) +{ + int self = isProcSelf(path, "exe"); + int x86 = FileIsX86ELF(path); + int x64 = my_context->box64path?FileIsX64ELF(path):0; + // hack to update the environ var if needed + if(envp == my_context->envv && environ) { + envp = environ; + } + printf_log(LOG_DEBUG, "execve(\"%s\", %p, %p) is x86=%d\n", path, argv, envp, x86); + if (x86 || x64 || self) { + int skip_first = 0; + if(strlen(path)>=strlen("wine-preloader") && strcmp(path+strlen(path)-strlen("wine-preloader"), "wine-preloader")==0) + skip_first++; + // count argv... + int n=skip_first; + while(argv[n]) ++n; + const char** newargv = (const char**)calloc(n+2, sizeof(char*)); + newargv[0] = x64?emu->context->box64path:emu->context->box64path; + memcpy(newargv+1, argv+skip_first, sizeof(char*)*(n+1)); + if(self) newargv[1] = emu->context->fullpath; + printf_log(LOG_DEBUG, " => execve(\"%s\", %p [\"%s\", \"%s\", \"%s\"...:%d])\n", emu->context->box64path, newargv, newargv[0], n?newargv[1]:"", (n>1)?newargv[2]:"",n); + int ret = execve(newargv[0], (char* const*)newargv, envp); + free(newargv); + return ret; + } + if(!strcmp(path + strlen(path) - strlen("/uname"), "/uname") + && argv[1] && (!strcmp(argv[1], "-m") || !strcmp(argv[1], "-p") || !strcmp(argv[1], "-i")) + && !argv[2]) { + // uname -m is redirected to box32 -m + path = my_context->box64path; + char *argv2[3] = { my_context->box64path, argv[1], NULL }; + return execve(path, argv2, envp); + } + + return execve(path, argv, envp); +} +#if 0 +// execvp should use PATH to search for the program first +EXPORT int32_t my32_execvp(x64emu_t* emu, const char* path, char* const argv[]) +{ + // need to use BOX32_PATH / PATH here... + char* fullpath = ResolveFile(path, &my_context->box32_path); + // use fullpath... + int self = isProcSelf(fullpath, "exe"); + int x86 = FileIsX86ELF(fullpath); + int x64 = my_context->box64path?FileIsX64ELF(path):0; + printf_log(LOG_DEBUG, "execvp(\"%s\", %p), IsX86=%d / fullpath=\"%s\"\n", path, argv, x86, fullpath); + free(fullpath); + if (x86 || self) { + // count argv... + int i=0; + while(argv[i]) ++i; + char** newargv = (char**)calloc(i+2, sizeof(char*)); + newargv[0] = x64?emu->context->box64path:emu->context->box64path; + for (int j=0; j<i; ++j) + newargv[j+1] = argv[j]; + if(self) newargv[1] = emu->context->fullpath; + printf_log(LOG_DEBUG, " => execvp(\"%s\", %p [\"%s\", \"%s\"...:%d])\n", newargv[0], newargv, newargv[1], i?newargv[2]:"", i); + int ret = execvp(newargv[0], newargv); + free(newargv); + 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 box32 -m + path = my_context->box64path; + char *argv2[3] = { my_context->box64path, argv[1], NULL }; + return execvp(path, argv2); + } + + // fullpath is gone, so the search will only be on PATH, not on BOX32_PATH (is that an issue?) + return execvp(path, argv); +} + +// execvp should use PATH to search for the program first +EXPORT int32_t my32_posix_spawnp(x64emu_t* emu, pid_t* pid, const char* path, + const posix_spawn_file_actions_t *actions, const posix_spawnattr_t* attrp, char* const argv[], char* const envp[]) +{ + // need to use BOX32_PATH / PATH here... + char* fullpath = ResolveFile(path, &my_context->box32_path); + // use fullpath... + int self = isProcSelf(fullpath, "exe"); + int x86 = FileIsX86ELF(fullpath); + int x64 = my_context->box64path?FileIsX64ELF(path):0; + printf_log(LOG_DEBUG, "posix_spawnp(%p, \"%s\", %p, %p, %p, %p), IsX86=%d / fullpath=\"%s\"\n", pid, path, actions, attrp, argv, envp, x86, fullpath); + free(fullpath); + if ((x86 || self)) { + // count argv... + int i=0; + while(argv[i]) ++i; + char** newargv = (char**)calloc(i+2, sizeof(char*)); + newargv[0] = x64?emu->context->box64path:emu->context->box64path; + for (int j=0; j<i; ++j) + newargv[j+1] = argv[j]; + if(self) newargv[1] = emu->context->fullpath; + printf_log(LOG_DEBUG, " => posix_spawnp(%p, \"%s\", %p, %p, %p [\"%s\", \"%s\"...:%d], %p)\n", pid, newargv[0], actions, attrp, newargv, newargv[1], i?newargv[2]:"", i, envp); + int ret = posix_spawnp(pid, newargv[0], actions, attrp, newargv, envp); + printf_log(LOG_DEBUG, "posix_spawnp returned %d\n", ret); + //free(newargv); + return ret; + } + // fullpath is gone, so the search will only be on PATH, not on BOX32_PATH (is that an issue?) + return posix_spawnp(pid, path, actions, attrp, argv, envp); +} +#endif +EXPORT void my32__Jv_RegisterClasses() {} + +EXPORT int32_t my32___cxa_thread_atexit_impl(x64emu_t* emu, void* dtor, void* obj, void* dso) +{ + printf_log(LOG_INFO, "Warning, call to __cxa_thread_atexit_impl(%p, %p, %p) ignored\n", dtor, obj, dso); + return 0; +} +#if 0 +#ifndef ANDROID +extern void __chk_fail(); +EXPORT unsigned long int my32___fdelt_chk (unsigned long int d) +{ + if (d >= FD_SETSIZE) + __chk_fail (); + + return d / __NFDBITS; +} +#endif + +EXPORT int32_t my32_getrandom(x64emu_t* emu, void* buf, uint32_t buflen, uint32_t flags) +{ + // not always implemented on old linux version... + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "getrandom"); + if(f) + return ((iFpuu_t)f)(buf, buflen, flags); + // do what should not be done, but it's better then nothing.... + FILE * rnd = fopen("/dev/urandom", "rb"); + uint32_t r = fread(buf, 1, buflen, rnd); + fclose(rnd); + return r; +} + +static struct passwd fakepwd = {}; +EXPORT void* my32_getpwuid(x64emu_t* emu, uint32_t uid) +{ + void *ret = NULL; + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "getpwuid"); + if(f) + ret = ((pFu_t)f)(uid); + + // In case of failure, provide a fake one. Evil hack :/ + if (!ret && !fakepwd.pw_name) { + fakepwd.pw_name = strdup("root"); + fakepwd.pw_passwd = strdup("fakehash"); + fakepwd.pw_uid = 0; + fakepwd.pw_gid = 0; + fakepwd.pw_gecos = strdup("root"); + fakepwd.pw_dir = getenv("HOME"); + fakepwd.pw_shell = strdup("/bin/bash"); + } + + return ret ? ret : (void*)&fakepwd; +} + +EXPORT int32_t my32_recvmmsg(x64emu_t* emu, int32_t fd, void* msgvec, uint32_t vlen, uint32_t flags, void* timeout) +{ + // Implemented starting glibc 2.12+ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "recvmmsg"); + if(f) + return ((iFipuup_t)f)(fd, msgvec, vlen, flags, timeout); + // Use the syscall + return syscall(__NR_recvmmsg, fd, msgvec, vlen, flags, timeout); +} + +EXPORT int32_t my32___sendmmsg(x64emu_t* emu, int32_t fd, void* msgvec, uint32_t vlen, uint32_t flags) +{ + // Implemented starting glibc 2.14+ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "__sendmmsg"); + if(f) + return ((iFipuu_t)f)(fd, msgvec, vlen, flags); + // Use the syscall + return syscall(__NR_sendmmsg, fd, msgvec, vlen, flags); +} + +EXPORT int32_t my32___register_atfork(x64emu_t *emu, void* prepare, void* parent, void* child, void* handle) +{ + // this is partly incorrect, because the emulated funcionts should be executed by actual fork and not by my32_atfork... + if(my_context->atfork_sz==my_context->atfork_cap) { + my_context->atfork_cap += 4; + my_context->atforks = (atfork_fnc_t*)realloc(my_context->atforks, my_context->atfork_cap*sizeof(atfork_fnc_t)); + } + my_context->atforks[my_context->atfork_sz].prepare = (uintptr_t)prepare; + my_context->atforks[my_context->atfork_sz].parent = (uintptr_t)parent; + my_context->atforks[my_context->atfork_sz].child = (uintptr_t)child; + my_context->atforks[my_context->atfork_sz].handle = handle; + return 0; +} + +EXPORT uint64_t my32___umoddi3(uint64_t a, uint64_t b) +{ + return a%b; +} +EXPORT uint64_t my32___udivdi3(uint64_t a, uint64_t b) +{ + return a/b; +} +EXPORT int64_t my32___divdi3(int64_t a, int64_t b) +{ + return a/b; +} + +EXPORT int32_t my32___poll_chk(void* a, uint32_t b, int c, int l) +{ + return poll(a, b, c); // no check... +} + +EXPORT int32_t my32_fcntl64(x64emu_t* emu, int32_t a, int32_t b, uint32_t d1, uint32_t d2, uint32_t d3, uint32_t d4, uint32_t d5, uint32_t d6) +{ + // Implemented starting glibc 2.14+ + library_t* lib = my_lib; + if(!lib) return 0; + iFiiV_t f = dlsym(lib->priv.w.lib, "fcntl64"); + if(b==F_SETFL) + d1 = of_convert32(d1); + if(b==F_GETLK64 || b==F_SETLK64 || b==F_SETLKW64) + { + my32_flock64_t fl; + AlignFlock64(&fl, (void*)d1); + int ret = f?f(a, b, &fl):fcntl(a, b, &fl); + UnalignFlock64((void*)d1, &fl); + return ret; + } + //TODO: check if better to use the syscall or regular fcntl? + //return syscall(__NR_fcntl64, a, b, d1); // should be enough + int ret = f?f(a, b, d1):fcntl(a, b, d1); + + if(b==F_GETFL && ret!=-1) + ret = of_unconvert32(ret); + + return ret; +} + +EXPORT int32_t my32_fcntl(x64emu_t* emu, int32_t a, int32_t b, uint32_t d1, uint32_t d2, uint32_t d3, uint32_t d4, uint32_t d5, uint32_t d6) +{ + if(b==F_SETFL && d1==0xFFFFF7FF) { + // special case for ~O_NONBLOCK... + int flags = fcntl(a, F_GETFL); + if(flags&X86_O_NONBLOCK) { + flags &= ~O_NONBLOCK; + return fcntl(a, b, flags); + } + return 0; + } + if(b==F_SETFL) + d1 = of_convert32(d1); + if(b==F_GETLK64 || b==F_SETLK64 || b==F_SETLKW64) + { + my32_flock64_t fl; + AlignFlock64(&fl, (void*)d1); + int ret = fcntl(a, b, &fl); + UnalignFlock64((void*)d1, &fl); + return ret; + } + int ret = fcntl(a, b, d1); + if(b==F_GETFL && ret!=-1) + ret = of_unconvert32(ret); + + return ret; +} +EXPORT int32_t my32___fcntl(x64emu_t* emu, int32_t a, int32_t b, uint32_t d1, uint32_t d2, uint32_t d3, uint32_t d4, uint32_t d5, uint32_t d6) __attribute__((alias("my32_fcntl"))); + +EXPORT int32_t my32_preadv64(x64emu_t* emu, int32_t fd, void* v, int32_t c, int64_t o) +{ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "preadv64"); + if(f) + return ((iFipiI_t)f)(fd, v, c, o); + return syscall(__NR_preadv, fd, v, c,(uint32_t)(o&0xffffffff), (uint32_t)((o>>32)&0xffffffff)); +} + +EXPORT int32_t my32_pwritev64(x64emu_t* emu, int32_t fd, void* v, int32_t c, int64_t o) +{ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "pwritev64"); + if(f) + return ((iFipiI_t)f)(fd, v, c, o); + #ifdef __arm__ + return syscall(__NR_pwritev, fd, v, c, 0, (uint32_t)(o&0xffffffff), (uint32_t)((o>>32)&0xffffffff)); + // on arm, 64bits args needs to be on even/odd register, so need to put a 0 for aligment + #else + return syscall(__NR_pwritev, fd, v, c,(uint32_t)(o&0xffffffff), (uint32_t)((o>>32)&0xffffffff)); + #endif +} + +EXPORT int32_t my32_accept4(x64emu_t* emu, int32_t fd, void* a, void* l, int32_t flags) +{ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "accept4"); + if(f) + return ((iFippi_t)f)(fd, a, l, flags); + if(!flags) + return accept(fd, a, l); + return syscall(__NR_accept4, fd, a, l, flags); +} + +EXPORT int32_t my32_fallocate64(int fd, int mode, int64_t offs, int64_t len) +{ + iFiiII_t f = NULL; + static int done = 0; + if(!done) { + library_t* lib = my_lib; + f = (iFiiII_t)dlsym(lib->priv.w.lib, "fallocate64"); + done = 1; + } + if(f) + return f(fd, mode, offs, len); + else + return syscall(__NR_fallocate, fd, mode, (uint32_t)(offs&0xffffffff), (uint32_t)((offs>>32)&0xffffffff), (uint32_t)(len&0xffffffff), (uint32_t)((len>>32)&0xffffffff)); + //return posix_fallocate64(fd, offs, len); +} + +EXPORT int my32_getopt(int argc, char* const argv[], const char *optstring) +{ + int ret = getopt(argc, argv, optstring); + my32_checkGlobalOpt(); + return ret; +} + +EXPORT int my32_getopt_long(int argc, char* const argv[], const char* optstring, const struct option *longopts, int *longindex) +{ + int ret = getopt_long(argc, argv, optstring, longopts, longindex); + my32_checkGlobalOpt(); + return ret; +} + +EXPORT int my32_getopt_long_only(int argc, char* const argv[], const char* optstring, const struct option *longopts, int *longindex) +{ + int ret = getopt_long_only(argc, argv, optstring, longopts, longindex); + my32_checkGlobalOpt(); + return ret; +} +#endif + +EXPORT struct __processor_model +{ + unsigned int __cpu_vendor; + unsigned int __cpu_type; + unsigned int __cpu_subtype; + unsigned int __cpu_features[1]; +} my32___cpu_model; + +#include "cpu_info.h" +void InitCpuModel() +{ + // some pseudo random cpu info... + my32___cpu_model.__cpu_vendor = VENDOR_INTEL; + my32___cpu_model.__cpu_type = INTEL_PENTIUM_M; + my32___cpu_model.__cpu_subtype = 0; // N/A + my32___cpu_model.__cpu_features[0] = (1<<FEATURE_CMOV) + | (1<<FEATURE_MMX) + | (1<<FEATURE_SSE) + | (1<<FEATURE_SSE2) + | (1<<FEATURE_SSE3) + | (1<<FEATURE_SSSE3) + | (1<<FEATURE_MOVBE) + | (1<<FEATURE_ADX); +} + +EXPORT const unsigned short int *my32___ctype_b; +EXPORT const int32_t *my32___ctype_tolower; +EXPORT const int32_t *my32___ctype_toupper; + +#ifdef ANDROID +static void ctSetup() +{ +} +#else +static void ctSetup() +{ + my32___ctype_b = *(__ctype_b_loc()); + my32___ctype_toupper = *(__ctype_toupper_loc()); + my32___ctype_tolower = *(__ctype_tolower_loc()); +} +#endif + +#if 0 +EXPORT void my32___register_frame_info(void* a, void* b) +{ + // nothing +} +EXPORT void* my32___deregister_frame_info(void* a) +{ + return NULL; +} + +EXPORT void* my32____brk_addr = NULL; +#endif +// longjmp / setjmp +typedef struct jump_buff_i386_s { + uint32_t save_ebx; + uint32_t save_esi; + uint32_t save_edi; + uint32_t save_ebp; + uint32_t save_esp; + uint32_t save_eip; +} jump_buff_i386_t; + +typedef struct __jmp_buf_tag_s { + jump_buff_i386_t __jmpbuf; + int __mask_was_saved; + sigset_t __saved_mask; +} __jmp_buf_tag_t; + +void EXPORT my32_longjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int32_t __val) +{ + jump_buff_i386_t *jpbuff = &((__jmp_buf_tag_t*)p)->__jmpbuf; + //restore regs + R_EBX = jpbuff->save_ebx; + R_ESI = jpbuff->save_esi; + R_EDI = jpbuff->save_edi; + R_EBP = jpbuff->save_ebp; + R_ESP = jpbuff->save_esp; + // jmp to saved location, plus restore val to eax + R_EAX = __val; + R_EIP = jpbuff->save_eip; + if(((__jmp_buf_tag_t*)p)->__mask_was_saved) { + sigprocmask(SIG_SETMASK, &((__jmp_buf_tag_t*)p)->__saved_mask, NULL); + } + if(emu->flags.quitonlongjmp) { + emu->flags.longjmp = 1; + emu->quit = 1; + } +} + +EXPORT int32_t my32___sigsetjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p, int savesigs) +{ + jump_buff_i386_t *jpbuff = &((__jmp_buf_tag_t*)p)->__jmpbuf; + // save the buffer + jpbuff->save_ebx = R_EBX; + jpbuff->save_esi = R_ESI; + jpbuff->save_edi = R_EDI; + jpbuff->save_ebp = R_EBP; + jpbuff->save_esp = R_ESP+4; // include "return address" + jpbuff->save_eip = *(uint32_t*)from_ptr(R_ESP); + if(savesigs) { + if(sigprocmask(SIG_SETMASK, NULL, &((__jmp_buf_tag_t*)p)->__saved_mask)) + ((__jmp_buf_tag_t*)p)->__mask_was_saved = 0; + else + ((__jmp_buf_tag_t*)p)->__mask_was_saved = 1; + } else + ((__jmp_buf_tag_t*)p)->__mask_was_saved = 0; + return 0; +} + +EXPORT int32_t my32__setjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p) +{ + return my32___sigsetjmp(emu, p, 0); +} +EXPORT int32_t my32_setjmp(x64emu_t* emu, /*struct __jmp_buf_tag __env[1]*/void *p) +{ + return my32___sigsetjmp(emu, p, 1); +} +#if 0 +EXPORT void my32___explicit_bzero_chk(x64emu_t* emu, void* dst, uint32_t len, uint32_t dstlen) +{ + memset(dst, 0, len); +} + +EXPORT void* my32_realpath(x64emu_t* emu, void* path, void* resolved_path) +{ + + if(isProcSelf(path, "exe")) { + return realpath(emu->context->fullpath, resolved_path); + } + return realpath(path, resolved_path); +} + +EXPORT int my32_readlinkat(x64emu_t* emu, int fd, void* path, void* buf, size_t bufsize) +{ + if(isProcSelf(path, "exe")) { + strncpy(buf, emu->context->fullpath, bufsize); + size_t l = strlen(emu->context->fullpath); + return (l>bufsize)?bufsize:(l+1); + } + return readlinkat(fd, path, buf, bufsize); +} + +#endif +EXPORT void* my32_mmap(x64emu_t* emu, void *addr, size_t length, int prot, int flags, int fd, int offset) +{ + if(prot&PROT_WRITE) + prot|=PROT_READ; // PROT_READ is implicit with PROT_WRITE on i386 + #ifdef __x86_64__ + flags |= MAP_32BIT; + #endif + if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "mmap(%p, %zu, 0x%x, 0x%x, %d, %d) =>", addr, length, prot, flags, fd, offset);} + void* new_addr = addr?addr:find32bitBlock(length); + void* ret = mmap(new_addr, length, prot, flags, fd, offset); + if(!addr && ret!=new_addr && ret!=(void*)-1) { + munmap(ret, length); + loadProtectionFromMap(); // reload map, because something went wrong previously + new_addr = find31bitBlockNearHint(addr, length, 0); // is this the best way? + ret = mmap(new_addr, length, prot, flags, fd, offset); + } + if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "%p\n", ret);} + #ifdef DYNAREC + if(box64_dynarec && ret!=(void*)-1) { + if(flags&0x100000 && addr!=ret) + { + // program used MAP_FIXED_NOREPLACE but the host linux didn't support it + // and responded with a different address, so ignore it + } else { + if(prot& PROT_EXEC) + addDBFromAddressRange((uintptr_t)ret, length); + else + cleanDBFromAddressRange((uintptr_t)ret, length, prot?0:1); + } + } + #endif + if(ret!=(void*)-1) + setProtection((uintptr_t)ret, length, prot); + return ret; +} + +EXPORT void* my32_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int flags, int fd, int64_t offset) +{ + if(prot&PROT_WRITE) + prot|=PROT_READ; // PROT_READ is implicit with PROT_WRITE on i386 + if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "mmap64(%p, %zu, 0x%x, 0x%x, %d, %ld) =>", addr, length, prot, flags, fd, offset);} + void* new_addr = (flags&MAP_FIXED)?addr:find31bitBlockNearHint(addr, length, 0); + void* ret = mmap64(new_addr, length, prot, flags, fd, offset); + if(!addr && ret!=new_addr && ret!=(void*)-1) { + munmap(ret, length); + loadProtectionFromMap(); // reload map, because something went wrong previously + new_addr = find31bitBlockNearHint(addr, length, 0); + ret = mmap64(new_addr, length, prot, flags, fd, offset); + } else if(addr && ret!=(void*)-1 && ret!=new_addr && + ((uintptr_t)ret&0xffff) && !(flags&MAP_FIXED) && box64_wine) { + munmap(ret, length); + loadProtectionFromMap(); // reload map, because something went wrong previously + new_addr = find31bitBlockNearHint(addr, length, 0); + ret = mmap64(new_addr, length, prot, flags, fd, offset); + if(ret!=(void*)-1 && ret!=addr && ((uintptr_t)ret&0xffff) && box64_wine) { + // addr is probably too high, start again with a low address + munmap(ret, length); + loadProtectionFromMap(); // reload map, because something went wrong previously + new_addr = find31bitBlockNearHint(NULL, length, 0); // is this the best way? + ret = mmap64(new_addr, length, prot, flags, fd, offset); + if(ret!=(void*)-1 && (uintptr_t)ret&0xffff) { + munmap(ret, length); + ret = (void*)-1; + } + } + } + if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "%p\n", ret);} + #ifdef DYNAREC + if(box64_dynarec && ret!=(void*)-1) { + if(flags&0x100000 && addr!=ret) + { + // program used MAP_FIXED_NOREPLACE but the host linux didn't support it + // and responded with a different address, so ignore it + } else { + if(prot& PROT_EXEC) + addDBFromAddressRange((uintptr_t)ret, length); + else + cleanDBFromAddressRange((uintptr_t)ret, length, prot?0:1); + } + } + #endif + if(ret!=(void*)-1) + setProtection((uintptr_t)ret, length, prot); + return ret; +} + +EXPORT void* my32_mremap(x64emu_t* emu, void* old_addr, size_t old_size, size_t new_size, int flags, void* new_addr) +{ + dynarec_log(/*LOG_DEBUG*/LOG_NONE, "mremap(%p, %zu, %zu, %d, %p)=>", old_addr, old_size, new_size, flags, new_addr); + void* ret = mremap(old_addr, old_size, new_size, flags, new_addr); + dynarec_log(/*LOG_DEBUG*/LOG_NONE, "%p\n", ret); + if(ret==(void*)-1) + return ret; // failed... + uint32_t prot = getProtection((uintptr_t)old_addr)&~PROT_CUSTOM; + if(ret==old_addr) { + if(old_size && old_size<new_size) { + setProtection((uintptr_t)ret+old_size, new_size-old_size, prot); + #ifdef DYNAREC + if(box64_dynarec) + addDBFromAddressRange((uintptr_t)ret+old_size, new_size-old_size); + #endif + } else if(old_size && new_size<old_size) { + freeProtection((uintptr_t)ret+new_size, old_size-new_size); + #ifdef DYNAREC + if(box64_dynarec) + cleanDBFromAddressRange((uintptr_t)ret+new_size, new_size-old_size, 1); + #endif + } else if(!old_size) { + setProtection((uintptr_t)ret, new_size, prot); + #ifdef DYNAREC + if(box64_dynarec) + addDBFromAddressRange((uintptr_t)ret, new_size); + #endif + } + } else { + if(old_size + #ifdef MREMAP_DONTUNMAP + && !(flags&MREMAP_DONTUNMAP) + #endif + ) { + freeProtection((uintptr_t)old_addr, old_size); + #ifdef DYNAREC + if(box64_dynarec) + cleanDBFromAddressRange((uintptr_t)old_addr, old_size, 1); + #endif + } + setProtection((uintptr_t)ret, new_size, prot); // should copy the protection from old block + #ifdef DYNAREC + if(box64_dynarec) + addDBFromAddressRange((uintptr_t)ret, new_size); + #endif + } + return ret; +} + +EXPORT int my32_munmap(x64emu_t* emu, void* addr, unsigned long length) +{ + dynarec_log(LOG_DEBUG, "munmap(%p, %lu)\n", addr, length); + #ifdef DYNAREC + if(box64_dynarec) { + cleanDBFromAddressRange((uintptr_t)addr, length, 1); + } + #endif + int ret = munmap(addr, length); + if(!ret) + freeProtection((uintptr_t)addr, length); + return ret; +} + +EXPORT int my32_mprotect(x64emu_t* emu, void *addr, unsigned long len, int prot) +{ + dynarec_log(LOG_DEBUG, "mprotect(%p, %lu, 0x%x)\n", addr, len, prot); + if(prot&PROT_WRITE) + prot|=PROT_READ; // PROT_READ is implicit with PROT_WRITE on i386 + int ret = mprotect(addr, len, prot); + #ifdef DYNAREC + if(box64_dynarec) { + if(prot& PROT_EXEC) + addDBFromAddressRange((uintptr_t)addr, len); + else + cleanDBFromAddressRange((uintptr_t)addr, len, 0); + } + #endif + if(!ret) + updateProtection((uintptr_t)addr, len, prot); + return ret; +} +#if 0 +#ifndef ANDROID +typedef struct my32_cookie_s { + uintptr_t r, w, s, c; + void* cookie; +} my32_cookie_t; + +static ssize_t my32_cookie_read(void *p, char *buf, size_t size) +{ + my32_cookie_t* cookie = (my32_cookie_t*)p; + return (ssize_t)RunFunction(my_context, cookie->r, 3, cookie->cookie, buf, size); +} +static ssize_t my32_cookie_write(void *p, const char *buf, size_t size) +{ + my32_cookie_t* cookie = (my32_cookie_t*)p; + return (ssize_t)RunFunction(my_context, cookie->w, 3, cookie->cookie, buf, size); +} +static int my32_cookie_seek(void *p, off64_t *offset, int whence) +{ + my32_cookie_t* cookie = (my32_cookie_t*)p; + return RunFunction(my_context, cookie->s, 3, cookie->cookie, offset, whence); +} +static int my32_cookie_close(void *p) +{ + my32_cookie_t* cookie = (my32_cookie_t*)p; + int ret = 0; + if(cookie->c) + ret = RunFunction(my_context, cookie->c, 1, cookie->cookie); + free(cookie); + return ret; +} +EXPORT void* my32_fopencookie(x64emu_t* emu, void* cookie, void* mode, void* read, void* write, void* seek, void* close) +{ + cookie_io_functions_t io_funcs = {read?my32_cookie_read:NULL, write?my32_cookie_write:NULL, seek?my32_cookie_seek:NULL, my32_cookie_close}; + my32_cookie_t *cb = (my32_cookie_t*)calloc(1, sizeof(my32_cookie_t)); + cb->r = (uintptr_t)read; + cb->w = (uintptr_t)write; + cb->s = (uintptr_t)seek; + cb->c = (uintptr_t)close; + cb->cookie = cookie; + return fopencookie(cb, mode, io_funcs); +} +#endif + +EXPORT long my32_prlimit64(void* pid, uint32_t res, void* new_rlim, void* old_rlim) +{ + return syscall(__NR_prlimit64, pid, res, new_rlim, old_rlim); +} + +EXPORT void* my32_reallocarray(void* ptr, size_t nmemb, size_t size) +{ + return realloc(ptr, nmemb*size); +} + +#ifndef __OPEN_NEEDS_MODE +# define __OPEN_NEEDS_MODE(oflag) \ + (((oflag) & O_CREAT) != 0) +// || ((oflag) & __O_TMPFILE) == __O_TMPFILE) +#endif +EXPORT int my32___open_nocancel(x64emu_t* emu, void* file, int oflag, int* b) +{ + int mode = 0; + if (__OPEN_NEEDS_MODE (oflag)) + mode = b[0]; + return openat(AT_FDCWD, file, oflag, mode); +} + +EXPORT int my32___libc_alloca_cutoff(x64emu_t* emu, size_t size) +{ + // not always implemented on old linux version... + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "__libc_alloca_cutoff"); + if(f) + return ((iFL_t)f)(size); + // approximate version but it's better than nothing.... + return (size<=(65536*4)); +} + +// DL functions from wrappedlibdl.c +void* my32_dlopen(x64emu_t* emu, void *filename, int flag); +int my32_dlclose(x64emu_t* emu, void *handle); +void* my32_dlsym(x64emu_t* emu, void *handle, void *symbol); +EXPORT int my32___libc_dlclose(x64emu_t* emu, void* handle) +{ + return my32_dlclose(emu, handle); +} +EXPORT void* my32___libc_dlopen_mode(x64emu_t* emu, void* name, int mode) +{ + return my32_dlopen(emu, name, mode); +} +EXPORT void* my32___libc_dlsym(x64emu_t* emu, void* handle, void* name) +{ + return my32_dlsym(emu, handle, name); +} +#endif +// all obstack function defined in obstack.c file +void obstackSetup(); +#if 0 +EXPORT int my32_nanosleep(const struct timespec *req, struct timespec *rem) +{ + if(!req) + return 0; // workaround for some strange calls + return nanosleep(req, rem); +} +#endif +// wrapped malloc using calloc, it seems x86 malloc set alloc'd block to zero somehow +EXPORT void* my32_malloc(unsigned long size) +{ + return calloc(1, size); +} +#if 0 +#ifndef __NR_memfd_create +#define MFD_CLOEXEC 0x0001U +#define MFD_ALLOW_SEALING 0x0002U +EXPORT int my32_memfd_create(x64emu_t* emu, void* name, uint32_t flags) +{ + // try to simulate that function + uint32_t fl = O_RDWR | O_CREAT; + if(flags&MFD_CLOEXEC) + fl |= O_CLOEXEC; + int tmp = shm_open(name, fl, S_IRWXU); + if(tmp<0) return -1; + shm_unlink(name); // remove the shm file, but it will still exist because it's currently in use + return tmp; +} +#endif + +#ifndef GRND_RANDOM +#define GRND_RANDOM 0x0002 +#endif +EXPORT int my32_getentropy(x64emu_t* emu, void* buffer, size_t length) +{ + library_t* lib = my_lib; + if(!lib) return 0; + void* f = dlsym(lib->priv.w.lib, "getentropy"); + if(f) + return ((iFpL_t)f)(buffer, length); + // custom implementation + if(length>256) { + errno = EIO; + return -1; + } + int ret = my32_getrandom(emu, buffer, length, GRND_RANDOM); + if(ret!=length) { + errno = EIO; + return -1; + } + return 0; +} + +EXPORT void my32_mcount(void* frompc, void* selfpc) +{ + // stub doing nothing... + return; +} + +#ifndef ANDROID +union semun { + int val; /* Value for SETVAL */ + struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */ + unsigned short *array; /* Array for GETALL, SETALL */ + struct seminfo *__buf; /* Buffer for IPC_INFO + (Linux-specific) */ +}; +#endif + +EXPORT int my32_semctl(x64emu_t* emu, int semid, int semnum, int cmd, union semun b) +{ + iFiiiV_t f = semctl; + return ((iFiiiV_t)f)(semid, semnum, cmd, b); +} + +#ifndef ANDROID +EXPORT int my32_on_exit(x64emu_t* emu, void* f, void* args) +{ + return on_exit(findon_exitFct(f), args); +} +#endif +#endif + +EXPORT long my32_strtol(void* nptr, ptr_t* endptr, int base) +{ + void* endp; + long ret = strtol(nptr, (char**)(endptr?(&endp):NULL), base); + if(endptr) + *endptr = to_ptrv(endp); + return ret; +} + +EXPORT char** my32_environ = NULL; +EXPORT char** my32__environ = NULL; +EXPORT char** my32___environ = NULL; // all aliases + +EXPORT char* my32___progname = NULL; +EXPORT char* my32___progname_full = NULL; +EXPORT char* my32_program_invocation_name = NULL; +EXPORT char* my32_program_invocation_short_name = NULL; + +EXPORT ptr_t my32_stdin = 0; +EXPORT ptr_t my32_stdout = 0; +EXPORT ptr_t my32_stderr = 0; + +EXPORT int my32___libc_single_threaded = 0; + +#define PRE_INIT\ + if(1) \ + my_lib = lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);\ + else + +#ifdef ANDROID +//#define NEEDED_LIBS \ +// "libm.so", "libdl.so" +#else +#define NEEDED_LIBS \ + "ld-linux.so.2", "libpthread.so.0", "librt.so.1", "libdl.so.2" +#endif + +#define CUSTOM_INIT \ + box64->libclib = lib; \ + my_lib = lib; \ + InitCpuModel(); \ + ctSetup(); \ + /*obstackSetup();*/ \ + my32_environ = my32__environ = my32___environ = box64->envv; \ + my32___progname_full = my32_program_invocation_name = box64->argv[0]; \ + my32___progname = my32_program_invocation_short_name = \ + strrchr(box64->argv[0], '/'); \ + my32_stdin = to_hashv(stdin); \ + my32_stdout = to_hashv(stdout);\ + my32_stderr = to_hashv(stderr); + +#include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedlibc_private.h b/src/wrapped32/wrappedlibc_private.h new file mode 100755 index 00000000..c43f0f21 --- /dev/null +++ b/src/wrapped32/wrappedlibc_private.h @@ -0,0 +1,2178 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA) && defined(GOS)) +#error Meh... +#endif + +// FILE* is h (because stdin/stdout/stderr might be 64bits, maybe other special file can be too) +// locale_t needs special handling, with to_locale / from_locale (and is a / A) + +// a64l +//GO(abort, vFv) +//GO(abs, iFi) +//GOW(accept, iFipp) +//GOM(accept4, iFEippi) //%% glibc 2.10+ +//GOW(access, iFpi) +// acct +//GOW(addmntent, iFpp) +// addseverity +// adjtime // Weak +// adjtimex // Weak +// __adjtimex +// advance // Weak +// __aeabi_assert +// __aeabi_atexit +// __aeabi_errno_addr +// __aeabi_localeconv +// __aeabi_MB_CUR_MAX +// __aeabi_memclr +// __aeabi_memclr4 +// __aeabi_memclr8 +// __aeabi_memcpy +// __aeabi_memcpy4 +// __aeabi_memcpy8 +// __aeabi_memmove +// __aeabi_memmove4 +// __aeabi_memmove8 +// __aeabi_memset +// __aeabi_memset4 +// __aeabi_memset8 +//DATAV(__after_morecore_hook, 4) +GO(alarm, iFu) +//GO2(aligned_alloc, pFuu, memalign) +//GO(alphasort, iFpp) +//GO(alphasort64, iFpp) +//DATA(argp_err_exit_status, 4) +// argp_error // Weak +// argp_failure // Weak +// argp_help // Weak +// argp_parse // Weak +// argp_program_bug_address // type B +// argp_program_version // type B +// argp_program_version_hook // type B +// argp_state_help // Weak +// argp_usage // Weak +// argz_add // Weak +// argz_add_sep // Weak +// argz_append // Weak +// __argz_count +// argz_count // Weak +// argz_create // Weak +//GOW(argz_create_sep, iFpipp) +// argz_delete +// argz_extract // Weak +//GOW(argz_insert, iFpppp) +// __argz_next +//GOW(argz_next, pFpLp) +// argz_replace // Weak +// __argz_stringify +//GOW(argz_stringify, vFpLi) +//GO(asctime, pFp) +//GOW(asctime_r, pFpp) +//GOWM(asprintf, iFEppV) //%% +//GOM(__asprintf, iFEppV) //%% +//GOM(__asprintf_chk, iFEpipV) //%% +// __assert +//GO(__assert_fail, vFppup) +//GO(__assert_perror_fail, vFipup) +//GO(atof, dFp) +//GO(atoi, iFp) +//GO(atol, lFp) +//GO(atoll, IFp) +// authdes_create +// authdes_getucred +// authdes_pk_create +// _authenticate +// authnone_create +// authunix_create +// authunix_create_default +//GOW(backtrace, iFpi) //TODO: probably a my_backtrace version, that use emulated stack instead +//GO(__backtrace, iFpi) +//GO(__backtrace_symbols, pFpi) +//GOW(backtrace_symbols, pFpi) +//GO(__backtrace_symbols_fd, vFpii) +//GOW(backtrace_symbols_fd, vFpii) +//GO(basename, pFp) +//GOW(bcmp, iFppL) +//GO(bcopy, vFppL) +// bdflush +//GOW(bind, iFipu) +// bindresvport +//GOW(bindtextdomain, pFpp) +//GOW(bind_textdomain_codeset, pFpp) +//GOW(brk, iFp) +// __bsd_getpgrp +// bsd_signal // Weak +//GOM(bsearch, pFEppLLp) //%% +GOW(btowc, iFi) +//GOW(bzero, vFpL) +//GO(__bzero, vFpL) +GOW(calloc, pFLL) +// callrpc +//GOW(canonicalize_file_name, pFp) +// capget +// capset +//GO(catclose, iFp) +//GO(catgets, pFpiip) +//GO(catopen, pFpi) +// cbc_crypt +//GO(cfgetispeed, uFp) +//GO(cfgetospeed, uFp) +//GO(cfmakeraw, vFp) +//GOW(cfree, vFp) +//GO(cfsetispeed, iFpu) +//GO(cfsetospeed, iFpu) +//GO(cfsetspeed, iFpi) +//GOW(chdir, iFp) +//DATA(__check_rhosts_file, 4) +// chflags +// __chk_fail +//GOW(chmod, iFpu) +GOW(chown, iFpuu) +//GO(chroot, iFp) +//GOW(clearenv, iFv) +//GO(clearerr, vFp) +//GO(clearerr_unlocked, vFp) +// clnt_broadcast +// clnt_create +// clnt_pcreateerror +// clnt_perrno +// clnt_perror +// clntraw_create +// clnt_spcreateerror +// clnt_sperrno +// clnt_sperror +// clnttcp_create +// clntudp_bufcreate +// clntudp_create +// clntunix_create +GO(clock, LFv) +// clone // Weak +// __clone +GOW(close, iFi) +// __close // Weak +//GOW(closedir, iFp) +GO(closelog, vFv) +//GO(__cmsg_nxthdr, pFpp) +//GO(confstr, uFipu) +// __confstr_chk +//GOW(connect, iFipu) +//GOW(__connect, iFipu) +// copysign // Weak +// copysignf // Weak +// copysignl // Weak +//GOW(creat, iFpu) +//GO(creat64, iFpu) +// create_module // Weak +//GO(ctermid, pFp) +//GO(ctime, pFp) +//GO(ctime_r, pFpp) +//DATAM(__ctype_b, 4) +//GO(__ctype_b_loc, pFv) +//GOW(__ctype_get_mb_cur_max, LFv) +//DATAM(__ctype_tolower, 4) +//GO(__ctype_tolower_loc, pFv) +//DATAM(__ctype_toupper, 4) +//GO(__ctype_toupper_loc, pFv) +// __curbrk // type B +//GO(cuserid, pFp) +GOM(__cxa_atexit, iFEppp) //%% +GOM(atexit, iFEp) //%% just in case +GOM(__cxa_finalize, vFEp) //%% +DATAM(__cpu_model, 16) +//GOM(__cxa_thread_atexit_impl, iFEppp) //%% +// __cyg_profile_func_enter +// __cyg_profile_func_exit +// daemon +//DATAV(daylight, 4) +// __daylight // type B +//GOW(dcgettext, pFppi) +//GO(__dcgettext, pFppi) +//GOW(dcngettext, pFpppui) +// __default_morecore +// __default_rt_sa_restorer_v1 +// __default_rt_sa_restorer_v2 +// __default_sa_restorer_v1 +// __default_sa_restorer_v2 +// delete_module +// des_setparity +//GOW(dgettext, pFpp) +//GO(__dgettext, pFpp) +//GO(difftime, dFuu) +//GO(dirfd, iFp) +//GO(dirname, pFp) +//GOS(div, pFpii) //%%,noE +// _dl_addr +//GOM(dl_iterate_phdr, iFEpp) //%% +// _dl_mcount_wrapper +// _dl_mcount_wrapper_check +// _dl_open_hook // type B +// _dl_starting_up // Weak +// _dl_sym +// _dl_vsym +//GOW(dngettext, pFpppu) +//GOM(dprintf, iFEipV) +//GOM(__dprintf_chk, iFEivpV) //%% +GO(drand48, dFv) +// drand48_r +GOW(dup, iFi) +GOW(dup2, iFii) +GO(__dup2, iFii) +GO(dup3, iFiiO) +//GOW(duplocale, pFp) +//GO(__duplocale, pFp) +// dysize +//GOW(eaccess, iFpi) +// ecb_crypt +// ecvt +//GO(ecvt_r, iFdipppL) +// endaliasent +// endfsent +GO(endgrent, vFv) +GO(endhostent, vFv) +//GOW(endmntent, iFp) +// __endmntent +// endnetent +// endnetgrent +GO(endprotoent, vFv) +GO(endpwent, vFv) +// endrpcent +GO(endservent, vFv) +GO(endspent, vFv) +// endttyent +// endusershell +GOW(endutent, vFv) +// endutxent +//DATAM(environ, 4) +//DATAM(_environ, 4) +//DATAM(__environ, 4) // type B +// envz_add +// envz_entry +// envz_get +// envz_merge +// envz_remove +// envz_strip +GOM(epoll_create, iFEi) //%% not needed, but used in syscall +GOM(epoll_create1, iFEO) //%% +//GOM(epoll_ctl, iFEiiip) //%% align epool_event structure +// epoll_pwait +//GOM(epoll_wait, iFEipii) //%% need realign of epoll_event structure +// erand48 +// erand48_r // Weak +//GO(err, vFippppppppp) +// errno // type B +//GO(__errno_location, pFv) +//GOW(error, vFiippppppppp) // Simple attempt: there is a vararg, but the alignment will/may be off if it tries some Double in the "printf" part +// error_at_line // Weak +// error_message_count // type B +// error_one_per_line // type B +// error_print_progname // type B +//GO(errx, vFippppppppp) +//GO(ether_aton, pFp) +//GO(ether_aton_r, pFpp) +//GO(ether_hostton, iFpp) +//GO(ether_line, iFppp) +//GO(ether_ntoa, pFp) +//GO(ether_ntoa_r, pFpp) +//GO(ether_ntohost, iFpp) +//GOW(euidaccess, iFpi) +//GO(eventfd, iFui) +//GO(eventfd_read, iFip) +//GO(eventfd_write, iFiU) +//GO2(execl, iFEpV, my_execv) +//GO2(execle, iFEpV, my_execve) // Nope! This one needs wrapping, because is char*, char*, ..., char*[] +//GO2(execlp, iFpV, execvp) +//GOWM(execv, iFEpp) //%% +//GOM(execve, iFEppp) //%% and this one too... +//GOWM(execvp, iFEpp) +GO(exit, vFi) +GO(_exit, vFi) +GOW(_Exit, vFi) +//GOM(__explicit_bzero_chk, vFEpuu) //%% not always defined +//GO(faccessat, iFipii) +// fattach +//GO(__fbufsize, uFp) +GOW(fchdir, iFi) +// fchflags +GOW(fchmod, iFiu) +//GO(fchmodat, iFipui) +GOW(fchown, iFiuu) +//GO(fchownat, iFipuii) +GO(fclose, iFH) +GOW(fcloseall, iFv) +GOM(fcntl, iFEiiN) //%% this also use a vararg for 3rd argument +GOM(__fcntl, iFEiiN) //%% +GOM(fcntl64, iFEiiN) //%% +//GO(fcvt, pFdipp) +//GO(fcvt_r, iFdipppL) +GO(fdatasync, iFi) +// fdetach +//GO(fdopen, pFip) +//GOW(fdopendir, pFi) +//GOW(feof, iFp) +//GO(feof_unlocked, iFp) +//GOW(ferror, iFp) +//GO(ferror_unlocked, iFp) +//GO(fexecve, iFipp) //TODO: Check if needed to be wrapped, and target checked for x86 / native? +GOW(fflush, iFh) +//GO(fflush_unlocked, iFS) +GO(ffs, iFi) +// __ffs +GOW(ffsl, iFi) +GO(ffsll, iFI) +GOW(fgetc, iFh) +GOW(fgetc_unlocked, iFh) +// fgetgrent +// fgetgrent_r // Weak +//GO(fgetpos, iFpp) +//GO(fgetpos64, iFpp) +// fgetpwent +// fgetpwent_r // Weak +//GOW(fgets, pFpip) +//GO(__fgets_chk, pFpuip) +// fgetspent +// fgetspent_r // Weak +//GO(fgets_unlocked, pFpip) +// __fgets_unlocked_chk +//GOW(fgetwc, iFp) +//GOW(fgetwc_unlocked, iFp) +//GO(fgetws, pFpip) +// __fgetws_chk +//GO(fgetws_unlocked, pFpip) +// __fgetws_unlocked_chk +//GO(fgetxattr, iFippu) +//GO(fileno, iFp) +//GOW(fileno_unlocked, iFp) +GOW(finite, iFd) +GO(__finite, iFd) +GOW(finitef, iFf) +// __finitef +// finitel // Weak +// __finitel +// __flbf +//GO(flistxattr, iFipu) +GOW(flock, iFii) +//GOW(flockfile, vFp) +GOW(_flushlbf, vFv) +//GO(fmemopen, pFpup) +// fmtmsg +//GO(fnmatch, iFppi) +GOM(fopen, hFEpp) //%% +//GOWM(fopen64, pFEpp) //%% +//GOM(fopencookie, pFEpppppp) //%% last 4p are a struct with 4 callbacks... +GOWM(fork, iFEv) //%% +GOM(__fork, iFEv) //%% +// __fortify_fail +GOW(fpathconf, iFii) +//GO(__fpending, uFp) +//GOM(fprintf, iFEppV) //%% +//GOM(__fprintf_chk, iFEpvpV) //%% +// __fpu_control // type B +//GO(__fpurge, vFp) +//GOW(fputc, iFip) +//GO(fputc_unlocked, iFip) +GOW(fputs, iFhp) // Weak +//GO(fputs_unlocked, iFpp) +//GO(fputwc, iFip) +//GO(fputwc_unlocked, iFip) +//GO(fputws, iFpp) +//GO(fputws_unlocked, iFpp) +//GOW(fread, LFpLLp) +//GO(__freadable, iFp) +//GO(__fread_chk, uFpuuup) +//GO(__freading, iFp) +//GO(fread_unlocked, uFpuup) +//GO(__fread_unlocked_chk, uFpuuup) +GO(free, vFp) +//GO(freeaddrinfo, vFp) +//DATAV(__free_hook, 4) +//GO(freeifaddrs, vFp) +GOW(freelocale, vFA) +GO(__freelocale, vFA) +//GO(fremovexattr, iFip) +//GO(freopen, pFppp) +//GO(freopen64, pFppp) +// frexp // Weak +// frexpf // Weak +// frexpl // Weak +//GO2(fscanf, iFppV, vfscanf) +//GO(fseek, iFpli) +//GO(fseeko, iFpli) +//GO(fseeko64, iFpIi) +//GO(__fsetlocking, iFpi) +//GO(fsetpos, iFpp) +//GO(fsetpos64, iFpp) +//GO(fsetxattr, iFippui) +//GOW(fstatfs, iFip) +//GOWM(fstatfs64, iFip) //%%,noE +//GO(fstatvfs, iFip) +//GOW(fstatvfs64, iFip) // alignment? +GOW(fsync, iFi) +//GOW(ftell, lFp) +//GO(ftello, lFp) +//GO(ftello64, IFp) +//GO(ftime, iFp) +//GO(ftok, iFpi) +GOW(ftruncate, iFiu) +GOW(ftruncate64, iFiI) +//GOW(ftrylockfile, iFp) +//GOM(fts_children, pFEpi) //%% +//GOM(fts_close, iFEp) //%% +//GOM(fts_open, pFEpip) //%% +//GOM(fts_read, pFEp) //%% +// fts_set +//GOM(ftw, iFEppi) //%% +//GOM(ftw64, iFEppi) //%% +//GOW(funlockfile, vFp) +//GO(futimens, iFip) +//GOW(futimes, iFip) //int futimes(int fd, const struct timeval tv[2]) +//GO(futimesat, iFippp) +// fwide +//GOWM(fwprintf, iFEppV) //%% +//GOM(__fwprintf_chk, iFEpvpV) //%% +//GO(__fwritable, iFp) +GOW(fwrite, LFpLLh) +//GO(fwrite_unlocked, uFpuup) +//GO(__fwriting, iFp) +// fwscanf +//GOM(__fxstat, iFEiip) //%% +//GOM(__fxstat64, iFEiip) //%% need reaalign of struct stat64 +//GOM(__fxstatat, iFEiippi) //%% +//GOM(__fxstatat64, iFEiippi) //%% struct stat64 again +// __gai_sigqueue +//GO(gai_strerror, pFi) +// __gconv_get_alias_db +// __gconv_get_cache +// __gconv_get_modules_db +// gcvt +//GO(getaddrinfo, iFpppp) +// getaliasbyname +// getaliasbyname_r +// getaliasent +// getaliasent_r +// get_avphys_pages // Weak +//GOW(getc, iFp) +GOW(getchar, iFv) +GO(getchar_unlocked, iFv) +GOM(getcontext, iFEp) //%% +//GOW(getc_unlocked, iFp) +//GO(get_current_dir_name, pFv) +//GOW(getcwd, pFpL) +//GO(__getcwd_chk, pFpLL) +//GO(getdate, pFp) +// getdate_err // type B +// getdate_r // Weak +//GOW(getdelim, iFppip) +//GOW(__getdelim, iFppip) +// getdirentries +// getdirentries64 +//GO(getdomainname, iFpu) +// __getdomainname_chk +GOW(getdtablesize, iFv) +GOW(getegid, iFv) +GO(getenv, pFp) +//GOW(geteuid, pFv) +// getfsent +// getfsfile +// getfsspec +GOW(getgid, iFv) +//GO(getgrent, pFv) +// getgrent_r +//GO(getgrgid, pFu) +//GO(getgrgid_r, iFuppup) +//GO(getgrnam, pFp) +//GO(getgrnam_r, iFpppup) +//GO(getgrouplist, iFpipp) +GOW(getgroups, iFiu) +// __getgroups_chk +//GO(gethostbyaddr, pFpui) +//GO(gethostbyaddr_r, iFpuippupp) +//GO(gethostbyname, pFp) +//GO(gethostbyname2, pFpi) +//GO(gethostbyname2_r, iFpippupp) +//GO(gethostbyname_r, iFpppupp) +//GO(gethostent, pFv) +//GO(gethostent_r, iFppupp) +// gethostid +//GOW(gethostname, iFpu) +// __gethostname_chk +//GO(getifaddrs, iFp) +// getipv4sourcefilter +//GOW(getitimer, iFip) +// get_kernel_syms // Weak +//GOW(getline, iFppp) +//GO(getloadavg, iFpi) +//GO(getlogin, pFv) +//GO(getlogin_r, iFpu) +// __getlogin_r_chk +//GO(getmntent, pFp) +// __getmntent_r +//GOW(getmntent_r, pFpppi) +// getmsg +// get_myaddress +//GO(getnameinfo, iFpupupui) +// getnetbyaddr +// getnetbyaddr_r +// getnetbyname +// getnetbyname_r +// getnetent +// getnetent_r +// getnetgrent +// getnetgrent_r // Weak +// getnetname +//GOW(get_nprocs, iFv) +//GOW(get_nprocs_conf, iFv) +//GOM(getopt, iFipp) //%noE +//GOM(getopt_long, iFipppp) //%noE +//GOM(getopt_long_only, iFipppp) //%noE +GOW(getpagesize, iFv) +GO(__getpagesize, iFv) +//GO(getpass, pFp) +//GOW(getpeername, iFipp) +GOW(getpgid, uFu) +// __getpgid +GO(getpgrp, iFv) +// get_phys_pages // Weak +GO(getpid, uFv) +GO(__getpid, uFv) +// getpmsg +GOW(getppid, uFv) +GO(getpriority, iFii) +//GOM(getrandom, iFEpuu) //%% +//GO(getprotobyname, pFp) +//GO(getprotobyname_r, iFpppup) +//GO(getprotobynumber, pFi) +//GO(getprotobynumber_r, iFippup) +//GO(getprotoent, pFv) +//GO(getprotoent_r, iFppup) +GOW(getpt, iFv) +// getpublickey +// getpw // Weak +//GO(getpwent, pFv) +// getpwent_r +//GO(getpwnam, pFp) +//GO(getpwnam_r, iFpppup) +//GOM(getpwuid, pFEu) +//GO(getpwuid_r, iFuppup) +//GOW(getresgid, iFppp) +//GOW(getresuid, iFppp) +//GO(getrlimit, iFip) +//GO(getrlimit64, iFip) +// getrpcbyname +// getrpcbyname_r +// getrpcbynumber +// getrpcbynumber_r +// getrpcent +// getrpcent_r +// getrpcport +//GOW(getrusage, iFip) +//GOW(gets, pFp) +// __gets_chk +// getsecretkey +//GO(getservbyname, pFpp) +//GO(getservbyname_r, iFppppup) +//GO(getservbyport, pFip) +//GO(getservbyport_r, iFipppup) +// getservent +//GO(getservent_r, iFppup) +GO(getsid, uFu) +//GOW(getsockname, iFipp) +//GOW(getsockopt, iFiiipp) +// getsourcefilter +//GO(getspent, pFv) +// getspent_r +//GO(getspnam, pFp) +// getspnam_r +// getsubopt +//GOW(gettext, pFp) +//GOW(gettimeofday, iFpp) +//GO(__gettimeofday, iFpp) +// getttyent +// getttynam +GOW(getuid, uFv) +// getusershell +//GOW(getutent, pFv) +//GOW(getutent_r, iFpp) +//GOW(getutid, pFp) +//GOW(getutid_r, iFppp) +//GOW(getutline, pFp) +//GOW(getutline_r, iFppp) +// getutmp +// getutmpx +// getutxent +// getutxid +// getutxline +// getw +//GO2(getwc, iFp, fgetwc) +GO(getwchar, iFv) +GO(getwchar_unlocked, iFv) +//GOW(getwc_unlocked, iFp) +//GO(getwd, pFp) +// __getwd_chk +//GO(getxattr, iFpppu) +//GOM(glob, iFEpipp) //%% +//GOM(glob64, iFEpipp) //%% +//GO(globfree, vFp) +//GO(globfree64, vFp) +// glob_pattern_p // Weak +//GO(gmtime, pFp) +//GO(__gmtime_r, pFpp) +//GOW(gmtime_r, pFpp) +GO(gnu_dev_major, uFU) +GO(gnu_dev_makedev, UFii) // dev_t seems to be a u64 +GO(gnu_dev_minor, uFU) +//GOW(gnu_get_libc_release, pFv) +//GOW(gnu_get_libc_version, pFv) +// __gnu_mcount_nc +// __gnu_Unwind_Find_exidx +GO(grantpt, iFi) +// group_member // Weak +// gsignal // Weak +// gtty +//GOW(hasmntopt, pFpp) +// hcreate +// hcreate_r +// hdestroy // Weak +// hdestroy_r +//DATA(h_errlist, 4) +// h_errno // type B +//GO(__h_errno_location, pFv) +//GO(herror, vFp) +// h_nerr // type R +// host2netname +// hsearch +// hsearch_r +//GO(hstrerror, pFi) +GO(htonl, uFu) +GO(htons, uFu) +//GO(iconv, LFLpppp) +//GO(iconv_canonicalize, pFp) +GO(iconv_close, iFL) +//GO(iconv_open, LFpp) +//GO(if_freenameindex, vFp) +//GO(if_indextoname, pFup) +//GO(if_nameindex, pFv) +//GO(if_nametoindex, uFp) +// imaxabs // Weak +GOW(imaxdiv, IFII) +//DATA(in6addr_any, 16) // type R +//DATA(in6addr_loopback, 16) // type R +// inb // Weak +//GOW(index, pFpi) +// inet6_opt_append +// inet6_opt_find +// inet6_opt_finish +// inet6_opt_get_val +// inet6_opt_init +// inet6_option_alloc +// inet6_option_append +// inet6_option_find +// inet6_option_init +// inet6_option_next +// inet6_option_space +// inet6_opt_next +// inet6_opt_set_val +// inet6_rth_add +// inet6_rth_getaddr +// inet6_rth_init +// inet6_rth_reverse +// inet6_rth_segments +// inet6_rth_space +//GO(inet_addr, uFp) +//GOW(inet_aton, iFpp) +// inet_lnaof +// inet_makeaddr +// inet_netof +//GO(inet_network, iFp) +// inet_nsap_addr +//GO(inet_nsap_ntoa, pFipp) +//GO(inet_ntoa, pFu) +//GO(inet_ntop, pFippu) +//GO(inet_pton, iFipp) +//GO(initgroups, iFpi) +// init_module +// initstate // Weak +//GOW(initstate_r, iFupup) +// inl // Weak +// innetgr +//GO(inotify_add_watch, iFipu) +GO(inotify_init, iFv) +GO(inotify_init1, iFi) +GO(inotify_rm_watch, iFii) +// insque +// __internal_endnetgrent +// __internal_getnetgrent_r +// __internal_setnetgrent +// inw // Weak +//DATA(_IO_2_1_stderr_, 152) //sizeof(struct _IO_FILE_plus) +//DATA(_IO_2_1_stdin_, 152) +//DATA(_IO_2_1_stdout_, 152) +//GO(_IO_adjust_column, uFupi) +// _IO_adjust_wcolumn +GO(ioctl, iFiLN) //the vararg is just to have optional arg of various type, but only 1 arg +//GO(_IO_default_doallocate, iFS) +//GO(_IO_default_finish, vFSi) +//GO(_IO_default_pbackfail, iFSi) +//GO(_IO_default_uflow, iFS) +//GO(_IO_default_xsgetn, LFSpL) +//GO(_IO_default_xsputn, LFSpL) +//GO(_IO_doallocbuf, vFS) +//GO(_IO_do_write, iFSpL) +// _IO_fclose +// _IO_fdopen +// _IO_feof +// _IO_ferror +// _IO_fflush +// _IO_fgetpos +// _IO_fgetpos64 +// _IO_fgets +//GO(_IO_file_attach, pFSi) +//GO(_IO_file_close, iFS) +//GO(_IO_file_close_it, iFS) +//GO(_IO_file_doallocate, iFS) +// _IO_file_finish +//GO(_IO_file_fopen, pFSppi) +//GO(_IO_file_init, vFS) +//DATA(_IO_file_jumps, 4) +//GO(_IO_file_open, pFSpiiii) +//GO(_IO_file_overflow, iFSi) +//GO(_IO_file_read, lFSpl) +//GO(_IO_file_seek, IFSIi) +//GO(_IO_file_seekoff, IFSIii) +//GO(_IO_file_setbuf, pFSpl) +//GOM(_IO_file_stat, iFESp) +//GO(_IO_file_sync, iFS) +//GO(_IO_file_underflow, iFS) +//GO(_IO_file_write, lFSpl) +//GO(_IO_file_xsputn, LFSpL) +//GO(_IO_flockfile, vFS) +//GO(_IO_flush_all, iFv) +//GO(_IO_flush_all_linebuffered, vFv) +// _IO_fopen +// _IO_fprintf // Weak +// _IO_fputs +// _IO_fread +//GO(_IO_free_backup_area, vFS) +// _IO_free_wbackup_area +// _IO_fsetpos +// _IO_fsetpos64 +// _IO_ftell +// _IO_ftrylockfile +//GO(_IO_funlockfile, vFS) +// _IO_fwrite +//GO(_IO_getc, iFS) +// _IO_getline +//GO(_IO_getline_info, LFSpLiip) +// _IO_gets +//GO(_IO_init, vFSi) +//GO(_IO_init_marker, vFpS) +// _IO_init_wmarker +// _IO_iter_begin +// _IO_iter_end +// _IO_iter_file +// _IO_iter_next +// _IO_least_wmarker +//GO(_IO_link_in, vFp) +//DATA(_IO_list_all, 4) +// _IO_list_lock +// _IO_list_resetlock +// _IO_list_unlock +//GO(_IO_marker_delta, iFp) +//GO(_IO_marker_difference, iFpp) +//GO(_IO_padn, iFpii) +//GO(_IO_peekc_locked, iFp) +GOW(ioperm, iFuui) +GOW(iopl, iFi) +// _IO_popen +// _IO_printf +//GO(_IO_proc_close, iFS) +//GO(_IO_proc_open, pFSpp) +//GO(_IO_putc, iFip) +// _IO_puts +//GO(_IO_remove_marker, vFp) +//GO(_IO_seekmark, iFSpi) +//GO(_IO_seekoff, IFSIii) +//GO(_IO_seekpos, IFSIi) +// _IO_seekwmark +//GO(_IO_setb, vFSppi) +// _IO_setbuffer +// _IO_setvbuf +//GO(_IO_sgetn, uFppu) +// _IO_sprintf +//GO(_IO_sputbackc, iFSi) +// _IO_sputbackwc +// _IO_sscanf +//GO(_IO_str_init_readonly, vFppi) +//GO(_IO_str_init_static, vFppup) +//GO(_IO_str_overflow, iFSi) +//GO(_IO_str_pbackfail, iFSi) +//GO(_IO_str_seekoff, UFSUii) +//GO(_IO_str_underflow, iFS) +//GO(_IO_sungetc, iFp) +// _IO_sungetwc +//GO(_IO_switch_to_get_mode, iFp) +// _IO_switch_to_main_wget_area +// _IO_switch_to_wbackup_area +// _IO_switch_to_wget_mode +// _IO_ungetc +//GO(_IO_un_link, vFp) +//GO(_IO_unsave_markers, vFp) +// _IO_unsave_wmarkers +//GOM(_IO_vfprintf, iFEpppp) //%% +//GOM(_IO_vfscanf, iFEppp) //%% +// _IO_vsprintf +// _IO_wdefault_doallocate +// _IO_wdefault_finish +// _IO_wdefault_pbackfail +// _IO_wdefault_uflow +// _IO_wdefault_xsgetn +// _IO_wdefault_xsputn +// _IO_wdoallocbuf +// _IO_wdo_write +//DATA(_IO_wfile_jumps, 4) +// _IO_wfile_overflow +// _IO_wfile_seekoff +// _IO_wfile_sync +// _IO_wfile_underflow +// _IO_wfile_xsputn +// _IO_wmarker_delta +// _IO_wsetb +// iruserok +// iruserok_af +GO(isalnum, iFi) +// __isalnum_l +// isalnum_l // Weak +GO(isalpha, iFi) +// __isalpha_l +// isalpha_l // Weak +GO(isascii, iFi) +// __isascii_l // Weak +// isastream +GOW(isatty, iFi) +GO(isblank, iFi) +// __isblank_l +// isblank_l // Weak +GO(iscntrl, iFi) +// __iscntrl_l +// iscntrl_l // Weak +// isctype // Weak +// __isctype +GO(isdigit, iFi) +// __isdigit_l +// isdigit_l // Weak +// isfdtype +GO(isgraph, iFi) +// __isgraph_l +// isgraph_l // Weak +GOW(isinf, iFd) +GO(__isinf, iFd) +GOW(isinff, iFf) +GO(__isinff, iFf) +// isinfl // Weak +// __isinfl +GO(islower, iFi) +// __islower_l +// islower_l // Weak +GOW(isnan, iFd) +GO(__isnan, iFd) +GOW(isnanf, iFf) +GO(__isnanf, iFf) +// isnanl // Weak +// __isnanl +//GOM(__isoc99_fscanf, iFEppV) //%% +// __isoc99_fwscanf +// __isoc99_scanf +//GOM(__isoc99_sscanf, iFEppV) //%% +// __isoc99_swscanf +//GOM(__isoc99_vfscanf, iFEppp) //%% +// __isoc99_vfwscanf +// __isoc99_vscanf +//GOM(__isoc99_vsscanf, iFEppp) //%% TODO: check if ok +// __isoc99_vswscanf +// __isoc99_vwscanf +// __isoc99_wscanf +GO(isprint, iFi) +// __isprint_l +// isprint_l // Weak +GO(ispunct, iFi) +// __ispunct_l +// ispunct_l // Weak +GO(isspace, iFi) +// __isspace_l +// isspace_l // Weak +GO(isupper, iFi) +// __isupper_l +// isupper_l // Weak +GOW(iswalnum, iFi) +// __iswalnum_l +//GOW(iswalnum_l, iFip) +GOW(iswalpha, iFi) +// __iswalpha_l +//GOW(iswalpha_l, iFip) +GOW(iswblank, iFi) +// __iswblank_l +GOW(iswblank_l, iFip) +GOW(iswcntrl, iFi) +// __iswcntrl_l +GOW(iswcntrl_l, iFip) +GOW(iswctype, iFiu) +// __iswctype +GO(__iswctype_l, iFuLp) +// iswctype_l // Weak +GOW(iswdigit, iFi) +// __iswdigit_l +//GOW(iswdigit_l, iFip) +GOW(iswgraph, iFi) +// __iswgraph_l +//GOW(iswgraph_l, iFip) +GOW(iswlower, iFi) +// __iswlower_l +//GOW(iswlower_l, iFip) +GOW(iswprint, iFi) +// __iswprint_l +//GOW(iswprint_l, iFip) +GOW(iswpunct, iFi) +// __iswpunct_l +//GOW(iswpunct_l, iFip) +GOW(iswspace, iFi) +// __iswspace_l +//GOW(iswspace_l, iFip) +GOW(iswupper, iFi) +// __iswupper_l +//GOW(iswupper_l, iFip) +GOW(iswxdigit, iFi) +// __iswxdigit_l +//GOW(iswxdigit_l, iFip) +GO(isxdigit, iFi) +// __isxdigit_l +// isxdigit_l // Weak +// _itoa_lower_digits // type R +// __ivaliduser +//GO(jrand48, iFp) +// jrand48_r // Weak +// key_decryptsession +// key_decryptsession_pk +// __key_decryptsession_pk_LOCAL // type B +// key_encryptsession +// key_encryptsession_pk +// __key_encryptsession_pk_LOCAL // type B +// key_gendes +// __key_gendes_LOCAL // type B +// key_get_conv +// key_secretkey_is_set +// key_setnet +// key_setsecret +GOW(kill, iFli) +GO(killpg, iFii) +// klogctl +// l64a +GO(labs, iFi) +// lchmod +//GOW(lchown, iFpuu) +// lckpwdf // Weak +// lcong48 +// lcong48_r // Weak +// ldexp // Weak +// ldexpf // Weak +// ldexpl // Weak +//GOS(ldiv, pFEpii) //%% return a struct, so address of stuct is on the stack, as a shadow 1st element +//GOM(lfind, pFEpppLp) //%% +//GO(lgetxattr, iFpppu) +GOM(__libc_alloca_cutoff, iFEL) //%% +// __libc_allocate_rtsig +// __libc_allocate_rtsig_private +//GO(__libc_calloc, pFLL) +// __libc_clntudp_bufcreate +GO(__libc_current_sigrtmax, iFv) +// __libc_current_sigrtmax_private +GO(__libc_current_sigrtmin, iFv) +// __libc_current_sigrtmin_private +//GOM(__libc_dlclose, iFEp) //%% +// __libc_dl_error_tsd +//GOM(__libc_dlopen_mode, pFEpi) //%% +//GOM(__libc_dlsym, pFEpp) //%% +// __libc_fatal +// __libc_fork +//GO(__libc_free, vFp) +// __libc_freeres +GOM(__libc_init_first, vFEipV) //%% +// _libc_intl_domainname // type R +//GO2(__libc_open, iFEpOu, my_open) +// __libc_longjmp +// __libc_mallinfo +//GO(__libc_malloc, pFL) +// __libc_mallopt +//GO(__libc_memalign, pFLL) +// __libc_pthread_init +//GO(__libc_pvalloc, pFL) +// __libc_pwrite +//GO2(__libc_read, lFipL, my_read) //%%,noE +//GO(__libc_realloc, pFpL) +// __libc_sa_len +// __libc_siglongjmp +GOM(__libc_start_main, iFEpippppp) //%% +GO2(__libc_sigaction, iFEipp, my32_sigaction) //%% +// __libc_system +// __libc_thread_freeres +//GO(__libc_valloc, pFL) +//GOW(link, iFpp) +//GO(linkat, iFipipi) +GOW(listen, iFii) +//GO(listxattr, iFppu) +// llabs +// lldiv +//GO(llistxattr, iFppu) +// llseek // Weak +// loc1 // type B +// loc2 // type B +//GOW(localeconv, pFv) +//GO(localtime, pFp) +//GOW(localtime_r, pFpp) +GO(lockf, iFiiu) +GO(lockf64, iFiiI) +// locs // type B +GOM(longjmp, vFEpi) //%% +GOM(_longjmp, vFEpi) //%% +GOM(__longjmp_chk, vFEpi) //%% +GO(lrand48, iFv) +// lrand48_r +//GO(lremovexattr, iFpp) +//GOM(lsearch, pFEpppLp) //%% +GOW(lseek, iFiii) +// __lseek // Weak +GOW(lseek64, IFiIi) +//GO(lsetxattr, iFpppui) +//GO(lutimes, iFpp) +//GOM(__lxstat, iFEipp) //%% +//GOM(__lxstat64, iFEipp) //%% +//GO(madvise, iFpLi) +GOM(makecontext, iFEppiV) //%% +//GOW(mallinfo, pFv) +GOM(malloc, pFL) //%%,noE +// malloc_get_state // Weak +//DATAV(__malloc_hook, 4) +//DATAV(__malloc_initialize_hook, 4) +// malloc_set_state // Weak +// malloc_stats // Weak +GOW(malloc_trim, iFu) +//GOW(malloc_usable_size, LFp) +GOW(mallopt, iFii) // Weak +// mallwatch // type B +//GO(mblen, iFpL) +//GOW(mbrlen, LFpLp) +//GO(__mbrlen, LFpLp) +//GOW(mbrtowc, LFppLp) +//GO(__mbrtowc, LFppLp) +//GOW(mbsinit, iFp) +//GOW(mbsnrtowcs, LFppLLp) +// __mbsnrtowcs_chk +//GOW(mbsrtowcs, LFppLp) +// __mbsrtowcs_chk +//GO(mbstowcs, LFppL) +// __mbstowcs_chk +//GO(mbtowc, iFppL) +// mcheck +// mcheck_check_all +// mcheck_pedantic +// _mcleanup +//GOWM(mcount, vFpp) //%%,noE +// _mcount +//GOW(memalign, pFLL) +//DATAV(__memalign_hook, 4) +//GOW(memccpy, pFppiL) +//GO(memchr, pFpiL) +GO(memcmp, iFppL) +GO(memcpy, pFppL) +GO(__memcpy_chk, pFppuL) +// memfrob +//GO(memmem, pFpupu) +//GO(memmove, pFppL) +//GO(__memmove_chk, pFppLL) +//GO(mempcpy, pFppL) +//GO(__mempcpy, pFppu) +// __mempcpy_chk +// __mempcpy_small +//GOW(memrchr, pFpiL) +//GO(memset, pFpiL) +//GO(__memset_chk, pFpiLL) +//GO(mincore, iFpLp) +//GOW(mkdir, iFpu) +//GO(mkdirat, iFipu) +//GO(mkdtemp, pFp) +//GO(mkfifo, iFpu) +//GO(mkfifoat, iFipu) +//GO(mkostemp, iFpi) +//GO(mkostemp64, iFpi) +//GO(mkstemp, iFp) +//GO(mkstemp64, iFp) +//GO(mktemp, pFp) +//GO(mktime, LFp) +//GO(mlock, iFpL) +//GO(mlockall, iFi) +//GOM(mmap, pFEpLiiii) //%% +//GOM(mmap64, pFEpLiiiI) //%% +// modf // Weak +// modff // Weak +// modfl // Weak +// moncontrol // Weak +// monstartup // Weak +// __monstartup +//DATA(__morecore, 4) +//GOW(mount, iFpppup) +// mprobe +//GOM(mprotect, iFEpLi) //%% +// mrand48 +// mrand48_r +//GOWM(mremap, pFEpLLiN) //%% 5th hidden paramerer "void* new_addr" if flags is MREMAP_FIXED +//GO(msgctl, iFiip) +//GOW(msgget, iFpi) +//GOW(msgrcv, lFipLli) +//GOW(msgsnd, iFipLi) +//GOW(msync, iFpLi) +// mtrace +//GO(munlock, iFpL) +//GO(munlockall, iFv) +//GOM(munmap, iFEpL) //%% +// muntrace +//GOWM(nanosleep, iFpp) //%%,noE +// __nanosleep // Weak +// netname2host +// netname2user +GOW(newlocale, aFipa) +GO(__newlocale, aFipa) +// nfsservctl +//GOM(nftw, iFEppii) //%% +//GOM(nftw64, iFEppii) //%% +//GOW(ngettext, pFppu) +GO(nice, iFi) +// _nl_default_dirname // type R +// _nl_domain_bindings // type B +//GO(nl_langinfo, pFu) +//GO(__nl_langinfo_l, pFup) +//GOW(nl_langinfo_l, pFup) +//DATAB(_nl_msg_cat_cntr, 4) // type B +// nrand48 +// nrand48_r // Weak +// __nss_configure_lookup +// __nss_database_lookup +// __nss_disable_nscd +// _nss_files_parse_grent +// _nss_files_parse_pwent +// _nss_files_parse_spent +// __nss_group_lookup +// __nss_group_lookup2 +// __nss_hostname_digits_dots +// __nss_hosts_lookup +// __nss_hosts_lookup2 +// __nss_lookup_function +// __nss_next +// __nss_next2 +// __nss_passwd_lookup +// __nss_passwd_lookup2 +// __nss_services_lookup2 +GOW(ntohl, uFu) +GOW(ntohs, uFu) +// ntp_adjtime // Weak +// ntp_gettime +// _null_auth // type B +// _obstack_allocated_p +//DATAM(obstack_alloc_failed_handler, 4) +//GOM(_obstack_begin, iFpLLpp) //%%,noE +// _obstack_begin_1 +//DATA(obstack_exit_failure, 4) +//GOM(_obstack_free, vFpp) //%%,noE +//GOM(obstack_free, vFpp) //%%,noE +// _obstack_memory_used +//GOM(_obstack_newchunk, vFpi) //%%,noE +// obstack_printf // Weak +// __obstack_printf_chk +//GOWM(obstack_vprintf, iFEpppp) //%% +// __obstack_vprintf_chk +//GOWM(on_exit, iFEpp) //%% +//GO2(__on_exit, iFEpp, my_on_exit) //%% +//GOWM(open, iFEpOu) //%% +//GOWM(__open, iFEpOu) //%% +//GO(__open_2, iFpO) +//GOWM(open64, iFEpOu) //%% +// __open64 // Weak +//GO(__open64_2, iFpO) +//GOW(openat, iFipON) +// __openat_2 +//GOW(openat64, iFipON) +//GO(__openat64_2, iFipON) +// __open_catalog +//GOW(opendir, pFp) +//GO(openlog, vFpii) +// open_memstream +// open_wmemstream +//DATAB(optarg, 4) +//DATA(opterr, 4) +//DATA(optind, 4) +//DATA(optopt, 4) +// outb // Weak +// outl // Weak +// outw // Weak +//GO(__overflow, iFpi) +//GO(parse_printf_format, uFpup) +// passwd2des +//GOW(pathconf, iFpi) +GOW(pause, iFv) +//GO(pclose, iFp) +//GO(perror, vFp) +// personality // Weak +//GOW(pipe, iFp) // the array of 2 int seems to converted as a pointer, on both x86 and arm (and x86_64 too) +// __pipe +//GOW(pipe2, iFpO) // assuming this works the same as pipe, so pointer for array of 2 int +// pivot_root +// pmap_getmaps +// pmap_getport +// pmap_rmtcall +// pmap_set +// pmap_unset +//GOW(poll, iFpui) // poll have an array of struct as 1st argument +//GO(__poll, iFpui) +//GO(popen, pFpp) +GO(posix_fadvise, iFiuui) +GO(posix_fadvise64, iFiuui) +GO(posix_fallocate, iFiii) +GO(posix_fallocate64, iFiII) +// posix_madvise +//GOW(posix_memalign, iFpLL) +// posix_openpt // Weak +//GO(posix_spawn, iFpppppp) +// posix_spawnattr_destroy +// posix_spawnattr_getflags +// posix_spawnattr_getpgroup +// posix_spawnattr_getschedparam +// posix_spawnattr_getschedpolicy +// posix_spawnattr_getsigdefault +// posix_spawnattr_getsigmask +// posix_spawnattr_init +// posix_spawnattr_setflags +// posix_spawnattr_setpgroup +// posix_spawnattr_setschedparam +// 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_spawnp, iFEpppppp) //%% +//GO(ppoll, iFpupp) +GOW(prctl, iFiLLLL) +//GOW(pread, lFipLl) +//GOW(pread64, lFipLI) +// __pread64 // Weak +// __pread64_chk +//GOM(preadv64, lFEipiI) //%% not always present +// __pread_chk +GOM(printf, iFEpV) //%% +GOM(__printf_chk, iFEvpV) //%% +//GO(__printf_fp, iFppp) // does this needs aligment? +// printf_size +// printf_size_info +// profil // Weak +// __profile_frequency +//DATAM(__progname, 4) +//DATAM(__progname_full, 4) +//DATAM(program_invocation_name, 4) +//DATAM(program_invocation_short_name, 4) +//GOW(pselect, iFippppp) +// psignal +//GO(ptrace, iFiupp) // will that work??? +//GO(ptsname, pFi) +//GOW(ptsname_r, iFipu) +// __ptsname_r_chk +GOW(putc, iFip) +GO(putchar, iFi) +GO(putchar_unlocked, iFi) +//GO(putc_unlocked, iFip) +//GO(putenv, iFp) +// putgrent +// putmsg +// putpmsg +// putpwent +GOW(puts, iFp) +// putspent +//GOW(pututline, pFp) +// pututxline +// putw +//GO(putwc, iFip) +// putwchar +GO(putwchar_unlocked, iFi) +//GO(putwc_unlocked, iFip) +// pvalloc // Weak +// pwrite // Weak +//GOW(pwrite64, lFipLI) +// __pwrite64 // Weak +//GOM(pwritev64, lFEipiI) //%% not always present +// qecvt +#ifdef HAVE_LD80BITS +//GO(qecvt_r, iFDipppL) +#else +//GO(qecvt_r, iFKipppL) +#endif +// qfcvt +#ifdef HAVE_LD80BITS +//GO(qfcvt_r, iFDipppL) +#else +//GO(qfcvt_r, iFKipppL) +#endif +// qgcvt +//GOM(qsort, vFEpLLp) //%% +//GOM(qsort_r, vFEpLLpp) //%% +// query_module // Weak +//GO(quotactl, iFipip) +GO(raise, iFi) +GO(rand, iFv) +GOW(random, iFv) +//GOW(random_r, iFpp) +//GO(rand_r, iFp) +//GOW(rawmemchr, pFpi) +//GO(__rawmemchr, pFpi) +// rcmd +// rcmd_af +// __rcmd_errstr // type B +//GOM(read, lFipL) //%%,noE +//GOW(__read, lFipL) +// readahead // Weak +//GO(__read_chk, lFipLL) +//GOM(readdir, pFEp) //%% should also be weak +//GO(readdir64, pFp) // check if alignement is correct +// readdir64_r +//GOM(readdir_r, iFEppp) //%% should also be weak +//GOM(readlink, iFEppL) //%% +//GOM(readlinkat, iFEippL) +// __readlinkat_chk +// __readlink_chk +//GO(readv, lFipi) +//GO(realloc, pFpL) +//DATAV(__realloc_hook, 4) +//GOM(realpath, pFEpp) //%% +//GO(__realpath_chk, pFppu) +// reboot +// re_comp // Weak +// re_compile_fastmap // Weak +//GOW(re_compile_pattern, pFpup) +//GO(recv, lFipLi) +//GO(__recv_chk, iFipuui) +//GOW(recvfrom, lFipLipp) +// __recvfrom_chk +//GOM(recvmmsg, iFEipuup) //%% actual recvmmsg is glibc 2.12+. The syscall is Linux 2.6.33+, so use syscall... +//GOW(recvmsg, lFipi) +// re_exec // Weak +//GOW(regcomp, iFppi) +//GOW(regerror, uFippu) +//GO(regexec, iFppupi) +//GOW(regfree, vFp) +//GOM(__register_atfork, iFEpppp) //%% +// register_printf_function // Weak +// registerrpc +// remap_file_pages // Weak +//GOW(re_match, iFppiip) +// re_match_2 // Weak +//GO(remove, iFp) +//GO(removexattr, iFpp) +// remque +//GO(rename, iFpp) +//GO(renameat, iFipip) +//GO(renameat2, iFipipu) +// _res // type B +//GOW(re_search, iFppiiip) +//GOW(re_search_2, iFppipiiipi) +// re_set_registers // Weak +GOW(re_set_syntax, uFu) +// _res_hconf // type B +//GO(__res_iclose, vFpi) +GO(__res_init, iFv) +//GO(__res_maybe_init, iFpi) +//GO(__res_nclose, vFp) +//GO(__res_ninit, iFp) +//DATA(__resp, 4) +// __res_randomid +//GO(__res_state, pFv) +//DATA(re_syntax_options, 4) // type B +// revoke +//GO(rewind, vFp) +//GO(rewinddir, vFp) +// rexec +// rexec_af +// rexecoptions // type B +//GOW(rindex, pFpi) +//GOW(rmdir, iFp) +//GO(readdir64_r, iFppp) // is this present? +// rpc_createerr // type B +// _rpc_dtablesize +// __rpc_thread_createerr +// __rpc_thread_svc_fdset +// __rpc_thread_svc_max_pollfd +// __rpc_thread_svc_pollfd +//GO(rpmatch, iFp) +// rresvport +// rresvport_af +// rtime +// ruserok +// ruserok_af +// ruserpass +//GOW(sbrk, pFl) +//GO(__sbrk, pFl) +// scalbn // Weak +// scalbnf // Weak +// scalbnl // Weak +//GOM(scandir, 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) +//GO(__sched_cpufree, vFp) +//GO(sched_getaffinity, iFiup) +GO(sched_getcpu, iFv) +//GO(__sched_getparam, iFip) +//GOW(sched_getparam, iFip) +GO(__sched_get_priority_max, iFi) +GOW(sched_get_priority_max, iFi) +GO(__sched_get_priority_min, iFi) +GOW(sched_get_priority_min, iFi) +GO(__sched_getscheduler, iFi) +GOW(sched_getscheduler, iFi) +//GOW(sched_rr_get_interval, iFip) +//GO(sched_setaffinity, iFiup) +//GOW(sched_setparam, iFip) +//GO(__sched_setscheduler, iFiip) +//GOW(sched_setscheduler, iFiip) +GO(__sched_yield, iFv) +GOW(sched_yield, iFv) +GO(__secure_getenv, pFp) +GO(secure_getenv, pFp) +// seed48 +// seed48_r // Weak +//GO(seekdir, vFpi) +//GOW(select, iFipppp) +//GO(__select, iFipppp) +//GO(semctl, iFiiiN) +GOW(semget, iFuii) +//GOW(semop, iFipL) +//GO(semtimedop, iFipup) +//GOW(send, lFipLi) +// __send // Weak +//GO(sendfile, lFiipL) +//GO(sendfile64, lFiipL) +//GOW(sendmsg, lFipi) +//GOM(__sendmmsg, iFEipuu) //%% actual __sendmmsg is glibc 2.14+. The syscall is Linux 3.0+, so use syscall... +//GOW(sendto, lFipLipu) +// setaliasent +//GOW(setbuf, vFpp) +//GOW(setbuffer, vFppL) +GOM(setcontext, iFEp) //%% +// setdomainname +GO(setegid, iFu) +//GOW(setenv, iFppi) +// _seterr_reply +GO(seteuid, iFu) +// setfsent +// setfsgid +// setfsuid +GOW(setgid, iFu) +GO(setgrent, vFv) +//GO(setgroups, iFup) +GO(sethostent, vFi) +// sethostid +//GO(sethostname, iFpu) +// setipv4sourcefilter +//GOW(setitimer, iFipp) +GOM(setjmp, iFEp) //%% +GOM(_setjmp, iFEp) //%% +//GO(setlinebuf, vFp) +GO(setlocale, aFia) +// setlogin +GO(setlogmask, iFi) +//GOW(setmntent, pFpp) +// __setmntent +// setnetent +// setnetgrent +GOW(setpgid, iFuu) +// __setpgid +GO(setpgrp, iFv) +GO(setpriority, iFiii) +GO(setprotoent, vFi) +GO(setpwent, vFv) +GOW(setregid, iFuu) +GOW(setresgid, iFuuu) +GOW(setresuid, iFuuu) +GOW(setreuid, iFuu) +//GO(setrlimit, iFip) +//GO(setrlimit64, iFip) +// setrpcent +// setservent +GOW(setsid, iFv) +//GOW(setsockopt, iFiiipu) +// setsourcefilter +GO(setspent, vFv) +// setstate // Weak +//GOW(setstate_r, iFpp) +//GOW(settimeofday, iFpp) +// setttyent +GOW(setuid, iFu) +// setusershell +GOW(setutent, vFv) +// setutxent +//GOW(setvbuf, iFppiL) +//GO(setxattr, iFpppui) +// sgetspent +// sgetspent_r // Weak +//GOW(shmat, pFipi) +//GOW(shmctl, iFiip) +//GOW(shmdt, iFp) +GOW(shmget, iFuui) +GOW(shutdown, iFii) +//GOWM(sigaction, iFEipp) //%% +//GOWM(__sigaction, iFEipp) //%% +//GO(sigaddset, iFpi) +// __sigaddset +GOWM(sigaltstack, iFEpp) //%% +// sigandset +GOW(sigblock, iFi) +//GO(sigdelset, iFpi) +// __sigdelset +//GO(sigemptyset, iFp) +//GO(sigfillset, iFp) +GO(siggetmask, iFv) +// sighold +// sigignore +GO(siginterrupt, iFii) // no need to wrap this one? +// sigisemptyset +//GO(sigismember, iFpi) +// __sigismember +GOM(siglongjmp, vFEip) //%% +GOW2(signal, pFEip, my_signal) +// signalfd +GO(__signbit, iFd) +GO(__signbitf, iFf) +// sigorset +// sigpause // Weak +// __sigpause +//GO(sigpending, iFp) +//GOW(sigprocmask, iFipp) +// sigqueue // Weak +// sigrelse +// sigreturn // Weak +GOM(sigset, pFEip) //%% +GOM(__sigsetjmp, iFEp) //%% +GOW(sigsetmask, iFi) +// sigstack +//GOW(sigsuspend, iFp) +// __sigsuspend +//GOW(sigtimedwait, iFppp) +//GOW(sigvec, iFipp) +//GOW(sigwait, iFpp) +//GOW(sigwaitinfo, iFpp) +GOW(sleep, uFu) +//GOM(snprintf, iFEpLpV) //%% +//GOM(__snprintf_chk, iFEpLiipV) //%% +//GOM(__snprintf, iFEpLpV) //%% +// sockatmark +GOW(socket, iFiii) +//GOW(socketpair, iFiiip) +//GO(splice, iFipipuu) +//GOM(sprintf, iFEppV) //%% +//GOM(__sprintf_chk, iFEpvvpV) //%% +// sprofil // Weak +GOW(srand, vFu) +GO(srand48, vFi) +// srand48_r // Weak +GOW(srandom, vFu) +//GOW(srandom_r, iFup) +//GOM(sscanf, iFEppV) //%% +// ssignal // Weak +// sstk +GOM(__stack_chk_fail, vFEv) //%% +//GOM(lstat64, iFpp) //%%,noE +//GOM(stat64, iFpp) //%%,noE +//GOW(statfs, iFpp) +// __statfs +//GOWM(statfs64, iFpp) //%%,noE +//GO(statvfs, iFpp) +//GOW(statvfs64, iFpp) // is alignment ok? +DATAM(stderr, 4) +DATAM(stdin, 4) +DATAM(stdout, 4) +// step // Weak +// stime +//GO(stpcpy, pFpp) +// __stpcpy +//GO(__stpcpy_chk, pFppL) +// __stpcpy_small +//GOW(stpncpy, pFppL) +//GO(__stpncpy, pFppL) +//GO(__stpncpy_chk, pFppLL) +//GOW(strcasecmp, iFpp) +//GO(__strcasecmp, iFpp) +// __strcasecmp_l +// strcasecmp_l // Weak +//GOW(strcasestr, pFpp) +//GO(__strcasestr, pFpp) +//GO(strcat, pFpp) +//GO(__strcat_chk, pFppL) +//GO(strchr, pFpi) +//GOW(strchrnul, pFpi) +GO(strcmp, iFpp) +//GO(strcoll, iFpp) +//GO(__strcoll_l, iFppp) +//GOW(strcoll_l, iFppp) +//GO(strcpy, pFpp) +//GO(__strcpy_chk, pFppL) +// __strcpy_small +GO(strcspn, LFpp) +// __strcspn_c1 +// __strcspn_c2 +// __strcspn_c3 +//GOW(strdup, pFp) +//GO(__strdup, pFp) +//GO(strerror, pFi) +//GO(strerror_l, pFip) +//GO(__strerror_r, pFipu) +//GOW(strerror_r, pFipu) +//GO(strfmon, lFpLpppppppppp) //vaarg, probably needs align, there are just double... +// __strfmon_l +// strfmon_l // Weak +// strfry +//GO(strftime, LFpLpp) +//GO(__strftime_l, LFpLppL) +//GOW(strftime_l, LFpLppL) +//GO(strlen, LFp) +//GOW(strncasecmp, iFppL) +// __strncasecmp_l +// strncasecmp_l // Weak +//GO(strncat, pFppL) +//GO(__strncat_chk, pFppLL) +//GO(strncmp, iFppL) +//GO(strncpy, pFppL) +//GO(__strncpy_chk, pFppLL) +//GOW(strndup, pFpL) +//GO(__strndup, pFpL) +//GO(strnlen, LFpL) +//GO(strpbrk, pFpp) +// __strpbrk_c2 +// __strpbrk_c3 +//GO(strptime, pFppp) +// strptime_l // Weak +//GO(strrchr, pFpi) +//GOW(strsep, pFpp) +// __strsep_1c +// __strsep_2c +// __strsep_3c +// __strsep_g +//GO(strsignal, pFi) +//GO(strspn, LFpp) +// __strspn_c1 +// __strspn_c2 +// __strspn_c3 +//GO(strstr, pFpp) +//GO(strtod, dFpp) +//GO(__strtod_internal, dFppi) +//GO(__strtod_l, dFppp) +//GOW(strtod_l, dFppu) +//GO(strtof, fFpp) +//GO(__strtof_internal, fFppp) +//GO(__strtof_l, fFppp) +//GOW(strtof_l, fFppu) +//GO(strtoimax, IFppi) +//GO(strtok, pFpp) +//GO(__strtok_r, pFppp) +//GOW(strtok_r, pFppp) +// __strtok_r_1c +GO(strtol, lFpBp_i) +#ifdef HAVE_LD80BITS +//GO(strtold, DFpp) +//GO(__strtold_internal, DFppi) +//GO(__strtold_l, DFppip) +//GOW(strtold_l, DFppu) +#else +//GO(strtold, KFpp) +//GO2(__strtold_internal, KFppi, __strtod_internal) +//GO2(__strtold_l, KFppip, __strtod_l) +//GOW2(strtold_l, KFppu, strtod_l) +#endif +//GO(__strtol_internal, lFppi) +//GO(strtoll, IFppi) +//GO(__strtol_l, lFppiip) +//GOW(strtol_l, lFppiip) +//GO(__strtoll_internal, IFppii) +//GO(__strtoll_l, IFppip) +//GOW(strtoll_l, IFppip) +//GOW(strtoq, IFppi) // is that ok? +//GO(strtoul, LFppi) +//GO(__strtoul_internal, LFppii) +//GO(strtoull, UFppi) +//GO(__strtoul_l, uFppip) +//GOW(strtoul_l, LFppip) +//GO(__strtoull_internal, UFppii) +//GO(__strtoull_l, UFppip) +//GOW(strtoull_l, UFppip) +//GO(strtoumax, UFppi) +//GOW(strtouq, UFppi) // ok? +//GOW(strverscmp, iFpp) +// __strverscmp +//GO(strxfrm, uFppu) +//GO(__strxfrm_l, uFppup) +//GO(strxfrm_l, uFppup) +// stty +// svcauthdes_stats // type B +// svcerr_auth +// svcerr_decode +// svcerr_noproc +// svcerr_noprog +// svcerr_progvers +// svcerr_systemerr +// svcerr_weakauth +// svc_exit +// svcfd_create +// svc_fdset // type B +// svc_getreq +// svc_getreq_common +// svc_getreq_poll +// svc_getreqset +// svc_max_pollfd // type B +// svc_pollfd // type B +// svcraw_create +// svc_register +// svc_run +// svc_sendreply +// svctcp_create +// svcudp_bufcreate +// svcudp_create +// svcudp_enablecache +// svcunix_create +// svcunixfd_create +// svc_unregister +//GO(swab, vFppi) +GOM(swapcontext, iFEpp) //%% +// swapoff // Weak +// swapon // Weak +//GOM(swprintf, iFEpupV) //%% +//GOM(__swprintf_chk, iFEpuiupV) //%% +//GO2(swscanf, iFppV, vswscanf) // swscanf va_list is only pointer, no realign to do +//GOW(symlink, iFpp) +//GO(symlinkat, iFpip) +GO(sync, vFv) +GO(syncfs, iFi) +// sync_file_range +GOM(syscall, uFEV) //%% +GOW(sysconf, lFi) +GO(__sysconf, lFi) +// sysctl // Weak +//GO(__sysctl, iFp) +//DATA(_sys_errlist, 4) +//DATA(sys_errlist, 4) +//GO(sysinfo, iFp) +//GO2(syslog, vFipV, vsyslog) +//GO2(__syslog_chk, vFiipV, __vsyslog_chk) +//DATA(_sys_nerr, 4) // type R +//DATA(sys_nerr, 4) // type R +//DATA(sys_sigabbrev, 4) +//DATA(_sys_siglist, 4) +//DATA(sys_siglist, 4) +//GOW(system, iFp) // Need to wrap to use box86 if needed? +//GOM(__sysv_signal, pFEip) //%% +//GOWM(sysv_signal, pFEip) //%% +GOW(tcdrain, iFi) +GO(tcflow, iFii) +GO(tcflush, iFii) +//GOW(tcgetattr, iFip) +GO(tcgetpgrp, iFi) +// tcgetsid +GO(tcsendbreak, iFii) +//GO(tcsetattr, iFiip) +GO(tcsetpgrp, iFii) +// tdelete // Weak +// tdestroy // Weak +// tee +//GO(telldir, iFp) +//GO(tempnam, pFpp) +//GOW(textdomain, pFp) +// tfind // Weak +//GO(time, LFp) +//GO(timegm, LFp) +// timelocal // Weak +GO(timerfd_create, iFii) +//GO(timerfd_gettime, iFip) +//GO(timerfd_settime, iFiipp) +//GOW(times, iFp) +//DATAV(timezone, 4) +//DATAB(__timezone, 4) // type B +//GO(tmpfile, pFv) +//GO(tmpfile64, pFv) +//GO(tmpnam, pFp) +//GO(tmpnam_r, pFp) +GO(toascii, iFi) +// __toascii_l // Weak +GO(tolower, iFi) +// _tolower +// __tolower_l +//GOW(tolower_l, iFip) +GO(toupper, iFi) +// _toupper +// __toupper_l +//GOW(toupper_l, iFip) +// towctrans // Weak +// __towctrans +// __towctrans_l +// towctrans_l // Weak +GO(towlower, iFi) +//GO(__towlower_l, iFip) +//GOW(towlower_l, iFip) +//GO(towupper, iFi) +//GO(__towupper_l, iFip) +//GOW(towupper_l, iFip) +// tr_break +//GOW(truncate, iFpu) +//GO(truncate64, iFpU) +// tsearch // Weak +//GO(ttyname, pFi) +//GOW(ttyname_r, iFipu) +// __ttyname_r_chk +// ttyslot +// twalk // Weak +//DATAV(tzname, 4) +//DATA(__tzname, 4) +GOW(tzset, vFv) +// ualarm +//GO(__uflow, iFp) +// ulckpwdf // Weak +// ulimit // Weak +GOW(umask, uFu) +//GOW(umount, iFp) +//GOW(umount2, iFpi) +//GOWM(uname, iFp) //%%,noE +//GO(__underflow, iFp) +//GOW(ungetc, iFip) +//GO(ungetwc, iFip) +//GOW(unlink, iFp) +//GO(unlinkat, iFipi) +GO(unlockpt, iFi) +//GOW(unsetenv, iFp) +// unshare +//GOW(updwtmp, vFpp) +// updwtmpx +// uselib +GOW(uselocale, aFa) +GO(__uselocale, aFa) +// user2netname +GO(usleep, iFu) +// ustat +//GO(utime, iFpp) +//GO(utimensat, iFippi) +//GOW(utimes, iFpp) //TODO: check, signature is int utimes(const char *filename, const struct timeval times[2]); +//GOW(utmpname, iFp) +// utmpxname +//GOW(valloc, pFu) +//GOM(vasprintf, iFEpppp) //%% +//GOM(__vasprintf_chk, iFEpippp) //%% +// vdprintf // Weak +// __vdprintf_chk +//GOM(verr, vFEpV) //%% +// verrx +//GO(versionsort, iFpp) +//GO(versionsort64, iFpp) //need to align dirent64? +GOWM(vfork, iFEv) //%% +// __vfork +//GOM(vfprintf, iFEppp) //%% +//GOM(__vfprintf_chk, iFEpvpp) //%% +//GOWM(vfscanf, iFEppp) //%% +// __vfscanf +//GOWM(vfwprintf, iFEppp) //%% +//GO2(__vfwprintf_chk, iFEpvpp, my_vfwprintf) +//GOW(vfwscanf, iFppp) +// vhangup +// vlimit +// vmsplice +//GOM(vprintf, iFEpp) //%% +//GOM(__vprintf_chk, iFEvpp) //%% +// vscanf // Weak +//GOWM(vsnprintf, iFEpLppp) //%% +//GOWM(__vsnprintf, iFEpuppp) //%% +//GOM(__vsnprintf_chk, iFEpuvvppp) //%% +//GOWM(vsprintf, iFEppp) //%% +//GOM(__vsprintf_chk, iFEpiLpp) //%% +//GOM(vsscanf, iFEppp) //%% +// __vsscanf // Weak +//GOWM(vswprintf, iFEpuppp) //%% +//GOWM(__vswprintf_chk, iFEpLiLppp) //%% +//GO(vswscanf, iFppp) +//GO(vsyslog, vFipp) +//GO(__vsyslog_chk, vFiipp) +// vtimes +//GOM(vwarn, vFEppp) //%% +// vwarnx +//GOM(vwprintf, iFEpp) //%% +//GO2(__vwprintf_chk, iFEvpp, my_vwprintf) +//GO(vwscanf, iFpp) +//GOW(wait, iFp) +//GOW(__wait, iFp) +//GOW(wait3, iFpip) +//GOW(wait4, iFipip) +//GOW(waitid, iFiipi) +//GOW(waitpid, lFlpi) +//GOW(__waitpid, lFlpi) +//GO(warn, vFppppppppp) +//GO(warnx, vFppppppppp) +//GOW(wcpcpy, pFpp) +// __wcpcpy_chk +//GOW(wcpncpy, pFpp) +// __wcpncpy_chk +//GOW(wcrtomb, LFpip) +// __wcrtomb_chk +//GOW(wcscasecmp, iFpp) +// __wcscasecmp_l +//GOW(wcscasecmp_l, iFppp) +//GOW(wcscat, pFpp) +//GO(__wcscat_chk, pFppu) +//GO(wcschr, pFpi) +// wcschrnul // Weak +//GO(wcscmp, iFpp) +//GOW(wcscoll, iFpp) +//GO(__wcscoll_l, iFppp) +//GOW(wcscoll_l, iFppp) +//GO(wcscpy, pFpp) +//GO(__wcscpy_chk, pFppu) +//GO(wcscspn, uFpp) +//GO(wcsdup, pFp) +//GO(wcsftime, LFpLpp) +//GO(__wcsftime_l, LFpLppp) +//GOW(wcsftime_l, LFpLppp) +//GOW(wcslen, LFp) +//GOW(wcsncasecmp, iFppu) +// __wcsncasecmp_l +//GOW(wcsncasecmp_l, iFppup) +//GO(wcsncat, pFppu) +// __wcsncat_chk +//GO(wcsncmp, iFppu) +//GOW(wcsncpy, pFppu) +//GO(__wcsncpy_chk, pFppuu) +//GOW(wcsnlen, LFpL) +//GOW(wcsnrtombs, LFppLLp) +// __wcsnrtombs_chk +//GO(wcspbrk, pFpp) +//GO(wcsrchr, pFpi) +//GOW(wcsrtombs, uFppup) +// __wcsrtombs_chk +//GO(wcsspn, uFpp) +//GO(wcsstr, pFpp) +//GO(wcstod, dFpp) +//GO(__wcstod_internal, dFppi) +// __wcstod_l +// wcstod_l // Weak +//GO(wcstof, fFpp) +// __wcstof_internal +// __wcstof_l +// wcstof_l // Weak +// wcstoimax +//GO(wcstok, pFppp) +//GO(wcstol, iFppi) +//GO(wcstold, DFpp) +// __wcstold_internal +// __wcstold_l +// wcstold_l // Weak +//GO(__wcstol_internal, iFppii) +//GO(wcstoll, IFppi) +// __wcstol_l +// wcstol_l // Weak +// __wcstoll_internal +// __wcstoll_l +// wcstoll_l // Weak +//GO(wcstombs, uFppu) +// __wcstombs_chk +// wcstoq // Weak +//GO(wcstoul, iFppi) +//GO(__wcstoul_internal, LFppii) +//GO(wcstoull, UFppi) +// __wcstoul_l +// wcstoul_l // Weak +// __wcstoull_internal +// __wcstoull_l +// wcstoull_l // Weak +// wcstoumax +// wcstouq // Weak +// wcswcs // Weak +//GO(wcswidth, iFpu) +//GO(wcsxfrm, uFppu) +//GOW(wcsxfrm_l, uFppup) +//GO(__wcsxfrm_l, uFppup) +GO(wctob, iFi) +//GO(wctomb, iFpi) +//GO(__wctomb_chk, iFpuL) +// wctrans // Weak +// __wctrans_l +// wctrans_l // Weak +//GOW(wctype, uFp) +GO(__wctype_l, uFpa) +GOW(wctype_l, uFpa) +//GO(wcwidth, iFu) +//GOW(wmemchr, pFpuL) +GO(wmemcmp, iFppL) +GOW(wmemcpy, pFppL) +GO(__wmemcpy_chk, pFppLL) +//GOW(wmemmove, pFppL) +// __wmemmove_chk +// wmempcpy // Weak +// __wmempcpy_chk +//GO(wmemset, pFpuL) +// __wmemset_chk +//GO(wordexp, iFppi) +//GO(wordfree, vFp) +// __woverflow +//GOM(wprintf, iFEpV) //%% +//GOM(__wprintf_chk, iFEipV) //%% +//GOW(write, lFipL) +//GOW(__write, lFipL) +//GOW(writev, lFipi) +// wscanf +// __wuflow +// __wunderflow +// xdecrypt +// xdr_accepted_reply +// xdr_array +// xdr_authdes_cred +// xdr_authdes_verf +// xdr_authunix_parms +// xdr_bool +// xdr_bytes +// xdr_callhdr +// xdr_callmsg +// xdr_char +// xdr_cryptkeyarg +// xdr_cryptkeyarg2 +// xdr_cryptkeyres +// xdr_des_block +// xdr_double +// xdr_enum +// xdr_float +// xdr_free +// xdr_getcredres +// xdr_hyper +//GO(xdr_int, iFpp) +// xdr_int16_t +// xdr_int32_t +// xdr_int64_t +// xdr_int8_t +// xdr_keybuf +// xdr_key_netstarg +// xdr_key_netstres +// xdr_keystatus +// xdr_long +// xdr_longlong_t +// xdrmem_create +// xdr_netnamestr +// xdr_netobj +// xdr_opaque +// xdr_opaque_auth +// xdr_pmap +// xdr_pmaplist +// xdr_pointer +// xdr_quad_t +// xdrrec_create +// xdrrec_endofrecord +// xdrrec_eof +// xdrrec_skiprecord +// xdr_reference +// xdr_rejected_reply +// xdr_replymsg +// xdr_rmtcall_args +// xdr_rmtcallres +// xdr_short +// xdr_sizeof +// xdrstdio_create +// xdr_string +// xdr_u_char +// xdr_u_hyper +//GO(xdr_u_int, iFpp) +// xdr_uint16_t +// xdr_uint32_t +// xdr_uint64_t +// xdr_uint8_t +// xdr_u_long +// xdr_u_longlong_t +// xdr_union +// xdr_unixcred +// xdr_u_quad_t +// xdr_u_short +// xdr_vector +// xdr_void +// xdr_wrapstring +// xencrypt +//GO(__xmknod, iFipup) +//GO(__xmknodat, iFiipip) +//GO(__xpg_basename, pFp) +// __xpg_sigpause // Weak +//GO(__xpg_strerror_r, pFipu) +// xprt_register +// xprt_unregister +//GOM(__xstat, iFEipp) //%% +//GOM(__xstat64, iFEipp) //%% + +// forcing a custom __gmon_start__ that does nothing +GOM(__gmon_start__, vFEv) //%% + +GOM(_Jv_RegisterClasses, vFv) //%%,noE dummy + +GOM(__fdelt_chk, LFL) //%%,noE + +GOM(getauxval, uFEu) //%% implemented since glibc 2.16 + +//GOM(prlimit64, lFpupp) //%%,noE +//GO(process_vm_readv, lFipLpLL) +//GO(process_vm_writev, lFipLpLL) +//GOM(reallocarray, pFpLL) //%%,noE +//GOM(__open_nocancel, iFEpOV) //%% +//GO2(__read_nocancel, lFipL, read) +GO2(__close_nocancel, iFi, close) + +//GOM(mkstemps64, iFEpi) //%% not always implemented +//GOM(getentropy, iFEpL) //%% starting from glibc 2.25 + +// not found (libitm???), but it seems OK to declare dummies: + +//GOM(_ITM_RU1, uFp) //%%,noE +//GOM(_ITM_RU4, uFp) //%%,noE +//GOM(_ITM_RU8, UFp) +//GOM(_ITM_memcpyRtWn, vFppu) //%%,noE register(2) +//GOM(_ITM_memcpyRnWt, vFppu) //%%,noE register(2) +//GOM(_ITM_addUserCommitAction, vFEpup) +GOM(_ITM_registerTMCloneTable, vFEpu) //%% +GOM(_ITM_deregisterTMCloneTable, vFEp) //%% + +GOM(__umoddi3, UFUU) //%%,noE +GOM(__udivdi3, UFUU) //%%,noE +GOM(__divdi3, IFII) //%%,noE +//GOM(__poll_chk, iFpuii) //%%,noE + +GOM(fallocate64, iFiiII) //%%,noE + +//DATAM(__libc_stack_end, sizeof(void*)) + +//DATAM(___brk_addr, 4) +//DATA(__libc_enable_secure, 4) + +//GOM(__register_frame_info, vFpp) //%%,noE faked function +//GOM(__deregister_frame_info, pFp) //%%,noE + +//GO(name_to_handle_at, iFipppi) // only glibc 2.14+, so may not be present... + +//GOM(modify_ldt, iFEipL) // there is suposedly no glibc wrapper for this one + +#ifdef ANDROID +GOM(__libc_init, vFEpppp) +GO(__errno, pFv) +#else +// Those symbols don't exist in non-Android builds +//GOM(__libc_init, +//GO(__errno, +#endif + +//GOM(stat, +//GOM(lstat, +//GOM(fstat, +//GO(setprogname, +//GO(getprogname, + +DATAM(__libc_single_threaded, 4) //B type diff --git a/src/wrapped32/wrappedlibdl.c b/src/wrapped32/wrappedlibdl.c new file mode 100755 index 00000000..c3a79feb --- /dev/null +++ b/src/wrapped32/wrappedlibdl.c @@ -0,0 +1,165 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <elf.h> +#include <link.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "emu/x64emu_private.h" +#include "library.h" +#include "librarian.h" +#include "box32context.h" +#include "elfloader.h" +#include "elfs/elfloader_private.h" +#include "x64emu.h" + + +#define LIBNAME libdl +#ifdef ANDROID + static const char* libdlName = "libdl.so"; +#else + static const char* libdlName = "libdl.so.2"; +#endif + +void* my_dlopen(x64emu_t* emu, void *filename, int flag) EXPORT; +void* my_dlmopen(x64emu_t* emu, void* mlid, void *filename, int flag) EXPORT; +char* my_dlerror(x64emu_t* emu) EXPORT; +void* my_dlsym(x64emu_t* emu, void *handle, void *symbol) EXPORT; +int my_dlclose(x64emu_t* emu, void *handle) EXPORT; +int my32_dladdr(x64emu_t* emu, void *addr, void *info) EXPORT; +int my32_dladdr1(x64emu_t* emu, void *addr, void *info, void** extra_info, int flags) EXPORT; +void* my_dlvsym(x64emu_t* emu, void *handle, void *symbol, const char *vername) EXPORT; +int my32_dlinfo(x64emu_t* emu, void* handle, int request, void* info) EXPORT; + +#ifndef RTLD_DL_SYMENT +#define RTLD_DL_SYMENT 1 +#endif +#ifndef RTLD_DL_LINKMAP +#define RTLD_DL_LINKMAP 2 +#endif + +void dl_clear_error(); +#define CLEARERR dl_clear_error() +void dl_set_error(const char*); +char* dl_last_error(); +library_t* dl_get_library(void* handle); + +typedef struct my_dl_info_32_s +{ + ptr_t dli_fname; // const char* + ptr_t dli_fbase; // void* + ptr_t dli_sname; // const char* + ptr_t dli_saddr; // void* +} my_dl_info_32_t; + +int my32_dladdr1(x64emu_t* emu, void *addr, void *i, void** extra_info, int flags) +{ + //int dladdr(void *addr, my_dl_info_32_t *info); + CLEARERR; + my_dl_info_32_t *info = (my_dl_info_32_t*)i; + printf_log(LOG_DEBUG, "Warning: partially unimplement call to dladdr/dladdr1(%p, %p, %p, %d)\n", addr, info, extra_info, flags); + + //emu->quit = 1; + library_t* lib = NULL; + info->dli_saddr = 0; + info->dli_fname = 0; + void* start = NULL; + const char* fname = NULL; + void* base = NULL; + const char* sname = FindSymbolName(my_context->maplib, addr, &start, NULL, &fname, &base, &lib); + info->dli_saddr = to_ptrv(start); + info->dli_fname = to_ptrv((void*)fname); + info->dli_fbase = to_ptrv(base); + info->dli_sname = to_ptrv((void*)sname); + printf_log(LOG_DEBUG, " dladdr return saddr=%p, fname=\"%s\", sname=\"%s\"\n", start, sname?sname:"", fname?fname:""); + if(flags==RTLD_DL_SYMENT) { + printf_log(LOG_INFO, "Warning, unimplement call to dladdr1 with RTLD_DL_SYMENT flags\n"); + } else if (flags==RTLD_DL_LINKMAP) { + printf_log(LOG_INFO, "Warning, unimplemented call to dladdr1 with RTLD_DL_LINKMAP flags\n"); + *(ptr_t*)extra_info = to_ptrv(getLinkMapLib32(lib)); + } + return (info->dli_sname)?1:0; // success is non-null here... +} +int my32_dladdr(x64emu_t* emu, void *addr, void *i) +{ + return my32_dladdr1(emu, addr, i, NULL, 0); +} + +int my32_dlinfo(x64emu_t* emu, void* handle, int request, void* info) +{ + (void)emu; + printf_dlsym(LOG_DEBUG, "Call to dlinfo(%p, %d, %p)\n", handle, request, info); + CLEARERR; + library_t *lib = dl_get_library(handle); + if(lib==(library_t*)-1LL) { + printf_dlsym(LOG_DEBUG, "dlinfo: %s\n", dl_last_error()); + return -1; + } + //elfheader_t *h = (GetElfIndex(lib)>-1)?my_context->elfs[GetElfIndex(lib)]:NULL; + switch(request) { + case 2: // RTLD_DI_LINKMAP + { + *(linkmap32_t**)info = getLinkMapLib32(lib); + } + return 0; + default: + printf_log(LOG_NONE, "Warning, unsupported call to dlinfo(%p, %d, %p)\n", handle, request, info); + { + char tmp[129] = {0}; + snprintf(tmp, 129, "unsupported call to dlinfo request:%d\n", request); + dl_set_error(tmp); + } + } + return -1; +} + +typedef struct my_dl_find_object_s { + uint64_t dlfo_flags; + ptr_t dlfo_map_start; + ptr_t dlfo_map_end; + ptr_t dlf_link_map; //struct link_map * + ptr_t dlfo_eh_frame; + // other stuff... +} my_dl_find_object_t; + +EXPORT int my32__dl_find_object(x64emu_t* emu, void* addr, my_dl_find_object_t* result) +{ + //printf_log(LOG_INFO, "Unimplemented _dl_find_object called\n"); + uintptr_t start=0, sz=0; + elfheader_t* h = FindElfAddress(my_context, (uintptr_t)addr); + if(h) { + // find an actual elf + const char* name = FindNearestSymbolName(h, addr, &start, &sz); + result->dlfo_map_start = start; + result->dlfo_map_end = start+sz-1; + result->dlfo_eh_frame = h->ehframehdr+h->delta; + result->dlfo_flags = 0; // unused it seems + result->dlf_link_map = to_ptrv(getLinkMapElf32(h)); + return 0; + } + return -1; +} + +//#define CUSTOM_INIT\ +// if(!box32_isglibc234) setNeededLibs(lib, 1, "libc.so.6"); + + +void closeAllDLOpenned(); + +#define PRE_INIT\ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ + else + +#define CUSTOM_FINI \ + closeAllDLOpenned(); + +// define all standard library functions +#include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedlibdl_private.h b/src/wrapped32/wrappedlibdl_private.h new file mode 100755 index 00000000..5df76d7d --- /dev/null +++ b/src/wrapped32/wrappedlibdl_private.h @@ -0,0 +1,15 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA) && defined(GOS)) +#error Meh... +#endif + +GOM(dladdr, iFEpp) +GOM(dladdr1, iFEpppi) +GO2(dlclose, iFEp, my_dlclose) +GO2(dlerror, pFEv, my_dlerror) +//DATAB(_dlfcn_hook, 4) +GOM(dlinfo, iFEpip) +GO2(dlmopen, pFEppi, my_dlmopen) +GO2(dlopen, pFEpi, my_dlopen) +GO2(dlsym, pFEpp, my_dlsym) +GO2(dlvsym, pFEppp, my_dlvsym) // Weak +GOM(_dl_find_object, iFEpp) diff --git a/src/wrapped32/wrappedlibm.c b/src/wrapped32/wrappedlibm.c new file mode 100755 index 00000000..a36a3227 --- /dev/null +++ b/src/wrapped32/wrappedlibm.c @@ -0,0 +1,154 @@ +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <complex.h> +#include <math.h> + +#include "wrappedlibs.h" + +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "x64emu.h" +#include "debug.h" +#include "box32.h" + +static const char* libmName = +#ifdef ANDROID + "libm.so" +#else + "libm.so.6" +#endif + ; +#define LIBNAME libm + +static library_t* my_lib = NULL; + +typedef float (*fFff_t) (float, float); +typedef double (*dFdd_t) (double, double); +typedef float (*fFf_t) (float); +typedef double (*dFd_t) (double); +#if 0 +typedef union my_float_complex_s { + float complex f; + uint64_t u64; +} my_float_complex_t; + +// complex <- FUNC(complex) wrapper +#define GO_cFc(N) \ +EXPORT void* my_##N(void* p, void* c) \ +{ \ + *(double complex*)p = N(*(double complex*)c); \ + return p; \ +} \ +EXPORT uint64_t my_##N##f(void* c) \ +{ \ + my_float_complex_t ret; \ + ret.f = N##f(*(float complex*)c); \ + return ret.u64; \ +} +// complex <- FUNC(complex, complex) wrapper +#define GO_cFcc(N) \ +EXPORT void* my_##N(void* p, void* c, void* d) \ +{ \ + *(double complex*)p = N(*(double complex*)c, *(double complex*)d); \ + return p; \ +} \ +EXPORT uint64_t my_##N##f(void* c, void* d) \ +{ \ + my_float_complex_t ret; \ + ret.f = N##f(*(float complex*)c, *(float complex*)c); \ + return ret.u64; \ +} + +GO_cFc(clog) +GO_cFc(csqrt) +GO_cFc(cproj) +GO_cFc(cexp) +GO_cFc(ccos) +GO_cFc(csin) +GO_cFc(ccosh) +GO_cFc(csinh) +GO_cFc(ctan) +GO_cFc(ctanh) +GO_cFc(cacos) +GO_cFc(casin) +GO_cFc(cacosh) +GO_cFc(casinh) +GO_cFc(catan) +GO_cFc(catanh) +GO_cFcc(cpow) + +#undef GO_cFc +#undef GO_cFcc +#endif + +#define FINITE(N, T, R, P, ...) \ +EXPORT R my32___##N##_finite P \ +{ \ + static int check = 0; \ + static T f = NULL; \ + if(!check) { \ + f = (T)dlsym(my_lib->w.lib, "__" #N "_finite"); \ + ++check; \ + } \ + if(f) \ + return f(__VA_ARGS__); \ + else \ + return N(__VA_ARGS__); \ +} + +#define F1F(N) FINITE(N, fFf_t, float, (float a), a) +#define F1D(N) FINITE(N, dFd_t, double, (double a), a) +#define F2F(N) FINITE(N, fFff_t, float, (float a, float b), a, b) +#define F2D(N) FINITE(N, dFdd_t, double, (double a, double b), a, b) + +F2F(powf) +F2D(pow) +F1F(sinhf) +F1D(sinh) +F1F(sqrtf) +F1D(sqrt) +F1F(acosf) +F1D(acos) +F1F(acoshf) +F1D(acosh) +F1F(asinf) +F1D(asin) +F2F(atan2f) +F2D(atan2) +F1F(coshf) +F1D(cosh) +F1F(exp2f) +F1D(exp2) +F1F(expf) +F1D(exp) +F2F(hypotf) +F2D(hypot) +F1F(log10f) +F1D(log10) +F1F(log2f) +F1D(log2) +F1F(logf) +F1D(log) + +#undef F2D +#undef F2F +#undef F1D +#undef F1F +#undef FINITE + +#define PRE_INIT\ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ + else + +#define CUSTOM_INIT \ + my_lib = lib; + +#define CUSTOM_FINI \ + my_lib = NULL; + +#include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedlibm_private.h b/src/wrapped32/wrappedlibm_private.h new file mode 100755 index 00000000..156cfac6 --- /dev/null +++ b/src/wrapped32/wrappedlibm_private.h @@ -0,0 +1,446 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) +#error meh! +#endif + +// Complex numbers are passed in as an address in the stack + +GOW(acos, dFd) +GOW(acosf, fFf) +GOM(__acosf_finite, fFf) //%noE +GOM(__acos_finite, dFd) //%noE +GOW(acosh, dFd) +GOW(acoshf, fFf) +GOM(__acoshf_finite, fFf) //%noE +GOM(__acosh_finite, dFd) //%noE +#ifdef HAVE_LD80BITS +GOW(acoshl, DFD) +#else +GOW2(acoshl, KFK, acosh) +#endif +#ifdef HAVE_LD80BITS +GOW(acosl, DFD) +#else +GOW2(acosl, KFK, acos) +#endif +GOW(asin, dFd) +GOW(asinf, fFf) +GOM(__asinf_finite, fFf) //%noE +GOM(__asin_finite, dFd) //%noE +GOW(asinh, dFd) +GOW(asinhf, fFf) +#ifdef HAVE_LD80BITS +GOW(asinhl, DFD) +#else +GOW2(asinhl, KFK, asinh) +#endif +#ifdef HAVE_LD80BITS +GOW(asinl, DFD) +#else +GOW2(asinl, KFK, asin) +#endif +GO(atan, dFd) +GOW(atan2, dFdd) +GOW(atan2f, fFff) +GOM(__atan2f_finite, fFff) //%noE +GOM(__atan2_finite, dFdd) //%noE +// atan2l // Weak +GOW(atanf, fFf) +GOW(atanh, dFd) +GOW(atanhf, fFf) +// __atanhf_finite +// __atanh_finite +#ifdef HAVE_LD80BITS +GOW(atanhl, DFD) +#else +GOW2(atanhl, KFK, atanh) +#endif +// atanl // Weak +//GOW(cabs, dFdd) // only 1 arg, but is a double complex +GOW(cabsf, fFff) // only 1 arg, but is a float complex +// cabsl // Weak +//GOWS(cacos, pFps) //%% complex +GOWM(cacosf, UFs) //%noE +//GOWS(cacosh, pFps) //%% complex +GOWM(cacoshf, UFs) //%noE +// cacoshl // Weak +// cacosl // Weak +//GOW(carg, dFdd) // 1arg, double complex +GOW(cargf, fFff) // 1arg, float complex +// cargl // Weak +//GOWS(casin, pFps) //%% complex +GOWM(casinf, UFs) //%noE +//GOWS(casinh, pFps) //%% complex +GOWM(casinhf, UFs) //%noE +// casinhl // Weak +// casinl // Weak +//GOWS(catan, pFps) //%% complex +GOWM(catanf, UFs) //%noE +//GOWS(catanh, pFps) //%% complex +GOWM(catanhf, UFs) //%noE +// catanhl // Weak +// catanl // Weak +GOW(cbrt, dFd) +GOW(cbrtf, fFf) +#ifdef HAVE_LD80BITS +GOW(cbrtl, DFD) +#else +GOW2(cbrtl, KFK, cbrt) +#endif +//GOWS(ccos, pFps) //%% return complex +GOWM(ccosf, UFs) //%noE return complex +//GOWS(ccosh, pFps) //%% return complex +GOWM(ccoshf, UFs) //%noE return complex +// ccoshl // Weak +// ccosl // Weak +//GOW(ceil, dFd) +//GOW(ceilf, fFf) +// ceill // Weak +//GOWS(cexp, pFps) //%% return complex +GOWM(cexpf, UFs) //%noE return complex +// cexpl // Weak +// cimag // Weak +// cimagf // Weak +// cimagl // Weak +//GOS(clog, pFps) //%% return a double complex, so ret 4 +// clog10 // Weak +// __clog10 +// clog10f // Weak +// __clog10f +// clog10l // Weak +// __clog10l +GOM(clogf, UFs) //%noE float complex doesn't trigger the ret 4, but returns an u64! +// clogl // Weak +// conj // Weak +// conjf // Weak +// conjl // Weak +GOW(copysign, dFdd) +GOW(copysignf, fFff) +// copysignl // Weak +GOW(cos, dFd) +GOW(cosf, fFf) +GOW(cosh, dFd) +GOW(coshf, fFf) +GOM(__coshf_finite, fFf) //%noE +GOM(__cosh_finite, dFd) //%noE +// coshl // Weak +// cosl // Weak +//GOWS(cpow, pFpsvvvvs) //%% return complex +GOWM(cpowf, UFsvvs) //%noE +// cpowl // Weak +//GOS(cproj, pFps) //%% double complex +GOM(cprojf, UFs) //%noE +// cprojl // Weak +// creal // Weak +// crealf // Weak +// creall // Weak +//GOWS(csin, pFps) //%% return complex +GOWM(csinf, UFs) //%noE return complex +//GOWS(csinh, pFps) //%% return complex +GOWM(csinhf, UFs) //%noE return complex +// csinhl // Weak +// csinl // Weak +//GOWS(csqrt, pFps) //%% +GOWM(csqrtf, UFs) //%noE +// csqrtl // Weak +//GOWS(ctan, pFps) //%% return complex +GOWM(ctanf, UFs) //%noE return complex +//GOWS(ctanh, pFps) //%% return complex +GOWM(ctanhf, UFs) //%noE return complex +// ctanhl // Weak +// ctanl // Weak +// __cxa_finalize // Weak +// drem // Weak +// dremf // Weak +// dreml // Weak +GOW(erf, dFd) +GOW(erfc, dFd) +GOW(erfcf, fFf) +#ifdef HAVE_LD80BITS +GOW(erfcl, DFD) +#else +GOW2(erfcl, KFK, erfc) +#endif +GOW(erff, fFf) +#ifdef HAVE_LD80BITS +GOW(erfl, DFD) +#else +GOW2(erfl, KFK, erf) +#endif +GOW(exp, dFd) +GOW(exp10, dFd) +GOW(exp10f, fFf) +// __exp10f_finite +// __exp10_finite +// exp10l // Weak +GOW(exp2, dFd) +GOW(exp2f, fFf) +GOM(__exp2f_finite, fFf) //%noE +GOM(__exp2_finite, dFd) //%noE +// exp2l // Weak +GOW(expf, fFf) +GOM(__expf_finite, fFf) //%noE +GOM(__exp_finite, dFd) //%noE +// expl // Weak +GOW(expm1, dFd) +GOW(expm1f, fFf) +// expm1l // Weak +GOW(fabs, dFd) +GOW(fabsf, fFf) +// fabsl // Weak +// fdim // Weak +// fdimf // Weak +// fdiml // Weak +GO(feclearexcept, iFi) +GO(fedisableexcept, iFi) +GO(feenableexcept, iFi) +GO(fegetenv, iFp) +GO(fegetexcept, iFv) +GO(fegetexceptflag, iFpi) +GO(fegetround, iFv) +GO(feholdexcept, iFp) +GO(feraiseexcept, iFi) +GO(fesetenv, iFp) +GO(fesetexceptflag, iFpi) +GO(fesetround, iFi) +GO(fetestexcept, iFi) +GO(feupdateenv, iFp) +GOW(finite, iFd) +// __finite +GOW(finitef, iFf) +GO(__finitef, iFf) +// finitel // Weak +// __finitel +GOW(floor, dFd) +GOW(floorf, fFf) +// floorl // Weak +GOW(fma, dFddd) +GOW(fmaf, fFfff) +// fmal // Weak +GOW(fmax, dFdd) +GOW(fmaxf, fFff) +// fmaxl // Weak +GOW(fmin, dFdd) +GOW(fminf, fFff) +// fminl // Weak +GOW(fmod, dFdd) +GOW(fmodf, fFff) +// __fmodf_finite +// __fmod_finite +#ifdef HAVE_LD80BITS +GOW(fmodl, DFDD) +#else +GOW2(fmodl, KFKK, fmod) +#endif +GO(__fpclassify, iFd) +GO(__fpclassifyf, iFf) +GOW(frexp, dFdp) +GOW(frexpf, fFfp) +#ifdef HAVE_LD80BITS +GOW(frexpl, DFDp) +#else +GOW2(frexpl, KFKp, frexp) +#endif +// gamma // Weak +// gammaf // Weak +// __gammaf_r_finite +// gammal // Weak +// __gamma_r_finite +// __gmon_start__ // Weak +GOW(hypot, dFdd) +GOW(hypotf, fFff) +GOM(__hypotf_finite, fFff) //%noE +GOM(__hypot_finite, dFdd) //%noE +// hypotl // Weak +GOW(ilogb, iFd) +GOW(ilogbf, iFf) +// ilogbl // Weak +// __issignaling +// __issignalingf +// _ITM_deregisterTMCloneTable // Weak +// _ITM_registerTMCloneTable // Weak +GO(j0, dFd) +GO(j0f, fFf) +// __j0f_finite +// __j0_finite +// j0l +GO(j1, dFd) +GO(j1f, fFf) +// __j1f_finite +// __j1_finite +// j1l +GO(jn, dFid) +GO(jnf, fFif) +// __jnf_finite +// __jn_finite +// jnl +GOW(ldexp, dFdi) +GOW(ldexpf, fFfi) +#ifdef HAVE_LD80BITS +GOW(ldexpl, DFD) +#else +GOW2(ldexpl, KFK, ldexp) +#endif +GOW(lgamma, dFd) +GOW(lgammaf, fFf) +GOW(lgammaf_r, fFfp) +// __lgammaf_r_finite +#ifdef HAVE_LD80BITS +GOW(lgammal, DFD) +#else +GOW2(lgammal, KFK, lgamma) +#endif +#ifdef HAVE_LD80BITS +GOW(lgammal_r, DFDp) +#else +GOW2(lgammal_r, KFKp, lgamma_r) +#endif +GOW(lgamma_r, dFdp) +// __lgamma_r_finite +DATAV(_LIB_VERSION, 4) +GOW(llrint, IFd) +GOW(llrintf, IFf) +// llrintl // Weak +GOW(llround, IFd) +GOW(llroundf, IFf) +// llroundl // Weak +GOW(log, dFd) +GOW(log10, dFd) +GOW(log10f, fFf) +GOM(__log10f_finite, fFf) //%noE +GOM(__log10_finite, dFd) //%noE +// log10l // Weak +GOW(log1p, dFd) +GOW(log1pf, fFf) +// log1pl // Weak +GOW(log2, dFd) +GOW(log2f, fFf) +GOM(__log2f_finite, fFf) //%noE +GOM(__log2_finite, dFd) //%noE +// log2l // Weak +GOW(logb, dFd) +GOW(logbf, fFf) +// logbl // Weak +GOW(logf, fFf) +GOM(__logf_finite, fFf) //%noE +GOM(__log_finite, dFd) //%noE +#ifdef HAVE_LD80BITS +GOW(logl, DFD) +#else +GOW2(logl, KFK, log) +#endif +GOW(lrint, iFd) +GOW(lrintf, iFf) +// lrintl // Weak +GOW(lround, iFd) +GOW(lroundf, iFf) +// lroundl // Weak +// matherr // Weak +GOW(modf, dFdp) +GOW(modff, fFfp) +// modfl // Weak +// nan // Weak +// nanf // Weak +// nanl // Weak +GOW(nearbyint, dFd) +GOW(nearbyintf, fFf) +// nearbyintl // Weak +GOW(nextafter, dFdd) +GOW(nextafterf, fFff) +// nextafterl // Weak +GOW(nexttoward, dFdD) +GOW(nexttowardf, fFfD) +// nexttowardl // Weak +GOW(pow, dFdd) +GOW(pow10, dFd) +GOW(pow10f, fFf) +#ifdef HAVE_LD80BITS +GOWM(pow10l, DFD) //%noE +#else +GOWM(pow10l, KFK) //%noE +#endif +GOW(powf, fFff) +GOM(__powf_finite, fFff) //%noE +GOM(__pow_finite, dFdd) //%noE +#ifdef HAVE_LD80BITS +GOW(powl, DFDD) +#else +GOW2(powl, KFKK, pow) +#endif +GOW(remainder, dFdd) +GOW(remainderf, fFff) +// __remainderf_finite +// __remainder_finite +// remainderl // Weak +GOW(remquo, dFddp) +GOW(remquof, fFffp) +// remquol // Weak +GOW(rint, dFd) +GOW(rintf, fFf) +// rintl // Weak +GOW(round, dFd) +GOW(roundf, fFf) +// roundl // Weak +// scalb // Weak +// scalbf // Weak +// __scalbf_finite +// __scalb_finite +// scalbl // Weak +GOW(scalbln, dFdi) +GOW(scalblnf, fFfi) +// scalblnl // Weak +GOW(scalbn, dFdi) +GOW(scalbnf, fFfi) +// scalbnl // Weak +// __signbit +// __signbitf +DATAB(signgam, 4) +// significand // Weak +// significandf // Weak +// significandl // Weak +GOW(sin, dFd) +GOW(sincos, vFdpp) +GOW(sincosf, vFfpp) +// sincosl // Weak +GOW(sinf, fFf) +GOW(sinh, dFd) +GOW(sinhf, fFf) +GOM(__sinhf_finite, fFf) //%noE +GOM(__sinh_finite, dFd) //%noE +// sinhl // Weak +// sinl // Weak +GOW(sqrt, dFd) +GOW(sqrtf, fFf) +GOM(__sqrtf_finite, fFf) //%noE +GOM(__sqrt_finite, dFd) //%noE +// sqrtl // Weak +GO(tan, dFd) +GOW(tanf, fFf) +GOW(tanh, dFd) +GOW(tanhf, fFf) +// tanhl // Weak +// tanl // Weak +GOW(tgamma, dFd) +GOW(tgammaf, fFf) +#ifdef HAVE_LD80BITS +GOW(tgammal, DFD) +#else +GOW2(tgammal, KFK, tgamma) +#endif +GOW(trunc, dFd) +GOW(truncf, fFf) +// truncl // Weak +GO(y0, dFd) +GO(y0f, fFf) +// __y0f_finite +// __y0_finite +// y0l +GO(y1, dFd) +GO(y1f, fFf) +// __y1f_finite +// __y1_finite +// y1l +GO(yn, dFid) +GO(ynf, fFif) +// __ynf_finite +// __yn_finite +// ynl diff --git a/src/wrapped32/wrappedlibpthread.c b/src/wrapped32/wrappedlibpthread.c new file mode 100755 index 00000000..d7881f6b --- /dev/null +++ b/src/wrapped32/wrappedlibpthread.c @@ -0,0 +1,97 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <errno.h> +#include <pthread.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "x64emu.h" +#include "emu/x64emu_private.h" +#include "box32context.h" +#include "librarian.h" + +static const char* libpthreadName = "libpthread.so.0"; +#define LIBNAME libpthread + +typedef int (*iFpp_t)(void*, void*); +typedef int (*iFppu_t)(void*, void*, uint32_t); +EXPORT int my32_pthread_setname_np(x64emu_t* emu, void* t, void* n) +{ + static void* f = NULL; + static int need_load = 1; + if(need_load) { + library_t* lib = GetLibInternal(libpthreadName); + if(!lib) return 0; + f = dlsym(lib->w.lib, "pthread_setname_np"); + need_load = 0; + } + if(f) + return ((iFpp_t)f)(t, n); + return 0; +} +EXPORT int my32_pthread_getname_np(x64emu_t* emu, void* t, void* n, uint32_t s) +{ + static void* f = NULL; + static int need_load = 1; + if(need_load) { + library_t* lib = GetLibInternal(libpthreadName); + if(!lib) return 0; + f = dlsym(lib->w.lib, "pthread_getname_np"); + need_load = 0; + } + if(f) + return ((iFppu_t)f)(t, n, s); + else + strncpy((char*)n, "dummy", s); + return 0; +} + +EXPORT int my32_pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) +{ + return pthread_rwlock_wrlock(rwlock); +} +EXPORT int my32_pthread_rwlock_rdlock(pthread_rwlock_t* rwlock) +{ + return pthread_rwlock_rdlock(rwlock); +} +EXPORT int my32_pthread_rwlock_unlock(pthread_rwlock_t *rwlock) +{ + return pthread_rwlock_unlock(rwlock); +} + +EXPORT int32_t my32_pthread_atfork(x64emu_t *emu, void* prepare, void* parent, void* child) +{ + // this is partly incorrect, because the emulated functions should be executed by actual fork and not by my32_atfork... + if(my_context->atfork_sz==my_context->atfork_cap) { + my_context->atfork_cap += 4; + my_context->atforks = (atfork_fnc_t*)realloc(my_context->atforks, my_context->atfork_cap*sizeof(atfork_fnc_t)); + } + int i = my_context->atfork_sz++; + my_context->atforks[i].prepare = (uintptr_t)prepare; + my_context->atforks[i].parent = (uintptr_t)parent; + my_context->atforks[i].child = (uintptr_t)child; + my_context->atforks[i].handle = NULL; + + return 0; +} +EXPORT int32_t my32___pthread_atfork(x64emu_t *emu, void* prepare, void* parent, void* child) __attribute__((alias("my32_pthread_atfork"))); + +EXPORT void my32___pthread_initialize() +{ + // nothing, the lib initialize itself now +} + +#define PRE_INIT\ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ + else + +#include "wrappedlib_init32.h" + diff --git a/src/wrapped32/wrappedlibpthread_private.h b/src/wrapped32/wrappedlibpthread_private.h new file mode 100755 index 00000000..be13d397 --- /dev/null +++ b/src/wrapped32/wrappedlibpthread_private.h @@ -0,0 +1,187 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) +#error meh! +#endif +// General note: pthread_t is unsigned long int +// cpu_set_t is a struct with an array, default size is fixed for all architecture + +// __errno_location +// fork +// __fork +// __h_errno_location +// _IO_flockfile +// _IO_ftrylockfile +// _IO_funlockfile +// __libc_allocate_rtsig +// __libc_current_sigrtmax +// __libc_current_sigrtmin +GOM(pthread_atfork, iFEppp) +GOM(__pthread_atfork, iFEppp) +GOM(pthread_attr_destroy, iFEp) +// pthread_attr_getaffinity_np +GOM(pthread_attr_getdetachstate, iFEpp) +GOM(pthread_attr_getguardsize, iFEpp) +GOM(pthread_attr_getinheritsched, iFEpp) +GOM(pthread_attr_getschedparam, iFEpp) +GOM(pthread_attr_getschedpolicy, iFEpp) +GOM(pthread_attr_getscope, iFEpp) +GOM(pthread_attr_getstack, iFEppp) +GOM(pthread_attr_getstackaddr, iFEpp) +GOM(pthread_attr_getstacksize, iFEpp) +GOM(pthread_attr_init, iFEp) +GOM(pthread_attr_setaffinity_np, iFEpup) +GOM(pthread_attr_setdetachstate, iFEpi) +GOM(pthread_attr_setguardsize, iFEpL) +GOM(pthread_attr_setinheritsched, iFEpi) +GOM(pthread_attr_setschedparam, iFEpp) +GOM(pthread_attr_setschedpolicy, iFEpi) +GOM(pthread_attr_setscope, iFEpi) +GOM(pthread_attr_setstack, iFEppL) +GOM(pthread_attr_setstackaddr, iFEpp) +GOM(pthread_attr_setstacksize, iFEpL) +GO(pthread_barrierattr_destroy, iFp) +GO(pthread_barrierattr_getpshared, iFpp) +GO(pthread_barrierattr_init, iFp) +GO(pthread_barrierattr_setpshared, iFpi) +GO(pthread_barrier_destroy, iFp) +GO(pthread_barrier_init, iFppu) +GO(pthread_barrier_wait, iFp) +GO(pthread_cancel, iFh) +GOM(_pthread_cleanup_pop, vFEpi) +GOM(_pthread_cleanup_pop_restore, vFEpi) +GOM(_pthread_cleanup_push, vFEppp) +GOM(_pthread_cleanup_push_defer, vFEppp) +// __pthread_cleanup_routine +GO(pthread_condattr_destroy, iFp) +GO(pthread_condattr_getclock, iFpp) +GO(pthread_condattr_getpshared, iFpp) +GO(pthread_condattr_init, iFp) +GO(pthread_condattr_setclock, iFpp) +GO(pthread_condattr_setpshared, iFpi) +GO2(pthread_cond_broadcast@GLIBC_2.0, iFEp, my32_pthread_cond_broadcast_old) +GO2(pthread_cond_destroy@GLIBC_2.0, iFEp, my32_pthread_cond_destroy_old) +GO2(pthread_cond_init@GLIBC_2.0, iFEpp, my32_pthread_cond_init_old) +GO2(pthread_cond_signal@GLIBC_2.0, iFEp, my32_pthread_cond_signal_old) +GO2(pthread_cond_timedwait@GLIBC_2.0, iFEppp, my32_pthread_cond_timedwait_old) +GO2(pthread_cond_wait@GLIBC_2.0, iFEpp, my32_pthread_cond_wait_old) +GO(pthread_cond_broadcast, iFp) +GO(pthread_cond_destroy, iFp) +GO(pthread_cond_init, iFpp) +GO(pthread_cond_signal, iFp) +GOM(pthread_cond_timedwait, iFEppp) +GOM(pthread_cond_wait, iFEpp) +GOM(pthread_create, iFEBh_ppp) +GOM(pthread_detach, iFEh) +GO(pthread_equal, iFhh) +GO(pthread_exit, vFp) +GOM(pthread_getaffinity_np, iFEpup) +GO(pthread_getattr_np, iFup) +GO(pthread_getconcurrency, iFv) +GO(pthread_getcpuclockid, iFup) +GO(pthread_getschedparam, iFupp) +GO(__pthread_getspecific, pFu) +GO(pthread_getspecific, pFu) +GOM(pthread_getname_np, iFEppu) //not present on Pandora +GOM(__pthread_initialize, vFv) //%noE doesn't exist anymore... +// __pthread_initialize_minimal +GO(pthread_join, iFHBp_) +GOM(__pthread_key_create, iFEpp) +GOM(pthread_key_create, iFEpp) +GO(pthread_key_delete, iFu) +GOM(pthread_kill, iFEpi) +// pthread_kill_other_threads_np +GO(__pthread_mutexattr_destroy, iFp) +GO(pthread_mutexattr_destroy, iFp) +GO(pthread_mutexattr_getprioceiling, iFpp) +GO(pthread_mutexattr_getprotocol, iFpp) +// pthread_mutexattr_getpshared +// pthread_mutexattr_getrobust_np +GO(pthread_mutexattr_gettype, iFpp) +GO(__pthread_mutexattr_init, iFp) +GO(pthread_mutexattr_init, iFp) +GO(pthread_mutexattr_setprioceiling, iFpi) +GO(pthread_mutexattr_setprotocol, iFpp) +GO(pthread_mutexattr_setpshared, iFpi) +// pthread_mutexattr_setrobust_np +GO(__pthread_mutexattr_settype, iFpi) +GO(pthread_mutexattr_settype, iFpi) +// pthread_mutex_consistent_np +GOM(__pthread_mutex_destroy, iFp) //%noE +GOM(pthread_mutex_destroy, iFp) //%noE +// pthread_mutex_getprioceiling +GOM(__pthread_mutex_init, iFpp) //%noE +GOM(pthread_mutex_init, iFpp) //%noE +GOM(__pthread_mutex_lock, iFp) //%noE +GOM(pthread_mutex_lock, iFp) //%noE +// pthread_mutex_setprioceiling +GOM(pthread_mutex_timedlock, iFpp) //%noE +GOM(__pthread_mutex_trylock, iFp) //%noE +GOM(pthread_mutex_trylock, iFp) //%noE +GOM(__pthread_mutex_unlock, iFp) //%noE +GOM(pthread_mutex_unlock, iFp) //%noE +GOM(pthread_once, iFEpp) +GOM(__pthread_once, iFEpp) +GOM(__pthread_register_cancel, vFEp) +// __pthread_register_cancel_defer +GO(pthread_rwlockattr_destroy, vFp) +GO(pthread_rwlockattr_getkind_np, iFpp) +// pthread_rwlockattr_getpshared +GO(pthread_rwlockattr_init, iFp) +GO(pthread_rwlockattr_setkind_np, iFpi) +// pthread_rwlockattr_setpshared +// __pthread_rwlock_destroy +GO(pthread_rwlock_destroy, iFp) +GO(__pthread_rwlock_init, iFpp) +GO(pthread_rwlock_init, iFpp) +GO(__pthread_rwlock_rdlock, iFp) +GOM(pthread_rwlock_rdlock, iFp) //%noE +// pthread_rwlock_timedrdlock +// pthread_rwlock_timedwrlock +// __pthread_rwlock_tryrdlock +GO(pthread_rwlock_tryrdlock, iFp) +// __pthread_rwlock_trywrlock +GO(pthread_rwlock_trywrlock, iFp) +GO(__pthread_rwlock_unlock, iFp) +GOM(pthread_rwlock_unlock, iFp) //%noE +GO(__pthread_rwlock_wrlock, iFp) +GOM(pthread_rwlock_wrlock, iFp) //%noE +GO(pthread_self, hFv) +GOM(pthread_setaffinity_np, iFELup) +GO(pthread_setcancelstate, iFip) +GO(pthread_setcanceltype, iFip) +GO(pthread_setconcurrency, iFi) +GOM(pthread_setname_np, iFEpp) // not present on the Pandora +GO(pthread_setschedparam, iFuip) +GO(pthread_setschedprio, iFpi) +GO(__pthread_setspecific, iFup) +GO(pthread_setspecific, iFup) +GO(pthread_sigmask, iFipp) +GO(pthread_spin_destroy, iFp) +GO(pthread_spin_init, iFpi) +GO(pthread_spin_lock, iFp) +GO(pthread_spin_trylock, iFp) +GO(pthread_spin_unlock, iFp) +GO(pthread_testcancel, vFv) +GO(pthread_timedjoin_np, iFppp) +GO(pthread_tryjoin_np, iFpp) +GOM(__pthread_unregister_cancel, vFEp) +// __pthread_unregister_cancel_restore +// __pthread_unwind +GOM(__pthread_unwind_next, vFEp) +GO(pthread_yield, iFv) +// raise +// __res_state +GO(sem_close, iFp) +GO(sem_destroy, iFp) +GO(sem_getvalue, iFpp) +GO(sem_init, iFpiu) +GO(sem_open, pFpOM) +GO(sem_post, iFp) +GO(sem_timedwait, iFpp) +GO(sem_trywait, iFp) +GO(sem_unlink, iFp) +GO(sem_wait, iFp) +// __sigaction +// system +// __vfork + +GOM(pthread_mutexattr_setkind_np, iFEpi) // deprecated diff --git a/src/wrapped32/wrappedlibrt.c b/src/wrapped32/wrappedlibrt.c new file mode 100755 index 00000000..84b7730e --- /dev/null +++ b/src/wrapped32/wrappedlibrt.c @@ -0,0 +1,80 @@ +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <signal.h> + +#include "wrappedlibs.h" + +#include "debug.h" +#include "wrapper32.h" +#include "bridge.h" +#include "librarian/library_private.h" +#include "x64emu.h" +#include "emu/x64emu_private.h" +#include "callback.h" +#include "librarian.h" +#include "box32context.h" +#include "emu/x64emu_private.h" + +#undef aio_suspend +#undef aio_return +#undef aio_write +#undef aio_read +#undef aio_error + +#undef clock_gettime + +static const char* librtName = "librt.so.1"; +#define LIBNAME librt + +#define SUPER() \ +GO(0) \ +GO(1) \ +GO(2) \ +GO(3) + +// sigev_notify +#define GO(A) \ +static uintptr_t my32_sigev_notify_fct_##A = 0; \ +static void my32_sigev_notify_##A(void* sigval) \ +{ \ + RunFunctionFmt(my32_sigev_notify_fct_##A, "p", to_ptrv(sigval));\ +} +SUPER() +#undef GO +static void* findsigev_notifyFct(void* fct) +{ + if(!fct) return fct; + if(GetNativeFnc((uintptr_t)fct)) return GetNativeFnc((uintptr_t)fct); + #define GO(A) if(my32_sigev_notify_fct_##A == (uintptr_t)fct) return my32_sigev_notify_##A; + SUPER() + #undef GO + #define GO(A) if(my32_sigev_notify_fct_##A == 0) {my32_sigev_notify_fct_##A = (uintptr_t)fct; return my32_sigev_notify_##A; } + SUPER() + #undef GO + printf_log(LOG_NONE, "Warning, no more slot for libpng12 sigev_notify callback\n"); + return NULL; +} + +#undef SUPER + +EXPORT int my32_timer_create(x64emu_t* emu, uint32_t clockid, void* sevp, timer_t* timerid) +{ + struct sigevent sevent; + memcpy(&sevent, sevp, sizeof(sevent)); + + if(sevent.sigev_notify == SIGEV_THREAD) { + sevent.sigev_notify_function = findsigev_notifyFct(sevent.sigev_notify_function); + } + + return timer_create(clockid, &sevent, timerid); +} + +#define PRE_INIT\ + if(1) \ + lib->w.lib = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL); \ + else + +#include "wrappedlib_init32.h" diff --git a/src/wrapped32/wrappedlibrt_private.h b/src/wrapped32/wrappedlibrt_private.h new file mode 100755 index 00000000..dffbc20f --- /dev/null +++ b/src/wrapped32/wrappedlibrt_private.h @@ -0,0 +1,50 @@ +#if !(defined(GO) && defined(GOM) && defined(GO2) && defined(DATA)) +#error Meh... +#endif + +//clockid_t is uint32? +// pid_t is uint32 too? (for clock_getcpuclockid) +// time_t is long +// timespec is struct LL +// itimerspec is struct 2 timespec (so LLLL) + +// aio_cancel +// aio_cancel64 +// aio_error +GO(aio_error64, iFp) +GO(aio_fsync, iFip) +GO(aio_fsync64, iFip) +// aio_init +// aio_read +GO(aio_read64, iFp) +// aio_return +GO(aio_return64, lFp) +GO(aio_suspend, iFpip) +GO(aio_suspend64, iFpip) +// aio_write +GO(aio_write64, iFp) +GO(clock_getcpuclockid, iFup) +GO(clock_getres, iFup) +//GO(clock_gettime, iFup) // p is *timespec +//GO(clock_nanosleep, iFuipp) +//GO(clock_settime, iFup) +// lio_listio +// lio_listio64 +// mq_close +GO(mq_getattr, iFip) +// mq_notify +// mq_open +// __mq_open_2 +// mq_receive +// mq_send +// mq_setattr +// mq_timedreceive +// mq_timedsend +// mq_unlink +GO(shm_open, iFpOu) +GO(shm_unlink, iFp) +//GOM(timer_create, iFEupp) +GO(timer_delete, iFu) +GO(timer_getoverrun, iFu) +//GO(timer_gettime, iFup) //time_t is L, timespec is struct LL, itimerspec (the p) is 2 timespec +//GO(timer_settime, iFuipp) //same, p are itimerspec |