Skip to content

Commit

Permalink
[BOX32] Handling of BOX64_MAXCPU for 32bits apps
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed Sep 30, 2024
1 parent 0980c44 commit 2a0489a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/wrapped32/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#() dFd -> dFd
#() dFp -> dFp
#() lFv -> lFv
#() lFi -> lFi
#() lFu -> lFu
#() lFl -> lFl
#() lFp -> lFp
Expand Down Expand Up @@ -188,6 +187,7 @@
#() dFdp -> dFdp
#() dFll -> dFll
#() dFpp -> dFpp
#() lFEi -> lFEi
#() lFEV -> lFEV
#() lFES -> lFES
#() lFii -> lFii
Expand Down Expand Up @@ -1177,6 +1177,9 @@ wrappedlibc:
- uFS:
- getwc
- UFp:
- lFi:
- __sysconf
- sysconf
- lFp:
- atol
- lFV:
Expand Down
3 changes: 3 additions & 0 deletions src/wrapped32/generated/wrappedlibctypes32.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef int32_t (*iFO_t)(int32_t);
typedef uint32_t (*uFp_t)(void*);
typedef uint32_t (*uFS_t)(void*);
typedef uint64_t (*UFp_t)(void*);
typedef intptr_t (*lFi_t)(int32_t);
typedef intptr_t (*lFp_t)(void*);
typedef intptr_t (*lFV_t)(...);
typedef intptr_t (*lFS_t)(void*);
Expand Down Expand Up @@ -103,6 +104,8 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void
GO(__close_nocancel, iFi_t) \
GO(sysinfo, iFp_t) \
GO(getwc, uFS_t) \
GO(__sysconf, lFi_t) \
GO(sysconf, lFi_t) \
GO(atol, lFp_t) \
GO(ftell, lFS_t) \
GO(__ctype_b_loc, pFv_t) \
Expand Down
4 changes: 2 additions & 2 deletions src/wrapped32/generated/wrapper32.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ typedef double (*dFi_t)(int32_t);
typedef double (*dFd_t)(double);
typedef double (*dFp_t)(void*);
typedef intptr_t (*lFv_t)(void);
typedef intptr_t (*lFi_t)(int32_t);
typedef intptr_t (*lFu_t)(uint32_t);
typedef intptr_t (*lFl_t)(intptr_t);
typedef intptr_t (*lFp_t)(void*);
Expand Down Expand Up @@ -278,6 +277,7 @@ typedef double (*dFdD_t)(double, long double);
typedef double (*dFdp_t)(double, void*);
typedef double (*dFll_t)(intptr_t, intptr_t);
typedef double (*dFpp_t)(void*, void*);
typedef intptr_t (*lFEi_t)(x64emu_t*, int32_t);
typedef intptr_t (*lFEV_t)(x64emu_t*, void*);
typedef intptr_t (*lFES_t)(x64emu_t*, void*);
typedef intptr_t (*lFii_t)(int32_t, int32_t);
Expand Down Expand Up @@ -1235,7 +1235,6 @@ void dFi_32(x64emu_t *emu, uintptr_t fcn) { dFi_t fn = (dFi_t)fcn; double db = f
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 dFp_32(x64emu_t *emu, uintptr_t fcn) { dFp_t fn = (dFp_t)fcn; double db = fn(from_ptriv(R_ESP + 4)); fpu_do_push(emu); ST0val = db; }
void lFv_32(x64emu_t *emu, uintptr_t fcn) { lFv_t fn = (lFv_t)fcn; R_EAX = to_long(fn()); }
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 lFu_32(x64emu_t *emu, uintptr_t fcn) { lFu_t fn = (lFu_t)fcn; R_EAX = to_long(fn(from_ptri(uint32_t, R_ESP + 4))); }
void lFl_32(x64emu_t *emu, uintptr_t fcn) { lFl_t fn = (lFl_t)fcn; R_EAX = to_long(fn(to_long(from_ptri(long_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))); }
Expand Down Expand Up @@ -1368,6 +1367,7 @@ void dFdD_32(x64emu_t *emu, uintptr_t fcn) { dFdD_t fn = (dFdD_t)fcn; double 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 dFll_32(x64emu_t *emu, uintptr_t fcn) { dFll_t fn = (dFll_t)fcn; double db = fn(to_long(from_ptri(long_t, R_ESP + 4)), to_long(from_ptri(long_t, R_ESP + 8))); fpu_do_push(emu); ST0val = db; }
void dFpp_32(x64emu_t *emu, uintptr_t fcn) { dFpp_t fn = (dFpp_t)fcn; double db = fn(from_ptriv(R_ESP + 4), from_ptriv(R_ESP + 8)); fpu_do_push(emu); ST0val = db; }
void lFEi_32(x64emu_t *emu, uintptr_t fcn) { lFEi_t fn = (lFEi_t)fcn; R_EAX = to_long(fn(emu, from_ptri(int32_t, R_ESP + 4))); }
void lFEV_32(x64emu_t *emu, uintptr_t fcn) { lFEV_t fn = (lFEV_t)fcn; R_EAX = to_long(fn(emu, from_ptrv(R_ESP + 4))); }
void lFES_32(x64emu_t *emu, uintptr_t fcn) { lFES_t fn = (lFES_t)fcn; R_EAX = to_long(fn(emu, io_convert32(from_ptriv(R_ESP + 4)))); }
void lFii_32(x64emu_t *emu, uintptr_t fcn) { lFii_t fn = (lFii_t)fcn; R_EAX = to_long(fn(from_ptri(int32_t, R_ESP + 4), from_ptri(int32_t, R_ESP + 8))); }
Expand Down
2 changes: 1 addition & 1 deletion src/wrapped32/generated/wrapper32.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void dFi_32(x64emu_t *emu, uintptr_t fnc);
void dFd_32(x64emu_t *emu, uintptr_t fnc);
void dFp_32(x64emu_t *emu, uintptr_t fnc);
void lFv_32(x64emu_t *emu, uintptr_t fnc);
void lFi_32(x64emu_t *emu, uintptr_t fnc);
void lFu_32(x64emu_t *emu, uintptr_t fnc);
void lFl_32(x64emu_t *emu, uintptr_t fnc);
void lFp_32(x64emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -229,6 +228,7 @@ void dFdD_32(x64emu_t *emu, uintptr_t fnc);
void dFdp_32(x64emu_t *emu, uintptr_t fnc);
void dFll_32(x64emu_t *emu, uintptr_t fnc);
void dFpp_32(x64emu_t *emu, uintptr_t fnc);
void lFEi_32(x64emu_t *emu, uintptr_t fnc);
void lFEV_32(x64emu_t *emu, uintptr_t fnc);
void lFES_32(x64emu_t *emu, uintptr_t fnc);
void lFii_32(x64emu_t *emu, uintptr_t fnc);
Expand Down
17 changes: 17 additions & 0 deletions src/wrapped32/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,23 @@ EXPORT FILE* my32_fopen64(x64emu_t* emu, const char* path, const char* mode)
return fopen64(path, mode);
}

#ifndef _SC_NPROCESSORS_ONLN
#define _SC_NPROCESSORS_ONLN 84
#endif
#ifndef _SC_NPROCESSORS_CONF
#define _SC_NPROCESSORS_CONF 83
#endif
EXPORT long my32_sysconf(x64emu_t* emu, int what) {
if(what==_SC_NPROCESSORS_ONLN) {
return getNCpu();
}
if(what==_SC_NPROCESSORS_CONF) {
return getNCpu();
}
return sysconf(what);
}
EXPORT long my32___sysconf(x64emu_t* emu, int what) __attribute__((alias("my32_sysconf")));

#if 0
EXPORT int my32_mkstemps64(x64emu_t* emu, char* template, int suffixlen)
{
Expand Down
4 changes: 2 additions & 2 deletions src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1768,8 +1768,8 @@ GO(sync, vFv)
GO(syncfs, iFi)
// sync_file_range
GOM(syscall, lFEV) //%%
GOW(sysconf, lFi)
GO(__sysconf, lFi)
GOWM(sysconf, lFEi)
GOM(__sysconf, lFEi)
// sysctl // Weak
//GO(__sysctl, iFp)
//DATA(_sys_errlist, 4)
Expand Down

0 comments on commit 2a0489a

Please sign in to comment.