linux-user: support of semtimedop syscall
PATCH v2 1/1 linux-user: support of semtimedop syscall
We should add support of semtimedop syscall as new version of
glibc 2.31 uses semop based on semtimedop (commit: https://gitlab.com/freedesktop-sdk/mirrors/sourceware/glibc/-/commit/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ).
--- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
linux-user/syscall.c +28 -6
@@ -1227,7 +1227,8 @@ static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,defined (TARGET_NR_pselect6) ||defined (TARGET_NR_pselect6) || \defined (TARGET_NR_nanosleep) ||defined (TARGET_NR_clock_settime) || \defined (TARGET_NR_utimensat) ||defined (TARGET_NR_mq_timedsend) || \ - defined(TARGET_NR_mq_timedreceive) +defined (TARGET_NR_mq_timedreceive) ||defined (TARGET_NR_ipc) || \ + defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop)static inline abi_long target_to_host_timespec (struct timespec *host_ts,abi_ulong target_addr) {
@@ -3875,25 +3876,39 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,return 0 ; } -static inline abi_long do_semop (int semid,abi_long ptr,unsigned nsops) +#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \ + defined(TARGET_NR_semtimedop) +static inline abi_long do_semtimedop (int semid, +abi_long ptr, +unsigned nsops, +abi_long timeout) {struct sembuf sops[nsops]; +struct timespec ts, *pts =NULL ;abi_long ret; +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + } +if (target_to_host_sembuf (sops, ptr, nsops))return -TARGET_EFAULT ; ret = -TARGET_ENOSYS ;#ifdef __NR_semtimedop - ret =get_errno (safe_semtimedop (semid, sops, nsops,NULL )); + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts));#endif #ifdef __NR_ipcif (ret == -TARGET_ENOSYS ) { - ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops,0 )); + ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops, pts)); }#endif return ret; } +#endif struct target_msqid_ds {
@@ -4369,7 +4384,10 @@ static abi_long do_ipc(CPUArchState *cpu_env,switch (call) {case IPCOP_semop: - ret =do_semop (first, ptr, second); + ret =do_semtimedop (first, ptr, second,0 ); +break ; +case IPCOP_semtimedop: + ret =do_semtimedop (first, ptr, second, third);break ;case IPCOP_semget:
@@ -9594,7 +9612,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#endif #ifdef TARGET_NR_semopcase TARGET_NR_semop: -return do_semop (arg1, arg2, arg3); +return do_semtimedop (arg1, arg2, arg3,0 ); +#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4);#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl:
--
2.17.1
Le 12/05/2020 à 09:45, Matus Kysel a écrit :
Quoted 8 lines
We should add support of semtimedop syscall as new version of
glibc 2.31 uses semop based on semtimedop (commit: https://gitlab.com/freedesktop-sdk/mirrors/sourceware/glibc/-/commit/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ).Signed-off-by Matus Kysel <[email protected]>--- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
Laurent Vivier
AppliedLe 12/05/2020 à 09:45, Matus Kysel a écrit :
Quoted 91 lines
We should add support of semtimedop syscall as new version of
glibc 2.31 uses semop based on semtimedop (commit: https://gitlab.com/freedesktop-sdk/mirrors/sourceware/glibc/-/commit/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ).Signed-off-by Matus Kysel <[email protected]>--- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)linux-user/syscall.c +28
-7@@ -1227,7 +1227,8 @@ static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,defined (TARGET_NR_pselect6) ||defined (TARGET_NR_pselect6) || \defined (TARGET_NR_nanosleep) ||defined (TARGET_NR_clock_settime) || \defined (TARGET_NR_utimensat) ||defined (TARGET_NR_mq_timedsend) || \ - defined(TARGET_NR_mq_timedreceive) +defined (TARGET_NR_mq_timedreceive) ||defined (TARGET_NR_ipc) || \ + defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop)static inline abi_long target_to_host_timespec (struct timespec *host_ts,abi_ulong target_addr) {@@ -3875,25 +3876,39 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,return 0 ; } -static inline abi_long do_semop (int semid,abi_long ptr,unsigned nsops) +#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \ + defined(TARGET_NR_semtimedop) +static inline abi_long do_semtimedop (int semid, +abi_long ptr, +unsigned nsops, +abi_long timeout) {struct sembuf sops[nsops]; +struct timespec ts, *pts =NULL ;abi_long ret; +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + } +if (target_to_host_sembuf (sops, ptr, nsops))return -TARGET_EFAULT ; ret = -TARGET_ENOSYS ;#ifdef __NR_semtimedop - ret =get_errno (safe_semtimedop (semid, sops, nsops,NULL )); + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts));#endif #ifdef __NR_ipcif (ret == -TARGET_ENOSYS ) { - ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops,0 )); + ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops, pts)); }#endif return ret; } +#endif struct target_msqid_ds {@@ -4369,7 +4384,10 @@ static abi_long do_ipc(CPUArchState *cpu_env,switch (call) {case IPCOP_semop: - ret =do_semop (first, ptr, second); + ret =do_semtimedop (first, ptr, second,0 ); +break ; +case IPCOP_semtimedop: + ret =do_semtimedop (first, ptr, second, third);break ;case IPCOP_semget:@@ -9594,7 +9612,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#endif #ifdef TARGET_NR_semopcase TARGET_NR_semop: -return do_semop (arg1, arg2, arg3); +return do_semtimedop (arg1, arg2, arg3,0 ); +#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4);#endif #ifdef TARGET_NR_semctlcase TARGET_NR_semctl: --
Quoted 3 lines
2.17.1
Applied to my linux-user branch.
Thanks,
Laurent
Le 28/05/2020 à 19:10, Laurent Vivier a écrit :
Quoted 89 lines
Le 12/05/2020 à 09:45, Matus Kysel a écrit :
Quoted 88 lines
We should add support of semtimedop syscall as new version of
glibc 2.31 uses semop based on semtimedop (commit: https://gitlab.com/freedesktop-sdk/mirrors/sourceware/glibc/-/commit/765cdd0bffd77960ae852104fc4ea5edcdb8aed3 ).Signed-off-by Matus Kysel <[email protected]>--- linux-user/syscall.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)linux-user/syscall.c +28
-6@@ -1227,7 +1227,8 @@ static inline abi_long copy_to_user_timeval64(abi_ulong target_tv_addr,defined (TARGET_NR_pselect6) ||defined (TARGET_NR_pselect6) || \defined (TARGET_NR_nanosleep) ||defined (TARGET_NR_clock_settime) || \defined (TARGET_NR_utimensat) ||defined (TARGET_NR_mq_timedsend) || \ - defined(TARGET_NR_mq_timedreceive) +defined (TARGET_NR_mq_timedreceive) ||defined (TARGET_NR_ipc) || \ + defined(TARGET_NR_semop) || defined(TARGET_NR_semtimedop)static inline abi_long target_to_host_timespec (struct timespec *host_ts,abi_ulong target_addr) {@@ -3875,25 +3876,39 @@ static inline abi_long target_to_host_sembuf(struct sembuf *host_sembuf,return 0 ; } -static inline abi_long do_semop (int semid,abi_long ptr,unsigned nsops) +#if defined(TARGET_NR_ipc) || defined(TARGET_NR_semop) || \ + defined(TARGET_NR_semtimedop) +static inline abi_long do_semtimedop (int semid, +abi_long ptr, +unsigned nsops, +abi_long timeout) {struct sembuf sops[nsops]; +struct timespec ts, *pts =NULL ;abi_long ret; +if (timeout) { + pts = &ts; +if (target_to_host_timespec (pts, timeout)) { +return -TARGET_EFAULT ; + } + } +if (target_to_host_sembuf (sops, ptr, nsops))return -TARGET_EFAULT ; ret = -TARGET_ENOSYS ;#ifdef __NR_semtimedop - ret =get_errno (safe_semtimedop (semid, sops, nsops,NULL )); + ret =get_errno (safe_semtimedop (semid, sops, nsops, pts));#endif #ifdef __NR_ipcif (ret == -TARGET_ENOSYS ) { - ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops,0 )); + ret =get_errno (safe_ipc (IPCOP_semtimedop, semid, nsops,0 , sops, pts)); }#endif return ret; } +#endif struct target_msqid_ds {@@ -4369,7 +4384,10 @@ static abi_long do_ipc(CPUArchState *cpu_env,switch (call) {case IPCOP_semop: - ret =do_semop (first, ptr, second); + ret =do_semtimedop (first, ptr, second,0 ); +break ; +case IPCOP_semtimedop: + ret =do_semtimedop (first, ptr, second, third);break ;case IPCOP_semget:@@ -9594,7 +9612,11 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,#endif #ifdef TARGET_NR_semopcase TARGET_NR_semop: -return do_semop (arg1, arg2, arg3); +return do_semtimedop (arg1, arg2, arg3,0 ); +#endif +#ifdef TARGET_NR_semtimedop +case TARGET_NR_semtimedop: +return do_semtimedop (arg1, arg2, arg3, arg4);#endif
Quoted 8 lines
Quoted 6 lines
linux-user/syscall.c +0
-1#ifdef TARGET_NR_semctlcase TARGET_NR_semctl: --2.17.1
Applied to my linux-user branch.
I'm sorry I have to remove this patch from my queue as it fails to build on ppc64 and s390x:
ppc64: https://travis-ci.com/github/vivier/qemu/jobs/342816606
s390x: https://travis-ci.com/github/vivier/qemu/jobs/342816607
For ppc64 (and other targets in fact), I think we just need a (long) cast on pts.
For s390x, it is clearly because ipc() has arguments in a different order. In glibc we have:
sysdeps/unix/sysv/linux/semtimedop.c:
return INLINE_SYSCALL_CALL (ipc, IPCOP_semtimedop, semid,
SEMTIMEDOP_IPC_ARGS (nsops, sops, timeout));
sysdeps/unix/sysv/linux/ipc_priv.h:
/* This macro is required to handle the s390 variants, which passes the
arguments in a different order than default. */
#define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
(__nsops), 0, (__sops), (__timeout)
sysdeps/unix/sysv/linux/s390/ipc_priv.h:
/* The s390 sys_ipc variant has only five parameters instead of six
(as for default variant). The difference is the handling of SEMTIMEDOP where on s390 the third parameter is used as a pointer to a struct timespec where the generic variant uses fifth parameter. */
#undef SEMTIMEDOP_IPC_ARGS
#define SEMTIMEDOP_IPC_ARGS(__nsops, __sops, __timeout) \
(__nsops), (__timeout), (__sops)
To be really clean the do_ipc() function should be also updated for the s390x target side.
Thanks,
Laurent