From patchwork Fri Jan 18 21:30:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 156079 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3744231jaa; Fri, 18 Jan 2019 13:56:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN4CZoSElr9kRxHLPlSRAeUYY/ZMkKmiYWe+FsyLGUEP+KzaCiJ8Si798YinQ/ZPhr1HhR1J X-Received: by 2002:adf:ee89:: with SMTP id b9mr18992209wro.246.1547848618609; Fri, 18 Jan 2019 13:56:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547848618; cv=none; d=google.com; s=arc-20160816; b=jMVNUxrlG8+SxyZjhCtCjJFAgnfn1Jp1Caaj+DV2VOA1vVEBnBB3H1Du+lwmucfXWE Q5BaAwhJ6lyRVPsdd1EljlusMb86KIaNoAlCtpjoF8Loj1NRs1+7a/WShUp/CF+dhqT+ hnQoSFYUZzhTG8lEK8yREp5b9q+G4ADF7FK4CJrbamBCgPrJ+ZbzjbEfS2JA2D/rl/F1 vh9MoDV5A8/jcPPMf1dYi575UieOsOQpyNz7RPxkY3EKAyJLnmfmYO1g5wxN4ehy2OGm m3GDcfru4aUE7Cqcuxcl7D3O338KIdpv6s++FD9grXGFSrqrjKK5bgFobvoieeP6Qd/3 qCOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=abx648KpDmxzA5gUxo/+UEW+pYX645WiVIJP5iJ8QA0=; b=IebwtFwbygF2aaf+d56UfjSyDb+r9E1L8HUA9GOVTqNwIRjuzrZET109xA3o/xNT3q Jh8l10HEttmdo9v10wxbohxUe8/2APlizLuOXCyLsQ6QXNR5y2Hgjvs5wOd2KSRjUdjc Si8MxmZKnae1Gfe7Tl1pkp+CiaXBxYc6sSdNjN1/PAAkwzJq37ZJpIlilu8QcjDkLceJ RAtJRsYAw9CgBtEVVjJ4+JKtWyXNfDm+Krv7LnzGI3Qb3XIEfx8UPrGe9D5vMyLaVjyD 9pkecuGIqqq1L3t9WjukWCL5XdnaHgL71tUHa1ga87J5/fLgQop3j7n9cy66ekgDm/5s db4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C4yqZTPS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n25si65593524wra.167.2019.01.18.13.56.58 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 18 Jan 2019 13:56:58 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=C4yqZTPS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:47748 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkc8H-0008WL-EG for patch@linaro.org; Fri, 18 Jan 2019 16:56:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkbkZ-0005HS-Ro for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkbkQ-0004hk-MZ for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:21 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:47056) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gkbkM-0004dE-Tp for qemu-devel@nongnu.org; Fri, 18 Jan 2019 16:32:16 -0500 Received: by mail-pl1-x644.google.com with SMTP id t13so6870391ply.13 for ; Fri, 18 Jan 2019 13:32:14 -0800 (PST) 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=abx648KpDmxzA5gUxo/+UEW+pYX645WiVIJP5iJ8QA0=; b=C4yqZTPS2p6XczItYJ5UVAoBJ2LmFhLjSqpT8Go16Ild3R+0nhWNjCAXmSghJUKFq0 gU+XDTeBLgazW01D0ZS/uLa8zPP7bqKbruA0VO4O+dqT5/XFvaoirncDTTdNrIjfG293 jUfUtHYxQzJ8fn4MHFZP41jLnAXlCoZFGUWcg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=abx648KpDmxzA5gUxo/+UEW+pYX645WiVIJP5iJ8QA0=; b=F3BRnLD5ZouURglDfPP7u9zYcS4/Kk7Q+ncVc2wR4QJhDIZiyuhOwV4sOttaZjmzLQ /gvPyINDCrKJ8JgZhxye5geZquqYYTYyhMM7QnWvZTijP377awgVV9tbx2mTVeBOLNLZ YozUXgkxMdji11lwX8weFsIokzh46hus7Wzz2aQVHrjh0hEc+hj6vSQCsmtMKOpIox4X 8ADxDEbb4jX2fZUkymZFYcax130GOAnk8rJgDbp9WklJoTsL0iQtSIOyvydgHgxSLjGG KjDNIsCT9CByKt26wp24fF6sP/0jMQIap5KLq5tmWjbnUxBSkIL8yuaoSUkqPs8td3HW wS6w== X-Gm-Message-State: AJcUukfIWQ3dMNiJdl0jUF/lLj0H3bvIywglag9wR1Bhym5aEhF/cZVM rGfIZhVrgcf0rD4XV6WLgTh4LSqQDCY= X-Received: by 2002:a17:902:d911:: with SMTP id c17mr21298461plz.151.1547847132327; Fri, 18 Jan 2019 13:32:12 -0800 (PST) Received: from cloudburst.twiddle.net ([2001:8000:10e0:a000:c673:a6b6:fdef:1933]) by smtp.gmail.com with ESMTPSA id v12sm5833667pgg.41.2019.01.18.13.32.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 13:32:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 19 Jan 2019 08:30:52 +1100 Message-Id: <20190118213122.22865-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20190118213122.22865-1-richard.henderson@linaro.org> References: <20190118213122.22865-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v6 19/49] linux-user: Split out wait4, waitid, waitpid 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: laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Note that waitid is universally provided and need not be conditional. Signed-off-by: Richard Henderson --- linux-user/syscall-defs.h | 5 ++ linux-user/syscall-proc.inc.c | 88 +++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 67 -------------------------- linux-user/strace.list | 9 ---- 4 files changed, 93 insertions(+), 76 deletions(-) -- 2.17.2 diff --git a/linux-user/syscall-defs.h b/linux-user/syscall-defs.h index 6f6f77927b..a84050a318 100644 --- a/linux-user/syscall-defs.h +++ b/linux-user/syscall-defs.h @@ -118,5 +118,10 @@ SYSCALL_DEF(shmget, ARG_DEC, ARG_DEC, ARG_HEX); /* Emulate vfork() with fork(). */ SYSCALL_DEF_FULL(vfork, .impl = impl_fork); #endif +SYSCALL_DEF(wait4, ARG_DEC, ARG_PTR, ARG_HEX, ARG_PTR); +SYSCALL_DEF(waitid, ARG_HEX, ARG_DEC, ARG_PTR, ARG_HEX); +#ifdef TARGET_NR_waitpid +SYSCALL_DEF(waitpid, ARG_DEC, ARG_PTR, ARG_HEX); +#endif SYSCALL_DEF(write, ARG_DEC, ARG_PTR, ARG_DEC); SYSCALL_DEF(writev, ARG_DEC, ARG_PTR, ARG_DEC); diff --git a/linux-user/syscall-proc.inc.c b/linux-user/syscall-proc.inc.c index b89ac56552..37f5bbe197 100644 --- a/linux-user/syscall-proc.inc.c +++ b/linux-user/syscall-proc.inc.c @@ -318,3 +318,91 @@ SYSCALL_IMPL(fork) return do_clone(cpu_env, TARGET_SIGCHLD, 0, 0, 0, 0); } #endif + +/* + * Map host to target signal numbers for the wait family of syscalls. + * Assume all other status bits are the same. + */ +int host_to_target_waitstatus(int status) +{ + if (WIFSIGNALED(status)) { + return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); + } + if (WIFSTOPPED(status)) { + return (host_to_target_signal(WSTOPSIG(status)) << 8) + | (status & 0xff); + } + return status; +} + +SYSCALL_IMPL(wait4) +{ + int status; + pid_t pid = arg1; + abi_ulong status_ptr = arg2; + int options = arg3; + abi_ulong target_rusage = arg4; + struct rusage rusage; + struct rusage *rusage_ptr = target_rusage ? &rusage : NULL; + abi_long ret; + + ret = get_errno(safe_wait4(pid, &status, options, rusage_ptr)); + if (!is_error(ret)) { + if (status_ptr && ret) { + status = host_to_target_waitstatus(status); + if (put_user_s32(status, status_ptr)) { + return -TARGET_EFAULT; + } + } + if (target_rusage) { + abi_long err = host_to_target_rusage(target_rusage, &rusage); + if (err) { + ret = err; + } + } + } + return ret; +} + +SYSCALL_IMPL(waitid) +{ + idtype_t idtype = arg1; + id_t id = arg2; + abi_ulong target_info = arg3; + int options = arg4; + siginfo_t info, *info_ptr = target_info ? &info : NULL; + abi_long ret; + + info.si_pid = 0; + ret = get_errno(safe_waitid(idtype, id, info_ptr, options, NULL)); + if (!is_error(ret) && target_info && info.si_pid != 0) { + target_siginfo_t *p = lock_user(VERIFY_WRITE, target_info, + sizeof(target_siginfo_t), 0); + if (!p) { + return -TARGET_EFAULT; + } + host_to_target_siginfo(p, &info); + unlock_user(p, target_info, sizeof(target_siginfo_t)); + } + return ret; +} + +#ifdef TARGET_NR_waitpid +SYSCALL_IMPL(waitpid) +{ + pid_t pid = arg1; + abi_ulong target_status = arg2; + int options = arg3; + int status; + abi_long ret; + + ret = get_errno(safe_wait4(pid, &status, options, NULL)); + if (!is_error(ret) + && target_status + && ret + && put_user_s32(host_to_target_waitstatus(status), target_status)) { + return -TARGET_EFAULT; + } + return ret; +} +#endif diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 1d18d28fbe..8da92dd188 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5218,20 +5218,6 @@ static abi_long do_signalfd4(int fd, abi_long mask, int flags) } #endif -/* Map host to target signal numbers for the wait family of syscalls. - Assume all other status bits are the same. */ -int host_to_target_waitstatus(int status) -{ - if (WIFSIGNALED(status)) { - return host_to_target_signal(WTERMSIG(status)) | (status & ~0x7f); - } - if (WIFSTOPPED(status)) { - return (host_to_target_signal(WSTOPSIG(status)) << 8) - | (status & 0xff); - } - return status; -} - #define TIMER_MAGIC 0x0caf0000 #define TIMER_MAGIC_MASK 0xffff0000 @@ -5344,32 +5330,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_waitpid - case TARGET_NR_waitpid: - { - int status; - ret = get_errno(safe_wait4(arg1, &status, arg3, 0)); - if (!is_error(ret) && arg2 && ret - && put_user_s32(host_to_target_waitstatus(status), arg2)) - return -TARGET_EFAULT; - } - return ret; -#endif -#ifdef TARGET_NR_waitid - case TARGET_NR_waitid: - { - siginfo_t info; - info.si_pid = 0; - ret = get_errno(safe_waitid(arg1, arg2, &info, arg4, NULL)); - if (!is_error(ret) && arg3 && info.si_pid != 0) { - if (!(p = lock_user(VERIFY_WRITE, arg3, sizeof(target_siginfo_t), 0))) - return -TARGET_EFAULT; - host_to_target_siginfo(p, &info); - unlock_user(p, arg3, sizeof(target_siginfo_t)); - } - } - return ret; -#endif #ifdef TARGET_NR_creat /* not on alpha */ case TARGET_NR_creat: if (!(p = lock_user_string(arg1))) @@ -6969,33 +6929,6 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, return do_syscall(cpu_env, arg1 & 0xffff, arg2, arg3, arg4, arg5, arg6, arg7, arg8, 0); #endif - case TARGET_NR_wait4: - { - int status; - abi_long status_ptr = arg2; - struct rusage rusage, *rusage_ptr; - abi_ulong target_rusage = arg4; - abi_long rusage_err; - if (target_rusage) - rusage_ptr = &rusage; - else - rusage_ptr = NULL; - ret = get_errno(safe_wait4(arg1, &status, arg3, rusage_ptr)); - if (!is_error(ret)) { - if (status_ptr && ret) { - status = host_to_target_waitstatus(status); - if (put_user_s32(status, status_ptr)) - return -TARGET_EFAULT; - } - if (target_rusage) { - rusage_err = host_to_target_rusage(target_rusage, &rusage); - if (rusage_err) { - ret = rusage_err; - } - } - } - } - return ret; #ifdef TARGET_NR_swapoff case TARGET_NR_swapoff: if (!(p = lock_user_string(arg1))) diff --git a/linux-user/strace.list b/linux-user/strace.list index 0d978ea580..afa1521e2d 100644 --- a/linux-user/strace.list +++ b/linux-user/strace.list @@ -1494,15 +1494,6 @@ #ifdef TARGET_NR_vserver { TARGET_NR_vserver, "vserver" , NULL, NULL, NULL }, #endif -#ifdef TARGET_NR_wait4 -{ TARGET_NR_wait4, "wait4" , NULL, NULL, NULL }, -#endif -#ifdef TARGET_NR_waitid -{ TARGET_NR_waitid, "waitid" , "%s(%#x,%d,%p,%#x)", NULL, NULL }, -#endif -#ifdef TARGET_NR_waitpid -{ TARGET_NR_waitpid, "waitpid" , "%s(%d,%p,%#x)", NULL, NULL }, -#endif #ifdef TARGET_NR_utimensat { TARGET_NR_utimensat, "utimensat", NULL, print_utimensat, NULL }, #endif