[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 31/37] linux-user: Sink call to do_safe_futex
From: |
Laurent Vivier |
Subject: |
[PULL 31/37] linux-user: Sink call to do_safe_futex |
Date: |
Wed, 28 Sep 2022 22:27:31 +0200 |
From: Richard Henderson <richard.henderson@linaro.org>
Leave only the argument adjustments within the shift,
and sink the actual syscall to the end. Sink the
timespec conversion as well, as there will be more users.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220829021006.67305-3-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 60 +++++++++++++++++++++++---------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index af3a605fc458..17e17f480456 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7773,11 +7773,11 @@ 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;
+ struct timespec ts, *pts = NULL;
+ void *haddr2 = NULL;
int base_op;
- /* ??? We assume FUTEX_* constants are the same on both host
- and target. */
+ /* We assume FUTEX_* constants are the same on both host and target. */
#ifdef FUTEX_CMD_MASK
base_op = op & FUTEX_CMD_MASK;
#else
@@ -7786,39 +7786,41 @@ static int do_futex(CPUState *cpu, bool time64,
target_ulong uaddr,
switch (base_op) {
case FUTEX_WAIT:
case FUTEX_WAIT_BITSET:
- if (timeout) {
- pts = &ts;
- if (time64
- ? target_to_host_timespec64(pts, timeout)
- : target_to_host_timespec(pts, timeout)) {
- return -TARGET_EFAULT;
- }
- } else {
- pts = NULL;
- }
- return do_safe_futex(g2h(cpu, uaddr),
- op, tswap32(val), pts, NULL, val3);
+ val = tswap32(val);
+ break;
case FUTEX_WAKE:
- return do_safe_futex(g2h(cpu, uaddr),
- op, val, NULL, NULL, 0);
+ timeout = 0;
+ break;
case FUTEX_FD:
- return do_safe_futex(g2h(cpu, uaddr),
- op, val, NULL, NULL, 0);
- case FUTEX_REQUEUE:
+ timeout = 0;
+ break;
case FUTEX_CMP_REQUEUE:
+ val3 = tswap32(val3);
+ /* fall through */
+ case FUTEX_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));
+ /*
+ * For these, the 4th argument is not TIMEOUT, but VAL2.
+ * But the prototype of do_safe_futex takes a pointer, so
+ * insert casts to satisfy the compiler. We do not need
+ * to tswap VAL2 since it's not compared to guest memory.
+ */
+ pts = (struct timespec *)(uintptr_t)timeout;
+ timeout = 0;
+ haddr2 = g2h(cpu, uaddr2);
+ break;
default:
return -TARGET_ENOSYS;
}
+ if (timeout) {
+ pts = &ts;
+ if (time64
+ ? target_to_host_timespec64(pts, timeout)
+ : target_to_host_timespec(pts, timeout)) {
+ return -TARGET_EFAULT;
+ }
+ }
+ return do_safe_futex(g2h(cpu, uaddr), op, val, pts, haddr2, val3);
}
#endif
--
2.37.3
- [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect(), (continued)
- [PULL 23/37] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect(), Laurent Vivier, 2022/09/28
- [PULL 22/37] linux-user/hppa: Increase guest stack size to 80MB for hppa target, Laurent Vivier, 2022/09/28
- [PULL 24/37] linux-user/hppa: Fix setup_sigcontext(), Laurent Vivier, 2022/09/28
- [PULL 26/37] linux-user: Don't assume 0 is not a valid host timer_t value, Laurent Vivier, 2022/09/28
- [PULL 30/37] linux-user: Combine do_futex and do_futex_time64, Laurent Vivier, 2022/09/28
- [PULL 27/37] linux-user/s390x: Save/restore fpc when handling a signal, Laurent Vivier, 2022/09/28
- [PULL 32/37] linux-user: Implement FUTEX_WAKE_BITSET, Laurent Vivier, 2022/09/28
- [PULL 33/37] linux-user: Convert signal number for FUTEX_FD, Laurent Vivier, 2022/09/28
- [PULL 29/37] linux-user: Set ELF_BASE_PLATFORM for MIPS, Laurent Vivier, 2022/09/28
- [PULL 19/37] linux-user: Add proper strace format strings for getdents()/getdents64(), Laurent Vivier, 2022/09/28
- [PULL 31/37] linux-user: Sink call to do_safe_futex,
Laurent Vivier <=
- [PULL 34/37] linux-user: Implement PI futexes, Laurent Vivier, 2022/09/28
- [PULL 35/37] linux-user: Update print_futex_op, Laurent Vivier, 2022/09/28
- [PULL 28/37] linux-user: Introduce stubs for ELF AT_BASE_PLATFORM, Laurent Vivier, 2022/09/28
- [PULL 37/37] linux-user: Add parameters of getrandom() syscall for strace, Laurent Vivier, 2022/09/28
- [PULL 25/37] linux-user: fix bug about missing signum convert of sigqueue, Laurent Vivier, 2022/09/28
- [PULL 36/37] linux-user: Lock log around strace, Laurent Vivier, 2022/09/28
- Re: [PULL 00/37] Linux user for 7.2 patches, Stefan Hajnoczi, 2022/09/29