Skip to content

Commit

Permalink
Fixed Box32 for Winlator Glibc (#2404)
Browse files Browse the repository at this point in the history
* 1

* 2

* 3

* 4

* Fix

* 5

* 6

* 7

* 8

* revert 8

* 9
  • Loading branch information
alexvorxx authored Feb 26, 2025
1 parent 48f51bd commit 4120dc1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
sudo chmod 755 -R /system
elif [[ ${{ matrix.platform }} == 'ANDROID_GLIBC' ]]; then
sudo apt-get -y install git gcc-aarch64-linux-gnu
echo "BOX64_PLATFORM_MARCRO=-DARM64=1 -DARM_DYNAREC=1 -DBAD_SIGNAL=1" >> $GITHUB_ENV
echo "BOX64_PLATFORM_MARCRO=-DARM64=1 -DWINLATOR_GLIBC=1 -DARM_DYNAREC=1 -DBAD_SIGNAL=1" >> $GITHUB_ENV
echo "BOX64_COMPILER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
else
sudo apt-get -y install git gcc-aarch64-linux-gnu
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(LX2160A "Set to ON if targeting an LX2160A based device" ${LX2160A})
option(ARM64 "Set to ON if targeting a generic ARM64 based device" ${ARM64})
option(ANDROID "Set to ON if targeting an Android device" ${ANDROID})
option(TERMUX "Set to ON if targeting an Android device with Termux" ${TERMUX})
option(WINLATOR_GLIBC "Set to ON if targeting an Android device with Winlator Glibc" ${WINLATOR_GLIBC})
option(USE_CCACHE "Set to ON to use ccache if present in the system" ${USE_CCACHE})
option(HAVE_TRACE "Set to ON to have Trace ability (needs ZydisInfo library)" ${HAVE_TRACE})
option(SAVE_MEM "Set to ON to build dynarec with some slower memory saving optimizations" ${SAVE_MEM})
Expand Down Expand Up @@ -256,6 +257,9 @@ endif()
if(TERMUX)
add_definitions(-DTERMUX)
endif()
if(WINLATOR_GLIBC)
add_definitions(-DWINLATOR_GLIBC)
endif()
if(BAD_SIGNAL)
add_definitions(-DBAD_SIGNAL)
endif()
Expand Down Expand Up @@ -875,7 +879,7 @@ if(BOX32)
OUTPUT "${BOX64_ROOT}/src/wrapped32/generated/functions_list.txt"
COMMAND "${PYTHON_EXECUTABLE}" "${BOX64_ROOT}/rebuild_wrappers_32.py"
"${BOX64_ROOT}"
"PANDORA" "HAVE_LD80BITS" "NOALIGN" "HAVE_TRACE" "ANDROID" "TERMUX" "STATICBUILD" "--"
"PANDORA" "HAVE_LD80BITS" "NOALIGN" "HAVE_TRACE" "ANDROID" "TERMUX" "WINLATOR_GLIBC" "STATICBUILD" "--"
${WRAPPEDS32_HEAD}
MAIN_DEPENDENCY "${BOX64_ROOT}/rebuild_wrappers_32.py"
DEPENDS ${WRAPPEDS32} ${WRAPPEDS32_HEAD}
Expand Down
3 changes: 2 additions & 1 deletion src/wrapped32/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@
#() LFXCii -> LFXCii
#() LFXLuu -> LFXLuu
#() LFXpLp -> LFXpLp
#() pEEipi -> pEEipi
#() pFEupi -> pFEupi
#() pFEupp -> pFEupp
#() pEEpii -> pEEpii
Expand Down Expand Up @@ -2012,6 +2011,8 @@
#() vFuuuuiiiiuuiiiiiii -> vFuuuuiiiiuuiiiiiii
#() vFXpuiiiiipuiiiiiiii -> vFXpuiiiiipuiiiiiiii
#() uFippuuuuiiiiuuiiiiiiiipp -> uFippuuuuiiiiuuiiiiiiiipp
#defined(WINLATOR_GLIBC) pEipi -> pEipi
#!defined(WINLATOR_GLIBC) pEEipi -> pEEipi
#defined(HAVE_LD80BITS) DED -> DED
#defined(HAVE_LD80BITS) DFDi -> DFDi
#defined(HAVE_LD80BITS) DEDD -> DEDD
Expand Down
18 changes: 16 additions & 2 deletions src/wrapped32/generated/wrapper32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,6 @@ typedef uintptr_t (*LEppLa_t)(void*, void*, uintptr_t, void*);
typedef uintptr_t (*LFXCii_t)(void*, uint8_t, int32_t, int32_t);
typedef uintptr_t (*LFXLuu_t)(void*, uintptr_t, uint32_t, uint32_t);
typedef uintptr_t (*LFXpLp_t)(void*, void*, uintptr_t, void*);
typedef void* (*pEEipi_t)(x64emu_t*, int32_t, void*, int32_t);
typedef void* (*pFEupi_t)(x64emu_t*, uint32_t, void*, int32_t);
typedef void* (*pFEupp_t)(x64emu_t*, uint32_t, void*, void*);
typedef void* (*pEEpii_t)(x64emu_t*, void*, int32_t, int32_t);
Expand Down Expand Up @@ -2107,6 +2106,14 @@ typedef void (*vFuuuuiiiiuuiiiiiii_t)(uint32_t, uint32_t, uint32_t, uint32_t, in
typedef void (*vFXpuiiiiipuiiiiiiii_t)(void*, void*, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, void*, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t);
typedef uint32_t (*uFippuuuuiiiiuuiiiiiiiipp_t)(int32_t, void*, void*, uint32_t, uint32_t, uint32_t, uint32_t, int32_t, int32_t, int32_t, int32_t, uint32_t, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, void*, void*);

#ifdef WINLATOR_GLIBC
typedef void* (*pEipi_t)(int32_t, void*, int32_t);
#endif

#ifndef WINLATOR_GLIBC
typedef void* (*pEEipi_t)(x64emu_t*, int32_t, void*, int32_t);
#endif

#if defined(HAVE_LD80BITS)
typedef long double (*DED_t)(long double);
typedef long double (*DFDi_t)(long double, int32_t);
Expand Down Expand Up @@ -3192,7 +3199,6 @@ void LEppLa_32(x64emu_t *emu, uintptr_t fcn) { LEppLa_t fn = (LEppLa_t)fcn; errn
void LFXCii_32(x64emu_t *emu, uintptr_t fcn) { LFXCii_t fn = (LFXCii_t)fcn; R_EAX = to_ulong(fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptri(uint8_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16))); }
void LFXLuu_32(x64emu_t *emu, uintptr_t fcn) { LFXLuu_t fn = (LFXLuu_t)fcn; R_EAX = to_ulong(fn(getDisplay(from_ptriv(R_ESP + 4)), from_ulong(from_ptri(ulong_t, R_ESP + 8)), from_ptri(uint32_t, R_ESP + 12), from_ptri(uint32_t, R_ESP + 16))); }
void LFXpLp_32(x64emu_t *emu, uintptr_t fcn) { LFXpLp_t fn = (LFXpLp_t)fcn; R_EAX = to_ulong(fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ulong(from_ptri(ulong_t, R_ESP + 12)), from_ptriv(R_ESP + 16))); }
void pEEipi_32(x64emu_t *emu, uintptr_t fcn) { pEEipi_t fn = (pEEipi_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); emu->libc_err = errno; }
void pFEupi_32(x64emu_t *emu, uintptr_t fcn) { pFEupi_t fn = (pFEupi_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); }
void pFEupp_32(x64emu_t *emu, uintptr_t fcn) { pFEupp_t fn = (pFEupp_t)fcn; R_EAX = to_ptrv(fn(emu, from_ptri(uint32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12))); }
void pEEpii_32(x64emu_t *emu, uintptr_t fcn) { pEEpii_t fn = (pEEpii_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(emu, from_ptriv(R_ESP + 4), from_ptri(int32_t, R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); emu->libc_err = errno; }
Expand Down Expand Up @@ -4140,6 +4146,14 @@ void vFuuuuiiiiuuiiiiiii_32(x64emu_t *emu, uintptr_t fcn) { vFuuuuiiiiuuiiiiiii_
void vFXpuiiiiipuiiiiiiii_32(x64emu_t *emu, uintptr_t fcn) { vFXpuiiiiipuiiiiiiii_t fn = (vFXpuiiiiipuiiiiiiii_t)fcn; fn(getDisplay(from_ptriv(R_ESP + 4)), from_ptriv(R_ESP + 8), from_ptri(uint32_t, R_ESP + 12), from_ptri(int32_t, R_ESP + 16), from_ptri(int32_t, R_ESP + 20), from_ptri(int32_t, R_ESP + 24), from_ptri(int32_t, R_ESP + 28), from_ptri(int32_t, R_ESP + 32), from_ptriv(R_ESP + 36), from_ptri(uint32_t, R_ESP + 40), from_ptri(int32_t, R_ESP + 44), from_ptri(int32_t, R_ESP + 48), from_ptri(int32_t, R_ESP + 52), from_ptri(int32_t, R_ESP + 56), from_ptri(int32_t, R_ESP + 60), from_ptri(int32_t, R_ESP + 64), from_ptri(int32_t, R_ESP + 68), from_ptri(int32_t, R_ESP + 72)); }
void uFippuuuuiiiiuuiiiiiiiipp_32(x64emu_t *emu, uintptr_t fcn) { uFippuuuuiiiiuuiiiiiiiipp_t fn = (uFippuuuuiiiiuuiiiiiiiipp_t)fcn; R_EAX = (uint32_t)fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptriv(R_ESP + 12), from_ptri(uint32_t, R_ESP + 16), from_ptri(uint32_t, R_ESP + 20), from_ptri(uint32_t, R_ESP + 24), from_ptri(uint32_t, R_ESP + 28), from_ptri(int32_t, R_ESP + 32), from_ptri(int32_t, R_ESP + 36), from_ptri(int32_t, R_ESP + 40), from_ptri(int32_t, R_ESP + 44), from_ptri(uint32_t, R_ESP + 48), from_ptri(uint32_t, R_ESP + 52), from_ptri(int32_t, R_ESP + 56), from_ptri(int32_t, R_ESP + 60), from_ptri(int32_t, R_ESP + 64), from_ptri(int32_t, R_ESP + 68), from_ptri(int32_t, R_ESP + 72), from_ptri(int32_t, R_ESP + 76), from_ptri(int32_t, R_ESP + 80), from_ptri(int32_t, R_ESP + 84), from_ptriv(R_ESP + 88), from_ptriv(R_ESP + 92)); }

#ifdef WINLATOR_GLIBC
void pEipi_32(x64emu_t *emu, uintptr_t fcn) { pEipi_t fn = (pEipi_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); emu->libc_err = errno; }
#endif

#ifndef WINLATOR_GLIBC
void pEEipi_32(x64emu_t *emu, uintptr_t fcn) { pEEipi_t fn = (pEEipi_t)fcn; errno = emu->libc_err; R_EAX = to_ptrv(fn(emu, from_ptri(int32_t, R_ESP + 4), from_ptriv(R_ESP + 8), from_ptri(int32_t, R_ESP + 12))); emu->libc_err = errno; }
#endif

#if defined(HAVE_LD80BITS)
void DED_32(x64emu_t *emu, uintptr_t fcn) { DED_t fn = (DED_t)fcn; errno = emu->libc_err; long double ld = fn(LD2localLD(from_ptrv(R_ESP + 4))); fpu_do_push(emu); ST0val = ld; emu->libc_err = errno; }
void DFDi_32(x64emu_t *emu, uintptr_t fcn) { DFDi_t fn = (DFDi_t)fcn; long double ld = fn(LD2localLD(from_ptrv(R_ESP + 4)), from_ptri(int32_t, R_ESP + 16)); fpu_do_push(emu); ST0val = ld; }
Expand Down
9 changes: 8 additions & 1 deletion src/wrapped32/generated/wrapper32.h
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,6 @@ void LEppLa_32(x64emu_t *emu, uintptr_t fnc);
void LFXCii_32(x64emu_t *emu, uintptr_t fnc);
void LFXLuu_32(x64emu_t *emu, uintptr_t fnc);
void LFXpLp_32(x64emu_t *emu, uintptr_t fnc);
void pEEipi_32(x64emu_t *emu, uintptr_t fnc);
void pFEupi_32(x64emu_t *emu, uintptr_t fnc);
void pFEupp_32(x64emu_t *emu, uintptr_t fnc);
void pEEpii_32(x64emu_t *emu, uintptr_t fnc);
Expand Down Expand Up @@ -2054,6 +2053,14 @@ void vFuuuuiiiiuuiiiiiii_32(x64emu_t *emu, uintptr_t fnc);
void vFXpuiiiiipuiiiiiiii_32(x64emu_t *emu, uintptr_t fnc);
void uFippuuuuiiiiuuiiiiiiiipp_32(x64emu_t *emu, uintptr_t fnc);

#ifdef WINLATOR_GLIBC
void pEipi_32(x64emu_t *emu, uintptr_t fnc);
#endif

#ifndef WINLATOR_GLIBC
void pEEipi_32(x64emu_t *emu, uintptr_t fnc);
#endif

#if defined(HAVE_LD80BITS)
void DED_32(x64emu_t *emu, uintptr_t fnc);
void DFDi_32(x64emu_t *emu, uintptr_t fnc);
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped32/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
#include <sys/sysinfo.h>
#include <sys/time.h>
#include <regex.h>
#ifndef WINLATOR_GLIBC
#include <sys/ipc.h>
#include <sys/shm.h>
#endif
#include <sys/wait.h>

#include "wrappedlibs.h"
Expand Down Expand Up @@ -3203,6 +3205,7 @@ EXPORT void my32_regfree(x64emu_t* emu, void* p)
regfree(&p_l);
}

#ifndef WINLATOR_GLIBC
EXPORT void* my32_shmat(x64emu_t*emu, int shmid, void* shmaddr, int flags)
{
size_t sz = 0;
Expand All @@ -3227,6 +3230,7 @@ EXPORT int my32_shmdt(x64emu_t* emu, void* addr)
{
return shmdt(addr);
}
#endif

#if 0
#ifndef __NR_memfd_create
Expand Down
7 changes: 6 additions & 1 deletion src/wrapped32/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,14 @@ GOW(setvbuf, iESpiL)
GO(setxattr, iEpppLi)
// sgetspent
// sgetspent_r // Weak
#ifdef WINLATOR_GLIBC
GOW(shmat, pEipi)
GOW(shmdt, iEp)
#else
GOWM(shmat, pEEipi)
GOW(shmctl, iEiip)
GOWM(shmdt, iEEp)
#endif
GOW(shmctl, iEiip)
GOW(shmget, iEiLi)
GOW(shutdown, iEii)
GOWM(sigaction, iEEipp) //%%
Expand Down

0 comments on commit 4120dc1

Please sign in to comment.