From: Riku Voipio <riku.voipio@iki.fi>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] linux-user: implement pipe2 syscall
Date: Tue, 5 May 2009 16:30:48 +0300 [thread overview]
Message-ID: <20090505133048.GA29646@kos.to> (raw)
implement pipe2 syscall. instead of calling pipe2 directly
(which was introduced in 2.6.27), emulate the flag functionality
with fcntl.
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
---
linux-user/syscall.c | 71 +++++++++++++++++++++++++++++++++++++------------
1 files changed, 53 insertions(+), 18 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1096bb1..12ae5dc 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -943,6 +943,53 @@ static abi_long do_select(int n,
return ret;
}
+static abi_long pipe_set_flag(int fd, int readcmd, int writecmd, long newflag)
+{
+ int flags = fcntl(fd, readcmd);
+ if (flags<0)
+ return get_errno(flags);
+ flags |= newflag;
+ flags = fcntl(fd, writecmd, flags);
+ return get_errno(flags);
+}
+
+static abi_long do_pipe(int pipedes, int flags)
+{
+ int host_pipe[2];
+ abi_long ret;
+ ret = pipe(host_pipe);
+ if (is_error(ret))
+ return get_errno(ret);
+#if defined(TARGET_MIPS)
+ CPUMIPSState *env = (CPUMIPSState*)cpu_env;
+ env->active_tc.gpr[3] = host_pipe[1];
+ ret = host_pipe[0];
+#elif defined(TARGET_SH4)
+ ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
+ ret = host_pipe[0];
+#else
+ if (put_user_s32(host_pipe[0], pipedes)
+ || put_user_s32(host_pipe[1], pipedes + sizeof(host_pipe[0])))
+ return -TARGET_EFAULT;
+#endif
+ if (flags & O_NONBLOCK) {
+ ret = pipe_set_flag(host_pipe[0], F_GETFL, F_SETFL, O_NONBLOCK);
+ if (is_error(ret))
+ return get_errno(ret);
+ ret = pipe_set_flag(host_pipe[1], F_GETFL, F_SETFL, O_NONBLOCK);
+ if (is_error(ret))
+ return get_errno(ret);
+ }
+ if (flags & O_CLOEXEC) {
+ ret = pipe_set_flag(host_pipe[0], F_GETFD, F_SETFD, FD_CLOEXEC);
+ if (is_error(ret))
+ return get_errno(ret);
+ ret = pipe_set_flag(host_pipe[1], F_GETFD, F_SETFD, FD_CLOEXEC);
+ if (is_error(ret))
+ return get_errno(ret);
+ }
+ return get_errno(ret);
+}
static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
abi_ulong target_addr,
@@ -4525,25 +4572,13 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
ret = get_errno(dup(arg1));
break;
case TARGET_NR_pipe:
- {
- int host_pipe[2];
- ret = get_errno(pipe(host_pipe));
- if (!is_error(ret)) {
-#if defined(TARGET_MIPS)
- CPUMIPSState *env = (CPUMIPSState*)cpu_env;
- env->active_tc.gpr[3] = host_pipe[1];
- ret = host_pipe[0];
-#elif defined(TARGET_SH4)
- ((CPUSH4State*)cpu_env)->gregs[1] = host_pipe[1];
- ret = host_pipe[0];
-#else
- if (put_user_s32(host_pipe[0], arg1)
- || put_user_s32(host_pipe[1], arg1 + sizeof(host_pipe[0])))
- goto efault;
-#endif
- }
- }
+ ret = do_pipe(arg1, 0);
+ break;
+#ifdef TARGET_NR_pipe2
+ case TARGET_NR_pipe2:
+ ret = do_pipe(arg1, arg2);
break;
+#endif
case TARGET_NR_times:
{
struct target_tms *tmsp;
--
1.6.2.1
next reply other threads:[~2009-05-05 13:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-05 13:30 Riku Voipio [this message]
2009-05-05 20:43 ` [Qemu-devel] [PATCH] linux-user: implement pipe2 syscall [v2] Riku Voipio
2009-05-05 22:58 ` [Qemu-devel] [PATCH] linux-user: implement pipe2 syscall Jamie Lokier
2009-05-06 8:00 ` Riku Voipio
2009-05-06 9:18 ` Martin Mohring
2009-05-06 10:53 ` Jamie Lokier
2009-05-06 11:02 ` Riku Voipio
2009-05-06 11:08 ` Jamie Lokier
2009-05-06 12:02 ` Riku Voipio
2009-05-06 12:23 ` Paul Brook
2009-05-06 14:26 ` Riku Voipio
2009-05-06 12:46 ` Martin Mohring
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=20090505133048.GA29646@kos.to \
--to=riku.voipio@iki.fi \
--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 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.