From patchwork Wed Jun 8 13:30:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 69653 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2515341qgf; Wed, 8 Jun 2016 07:07:11 -0700 (PDT) X-Received: by 10.55.165.69 with SMTP id o66mr4834603qke.153.1465394413201; Wed, 08 Jun 2016 07:00:13 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id g124si707900qke.278.2016.06.08.07.00.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Jun 2016 07:00:13 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAe1k-0005rC-Kh for patch@linaro.org; Wed, 08 Jun 2016 10:00:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZi-0004Yd-Ds for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAdZg-0005rm-4O for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:13 -0400 Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]:35713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAdZf-0005rJ-OF for qemu-devel@nongnu.org; Wed, 08 Jun 2016 09:31:12 -0400 Received: by mail-lf0-x22e.google.com with SMTP id u74so5857441lff.2 for ; Wed, 08 Jun 2016 06:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EkdId3IEY8+yPSvDQI+Sz17soBnw/JpJM3zO5cunKz0=; b=Iopp3bybm5GppJRtmwVmvmFUCXjyLt8ChftDqqF5Vxi2MZdmZp/KqMd3UYPOL3xoal Q5OthqdPEGWdqW09uHsXYPnzqc4CUCEgHktw5ng7QhiH91hyK71gKnZ4Vd1v3R2rzEvp OHzRTtOfO/cLj1FoX1nlwJuZ4h3MX8ZY3sDQg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EkdId3IEY8+yPSvDQI+Sz17soBnw/JpJM3zO5cunKz0=; b=XGbCiz6TwtU3m3dKPBWE8nFiDsUMt0OhGahPEg+LW2LSxJAWL25MOA3+BA+55u8z6a AAzQIGUZMs6MVsdv9OT1nXUX+kX/WGd0Vvdk35Gb+LUY2ux5/CMhhL7NMBsOtPePiJ7t PBWRgqeUkTAbN+GyIgF/3fsIeXd7bms1XncVM3vWKeoykevlHXkXwOC/TI/ttIpIGkyt +8KNhkQ4lT7duTa4DE1IAZ9EJHhl4CFrPxkyWaYGKPoW3rCXyIjG1qiiKj3k5w9OLt21 s/rKEVPk2Y98mMu/ehHX6eCFtCSHBPHL3Bz9KjFLXo9xe3R6Kuk2ruHpaTPSvUTjVMy7 HzAQ== X-Gm-Message-State: ALyK8tKd7Jdo04w/BRXmclTxVY8s/KFUV4pANBCvgVb+KuFkuFo7selxPNJofXEFibYaUWCw X-Received: by 10.25.207.70 with SMTP id f67mr3726212lfg.62.1465392671008; Wed, 08 Jun 2016 06:31:11 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id 2sm139854lja.37.2016.06.08.06.31.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 08 Jun 2016 06:31:09 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 8 Jun 2016 16:30:17 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22e Subject: [Qemu-devel] [PULL 36/44] 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: Peter Maydell Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Signed-off-by: Riku Voipio --- linux-user/syscall.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index a931919..8bb9adf 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -429,16 +429,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 @@ -706,6 +696,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) @@ -8964,7 +8957,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; @@ -8984,8 +8976,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; @@ -9010,8 +9004,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); @@ -9019,9 +9013,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, if (arg4) { unlock_user(target_set, arg4, 0); } - } else + break; + } +# endif +# 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 - ret = get_errno(poll(pfd, nfds, timeout)); + default: + g_assert_not_reached(); + } if (!is_error(ret)) { for(i = 0; i < nfds; i++) {