qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v7 43/74] linux-user: Split out pipe, pipe2
Date: Sun, 19 May 2019 13:36:55 -0700	[thread overview]
Message-ID: <20190519203726.20729-44-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190519203726.20729-1-richard.henderson@linaro.org>

Note that pipe2 is universally available for guests.
Implement host support with syscall when !CONFIG_PIPE2.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 linux-user/syscall-defs.h     | 10 ++++++
 linux-user/syscall-file.inc.c | 51 +++++++++++++++++++++++++++
 linux-user/syscall.c          | 65 +++++++----------------------------
 linux-user/strace.list        |  6 ----
 4 files changed, 74 insertions(+), 58 deletions(-)

diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 062adddd75..bd3301a72f 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -132,6 +132,16 @@ SYSCALL_DEF(open_by_handle_at, ARG_DEC, ARG_PTR, ARG_OPENFLAG);
 #ifdef TARGET_NR_pause
 SYSCALL_DEF(pause);
 #endif
+#ifdef TARGET_NR_pipe
+# if defined(TARGET_ALPHA) || defined(TARGET_MIPS) || \
+     defined(TARGET_SH4) || defined(TARGET_SPARC)
+/* ??? We have no way for strace to display the second returned fd.  */
+SYSCALL_DEF(pipe);
+# else
+SYSCALL_DEF(pipe, ARG_PTR);
+# endif
+#endif
+SYSCALL_DEF(pipe2, ARG_PTR, ARG_OPENFLAG);
 SYSCALL_DEF_FULL(pread64, .impl = impl_pread64,
                  .args = args_pread64_pwrite64,
                  .arg_type = { ARG_DEC, ARG_PTR, ARG_DEC, ARG_DEC64 });
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 7d97dd1ec1..5bd9eaa002 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -726,6 +726,57 @@ SYSCALL_IMPL(open_by_handle_at)
     return ret;
 }
 
+static abi_long do_pipe(CPUArchState *cpu_env, abi_ulong target_fds,
+                        int target_flags, bool is_pipe2)
+{
+    int host_flags = target_to_host_bitmask(target_flags, fcntl_flags_tbl);
+    int host_fds[2];
+    abi_long ret;
+
+    ret = pipe2(host_fds, host_flags);
+    if (is_error(ret)) {
+        return get_errno(ret);
+    }
+
+    /*
+     * Several targets have special calling conventions for the original
+     * pipe syscall, but didn't replicate this into the pipe2 syscall.
+     */
+    if (!is_pipe2) {
+#if defined(TARGET_ALPHA)
+        cpu_env->ir[IR_A4] = host_fds[1];
+        return host_fds[0];
+#elif defined(TARGET_MIPS)
+        cpu_env->active_tc.gpr[3] = host_fds[1];
+        return host_fds[0];
+#elif defined(TARGET_SH4)
+        cpu_env->gregs[1] = host_fds[1];
+        return host_fds[0];
+#elif defined(TARGET_SPARC)
+        cpu_env->regwptr[1] = host_fds[1];
+        return host_fds[0];
+#endif
+    }
+
+    if (put_user_s32(host_fds[0], target_fds)
+        || put_user_s32(host_fds[1], target_fds + 4)) {
+        return -TARGET_EFAULT;
+    }
+    return 0;
+}
+
+#ifdef TARGET_NR_pipe
+SYSCALL_IMPL(pipe)
+{
+    return do_pipe(cpu_env, arg1, 0, false);
+}
+#endif
+
+SYSCALL_IMPL(pipe2)
+{
+    return do_pipe(cpu_env, arg1, arg2, true);
+}
+
 /*
  * Both pread64 and pwrite64 merge args into a 64-bit offset,
  * but the input registers and ordering are target specific.
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index bab9a57ee0..cda1f8a205 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -207,6 +207,9 @@ _syscall0(int, sys_gettid)
 #ifndef __NR_dup3
 #define __NR_dup3  -1
 #endif
+#ifndef __NR_pipe2
+#define __NR_pipe2  -1
+#endif
 #ifndef __NR_syncfs
 #define __NR_syncfs  -1
 #endif
@@ -273,6 +276,16 @@ _syscall5(int, kcmp, pid_t, pid1, pid_t, pid2, int, type,
 #ifndef CONFIG_SYNCFS
 _syscall1(int, syncfs, int, fd)
 #endif
+#ifndef CONFIG_PIPE2
+static int pipe2(int *fds, int flags)
+{
+    if (flags) {
+        return syscall(__NR_pipe2, fds, flags);
+    } else {
+        return pipe(fds);
+    }
+}
+#endif
 
 static bitmask_transtbl fcntl_flags_tbl[] = {
   { TARGET_O_ACCMODE,   TARGET_O_WRONLY,    O_ACCMODE,   O_WRONLY,    },
@@ -1124,49 +1137,6 @@ static abi_long do_old_select(abi_ulong arg1)
 #endif
 #endif
 
-static abi_long do_pipe2(int host_pipe[], int flags)
-{
-#ifdef CONFIG_PIPE2
-    return pipe2(host_pipe, flags);
-#else
-    return -ENOSYS;
-#endif
-}
-
-static abi_long do_pipe(void *cpu_env, abi_ulong pipedes,
-                        int flags, int is_pipe2)
-{
-    int host_pipe[2];
-    abi_long ret;
-    ret = flags ? do_pipe2(host_pipe, flags) : pipe(host_pipe);
-
-    if (is_error(ret))
-        return get_errno(ret);
-
-    /* Several targets have special calling conventions for the original
-       pipe syscall, but didn't replicate this into the pipe2 syscall.  */
-    if (!is_pipe2) {
-#if defined(TARGET_ALPHA)
-        ((CPUAlphaState *)cpu_env)->ir[IR_A4] = host_pipe[1];
-        return host_pipe[0];
-#elif defined(TARGET_MIPS)
-        ((CPUMIPSState*)cpu_env)->active_tc.gpr[3] = host_pipe[1];
-        return host_pipe[0];
-#elif defined(TARGET_SH4)
-        ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
-        return host_pipe[0];
-#elif defined(TARGET_SPARC)
-        ((CPUSPARCState*)cpu_env)->regwptr[1] = host_pipe[1];
-        return host_pipe[0];
-#endif
-    }
-
-    if (put_user_s32(host_pipe[0], pipedes)
-        || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0])))
-        return -TARGET_EFAULT;
-    return get_errno(ret);
-}
-
 static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
                                               abi_ulong target_addr,
                                               socklen_t len)
@@ -5376,15 +5346,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
     void *p;
 
     switch(num) {
-#ifdef TARGET_NR_pipe
-    case TARGET_NR_pipe:
-        return do_pipe(cpu_env, arg1, 0, 0);
-#endif
-#ifdef TARGET_NR_pipe2
-    case TARGET_NR_pipe2:
-        return do_pipe(cpu_env, arg1,
-                       target_to_host_bitmask(arg2, fcntl_flags_tbl), 1);
-#endif
     case TARGET_NR_times:
         {
             struct target_tms *tmsp;
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 2f78f4685b..a1c3dd98e0 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -860,9 +860,6 @@
 #ifdef TARGET_NR_personality
 { TARGET_NR_personality, "personality" , NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pipe
-{ TARGET_NR_pipe, "pipe" , NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_pivot_root
 { TARGET_NR_pivot_root, "pivot_root" , NULL, NULL, NULL },
 #endif
@@ -1377,9 +1374,6 @@
 #ifdef TARGET_NR_sync_file_range2
 { TARGET_NR_sync_file_range2, "sync_file_range2", NULL, NULL, NULL },
 #endif
-#ifdef TARGET_NR_pipe2
-{ TARGET_NR_pipe2, "pipe2", NULL, NULL, NULL },
-#endif
 #ifdef TARGET_NR_atomic_cmpxchg_32
 { TARGET_NR_atomic_cmpxchg_32, "atomic_cmpxchg_32", NULL, NULL, NULL },
 #endif
-- 
2.17.1



  parent reply	other threads:[~2019-05-19 21:24 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-19 20:36 [Qemu-devel] [PATCH v7 00/74] linux-user: Split do_syscall Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 01/74] linux-user: Setup split syscall infrastructure Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 02/74] linux-user: Split out open, open_at Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 03/74] linux-user: Share more code for open and openat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 04/74] linux-user: Tidy do_openat loop over fakes Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 05/74] linux-user: Split out readlink, readlinkat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 06/74] linux-user: Split out close Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 07/74] linux-user: Split out read, write Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 08/74] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 09/74] linux-user: Split out readv, writev Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 10/74] linux-user: Split out pread64, pwrite64 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 11/74] linux-user: Split out preadv, pwritev Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 12/74] linux-user: Split out name_to_handle_at, open_by_handle_at Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 13/74] linux-user: Split out ipc syscalls Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 14/74] linux-user: Split out memory syscalls Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 15/74] linux-user: Split out exit Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 16/74] linux-user: Split out brk Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 17/74] linux-user: Split out clone, fork, vfork Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 18/74] linux-user: Split out wait4, waitid, waitpid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 19/74] linux-user: Implement rusage argument to waitid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 20/74] linux-user: Split out creat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 21/74] linux-user: Split out link, linkat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 22/74] linux-user: Split out unlink, unlinkat, rmdir Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 23/74] linux-user: Split out execve Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 24/74] linux-user: Implement execveat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 25/74] linux-user: Split out chdir Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 26/74] linux-user: Split out time Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 27/74] linux-user: Split out mknod, mknodat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 28/74] linux-user: Split out chmod, fchmod, fchmodat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 29/74] linux-user: Split out lseek, llseek Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 30/74] linux-user: Split out getpid, getppid, getxpid Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 31/74] linux-user: Split out mount Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 32/74] linux-user: Split out umount, umount2 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 33/74] linux-user: Split out stime Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 34/74] linux-user: Split out alarm, pause Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 35/74] linux-user: Split out utime, utimes, futimesat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 36/74] linux-user: Split out access, faccessat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 37/74] linux-user: Split out nice Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 38/74] linux-user: Split out sync, syncfs Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 39/74] linux-user: Split out kill Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 40/74] linux-user: Split out rename, renameat, renameat2 Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 41/74] linux-user: Split out mkdir, mkdirat Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 42/74] linux-user: Split out dup, dup2, dup3 Richard Henderson
2019-05-19 20:36 ` Richard Henderson [this message]
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 44/74] linux-user: Split out times Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 45/74] linux-user: Split out acct Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 46/74] linux-user: Move syscall_init to the end Richard Henderson
2019-05-19 20:36 ` [Qemu-devel] [PATCH v7 47/74] linux-user: Split out ioctl Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 48/74] linux-user: Fix types in ioctl logging Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 49/74] linux-user: Remove sentinel from ioctl_entries Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 50/74] linux-user: Split out fcntl, fcntl64 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 51/74] linux-user: Split out setpgid Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 52/74] linux-user: Split out umask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 53/74] linux-user: Split out chroot Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 54/74] linux-user: Split out getpgid, getpgrp Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 55/74] linux-user: Split out getsid, setsid Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 56/74] linux-user: Split out sigaction, rt_sigaction Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 57/74] linux-user: Split out sgetmask, ssetmask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 58/74] linux-user: Split out sigprocmask, rt_sigprocmask Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 59/74] linux-user: Split out sigpending, rt_sigpending Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 60/74] linux-user: Split out sigsuspend, rt_sigsuspend Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 61/74] linux-user: Split out rt_sigtimedwait Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 62/74] linux-user: Split out rt_sigqueueinfo, rt_tgsigqueueinfo Richard Henderson
2019-05-20  6:04   ` Aleksandar Markovic
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 63/74] linux-user: Split out sigreturn, rt_sigreturn Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 64/74] linux-user: Split out gethostname, sethostname Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 65/74] linux-user: Split out getrlimit, setrlimit Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 66/74] linux-user: Split out getrusage Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 67/74] linux-user: Split out gettimeofday, settimeofday Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 68/74] linux-user: Split out select, _newselect Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 69/74] linux-user: Split out pselect6 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 70/74] linux-user: Split out symlink, symlinkat Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 71/74] linux-user: Split out swapon, swapoff Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 72/74] linux-user: Split out reboot Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 73/74] linux-user: Split out truncate, truncate64, ftruncate, ftruncate64 Richard Henderson
2019-05-19 20:37 ` [Qemu-devel] [PATCH v7 74/74] linux-user: Split out getpriority, setpriority Richard Henderson
2019-05-20  6:21 ` [Qemu-devel] [PATCH v7 00/74] linux-user: Split do_syscall Laurent Vivier
2019-05-20  9:42 ` Peter Maydell
2019-05-20 10:13   ` Aleksandar Markovic
2019-05-22  6:11 ` Aleksandar Markovic
     [not found]   ` <CAL1e-=i_=EQ02A1DGmVgqNi1ik=h39FZTOsxkGWfMa4ZoM6rjg@mail.gmail.com>
2019-05-22 11:29     ` Richard Henderson

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=20190519203726.20729-44-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=laurent@vivier.eu \
    --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).