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 v6 44/49] linux-user: Split out pipe, pipe2
Date: Sat, 19 Jan 2019 08:31:17 +1100	[thread overview]
Message-ID: <20190118213122.22865-44-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190118213122.22865-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 5e8298fdb3..90aacfacaf 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -720,6 +720,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 29a9d5fce4..3a322a61ca 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -207,6 +207,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,	\
 #ifndef __NR_dup3
 #define __NR_dup3  -1
 #endif
+#ifndef __NR_pipe2
+#define __NR_pipe2  -1
+#endif
 #ifndef __NR_syncfs
 #define __NR_syncfs  -1
 #endif
@@ -283,6 +286,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,    },
@@ -1134,49 +1147,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)
@@ -5323,15 +5293,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 151b0eb42d..ac25e13bfa 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.2

  parent reply	other threads:[~2019-01-18 21:33 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18 21:30 [Qemu-devel] [PATCH v6 00/49] linux-user: Split do_syscall Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 01/49] linux-user: Setup split syscall infrastructure Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 03/49] linux-user: Split out open, open_at Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 04/49] linux-user: Share more code for open and openat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 05/49] linux-user: Tidy do_openat loop over fakes Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 06/49] linux-user: Split out readlink, readlinkat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 07/49] linux-user: Split out close Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 08/49] linux-user: Split out read, write Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 09/49] linux-user: Reduce regpairs_aligned & target_offset64 ifdefs Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 10/49] linux-user: Split out readv, writev Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 11/49] linux-user: Split out pread64, pwrite64 Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 12/49] linux-user: Split out preadv, pwritev Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 13/49] linux-user: Split out name_to_handle_at, open_by_handle_at Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 14/49] linux-user: Split out ipc syscalls Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 15/49] linux-user: Split out memory syscalls Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 16/49] linux-user: Split out exit Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 17/49] linux-user: Split out brk Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 18/49] linux-user: Split out clone, fork, vfork Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 19/49] linux-user: Split out wait4, waitid, waitpid Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 20/49] linux-user: Implement rusage argument to waitid Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 21/49] linux-user: Split out creat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 22/49] linux-user: Split out link, linkat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 23/49] linux-user: Split out unlink, unlinkat, rmdir Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 24/49] linux-user: Split out execve Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 25/49] linux-user: Implement execveat Richard Henderson
2019-01-18 21:30 ` [Qemu-devel] [PATCH v6 26/49] linux-user: Split out chdir Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 27/49] linux-user: Split out time Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 28/49] linux-user: Split out mknod, mknodat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 29/49] linux-user: Split out chmod, fchmod, fchmodat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 30/49] linux-user: Split out lseek, llseek Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 31/49] linux-user: Split out getpid, getppid, getxpid Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 32/49] linux-user: Split out mount Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 33/49] linux-user: Split out umount, umount2 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 34/49] linux-user: Split out stime Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 35/49] linux-user: Split out alarm, pause Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 36/49] linux-user: Split out utime, utimes, futimesat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 37/49] linux-user: Split out access, faccessat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 38/49] linux-user: Split out nice Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 39/49] linux-user: Split out sync, syncfs Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 40/49] linux-user: Split out kill Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 41/49] linux-user: Split out rename, renameat, renameat2 Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 42/49] linux-user: Split out mkdir, mkdirat Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 43/49] linux-user: Split out dup, dup2, dup3 Richard Henderson
2019-01-18 21:31 ` Richard Henderson [this message]
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 45/49] linux-user: Split out times Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 46/49] linux-user: Split out acct Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 47/49] linux-user: Move syscall_init to the end Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 48/49] linux-user: Split out ioctl Richard Henderson
2019-02-13 13:09   ` Laurent Vivier
2019-02-13 13:46     ` Laurent Vivier
2019-04-09 23:15       ` Richard Henderson
2019-04-09 23:15         ` Richard Henderson
2019-04-09 23:30         ` Richard Henderson
2019-04-09 23:30           ` Richard Henderson
2019-04-10  1:55           ` Richard Henderson
2019-04-10  1:55             ` Richard Henderson
2019-05-09 15:44             ` Laurent Vivier
2019-05-09 15:54               ` Richard Henderson
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 49/49] linux-user: Split out fcntl, fcntl64 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=20190118213122.22865-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).