From: riku.voipio@linaro.org
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PULL 03/24] linux-user: Use safe_syscall wrapper for fcntl
Date: Fri, 24 Jun 2016 12:52:58 +0300 [thread overview]
Message-ID: <7fd7b54fdf64a882ca0c8081deff82b570ab0b13.1466760944.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1466760944.git.riku.voipio@linaro.org>
From: Peter Maydell <peter.maydell@linaro.org>
Use the safe_syscall wrapper for fcntl. This is straightforward now
that we always use 'struct fcntl64' on the host, as we don't need
to select whether to call the host's fcntl64 or fcntl syscall
(a detail that the libc previously hid for us).
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
linux-user/syscall.c | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ee05405..8dc8c7a 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -783,6 +783,16 @@ safe_syscall5(int, mq_timedreceive, int, mqdes, char *, msg_ptr,
* the libc function.
*/
#define safe_ioctl(...) safe_syscall(__NR_ioctl, __VA_ARGS__)
+/* Similarly for fcntl. Note that callers must always:
+ * pass the F_GETLK64 etc constants rather than the unsuffixed F_GETLK
+ * use the flock64 struct rather than unsuffixed flock
+ * This will then work and use a 64-bit offset for both 32-bit and 64-bit hosts.
+ */
+#ifdef __NR_fcntl64
+#define safe_fcntl(...) safe_syscall(__NR_fcntl64, __VA_ARGS__)
+#else
+#define safe_fcntl(...) safe_syscall(__NR_fcntl, __VA_ARGS__)
+#endif
static inline int host_to_target_sock_type(int host_type)
{
@@ -5740,7 +5750,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret) {
return ret;
}
- ret = get_errno(fcntl(fd, host_cmd, &fl64));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
if (ret == 0) {
ret = copy_to_user_flock(arg, &fl64);
}
@@ -5752,7 +5762,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret) {
return ret;
}
- ret = get_errno(fcntl(fd, host_cmd, &fl64));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
break;
case TARGET_F_GETLK64:
@@ -5760,7 +5770,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret) {
return ret;
}
- ret = get_errno(fcntl(fd, host_cmd, &fl64));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
if (ret == 0) {
ret = copy_to_user_flock64(arg, &fl64);
}
@@ -5771,23 +5781,25 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
if (ret) {
return ret;
}
- ret = get_errno(fcntl(fd, host_cmd, &fl64));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
break;
case TARGET_F_GETFL:
- ret = get_errno(fcntl(fd, host_cmd, arg));
+ ret = get_errno(safe_fcntl(fd, host_cmd, arg));
if (ret >= 0) {
ret = host_to_target_bitmask(ret, fcntl_flags_tbl);
}
break;
case TARGET_F_SETFL:
- ret = get_errno(fcntl(fd, host_cmd, target_to_host_bitmask(arg, fcntl_flags_tbl)));
+ ret = get_errno(safe_fcntl(fd, host_cmd,
+ target_to_host_bitmask(arg,
+ fcntl_flags_tbl)));
break;
#ifdef F_GETOWN_EX
case TARGET_F_GETOWN_EX:
- ret = get_errno(fcntl(fd, host_cmd, &fox));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fox));
if (ret >= 0) {
if (!lock_user_struct(VERIFY_WRITE, target_fox, arg, 0))
return -TARGET_EFAULT;
@@ -5805,7 +5817,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
fox.type = tswap32(target_fox->type);
fox.pid = tswap32(target_fox->pid);
unlock_user_struct(target_fox, arg, 0);
- ret = get_errno(fcntl(fd, host_cmd, &fox));
+ ret = get_errno(safe_fcntl(fd, host_cmd, &fox));
break;
#endif
@@ -5815,11 +5827,11 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
case TARGET_F_GETSIG:
case TARGET_F_SETLEASE:
case TARGET_F_GETLEASE:
- ret = get_errno(fcntl(fd, host_cmd, arg));
+ ret = get_errno(safe_fcntl(fd, host_cmd, arg));
break;
default:
- ret = get_errno(fcntl(fd, cmd, arg));
+ ret = get_errno(safe_fcntl(fd, cmd, arg));
break;
}
return ret;
@@ -10252,7 +10264,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
if (ret) {
break;
}
- ret = get_errno(fcntl(arg1, cmd, &fl));
+ ret = get_errno(safe_fcntl(arg1, cmd, &fl));
break;
default:
ret = do_fcntl(arg1, arg2, arg3);
--
2.1.4
next prev parent reply other threads:[~2016-06-24 9:53 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-24 9:52 [Qemu-devel] [PULL 00/24] linux-user changes riku.voipio
2016-06-24 9:52 ` [Qemu-devel] [PULL 01/24] linux-user: Avoid possible misalignment in host_to_target_siginfo() riku.voipio
2016-06-24 9:52 ` [Qemu-devel] [PULL 02/24] linux-user: Use __get_user() and __put_user() to handle structs in do_fcntl() riku.voipio
2016-06-24 9:52 ` riku.voipio [this message]
2016-06-24 9:52 ` [Qemu-devel] [PULL 04/24] linux-user: Don't use sigfillset() on uc->uc_sigmask riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 05/24] configure: Don't override ARCH=unknown if enabling TCI riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 06/24] configure: Don't allow user-only targets for unknown CPU architectures riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 07/24] user-exec: Delete now-unused hppa and m68k cpu_signal_handler() code riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 08/24] user-exec: Remove unused code for OSX hosts riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 09/24] linux-user: Create a hostdep.h for each host architecture riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 10/24] linux-user: Fix wrong type used for argument to rt_sigqueueinfo riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 11/24] linux-user: Support F_GETPIPE_SZ and F_SETPIPE_SZ fcntls riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 12/24] linux-user: add socketcall() strace riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 13/24] linux-user: add socket() strace riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 14/24] linux-user: fix clone() strace riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 15/24] linux-user: update get_thread_area/set_thread_area strace riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 16/24] linux-user: add missing return in netlink switch statement riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 17/24] linux-user: fd_trans_host_to_target_data() must process only received data riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 18/24] linux-user: don't swap NLMSG_DATA() fields riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 19/24] linux-user: fix x86_64 safe_syscall riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 20/24] linux-user: Provide safe_syscall for i386 riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 21/24] linux-user: Provide safe_syscall for arm riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 22/24] linux-user: Provide safe_syscall for aarch64 riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 23/24] linux-user: Provide safe_syscall for s390x riku.voipio
2016-06-24 9:53 ` [Qemu-devel] [PULL 24/24] linux-user: Provide safe_syscall for ppc64 riku.voipio
2016-06-24 13:36 ` [Qemu-devel] [PULL 00/24] linux-user changes Peter Maydell
2016-06-26 10:34 ` Riku Voipio
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=7fd7b54fdf64a882ca0c8081deff82b570ab0b13.1466760944.git.riku.voipio@linaro.org \
--to=riku.voipio@linaro.org \
--cc=peter.maydell@linaro.org \
--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).