Skip to content

Commit

Permalink
Wrapped a handful of time64 functions (ptitSeb#969)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Aleksander Pyrkosz <you@example.com>
  • Loading branch information
kpyrkosz and Krzysztof Aleksander Pyrkosz authored Jun 15, 2024
1 parent 2e589f4 commit d3d971d
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions src/include/stat64_helper.h
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions src/libtools/myalign.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#undef _LARGEFILE_SOURCE
#undef _FILE_OFFSET_BITS
#undef _TIME_BITS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
85 changes: 85 additions & 0 deletions src/libtools/stat64_helper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#define _TIME_BITS 64
#define _FILE_OFFSET_BITS 64

#include <string.h>
#include <sys/stat.h>

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;
}
1 change: 1 addition & 0 deletions src/libtools/vkalign.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#undef _LARGEFILE_SOURCE
#undef _FILE_OFFSET_BITS
#undef _TIME_BITS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped/generated/functions_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3175,10 +3175,13 @@ wrappedlibc:
- vFpp:
- vFpV:
- iFip:
- __fstat64_time64
- fstat
- iFpi:
- iFpL:
- iFpp:
- __lstat64_time64
- __stat64_time64
- execvp
- lstat
- lstat64
Expand Down Expand Up @@ -3264,6 +3267,7 @@ wrappedlibc:
- iFipii:
- iFipuu:
- iFippi:
- __fstatat64_time64
- iFippL:
- readlinkat
- iFpvpp:
Expand Down
4 changes: 4 additions & 0 deletions src/wrapped/generated/wrappedlibctypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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) \
Expand Down
22 changes: 22 additions & 0 deletions src/wrapped/wrappedlibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "bridge.h"
#include "globalsymbols.h"
#include "rcfile.h"
#include "stat64_helper.h"

#ifdef PANDORA
#ifndef __NR_preadv
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
29 changes: 26 additions & 3 deletions src/wrapped/wrappedlibc_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -2243,16 +2243,39 @@ 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)
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
Expand Down

0 comments on commit d3d971d

Please sign in to comment.