[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/38] linux-user: Combine do_futex and do_futex_time64
From: |
Laurent Vivier |
Subject: |
[PULL 30/38] linux-user: Combine do_futex and do_futex_time64 |
Date: |
Wed, 28 Sep 2022 10:15:09 +0200 |
From: Richard Henderson <richard.henderson@linaro.org>
Pass a boolean to select between time32 and time64.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-2-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 67 ++++++++------------------------------------
1 file changed, 11 insertions(+), 56 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e0e0f058121f..af3a605fc458 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7768,9 +7768,10 @@ static int do_safe_futex(int *uaddr, int op, int val,
futexes locally would make futexes shared between multiple processes
tricky. However they're probably useless because guest atomic
operations won't work either. */
-#if defined(TARGET_NR_futex)
-static int do_futex(CPUState *cpu, target_ulong uaddr, int op, int val,
- target_ulong timeout, target_ulong uaddr2, int val3)
+#if defined(TARGET_NR_futex) || defined(TARGET_NR_futex_time64)
+static int do_futex(CPUState *cpu, bool time64, target_ulong uaddr,
+ int op, int val, target_ulong timeout,
+ target_ulong uaddr2, int val3)
{
struct timespec ts, *pts;
int base_op;
@@ -7787,7 +7788,11 @@ static int do_futex(CPUState *cpu, target_ulong uaddr,
int op, int val,
case FUTEX_WAIT_BITSET:
if (timeout) {
pts = &ts;
- target_to_host_timespec(pts, timeout);
+ if (time64
+ ? target_to_host_timespec64(pts, timeout)
+ : target_to_host_timespec(pts, timeout)) {
+ return -TARGET_EFAULT;
+ }
} else {
pts = NULL;
}
@@ -7817,56 +7822,6 @@ static int do_futex(CPUState *cpu, target_ulong uaddr,
int op, int val,
}
#endif
-#if defined(TARGET_NR_futex_time64)
-static int do_futex_time64(CPUState *cpu, target_ulong uaddr, int op,
- int val, target_ulong timeout,
- target_ulong uaddr2, int val3)
-{
- struct timespec ts, *pts;
- int base_op;
-
- /* ??? We assume FUTEX_* constants are the same on both host
- and target. */
-#ifdef FUTEX_CMD_MASK
- base_op = op & FUTEX_CMD_MASK;
-#else
- base_op = op;
-#endif
- switch (base_op) {
- case FUTEX_WAIT:
- case FUTEX_WAIT_BITSET:
- if (timeout) {
- pts = &ts;
- if (target_to_host_timespec64(pts, timeout)) {
- return -TARGET_EFAULT;
- }
- } else {
- pts = NULL;
- }
- return do_safe_futex(g2h(cpu, uaddr), op,
- tswap32(val), pts, NULL, val3);
- case FUTEX_WAKE:
- return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
- case FUTEX_FD:
- return do_safe_futex(g2h(cpu, uaddr), op, val, NULL, NULL, 0);
- case FUTEX_REQUEUE:
- case FUTEX_CMP_REQUEUE:
- case FUTEX_WAKE_OP:
- /* For FUTEX_REQUEUE, FUTEX_CMP_REQUEUE, and FUTEX_WAKE_OP, the
- TIMEOUT parameter is interpreted as a uint32_t by the kernel.
- But the prototype takes a `struct timespec *'; insert casts
- to satisfy the compiler. We do not need to tswap TIMEOUT
- since it's not compared to guest memory. */
- pts = (struct timespec *)(uintptr_t) timeout;
- return do_safe_futex(g2h(cpu, uaddr), op, val, pts, g2h(cpu, uaddr2),
- (base_op == FUTEX_CMP_REQUEUE
- ? tswap32(val3) : val3));
- default:
- return -TARGET_ENOSYS;
- }
-}
-#endif
-
#if defined(TARGET_NR_name_to_handle_at) && defined(CONFIG_OPEN_BY_HANDLE)
static abi_long do_name_to_handle_at(abi_long dirfd, abi_long pathname,
abi_long handle, abi_long mount_id,
@@ -12372,11 +12327,11 @@ static abi_long do_syscall1(CPUArchState *cpu_env,
int num, abi_long arg1,
#endif
#ifdef TARGET_NR_futex
case TARGET_NR_futex:
- return do_futex(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
+ return do_futex(cpu, false, arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef TARGET_NR_futex_time64
case TARGET_NR_futex_time64:
- return do_futex_time64(cpu, arg1, arg2, arg3, arg4, arg5, arg6);
+ return do_futex(cpu, true, arg1, arg2, arg3, arg4, arg5, arg6);
#endif
#ifdef CONFIG_INOTIFY
#if defined(TARGET_NR_inotify_init)
--
2.37.3
- [PULL 19/38] linux-user: Add proper strace format strings for getdents()/getdents64(), (continued)
- [PULL 19/38] linux-user: Add proper strace format strings for getdents()/getdents64(), Laurent Vivier, 2022/09/28
- [PULL 14/38] linux-user: Fix madvise(MADV_DONTNEED) on alpha, Laurent Vivier, 2022/09/28
- [PULL 05/38] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls, Laurent Vivier, 2022/09/28
- [PULL 10/38] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch, Laurent Vivier, 2022/09/28
- [PULL 13/38] linux-user: Provide MADV_* definitions, Laurent Vivier, 2022/09/28
- [PULL 23/38] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect(), Laurent Vivier, 2022/09/28
- [PULL 17/38] tests/tcg/linux-test: Add linux-madvise test, Laurent Vivier, 2022/09/28
- [PULL 12/38] linux-user: Show timespec on strace for futex(), Laurent Vivier, 2022/09/28
- [PULL 01/38] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default, Laurent Vivier, 2022/09/28
- [PULL 06/38] linux-user: Log failing executable in EXCP_DUMP(), Laurent Vivier, 2022/09/28
- [PULL 30/38] linux-user: Combine do_futex and do_futex_time64,
Laurent Vivier <=
- [PULL 26/38] linux-user: Don't assume 0 is not a valid host timer_t value, Laurent Vivier, 2022/09/28
- [PULL 27/38] linux-user/s390x: Save/restore fpc when handling a signal, Laurent Vivier, 2022/09/28
- [PULL 35/38] linux-user: Update print_futex_op, Laurent Vivier, 2022/09/28
- [PULL 22/38] linux-user/hppa: Increase guest stack size to 80MB for hppa target, Laurent Vivier, 2022/09/28
- [PULL 31/38] linux-user: Sink call to do_safe_futex, Laurent Vivier, 2022/09/28
- [PULL 34/38] linux-user: Implement PI futexes, Laurent Vivier, 2022/09/28
- [PULL 29/38] linux-user: Set ELF_BASE_PLATFORM for MIPS, Laurent Vivier, 2022/09/28
- [PULL 15/38] linux-user: Implement stracing madvise(), Laurent Vivier, 2022/09/28