From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH] linux-user: fix convertion of flock/flock64 l_type field
Date: Tue, 8 May 2018 18:36:39 +0200 [thread overview]
Message-ID: <20180508163639.7138-1-laurent@vivier.eu> (raw)
As l_type values (F_RDLCK, F_WRLCK, F_UNLCK, F_EXLCK, F_SHLCK)
are not bitmasks, we can't use target_to_host_bitmask() and
host_to_target_bitmask() to convert them.
Introduce target_to_host_flock() and host_to_target_flock()
to convert values between host and target.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 48 +++++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e4825747f9..fdf6766eca 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6546,15 +6546,33 @@ static int target_to_host_fcntl_cmd(int cmd)
return -TARGET_EINVAL;
}
-#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a }
-static const bitmask_transtbl flock_tbl[] = {
- TRANSTBL_CONVERT(F_RDLCK),
- TRANSTBL_CONVERT(F_WRLCK),
- TRANSTBL_CONVERT(F_UNLCK),
- TRANSTBL_CONVERT(F_EXLCK),
- TRANSTBL_CONVERT(F_SHLCK),
- { 0, 0, 0, 0 }
-};
+static unsigned int target_to_host_flock(unsigned int type)
+{
+ switch (type) {
+#define TRANSTBL_CONVERT(a) case TARGET_##a: return a;
+ TRANSTBL_CONVERT(F_RDLCK)
+ TRANSTBL_CONVERT(F_WRLCK)
+ TRANSTBL_CONVERT(F_UNLCK)
+ TRANSTBL_CONVERT(F_EXLCK)
+ TRANSTBL_CONVERT(F_SHLCK)
+#undef TRANSTBL_CONVERT
+ }
+ return type;
+}
+
+static unsigned int host_to_target_flock(unsigned int type)
+{
+ switch (type) {
+#define TRANSTBL_CONVERT(a) case a: return TARGET_##a;
+ TRANSTBL_CONVERT(F_RDLCK)
+ TRANSTBL_CONVERT(F_WRLCK)
+ TRANSTBL_CONVERT(F_UNLCK)
+ TRANSTBL_CONVERT(F_EXLCK)
+ TRANSTBL_CONVERT(F_SHLCK)
+#undef TRANSTBL_CONVERT
+ }
+ return type;
+}
static inline abi_long copy_from_user_flock(struct flock64 *fl,
abi_ulong target_flock_addr)
@@ -6567,7 +6585,7 @@ static inline abi_long copy_from_user_flock(struct flock64 *fl,
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ fl->l_type = target_to_host_flock(l_type);
__get_user(fl->l_whence, &target_fl->l_whence);
__get_user(fl->l_start, &target_fl->l_start);
__get_user(fl->l_len, &target_fl->l_len);
@@ -6586,7 +6604,7 @@ static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr,
return -TARGET_EFAULT;
}
- l_type = host_to_target_bitmask(fl->l_type, flock_tbl);
+ l_type = host_to_target_flock(fl->l_type);
__put_user(l_type, &target_fl->l_type);
__put_user(fl->l_whence, &target_fl->l_whence);
__put_user(fl->l_start, &target_fl->l_start);
@@ -6611,7 +6629,7 @@ static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ fl->l_type = target_to_host_flock(l_type);
__get_user(fl->l_whence, &target_fl->l_whence);
__get_user(fl->l_start, &target_fl->l_start);
__get_user(fl->l_len, &target_fl->l_len);
@@ -6630,7 +6648,7 @@ static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr,
return -TARGET_EFAULT;
}
- l_type = host_to_target_bitmask(fl->l_type, flock_tbl);
+ l_type = host_to_target_flock(fl->l_type);
__put_user(l_type, &target_fl->l_type);
__put_user(fl->l_whence, &target_fl->l_whence);
__put_user(fl->l_start, &target_fl->l_start);
@@ -6652,7 +6670,7 @@ static inline abi_long copy_from_user_flock64(struct flock64 *fl,
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ fl->l_type = target_to_host_flock(l_type);
__get_user(fl->l_whence, &target_fl->l_whence);
__get_user(fl->l_start, &target_fl->l_start);
__get_user(fl->l_len, &target_fl->l_len);
@@ -6671,7 +6689,7 @@ static inline abi_long copy_to_user_flock64(abi_ulong target_flock_addr,
return -TARGET_EFAULT;
}
- l_type = host_to_target_bitmask(fl->l_type, flock_tbl);
+ l_type = host_to_target_flock(fl->l_type);
__put_user(l_type, &target_fl->l_type);
__put_user(fl->l_whence, &target_fl->l_whence);
__put_user(fl->l_start, &target_fl->l_start);
--
2.14.3
next reply other threads:[~2018-05-08 16:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-08 16:36 Laurent Vivier [this message]
2018-05-08 17:08 ` [Qemu-devel] [PATCH] linux-user: fix convertion of flock/flock64 l_type field Max Filippov
2018-05-08 18:55 ` Eric Blake
2018-05-08 19:57 ` 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=20180508163639.7138-1-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=qemu-devel@nongnu.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).