aboutsummaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2018-05-15 10:04:22 +0100
committerPeter Maydell <peter.maydell@linaro.org>2018-05-15 10:04:22 +0100
commitf39ddb3a08df2d2573d6aff062190f093912f9ef (patch)
tree06ac1527235b1164670d873019b96782caafb86e /linux-user/syscall.c
parentc691c8761616cff9c58caf345bfa7ae450e00088 (diff)
parentf606e4d6258fa82c3f6c1cc762ebe483db5f5db6 (diff)
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-2.13-pull-request' into staging
# gpg: Signature made Mon 14 May 2018 19:15:02 BST # gpg: using RSA key F30C38BD3F2FBE3C # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" # gpg: aka "Laurent Vivier <laurent@vivier.eu>" # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/linux-user-for-2.13-pull-request: linux-user: correctly align types in thunking code linux-user: fix UNAME_MACHINE for sparc/sparc64 linux-user: add sparc/sparc64 specific errno linux-user: fix conversion of flock/flock64 l_type field linux-user: update sparc/syscall_nr.h to linux header 4.16 linux-user: fix flock/flock64 padding linux-user: define correct fcntl() values for sparc Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'linux-user/syscall.c')
-rw-r--r--linux-user/syscall.c66
1 files changed, 48 insertions, 18 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index e4825747f9..af8603f1b7 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6546,28 +6546,50 @@ 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 }
-};
+#define FLOCK_TRANSTBL \
+ switch (type) { \
+ TRANSTBL_CONVERT(F_RDLCK); \
+ TRANSTBL_CONVERT(F_WRLCK); \
+ TRANSTBL_CONVERT(F_UNLCK); \
+ TRANSTBL_CONVERT(F_EXLCK); \
+ TRANSTBL_CONVERT(F_SHLCK); \
+ }
+
+static int target_to_host_flock(int type)
+{
+#define TRANSTBL_CONVERT(a) case TARGET_##a: return a
+ FLOCK_TRANSTBL
+#undef TRANSTBL_CONVERT
+ return -TARGET_EINVAL;
+}
+
+static int host_to_target_flock(int type)
+{
+#define TRANSTBL_CONVERT(a) case a: return TARGET_##a
+ FLOCK_TRANSTBL
+#undef TRANSTBL_CONVERT
+ /* if we don't know how to convert the value coming
+ * from the host we copy to the target field as-is
+ */
+ return type;
+}
static inline abi_long copy_from_user_flock(struct flock64 *fl,
abi_ulong target_flock_addr)
{
struct target_flock *target_fl;
- short l_type;
+ int l_type;
if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
return -TARGET_EFAULT;
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ l_type = target_to_host_flock(l_type);
+ if (l_type < 0) {
+ return l_type;
+ }
+ fl->l_type = 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 +6608,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);
@@ -6604,14 +6626,18 @@ static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl,
abi_ulong target_flock_addr)
{
struct target_oabi_flock64 *target_fl;
- short l_type;
+ int l_type;
if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
return -TARGET_EFAULT;
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ l_type = target_to_host_flock(l_type);
+ if (l_type < 0) {
+ return l_type;
+ }
+ fl->l_type = 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 +6656,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);
@@ -6645,14 +6671,18 @@ static inline abi_long copy_from_user_flock64(struct flock64 *fl,
abi_ulong target_flock_addr)
{
struct target_flock64 *target_fl;
- short l_type;
+ int l_type;
if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) {
return -TARGET_EFAULT;
}
__get_user(l_type, &target_fl->l_type);
- fl->l_type = target_to_host_bitmask(l_type, flock_tbl);
+ l_type = target_to_host_flock(l_type);
+ if (l_type < 0) {
+ return l_type;
+ }
+ fl->l_type = 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 +6701,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);