From d3d971d449a6eb36d068d2a2663d815c08421947 Mon Sep 17 00:00:00 2001 From: Krzysztof Aleksander Pyrkosz <49622294+kpyrkosz@users.noreply.github.com> Date: Sat, 15 Jun 2024 20:59:26 +0000 Subject: [PATCH] Wrapped a handful of time64 functions (#969) Co-authored-by: Krzysztof Aleksander Pyrkosz --- CMakeLists.txt | 1 + src/include/stat64_helper.h | 9 +++ src/libtools/myalign.c | 1 + src/libtools/stat64_helper.c | 85 ++++++++++++++++++++++++ src/libtools/vkalign.c | 1 + src/wrapped/generated/functions_list.txt | 4 ++ src/wrapped/generated/wrappedlibctypes.h | 4 ++ src/wrapped/wrappedlibc.c | 22 ++++++ src/wrapped/wrappedlibc_private.h | 29 +++++++- 9 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 src/include/stat64_helper.h create mode 100644 src/libtools/stat64_helper.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f093c183a0..c862806934 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,6 +345,7 @@ set(ELFLOADER_SRC "${BOX86_ROOT}/src/libtools/auxval.c" "${BOX86_ROOT}/src/libtools/myalign.c" "${BOX86_ROOT}/src/libtools/myalign64.c" + "${BOX86_ROOT}/src/libtools/stat64_helper.c" "${BOX86_ROOT}/src/libtools/myfts.c" "${BOX86_ROOT}/src/libtools/sdl1rwops.c" "${BOX86_ROOT}/src/libtools/sdl2rwops.c" diff --git a/src/include/stat64_helper.h b/src/include/stat64_helper.h new file mode 100644 index 0000000000..632ebfc2c8 --- /dev/null +++ b/src/include/stat64_helper.h @@ -0,0 +1,9 @@ +#ifndef __STAT64_HELPER_H_ +#define __STAT64_HELPER_H_ + +int stat64_time64_helper(void *path, void *buf); +int fstatat64_time64_helper(int dirfd, void *path, void *buf, int flags); +int fstat64_time64_helper(int fd, void *buf); +int lstat64_time64_helper(void *path, void *buf); + +#endif diff --git a/src/libtools/myalign.c b/src/libtools/myalign.c index 7e5b9aee8a..f931279b85 100755 --- a/src/libtools/myalign.c +++ b/src/libtools/myalign.c @@ -1,5 +1,6 @@ #undef _LARGEFILE_SOURCE #undef _FILE_OFFSET_BITS +#undef _TIME_BITS #include #include #include diff --git a/src/libtools/stat64_helper.c b/src/libtools/stat64_helper.c new file mode 100644 index 0000000000..4d60bc459a --- /dev/null +++ b/src/libtools/stat64_helper.c @@ -0,0 +1,85 @@ +#define _TIME_BITS 64 +#define _FILE_OFFSET_BITS 64 + +#include +#include + +void stat64_time64_armhf_to_i386(struct stat *src, char *dest) { + /* + i386 t64 + size of stat struct 108 + Offset of st_dev 0 size 8 + Offset of st_ino 8 size 8 + Offset of st_mode 16 size 4 + Offset of st_nlink 20 size 4 + Offset of st_uid 24 size 4 + Offset of st_gid 28 size 4 + Offset of st_rdev 32 size 8 + Offset of st_size 40 size 8 + Offset of st_blksize 48 size 4 + Offset of st_blocks 52 size 8 + Offset of st_atim 60 size 16 + Offset of st_mtim 76 size 16 + Offset of st_ctim 92 size 16 + + armhf t64 + size of stat struct 112 + Offset of st_dev 0 size 8 + Offset of st_ino 8 size 8 + Offset of st_mode 16 size 4 + Offset of st_nlink 20 size 4 + Offset of st_uid 24 size 4 + Offset of st_gid 28 size 4 + Offset of st_rdev 32 size 8 + Offset of st_size 40 size 8 + Offset of st_blksize 48 size 4 + Offset of st_blocks 56 size 8 + Offset of st_atim 64 size 16 + Offset of st_mtim 80 size 16 + Offset of st_ctim 96 size 16 + */ + + char *st = (char *)src; + memset(dest, 0, 108); + memcpy(dest, st, 8); + memcpy(dest + 8, st + 8, 8); + memcpy(dest + 16, st + 16, 4); + memcpy(dest + 20, st + 20, 4); + memcpy(dest + 24, st + 24, 4); + memcpy(dest + 28, st + 28, 4); + memcpy(dest + 32, st + 32, 8); + memcpy(dest + 40, st + 40, 8); + memcpy(dest + 48, st + 48, 4); + memcpy(dest + 52, st + 56, 8); + memcpy(dest + 60, st + 64, 16); + memcpy(dest + 76, st + 80, 16); + memcpy(dest + 92, st + 96, 16); +} + +int stat64_time64_helper(void *path, void *buf) { + struct stat st; + int r = stat(path, &st); + stat64_time64_armhf_to_i386(&st, buf); + return r; +} + +int fstatat64_time64_helper(int dirfd, void *path, void *buf, int flags) { + struct stat st; + int r = fstatat(dirfd, path, &st, flags); + stat64_time64_armhf_to_i386(&st, buf); + return r; +} + +int fstat64_time64_helper(int fd, void *buf) { + struct stat st; + int r = fstat(fd, &st); + stat64_time64_armhf_to_i386(&st, buf); + return r; +} + +int lstat64_time64_helper(void *path, void *buf) { + struct stat st; + int r = lstat(path, &st); + stat64_time64_armhf_to_i386(&st, buf); + return r; +} diff --git a/src/libtools/vkalign.c b/src/libtools/vkalign.c index 07d848b0ab..fae80b09ed 100644 --- a/src/libtools/vkalign.c +++ b/src/libtools/vkalign.c @@ -1,5 +1,6 @@ #undef _LARGEFILE_SOURCE #undef _FILE_OFFSET_BITS +#undef _TIME_BITS #include #include #include diff --git a/src/wrapped/generated/functions_list.txt b/src/wrapped/generated/functions_list.txt index 5a82673c1b..28edd0a394 100644 --- a/src/wrapped/generated/functions_list.txt +++ b/src/wrapped/generated/functions_list.txt @@ -3175,10 +3175,13 @@ wrappedlibc: - vFpp: - vFpV: - iFip: + - __fstat64_time64 - fstat - iFpi: - iFpL: - iFpp: + - __lstat64_time64 + - __stat64_time64 - execvp - lstat - lstat64 @@ -3264,6 +3267,7 @@ wrappedlibc: - iFipii: - iFipuu: - iFippi: + - __fstatat64_time64 - iFippL: - readlinkat - iFpvpp: diff --git a/src/wrapped/generated/wrappedlibctypes.h b/src/wrapped/generated/wrappedlibctypes.h index 608ed77db9..b9d1972b70 100644 --- a/src/wrapped/generated/wrappedlibctypes.h +++ b/src/wrapped/generated/wrappedlibctypes.h @@ -136,7 +136,10 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(getpwuid, pFu_t) \ GO(__secure_getenv, pFp_t) \ GO(secure_getenv, pFp_t) \ + GO(__fstat64_time64, iFip_t) \ GO(fstat, iFip_t) \ + GO(__lstat64_time64, iFpp_t) \ + GO(__stat64_time64, iFpp_t) \ GO(execvp, iFpp_t) \ GO(lstat, iFpp_t) \ GO(lstat64, iFpp_t) \ @@ -175,6 +178,7 @@ typedef int32_t (*iFpLiLppp_t)(void*, uintptr_t, int32_t, uintptr_t, void*, void GO(__syslog_chk, vFiipV_t) \ GO(__libc_init, vFpppp_t) \ GO(ptrace, iFiupp_t) \ + GO(__fstatat64_time64, iFippi_t) \ GO(readlinkat, iFippL_t) \ GO(__vfwprintf_chk, iFpvpp_t) \ GO(_IO_vfprintf, iFpppp_t) \ diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 4abb88f9fd..bb0cee81d7 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -60,6 +60,7 @@ #include "bridge.h" #include "globalsymbols.h" #include "rcfile.h" +#include "stat64_helper.h" #ifdef PANDORA #ifndef __NR_preadv @@ -1343,6 +1344,7 @@ EXPORT int my_stat64(x86emu_t* emu, void* path, void* buf) UnalignStat64(&st, buf); return r; } + EXPORT int my_lstat64(x86emu_t* emu, void* path, void* buf) { (void)emu; @@ -1352,6 +1354,26 @@ EXPORT int my_lstat64(x86emu_t* emu, void* path, void* buf) return r; } +EXPORT int my___stat64_time64(x86emu_t* emu, void* path, void* buf) +{ + return stat64_time64_helper(path, buf); +} + +EXPORT int my___fstatat64_time64(x86emu_t* emu, int dirfd, void* path, void* buf, int flags) +{ + return fstatat64_time64_helper(dirfd, path, buf, flags); +} + +EXPORT int my___fstat64_time64(x86emu_t* emu, int fd, void* buf) +{ + return fstat64_time64_helper(fd, buf); +} + +EXPORT int my___lstat64_time64(x86emu_t* emu, void* path, void* buf) +{ + return lstat64_time64_helper(path, buf); +} + EXPORT int my___xstat(x86emu_t* emu, int v, void* path, void* buf) { (void)emu; diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index 9c4c934d51..aa35f7dbae 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -2243,9 +2243,6 @@ GO(gmtime64, pFp) GO(gmtime64_r, pFpp) GO(localtime64, pFpp) GO(localtime64_r, pFpp) -GO(mktime64, UFp) -GO(timegm64, UFp) -GO(timelocal64, UFp) GO(__clock_gettime64, iFpp) GO(__stat_time64, iFpp) //needs alignement? GO(__fstat_time64, iFip) @@ -2253,6 +2250,32 @@ GO(__lstat_time64, iFpp) GO(__fstatat_time64, iFippi) GO(__futimens_time64, iFip) GO(__utimensat_time64, iFippi) +//tested +GOW(__gettimeofday64, iFpp) +GO(__mktime64, IFp) +GOM(__lstat64_time64, iFEpp) +GOM(__stat64_time64, iFEpp) +GOM(__fstatat64_time64, iFEippi) +GOM(__fstat64_time64, iFEip) +GO(__ctime64, pFp) +GO(__gmtime64, pFp) +GO(__localtime64, pFpp) +GO(mktime64, IFp) +GO(timegm64, IFp) +GO(timelocal64, IFp) +GO(__clock_getres64, iFpp) +GO(__futimens64, iFip) +GO(__time64, IFp) +GO(timespec_get, iFpi) + +//untested +GOW(__getrusage64, iFip) +GOW(__getsockopt64, iFiiipp) +GO(__ioctl_time64, iFiLN) +GOW(__recvmsg64, lFipi) +GOW(__select64, iFipppp) +GOW(__sendmsg64, lFipi) +GOW(__setsockopt64, iFiiipu) GOM(fstatat64, iFippi) //%%,noE GOM(fstat64, iFip) //%%,noE