From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1KjU-0002lV-6G for qemu-devel@nongnu.org; Tue, 05 May 2009 09:30:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1KjT-0002kM-HD for qemu-devel@nongnu.org; Tue, 05 May 2009 09:30:51 -0400 Received: from [199.232.76.173] (port=42659 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1KjT-0002k0-C8 for qemu-devel@nongnu.org; Tue, 05 May 2009 09:30:51 -0400 Received: from naru.obs2.net ([84.20.150.76]:56652) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M1KjS-0003Oc-Il for qemu-devel@nongnu.org; Tue, 05 May 2009 09:30:51 -0400 Received: from kos.to (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by narury.org (Postfix) with ESMTP id 26CBC327404B for ; Tue, 5 May 2009 16:30:49 +0300 (EEST) Date: Tue, 5 May 2009 16:30:48 +0300 From: Riku Voipio Message-ID: <20090505133048.GA29646@kos.to> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [Qemu-devel] [PATCH] linux-user: implement pipe2 syscall List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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