All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org, Riku Voipio <riku.voipio@iki.fi>,
	Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH 16/18] linux-user: Use safe_syscall wrapper for fcntl
Date: Mon,  6 Jun 2016 19:58:17 +0100	[thread overview]
Message-ID: <1465239499-5048-17-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1465239499-5048-1-git-send-email-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>
---
 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 f3a487e..249d246 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -764,6 +764,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)
 {
@@ -5092,7 +5102,7 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         if (copy_from_user_flock(&fl64, arg)) {
             return -TARGET_EFAULT;
         }
-        ret = get_errno(fcntl(fd, host_cmd, &fl64));
+        ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
         if (ret == 0) {
             if (copy_to_user_flock(arg, &fl64)) {
                 return -TARGET_EFAULT;
@@ -5105,14 +5115,14 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         if (copy_from_user_flock(&fl64, arg)) {
             return -TARGET_EFAULT;
         }
-        ret = get_errno(fcntl(fd, host_cmd, &fl64));
+        ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
         break;
 
     case TARGET_F_GETLK64:
         if (copy_from_user_flock64(&fl64, arg)) {
             return -TARGET_EFAULT;
         }
-        ret = get_errno(fcntl(fd, host_cmd, &fl64));
+        ret = get_errno(safe_fcntl(fd, host_cmd, &fl64));
         if (ret == 0) {
             if (copy_to_user_flock64(arg, &fl64)) {
                 return -TARGET_EFAULT;
@@ -5124,23 +5134,25 @@ static abi_long do_fcntl(int fd, int cmd, abi_ulong arg)
         if (copy_from_user_flock64(&fl64, arg)) {
             return -TARGET_EFAULT;
         }
-        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;
@@ -5158,7 +5170,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
 
@@ -5168,11 +5180,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;
@@ -9605,7 +9617,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
             if (copyfrom(&fl, arg3)) {
                 goto efault;
             }
-            ret = get_errno(fcntl(arg1, cmd, &fl));
+            ret = get_errno(safe_fcntl(arg1, cmd, &fl));
 	    break;
         default:
             ret = do_fcntl(arg1, arg2, arg3);
-- 
1.9.1

  parent reply	other threads:[~2016-06-06 19:24 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 18:58 [Qemu-devel] [PATCH 00/18] linux-user: Extend safe_syscall wrapper use Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 01/18] linux-user: Use safe_syscall wrapper for readv and writev syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 02/18] linux-user: Use safe_syscall wrapper for connect syscall Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 03/18] linux-user: Use safe_syscall wrapper for send* and recv* syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 04/18] linux-user: Use safe_syscall wrapper for msgsnd and msgrcv Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 05/18] linux-user: Use safe_syscall wrapper for mq_timedsend and mq_timedreceive Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 06/18] linux-user: Use safe_syscall wrapper for flock Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 07/18] linux-user: Use safe_syscall wrapper for rt_sigtimedwait syscall Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 08/18] linux-user: Use safe_syscall wrapper for sleep syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 09/18] linux-user: Use safe_syscall wrapper for poll and ppoll syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 10/18] linux-user: Use safe_syscall wrapper for epoll_wait syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 11/18] linux-user: Use safe_syscall wrapper for semop Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 12/18] linux-user: Use safe_syscall wrapper for accept and accept4 syscalls Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 13/18] linux-user: Use safe_syscall wrapper for ioctl Peter Maydell
2016-06-06 18:58 ` [Qemu-devel] [PATCH 14/18] linux-user: Use __get_user() and __put_user() to handle structs in do_fcntl() Peter Maydell
2016-06-07 20:41   ` Laurent Vivier
2016-06-07 21:20     ` Peter Maydell
2016-06-08  9:33       ` Laurent Vivier
2016-06-06 18:58 ` [Qemu-devel] [PATCH 15/18] linux-user: Correct signedness of target_flock l_start and l_len fields Peter Maydell
2016-06-07 20:00   ` Laurent Vivier
2016-06-06 18:58 ` Peter Maydell [this message]
2016-06-06 18:58 ` [Qemu-devel] [PATCH 17/18] linux-user: Make target_strerror() return 'const char *' Peter Maydell
2016-06-07 19:56   ` Laurent Vivier
2016-06-06 18:58 ` [Qemu-devel] [PATCH 18/18] linux-user: Special-case ERESTARTSYS in target_strerror() Peter Maydell
2016-06-07 19:53   ` Laurent Vivier
2016-06-07 21:31     ` Peter Maydell
2016-06-08  9:20 ` [Qemu-devel] [PATCH 00/18] linux-user: Extend safe_syscall wrapper use Riku Voipio
2016-06-08 11:26   ` 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=1465239499-5048-17-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=laurent@vivier.eu \
    --cc=patches@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.