From patchwork Wed May 25 10:31:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 68574 Delivered-To: patch@linaro.org Received: by 10.140.92.199 with SMTP id b65csp1146117qge; Wed, 25 May 2016 04:09:15 -0700 (PDT) X-Received: by 10.55.217.89 with SMTP id u86mr2752737qki.167.1464174555563; Wed, 25 May 2016 04:09:15 -0700 (PDT) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 4si2520642qke.244.2016.05.25.04.09.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 25 May 2016 04:09:15 -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]:58977 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Wgd-0000Iq-26 for patch@linaro.org; Wed, 25 May 2016 07:09:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5W7I-0001Nc-Rk for qemu-devel@nongnu.org; Wed, 25 May 2016 06:32:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5W7B-0003L1-UX for qemu-devel@nongnu.org; Wed, 25 May 2016 06:32:44 -0400 Received: from mail-lb0-x231.google.com ([2a00:1450:4010:c04::231]:34550) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5W7B-0003KE-9x for qemu-devel@nongnu.org; Wed, 25 May 2016 06:32:37 -0400 Received: by mail-lb0-x231.google.com with SMTP id sh2so14049904lbb.1 for ; Wed, 25 May 2016 03:32:36 -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=gqWO3bCoVOPgzVAaU2mt3GwgwIyUSZeDWiu4w4jHOU0=; b=DzEXokgnL1HZIXh8IeRneWGNAStuzu2zUqctObhQOq7sy9/6qv0aQhU+MDD5mKf1HG z0QeZPmb3yzz5SJkiB58KukpuoLQCMfp/T5uPsfwPwbF0Y15FqPdhnSAEN1q2HVWY3nw oFImL0DLMQ5KoCHdRE5EPeVTplEXsUoW+XI+Y= 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=gqWO3bCoVOPgzVAaU2mt3GwgwIyUSZeDWiu4w4jHOU0=; b=hZ0hKuMSsySHncYcmwlwV07DrwDtzBUhPhxtqREgHQlbM05EoM6rpfPMcvgEcjBgKL BaSSHy+vJg+UAIAJse4DOJ2N24F1ncqcAexAvNpLi+CeRH74vh7+XnUN3hcCguJQmDCz aUZtMG4KS3Yr+r/osA9S8Fcgudo72F0Cf4BNyYS2FnU6hGH81W074Q8T2W4qDR+auEiQ s9fJIHlQejwqGqJ79BcjDuEw0uW9S86bwZpBvF0cDq6w2MVtSFpmH6gY0J67XCmilKil l72etyFCmgTCrUyJN+cZObTjfyWB+45AQcAh/HqhQwP4I0aH0O9S/Y6Mjwu3IzwFLxwq qyMA== X-Gm-Message-State: ALyK8tKuHMgx9fY7tcwMXGtTeaXsTRJis1UBY4yIMl/C93q4AdS8jEPmgVAa0nAwlO9iXZCC X-Received: by 10.112.154.5 with SMTP id vk5mr968726lbb.126.1464172356058; Wed, 25 May 2016 03:32:36 -0700 (PDT) Received: from beaming.home (91-157-168-132.elisa-laajakaista.fi. [91.157.168.132]) by smtp.gmail.com with ESMTPSA id o75sm1379610lfi.9.2016.05.25.03.32.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 May 2016 03:32:35 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 25 May 2016 13:31:59 +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:c04::231 Subject: [Qemu-devel] [PULL 27/38] linux-user: Use safe_syscall for pselect, select 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 pselect and select syscalls. Since not every architecture has the select syscall, we now have to implement select in terms of pselect, which means doing timeval<->timespec conversion. (Five years on from the initial patch that added pselect support to QEMU and a decade after pselect6 went into the kernel, it seems safe to not try to support hosts with header files which don't define __NR_pselect6.) Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) -- 2.1.4 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index dea827f..c9c2ae9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -430,15 +430,6 @@ _syscall5(int, sys_ppoll, struct pollfd *, fds, nfds_t, nfds, size_t, sigsetsize) #endif -#if defined(TARGET_NR_pselect6) -#ifndef __NR_pselect6 -# define __NR_pselect6 -1 -#endif -#define __NR_sys_pselect6 __NR_pselect6 -_syscall6(int, sys_pselect6, int, nfds, fd_set *, readfds, fd_set *, writefds, - fd_set *, exceptfds, struct timespec *, timeout, void *, sig); -#endif - #if defined(TARGET_NR_prlimit64) #ifndef __NR_prlimit64 # define __NR_prlimit64 -1 @@ -704,6 +695,8 @@ safe_syscall4(pid_t, wait4, pid_t, pid, int *, status, int, options, \ safe_syscall5(int, waitid, idtype_t, idtype, id_t, id, siginfo_t *, infop, \ int, options, struct rusage *, rusage) 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) static inline int host_to_target_sock_type(int host_type) { @@ -1115,7 +1108,8 @@ static abi_long do_select(int n, { fd_set rfds, wfds, efds; fd_set *rfds_ptr, *wfds_ptr, *efds_ptr; - struct timeval tv, *tv_ptr; + struct timeval tv; + struct timespec ts, *ts_ptr; abi_long ret; ret = copy_from_user_fdset_ptr(&rfds, &rfds_ptr, rfd_addr, n); @@ -1134,12 +1128,15 @@ static abi_long do_select(int n, if (target_tv_addr) { if (copy_from_user_timeval(&tv, target_tv_addr)) return -TARGET_EFAULT; - tv_ptr = &tv; + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + ts_ptr = &ts; } else { - tv_ptr = NULL; + ts_ptr = NULL; } - ret = get_errno(select(n, rfds_ptr, wfds_ptr, efds_ptr, tv_ptr)); + ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, + ts_ptr, NULL)); if (!is_error(ret)) { if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n)) @@ -1149,8 +1146,13 @@ static abi_long do_select(int n, if (efd_addr && copy_to_user_fdset(efd_addr, &efds, n)) return -TARGET_EFAULT; - if (target_tv_addr && copy_to_user_timeval(target_tv_addr, &tv)) - return -TARGET_EFAULT; + if (target_tv_addr) { + tv.tv_sec = ts.tv_sec; + tv.tv_usec = ts.tv_nsec / 1000; + if (copy_to_user_timeval(target_tv_addr, &tv)) { + return -TARGET_EFAULT; + } + } } return ret; @@ -7206,8 +7208,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, sig_ptr = NULL; } - ret = get_errno(sys_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, - ts_ptr, sig_ptr)); + ret = get_errno(safe_pselect6(n, rfds_ptr, wfds_ptr, efds_ptr, + ts_ptr, sig_ptr)); if (!is_error(ret)) { if (rfd_addr && copy_to_user_fdset(rfd_addr, &rfds, n))