From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [Qemu-devel] [PATCH v6 43/49] linux-user: Split out dup, dup2, dup3
Date: Sat, 19 Jan 2019 08:31:16 +1100 [thread overview]
Message-ID: <20190118213122.22865-43-richard.henderson@linaro.org> (raw)
In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org>
Note that dup3 is universally available for guests.
Implement host support with syscall when !CONFIG_DUP3.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
linux-user/syscall-defs.h | 5 +++++
linux-user/syscall-file.inc.c | 42 +++++++++++++++++++++++++++++++++++
linux-user/syscall.c | 33 +++------------------------
linux-user/strace.list | 6 -----
4 files changed, 50 insertions(+), 36 deletions(-)
diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h
index 8b6d8f75ff..062adddd75 100644
--- a/linux-user/syscall-defs.h
+++ b/linux-user/syscall-defs.h
@@ -34,6 +34,11 @@ SYSCALL_DEF(close, ARG_DEC);
#ifdef TARGET_NR_creat
SYSCALL_DEF(creat, ARG_STR, ARG_MODEFLAG);
#endif
+SYSCALL_DEF(dup, ARG_DEC);
+#ifdef TARGET_NR_dup2
+SYSCALL_DEF(dup2, ARG_DEC, ARG_DEC);
+#endif
+SYSCALL_DEF(dup3, ARG_DEC, ARG_DEC, ARG_OPENFLAG);
SYSCALL_DEF(exit, ARG_DEC);
SYSCALL_DEF(execve, ARG_STR, ARG_PTR, ARG_PTR);
SYSCALL_DEF(execveat, ARG_ATDIRFD, ARG_STR, ARG_PTR, ARG_PTR, ARG_ATFLAG);
diff --git a/linux-user/syscall-file.inc.c b/linux-user/syscall-file.inc.c
index 83174c5781..5e8298fdb3 100644
--- a/linux-user/syscall-file.inc.c
+++ b/linux-user/syscall-file.inc.c
@@ -94,6 +94,48 @@ SYSCALL_IMPL(creat)
}
#endif
+SYSCALL_IMPL(dup)
+{
+ abi_long ret = get_errno(dup(arg1));
+ if (ret >= 0) {
+ fd_trans_dup(arg1, ret);
+ }
+ return ret;
+}
+
+#ifdef TARGET_NR_dup2
+SYSCALL_IMPL(dup2)
+{
+ abi_long ret = get_errno(dup2(arg1, arg2));
+ if (ret >= 0) {
+ fd_trans_dup(arg1, arg2);
+ }
+ return ret;
+}
+#endif
+
+SYSCALL_IMPL(dup3)
+{
+ int ofd = arg1;
+ int nfd = arg2;
+ int host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
+ abi_long ret;
+
+#ifdef CONFIG_DUP3
+ ret = dup3(ofd, nfd, host_flags);
+#else
+ if (host_flags == 0) {
+ if (ofd == nfd) {
+ return -TARGET_EINVAL;
+ }
+ ret = dup2(ofd, nfd);
+ } else {
+ ret = syscall(__NR_dup3, ofd, nfd, host_flags);
+ }
+#endif
+ return get_errno(ret);
+}
+
SYSCALL_IMPL(faccessat)
{
return do_faccessat(arg1, arg2, arg3);
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 7874a48840..29a9d5fce4 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -204,6 +204,9 @@ static type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5, \
* Performing a bogus sysacll is lazier than boilerplating
* the replacement functions here in C.
*/
+#ifndef __NR_dup3
+#define __NR_dup3 -1
+#endif
#ifndef __NR_syncfs
#define __NR_syncfs -1
#endif
@@ -5320,12 +5323,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
void *p;
switch(num) {
- case TARGET_NR_dup:
- ret = get_errno(dup(arg1));
- if (ret >= 0) {
- fd_trans_dup(arg1, ret);
- }
- return ret;
#ifdef TARGET_NR_pipe
case TARGET_NR_pipe:
return do_pipe(cpu_env, arg1, 0, 0);
@@ -5380,30 +5377,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,
ret = get_errno(chroot(p));
unlock_user(p, arg1, 0);
return ret;
-#ifdef TARGET_NR_dup2
- case TARGET_NR_dup2:
- ret = get_errno(dup2(arg1, arg2));
- if (ret >= 0) {
- fd_trans_dup(arg1, arg2);
- }
- return ret;
-#endif
-#if defined(CONFIG_DUP3) && defined(TARGET_NR_dup3)
- case TARGET_NR_dup3:
- {
- int host_flags;
-
- if ((arg3 & ~TARGET_O_CLOEXEC) != 0) {
- return -EINVAL;
- }
- host_flags = target_to_host_bitmask(arg3, fcntl_flags_tbl);
- ret = get_errno(dup3(arg1, arg2, host_flags));
- if (ret >= 0) {
- fd_trans_dup(arg1, arg2);
- }
- return ret;
- }
-#endif
#ifdef TARGET_NR_getpgrp
case TARGET_NR_getpgrp:
return get_errno(getpgrp());
diff --git a/linux-user/strace.list b/linux-user/strace.list
index 678feeeb7b..151b0eb42d 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -91,12 +91,6 @@
#ifdef TARGET_NR_dipc
{ TARGET_NR_dipc, "dipc" , NULL, NULL, NULL },
#endif
-#ifdef TARGET_NR_dup
-{ TARGET_NR_dup, "dup" , NULL, NULL, NULL },
-#endif
-#ifdef TARGET_NR_dup2
-{ TARGET_NR_dup2, "dup2" , NULL, NULL, NULL },
-#endif
#ifdef TARGET_NR_epoll_create
{ TARGET_NR_epoll_create, "epoll_create" , NULL, NULL, NULL },
#endif
--
2.17.2
next prev 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 ` Richard Henderson [this message]
2019-01-18 21:31 ` [Qemu-devel] [PATCH v6 44/49] linux-user: Split out pipe, pipe2 Richard Henderson
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-43-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).