From patchwork Mon Jun 6 18:58:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 9159019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6507E60573 for ; Mon, 6 Jun 2016 18:59:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54EFE28352 for ; Mon, 6 Jun 2016 18:59:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 499F02835A; Mon, 6 Jun 2016 18:59:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA6FE28352 for ; Mon, 6 Jun 2016 18:59:03 +0000 (UTC) Received: from localhost ([::1]:44575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjq-0000CP-PO for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 14:59:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjI-00008W-JN for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9zjG-0003mq-Cs for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:27 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:57545) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9zjG-0003md-4l for qemu-devel@nongnu.org; Mon, 06 Jun 2016 14:58:26 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1b9zjF-0008R3-FB; Mon, 06 Jun 2016 19:58:25 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 19:58:10 +0100 Message-Id: <1465239499-5048-10-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> References: <1465239499-5048-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH 09/18] linux-user: Use safe_syscall wrapper for poll and ppoll syscalls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , Laurent Vivier , patches@linaro.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the safe_syscall wrapper for the poll and ppoll syscalls. Since not all host architectures will have a poll syscall, we have to rewrite the TARGET_NR_poll handling to use ppoll instead (we can assume everywhere has ppoll by now). We take the opportunity to switch to the code structure already used in the implementation of epoll_wait and epoll_pwait, which uses a switch() to avoid interleaving #if and if (), and to stop using a variable with a leading '_' which is in the implementation's namespace. Signed-off-by: Peter Maydell --- linux-user/syscall.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index c87665a..f1cf809 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -416,16 +416,6 @@ static int sys_inotify_init1(int flags) #undef TARGET_NR_inotify_rm_watch #endif /* CONFIG_INOTIFY */ -#if defined(TARGET_NR_ppoll) -#ifndef __NR_ppoll -# define __NR_ppoll -1 -#endif -#define __NR_sys_ppoll __NR_ppoll -_syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, - struct timespec *, timeout, const sigset_t *, sigmask, - size_t, sigsetsize) -#endif - #if defined(TARGET_NR_prlimit64) #ifndef __NR_prlimit64 # define __NR_prlimit64 -1 @@ -693,6 +683,9 @@ safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ safe_syscall3(int, execve, const char *, filename, char **, argv, char **, envp) safe_syscall6(int, pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, \ fd_set *, exceptfds, struct timespec *, timeout, void *, sig) +safe_syscall5(int, ppoll, struct pollfd *, ufds, unsigned int, nfds, + struct timespec *, tsp, const sigset_t *, sigmask, + size_t, sigsetsize) safe_syscall6(int,futex,int *,uaddr,int,op,int,val, \ const struct timespec *,timeout,int *,uaddr2,int,val3) safe_syscall2(int, rt_sigsuspend, sigset_t *, newset, size_t, sigsetsize) @@ -8323,7 +8316,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, { struct target_pollfd *target_pfd; unsigned int nfds = arg2; - int timeout = arg3; struct pollfd *pfd; unsigned int i; @@ -8343,8 +8335,10 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, } } + switch (num) { # ifdef TARGET_NR_ppoll - if (num == TARGET_NR_ppoll) { + case TARGET_NR_ppoll: + { struct timespec _timeout_ts, *timeout_ts = &_timeout_ts; target_sigset_t *target_set; sigset_t _set, *set = &_set; @@ -8369,8 +8363,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, set = NULL; } - ret = get_errno(sys_ppoll(pfd, nfds, timeout_ts, - set, SIGSET_T_SIZE)); + ret = get_errno(safe_ppoll(pfd, nfds, timeout_ts, + set, SIGSET_T_SIZE)); if (!is_error(ret) && arg3) { host_to_target_timespec(arg3, timeout_ts); @@ -8378,9 +8372,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (arg4) { unlock_user(target_set, arg4, 0); } - } else + break; + } # endif - ret = get_errno(poll(pfd, nfds, timeout)); +# ifdef TARGET_NR_poll + case TARGET_NR_poll: + { + struct timespec ts, *pts; + + if (arg3 >= 0) { + /* Convert ms to secs, ns */ + ts.tv_sec = arg3 / 1000; + ts.tv_nsec = (arg3 % 1000) * 1000000LL; + pts = &ts; + } else { + /* -ve poll() timeout means "infinite" */ + pts = NULL; + } + ret = get_errno(safe_ppoll(pfd, nfds, pts, NULL, 0)); + break; + } +# endif + default: + g_assert_not_reached(); + } if (!is_error(ret)) { for(i = 0; i < nfds; i++) {