From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [PATCH 2/8] linux-user: Sink call to do_safe_futex
Date: Sun, 28 Aug 2022 19:10:00 -0700 [thread overview]
Message-ID: <20220829021006.67305-3-richard.henderson@linaro.org> (raw)
In-Reply-To: <20220829021006.67305-1-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>
---
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 a7e66d8d28..8fbd5a9556 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -7758,11 +7758,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
@@ -7771,39 +7771,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.34.1
next prev parent reply other threads:[~2022-08-29 2:12 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 2:09 [PATCH 0/8] linux-user: Futex improvements Richard Henderson
2022-08-29 2:09 ` [PATCH 1/8] linux-user: Combine do_futex and do_futex_time64 Richard Henderson
2022-09-27 9:48 ` Laurent Vivier
2022-08-29 2:10 ` Richard Henderson [this message]
2022-09-27 9:53 ` [PATCH 2/8] linux-user: Sink call to do_safe_futex Laurent Vivier
2022-08-29 2:10 ` [PATCH 3/8] linux-user: Implement FUTEX_WAKE_BITSET Richard Henderson
2022-09-27 9:54 ` Laurent Vivier
2022-08-29 2:10 ` [PATCH 4/8] linux-user: Convert signal number for FUTEX_FD Richard Henderson
2022-09-27 9:56 ` Laurent Vivier
2022-08-29 2:10 ` [PATCH 5/8] linux-user: Implement PI futexes Richard Henderson
2022-09-27 10:29 ` Laurent Vivier
2022-08-29 2:10 ` [PATCH 6/8] linux-user: Update print_futex_op Richard Henderson
2022-09-27 10:31 ` Laurent Vivier
2022-08-29 2:10 ` [PATCH 7/8] linux-user: Lock log around strace Richard Henderson
2022-09-27 10:33 ` Laurent Vivier
2022-08-29 2:10 ` [PATCH 8/8] linux-user: Log tid for strace Richard Henderson
2022-09-27 10:34 ` Laurent Vivier
2022-09-28 20:33 ` Laurent Vivier
2022-09-27 10:59 ` [PATCH 0/8] linux-user: Futex improvements Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220829021006.67305-3-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).