From: Max Filippov <jcmvbkbc@gmail.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Max Filippov <jcmvbkbc@gmail.com>,
Riku Voipio <riku.voipio@iki.fi>,
Laurent Vivier <laurent@vivier.eu>,
Richard Henderson <richard.henderson@linaro.org>
Subject: [Qemu-devel] [PULL 1/1] linux-user: fix preadv/pwritev offsets
Date: Mon, 9 Apr 2018 19:17:45 -0700 [thread overview]
Message-ID: <20180410021745.32378-2-jcmvbkbc@gmail.com> (raw)
In-Reply-To: <20180410021745.32378-1-jcmvbkbc@gmail.com>
preadv/pwritev accept low and high parts of file offset in two separate
parameters. When host bitness doesn't match guest bitness these parts
must be appropriately recombined.
Introduce target_to_host_low_high that does this recombination and use
it in preadv/pwritev syscalls.
This fixes glibc testsuite test misc/tst-preadvwritev64.
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
---
linux-user/syscall.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 5ef517613577..0eab5cc6ade1 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -3386,6 +3386,23 @@ static abi_long do_getsockopt(int sockfd, int level, int optname,
return ret;
}
+/* Convert target low/high pair representing file offset into the host
+ * low/high pair. This function doesn't handle offsets bigger than 64 bits
+ * as the kernel doesn't handle them either.
+ */
+static void target_to_host_low_high(abi_ulong tlow,
+ abi_ulong thigh,
+ unsigned long *hlow,
+ unsigned long *hhigh)
+{
+ uint64_t off = tlow |
+ ((unsigned long long)thigh << TARGET_LONG_BITS / 2) <<
+ TARGET_LONG_BITS / 2;
+
+ *hlow = off;
+ *hhigh = (off >> HOST_LONG_BITS / 2) >> HOST_LONG_BITS / 2;
+}
+
static struct iovec *lock_iovec(int type, abi_ulong target_addr,
abi_ulong count, int copy)
{
@@ -10449,7 +10466,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
{
struct iovec *vec = lock_iovec(VERIFY_WRITE, arg2, arg3, 0);
if (vec != NULL) {
- ret = get_errno(safe_preadv(arg1, vec, arg3, arg4, arg5));
+ unsigned long low, high;
+
+ target_to_host_low_high(arg4, arg5, &low, &high);
+ ret = get_errno(safe_preadv(arg1, vec, arg3, low, high));
unlock_iovec(vec, arg2, arg3, 1);
} else {
ret = -host_to_target_errno(errno);
@@ -10462,7 +10482,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
{
struct iovec *vec = lock_iovec(VERIFY_READ, arg2, arg3, 1);
if (vec != NULL) {
- ret = get_errno(safe_pwritev(arg1, vec, arg3, arg4, arg5));
+ unsigned long low, high;
+
+ target_to_host_low_high(arg4, arg5, &low, &high);
+ ret = get_errno(safe_pwritev(arg1, vec, arg3, low, high));
unlock_iovec(vec, arg2, arg3, 0);
} else {
ret = -host_to_target_errno(errno);
--
2.11.0
next prev parent reply other threads:[~2018-04-10 2:18 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-10 2:17 [Qemu-devel] [PULL 0/1] linux-user: fix file offset for preadv/pwritev Max Filippov
2018-04-10 2:17 ` Max Filippov [this message]
2018-04-10 3:20 ` [Qemu-devel] [PULL 1/1] linux-user: fix preadv/pwritev offsets Richard Henderson
2018-04-10 3:29 ` Max Filippov
2018-04-10 4:05 ` Richard Henderson
2018-04-10 11:48 ` [Qemu-devel] [PULL 0/1] linux-user: fix file offset for preadv/pwritev Peter Maydell
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=20180410021745.32378-2-jcmvbkbc@gmail.com \
--to=jcmvbkbc@gmail.com \
--cc=laurent@vivier.eu \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=riku.voipio@iki.fi \
/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).