linux-user: Adding support for a group of 4 time64 syscalls
cover linux-user: Adding support for a group of 4 time64 syscalls
This two patch series introduces functionality for following Year 2038 safe syscalls:
--Introduced in first patch--*ppoll_time64()*pselect6_time64()
--Introduced in second patch--*utimensat_time64()*semtimedop_time64()
Testing notes:
The implementations of these time64 syscalls was tested using tests from the LTP test suite which was built inside a chroot.
Filip Bozuta (2):
linux-user: Add support for ppoll_time64() and pselect6_time64()
linux-user: Add support for utimensat_time64() and semtimedop_time64()
linux-user/syscall.c | 154 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 131 insertions(+), 23 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 linux-user: Add support for 'ppoll_time64()' and 'pselect6_time64()'
This patch introduces functionality for following time64 syscalls:
*ppoll_time64
This is a year 2038 safe variant of:
int poll(struct pollfd *fds, nfds_t nfds, int timeout) -- wait for some event on a file descriptor --
man page: https://man7.org/linux/man-pages/man2/ppoll.2.html
*pselect6_time64
This is a year 2038 safe variant of:
int pselect6(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask);
-- synchronous I/O multiplexing --
man page: https://man7.org/linux/man-pages/man2/pselect6.2.html
Implementation notes:
Year 2038 safe syscalls in this patch were implemented with the same code as their regular variants (ppoll() and pselect()). A switch/case statement was used to call an apropriate converting function for 'struct timespec' between target and host. (target_to_host/host_to_target_timespec() for regular and
target_to_host/host_to_target_timespec64() for time64 variants)
--- linux-user/syscall.c | 101 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 15 deletions(-)
linux-user/syscall.c +86 -15
@@ -397,7 +397,7 @@ static int sys_getcwd1(char *buf, size_t size)return strlen (buf)+1 ; } -#ifdef TARGET_NR_utimensat +#if defined(TARGET_NR_utimensat)#if defined(__NR_utimensat)#define __NR_sys_utimensat __NR_utimensat _syscall4(int,sys_utimensat,int,dirfd,const char *,pathname,
@@ -763,11 +763,11 @@ safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ int, options, struct rusage *, rusage) safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp)#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ - defined(TARGET_NR_pselect6) + defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64) safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ fd_set *, exceptfds, struct timespec *, timeout, void *, sig)#endif -#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_poll) +#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_ppoll_time64) safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds, struct timespec *, tsp, const sigset_t *, sigmask, size_t, sigsetsize)
@@ -984,7 +984,7 @@ abi_long do_brk(abi_ulong new_brk) }#if defined(TARGET_NR_select) || defined(TARGET_NR__newselect) || \ - defined(TARGET_NR_pselect6) + defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)static inline abi_long copy_from_user_fdset (fd_set *fds,abi_ulong target_fds_addr,int n)
@@ -1252,7 +1252,8 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts, }#endif -#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) +#if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ + defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64)static inline abi_long target_to_host_timespec64 (struct timespec *host_ts,abi_ulong target_addr) {
@@ -9043,8 +9044,13 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#endif return ret;#endif +#if defined(TARGET_NR_pselect6) || defined(TARGET_NR_pselect6_time64)#ifdef TARGET_NR_pselect6case TARGET_NR_pselect6: +#endif +#ifdef TARGET_NR_pselect6_time64 +case TARGET_NR_pselect6_time64: +#endif {abi_long rfd_addr, wfd_addr, efd_addr, n, ts_addr;fd_set rfds, wfds, efds;
@@ -9088,8 +9094,21 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,* use the do_select() helper ... */ if (ts_addr) { -if (target_to_host_timespec (&ts, ts_addr)) { -return -TARGET_EFAULT ; +switch (num) { +#ifdef TARGET_NR_pselect6 +case TARGET_NR_pselect6: +if (target_to_host_timespec (&ts, ts_addr)) { +return -TARGET_EFAULT ; + } +break ; +#endif +#ifdef TARGET_NR_pselect6_time64 +case TARGET_NR_pselect6_time64: +if (target_to_host_timespec64 (&ts, ts_addr)) { +return -TARGET_EFAULT ; + } +break ; +#endif } ts_ptr = &ts; }else {
@@ -9140,8 +9159,22 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,if (efd_addr &©_to_user_fdset (efd_addr, &efds, n))return -TARGET_EFAULT ; -if (ts_addr &&host_to_target_timespec (ts_addr, &ts)) -return -TARGET_EFAULT ; +switch (num) { +#ifdef TARGET_NR_pselect6 +case TARGET_NR_pselect6: +if (ts_addr &&host_to_target_timespec (ts_addr, &ts)) { +return -TARGET_EFAULT ; + } +break ; +#endif +#ifdef TARGET_NR_pselect6_time64 +case TARGET_NR_pselect6_time64: +if (ts_addr &&host_to_target_timespec64 (ts_addr, &ts)) { +return -TARGET_EFAULT ; + } +break ; +#endif + } } }return ret;
@@ -10076,12 +10109,16 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,case TARGET_NR__newselect:return do_select (arg1, arg2, arg3, arg4, arg5);#endif -#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) +#if defined(TARGET_NR_poll) || defined(TARGET_NR_ppoll) || \ + defined(TARGET_NR_ppoll_time64)# ifdef TARGET_NR_pollcase TARGET_NR_poll:# endif # ifdef TARGET_NR_ppollcase TARGET_NR_ppoll: +# endif +# ifdef TARGET_NR_ppoll_time64 +case TARGET_NR_ppoll_time64:# endif {struct target_pollfd *target_pfd;
@@ -10110,17 +10147,38 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, }switch (num) { -# ifdef TARGET_NR_ppoll +#if defined(TARGET_NR_ppoll) || defined(TARGET_NR_ppoll_time64) +#ifdef TARGET_NR_ppollcase TARGET_NR_ppoll: +#endif +#ifdef TARGET_NR_ppoll_time64 +case TARGET_NR_ppoll_time64: +#endif {struct timespec _timeout_ts, *timeout_ts = &_timeout_ts;target_sigset_t *target_set;sigset_t _set, *set = &_set;if (arg3) { -if (target_to_host_timespec (timeout_ts, arg3)) { -unlock_user (target_pfd, arg1,0 ); -return -TARGET_EFAULT ; +switch (num) { +#ifdef TARGET_NR_ppoll +case TARGET_NR_ppoll: +if (target_to_host_timespec (timeout_ts, arg3)) { +unlock_user (target_pfd, arg1,0 ); +return -TARGET_EFAULT ; + } +break ; +#endif +#ifdef TARGET_NR_ppoll_time64 +case TARGET_NR_ppoll_time64: +if (target_to_host_timespec64 (timeout_ts, arg3)) { +unlock_user (target_pfd, arg1,0 ); +return -TARGET_EFAULT ; + } +break ; +#endif +default : +g_assert_not_reached (); } }else { timeout_ts =NULL ;
@@ -10146,7 +10204,20 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, set, SIGSET_T_SIZE));if (!is_error (ret) && arg3) { -host_to_target_timespec (arg3, timeout_ts); +switch (num) { +#ifdef TARGET_NR_ppoll +case TARGET_NR_ppoll: +host_to_target_timespec (arg3, timeout_ts); +break ; +#endif +#ifdef TARGET_NR_ppoll_time64 +case TARGET_NR_ppoll_time64: +host_to_target_timespec64 (arg3, timeout_ts); +break ; +#endif +default : +g_assert_not_reached (); + } }if (arg4) {unlock_user (target_set, arg4,0 );
Signature · 1 line
2.25.1
Re: [PATCH 1/2] linux-user: Add support for 'ppoll_time64()' and 'pselect6_time64()'
Le 12/08/2020 à 15:57, Filip Bozuta a écrit :
Quoted 29 lines
This patch introduces functionality for following time64 syscalls:
*ppoll_time64This is a year 2038 safe variant of:
int
poll(struct pollfd *fds, nfds_t nfds, int timeout)-- wait for some event on a file descriptor --
man page: https://man7.org/linux/man-pages/man2/ppoll.2.html
*pselect6_time64This is a year 2038 safe variant of:
int pselect6(int nfds,
fd_set*readfds,fd_set*writefds,
fd_set*exceptfds, const struct timespec *timeout, constsigset_t*sigmask);
-- synchronous I/O multiplexing --
man page: https://man7.org/linux/man-pages/man2/pselect6.2.htmlImplementation notes:
Year 2038 safe syscalls in this patch were implemented with the same code as their regular variants (
ppoll()andpselect()). A switch/case statement was used to call an apropriate converting function for 'struct timespec' between target and host. (target_to_host/host_to_target_timespec() for regular and
target_to_host/host_to_target_timespec64() for time64 variants)
Quoted 5 lines
Signed-off-by Filip Bozuta <[email protected]>--- linux-user/syscall.c | 101 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 86 insertions(+), 15 deletions(-)
I think it would be cleaner if you move the code to new functions, do_ppoll() and do_pselect6() first, and then you introduce a new parameter "bool time64" to implement the time64 variant (rather than a switch()) as you do in PATCH 2.
Thanks,
Laurent
PATCH 2/2 linux-user: Add support for 'utimensat_time64()' and 'semtimedop_time64()'
In reply to Filip BozutaThis patch introduces functionality for following time64 syscalls:
*utimensat_time64()
int utimensat(int dirfd, const char *pathname,
const struct timespec times[2], int flags);
-- change file timestamps with nanosecond precision -- man page: https://man7.org/linux/man-pages/man2/utimensat.2.html
*semtimedop_time64()
int semtimedop(int semid, struct sembuf *sops, size_t nsops,
const struct timespec *timeout);
-- System V semaphore operations --
man page: https://www.man7.org/linux/man-pages/man2/semtimedop.2.html
Implementation notes:
Syscall 'utimensat_time64()' is implemented in similar way as its regular variants only difference being that time64 converting function is used to convert values of 'struct timespec' between host and target ('target_to_host_timespec64()').
For syscall 'semtimedop_time64()' and additional argument is added in function 'do_semtimedop()' through which the aproppriate 'struct timespec' converting function is called (0 for regular target_to_host_timespec() and anything else for target_to_host_timespec64()). For 'do_ipc()' an check was added as that additional argument: 'TARGET_ABI_BITS == 64'.
--- linux-user/syscall.c | 55 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-)
linux-user/syscall.c +46 -9
@@ -1253,7 +1253,8 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,#endif #if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ - defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) + defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) || \ + defined(TARGET_NR_utimensat_time64) || defined(TARGET_NR_semtimedop_time64)static inline abi_long target_to_host_timespec64 (struct timespec *host_ts,abi_ulong target_addr) {
@@ -3886,7 +3887,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, }#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \ - defined(TARGET_NR_semtimedop) + defined(TARGET_NR_semtimedop) || defined(TARGET_NR_semtimedop_time64)/* * This macro is required to handle the s390 variants, which passes the
@@ -3903,7 +3904,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,static inline abi_long do_semtimedop (int semid,abi_long ptr,unsigned nsops, -abi_long timeout) +abi_long timeout,int time64) {struct sembuf sops[nsops];struct timespec ts, *pts =NULL ;
@@ -3911,7 +3912,10 @@ static inline abi_long do_semtimedop(int semid,if (timeout) { pts = &ts; -if (target_to_host_timespec (pts, timeout)) { +if (!time64 &&target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } +if (time64 &&target_to_host_timespec64 (pts, timeout)) {return -TARGET_EFAULT ; } }
@@ -4426,7 +4430,7 @@ static abi_long do_ipc(CPUArchState *cpu_env,switch (call) {case IPCOP_semop: - ret =do_semtimedop (first, ptr, second,0 ); + ret =do_semtimedop (first, ptr, second,0 ,0 );break ;case IPCOP_semtimedop:/*
@@ -4436,9 +4440,9 @@ static abi_long do_ipc(CPUArchState *cpu_env,* to a struct timespec where the generic variant uses fifth parameter. */ #if defined(TARGET_S390X ) - ret =do_semtimedop (first, ptr, second, third); + ret =do_semtimedop (first, ptr, second, third,TARGET_ABI_BITS ==64 );#else - ret =do_semtimedop (first, ptr, second, fifth); + ret =do_semtimedop (first, ptr, second, fifth,TARGET_ABI_BITS ==64 );#endif break ;
@@ -9783,11 +9787,15 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#endif #ifdef TARGET_NR_semopcase TARGET_NR_semop: -return do_semtimedop (arg1, arg2, arg3,0 ); +return do_semtimedop (arg1, arg2, arg3,0 ,0 );#endif #ifdef TARGET_NR_semtimedopcase TARGET_NR_semtimedop: -return do_semtimedop (arg1, arg2, arg3, arg4); +return do_semtimedop (arg1, arg2, arg3, arg4,0 ); +#endif +#ifdef TARGET_NR_semtimedop_time64 +case TARGET_NR_semtimedop_time64: +return do_semtimedop (arg1, arg2, arg3, arg4,1 );#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl:
@@ -11969,6 +11977,35 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, }return ret;#endif +#ifdef TARGET_NR_utimensat_time64 +case TARGET_NR_utimensat_time64: + { +struct timespec *tsp, ts[2 ]; +if (!arg3) { + tsp =NULL ; + }else { +if (target_to_host_timespec64 (ts, arg3)) { +return -TARGET_EFAULT ; + } +if (target_to_host_timespec64 (ts +1 , arg3 + +sizeof (struct target__kernel_timespec ))) { +return -TARGET_EFAULT ; + } + tsp = ts; + } +if (!arg2) + ret =get_errno (sys_utimensat (arg1,NULL , tsp, arg4)); +else { + p =lock_user_string (arg2); +if (!p) { +return -TARGET_EFAULT ; + } + ret =get_errno (sys_utimensat (arg1,path (p), tsp, arg4)); +unlock_user (p, arg2,0 ); + } + } +return ret; +#endif #ifdef TARGET_NR_futexcase TARGET_NR_futex:return do_futex (arg1, arg2, arg3, arg4, arg5, arg6);
Signature · 1 line
2.25.1
Re: [PATCH 2/2] linux-user: Add support for 'utimensat_time64()' and 'semtimedop_time64()'
Le 12/08/2020 à 15:57, Filip Bozuta a écrit :
Quoted 58 lines
This patch introduces functionality for following time64 syscalls:
*utimensat_time64()int utimensat(int dirfd, const char *pathname,
const struct timespec times[2], int flags);
-- change file timestamps with nanosecond precision -- man page: https://man7.org/linux/man-pages/man2/utimensat.2.html
*semtimedop_time64()int semtimedop(int semid, struct sembuf *sops,
size_tnsops,
const struct timespec *timeout);
-- System V semaphore operations --
man page: https://www.man7.org/linux/man-pages/man2/semtimedop.2.htmlImplementation notes:
Syscall '
utimensat_time64()' is implemented in similar way as its regular variants only difference being that time64 converting function is used to convert values of 'struct timespec' between host and target ('target_to_host_timespec64()').For syscall '
semtimedop_time64()' and additional argument is added in function 'do_semtimedop()' through which the aproppriate 'struct timespec' converting function is called (0 for regulartarget_to_host_timespec()and anything else fortarget_to_host_timespec64()). For 'do_ipc()' an check was added as that additional argument: 'TARGET_ABI_BITS== 64'.Signed-off-by Filip Bozuta <[email protected]>--- linux-user/syscall.c | 55 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-)linux-user/syscall.c +3
-2@@ -1253,7 +1253,8 @@ static inline abi_long target_to_host_timespec(struct timespec *host_ts,#endif #if defined(TARGET_NR_clock_settime64) || defined(TARGET_NR_futex_time64) || \ - defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) + defined(TARGET_NR_pselect6_time64) || defined(TARGET_NR_ppoll_time64) || \ + defined(TARGET_NR_utimensat_time64) || defined(TARGET_NR_semtimedop_time64)static inline abi_long target_to_host_timespec64 (struct timespec *host_ts,abi_ulong target_addr) {@@ -3886,7 +3887,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, }#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \ - defined(TARGET_NR_semtimedop) + defined(TARGET_NR_semtimedop) || defined(TARGET_NR_semtimedop_time64)/* * This macro is required to handle the s390 variants, which passes the
linux-user/syscall.c static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf, · line 3907
Quoted 5 lines
linux-user/syscall.c +1
-1@@ -3903,7 +3904,7 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,static inline abi_long do_semtimedop (int semid,abi_long ptr,unsigned nsops, -abi_long timeout) +abi_long timeout,int time64)
"bool time64" would be cleaner
Quoted 4 lines
linux-user/syscall.c +0
-0{struct sembuf sops[nsops];struct timespec ts, *pts =NULL ;
linux-user/syscall.c static inline abi_long do_semtimedop(int semid, · line 3920
Quoted 10 lines
linux-user/syscall.c +4
-1@@ -3911,7 +3912,10 @@ static inline abi_long do_semtimedop(int semid,if (timeout) { pts = &ts; -if (target_to_host_timespec (pts, timeout)) { +if (!time64 &&target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } +if (time64 &&target_to_host_timespec64 (pts, timeout)) {return -TARGET_EFAULT ; }
why not:
if (time64) {
if (target_to_host_timespec64(pts, timeout)) {
return -TARGET_EFAULT;
}
} else {
if (target_to_host_timespec(pts, timeout)) {
return -TARGET_EFAULT;
}
}I think it's clearer.
With that fixed: