[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3]
From: |
riku . voipio |
Subject: |
[Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3] |
Date: |
Fri, 12 Jun 2009 16:50:26 +0300 |
From: Riku Voipio <address@hidden>
implement pipe2 syscall.
[v2] fix do_pipe on mips and sh4
[v3] use pipe2 to ensure atomicity, but only when it is available.
Signed-off-by: Riku Voipio <address@hidden>
---
configure | 21 +++++++++++++++++++
linux-user/syscall.c | 55 +++++++++++++++++++++++++++++++++----------------
2 files changed, 58 insertions(+), 18 deletions(-)
diff --git a/configure b/configure
index ecea67c..4187eb2 100755
--- a/configure
+++ b/configure
@@ -1300,6 +1300,24 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
utimens=yes
fi
+# check if pipe2 is there
+pipe2=no
+cat > $TMPC << EOF
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <fcntl.h>
+
+int main(void)
+{
+ int pipefd[2];
+ pipe2(pipefd, O_CLOEXEC);
+ return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+ pipe2=yes
+fi
+
# Check if tools are available to build documentation.
if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o !
-x "`which pod2man 2>/dev/null`" \) ; then
build_docs="no"
@@ -1701,6 +1719,9 @@ fi
if test "$utimens" = "yes" ; then
echo "#define CONFIG_UTIMENSAT 1" >> $config_h
fi
+if test "$pipe2" = "yes" ; then
+ echo "#define CONFIG_PIPE2 1" >> $config_h
+fi
if test "$inotify" = "yes" ; then
echo "#define CONFIG_INOTIFY 1" >> $config_h
fi
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 3fc6cbc..36eb9f5 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -944,6 +944,37 @@ static abi_long do_select(int n,
return ret;
}
+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, int pipedes, int flags)
+{
+ 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);
+#if defined(TARGET_MIPS)
+ ((CPUMIPSState*)cpu_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
+ return get_errno(ret);
+}
+
static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
abi_ulong target_addr,
socklen_t len)
@@ -4529,25 +4560,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(cpu_env, arg1, 0);
+ break;
+#ifdef TARGET_NR_pipe2
+ case TARGET_NR_pipe2:
+ ret = do_pipe(cpu_env, arg1, arg2);
break;
+#endif
case TARGET_NR_times:
{
struct target_tms *tmsp;
--
1.6.2.1
- Re: [Qemu-devel] [PATCH 04/21] linux-user: added x86 and x86_64 support for ELF coredump, (continued)
- [Qemu-devel] [PATCH 19/21] linux-user: initialize mmap_mutex properly, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 13/21] linux-user: support private futexes, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 14/21] add futex wake op, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 07/21] linux-user: fix utimensat, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 15/21] linux-user: update syscall list, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 02/21] Implement shm* syscalls and fix 64/32bit errors, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 10/21] linux-user: Added IP_ADD_MEMBERSHIP/IP_DROP_MEMBERSHIP flags to setsockopt, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 12/21] linux-user: include linux/fs.h, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 20/21] linux-user/syscall.c: define _ATFILE_SOURCE, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 16/21] linux-user: implement pipe2 [v3],
riku . voipio <=
- [Qemu-devel] [PATCH 17/21] linux-user: add tee, splice and vmsplice, riku . voipio, 2009/06/12
- [Qemu-devel] [PATCH 08/21] Fix struct termios host - target translation, riku . voipio, 2009/06/12