From patchwork Sun Jun 10 03:01:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138107 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2586570lji; Sat, 9 Jun 2018 20:26:00 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKJggoNqncM6zjlhHQQe3Cb9olz+g+EYgCswKfM+SP5sLXaViDoB7t6F2Gd+jAKOBNMzLT1 X-Received: by 2002:aed:3e6f:: with SMTP id m44-v6mr11839170qtf.4.1528601159923; Sat, 09 Jun 2018 20:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528601159; cv=none; d=google.com; s=arc-20160816; b=S8JQaMkjwpY7iUrhr2c95nAsfNorvwQSb8kfJFpdxQMTpV0LoA+/+152ihC6S7zU0E lTyxkAp8YHBAVQV4J2VPnJsXrzYyQZ4uam+GefFAh6m2PTQzlZo3E/DKY3M+/Zt+LWES IT4n9UIWs/j4QLLZP6fnptcu3lFvW9TphEbF8TDbr50KbpC0upUuYOiO6AFdaLJTTgaD E0QJy3tF8ZQsB6QVkmEHY+7dqUcXYCShmLcfQWnxbCFWfD+NZ7nEDGhwEhFs1QYlCBrh m99BSMofDQo/y82jnc46O/DXh6oGleGEGmUUyBmDfRhOpDDFlvR8KW29q/bRVif4xAQ/ S0QQ== 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:arc-authentication-results; bh=jy7CgZicyeGhKGBp2uV1pJO87lURt3gu4HYMf+LnvLo=; b=d3eK50yoMcEwpao6bgKE7eWV7LBTtk9sA8jb28nGIhRkz/kjxxMAKyYjkNOZvFtt4U LQln8WePJu/zDYXkO9KjScacpMxl5ThDTpO5rEXpgCz2OvHwqAJX0fYvIkniwt0Xoaz4 Ne+bqANuj016Kd9qc1tElZf6GhJqunQB1hV+t0XImGFajfQb2KWN4nRg8j3fpoUDOJhT y1BrqQjSNMb8CiJKC8ali1q14pTLN8s88vIRm+cAJzz1SbbC5PHpD9ThQg5fABYEp4NC 0lRFD4Y6blIcLMfjExet0ukMlBhVw7BkL+EU2uzSBvKgs2396wkfXgHNgLMR/Wgo5bN0 uGVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TKVh/w1Q; 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 sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id v44-v6si4550958qvc.183.2018.06.09.20.25.59 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 20:25:59 -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 header.s=google header.b=TKVh/w1Q; 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 sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqzP-0004fr-9q for patch@linaro.org; Sat, 09 Jun 2018 23:25:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqdz-0002e7-JP for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqdy-0003bQ-CD for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:51 -0400 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:38799) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqdy-0003bD-4R for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:03:50 -0400 Received: by mail-pl0-x242.google.com with SMTP id b14-v6so10400850pls.5 for ; Sat, 09 Jun 2018 20:03:49 -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=jy7CgZicyeGhKGBp2uV1pJO87lURt3gu4HYMf+LnvLo=; b=TKVh/w1Q8tBvFsLCeU6VCmeySOrjQyftsU0D3l4ImJNnMiMy9ZmxLRSXg/sqR+g/Ej yxO+/40v9D0C2y+6uEq3ommq72zfy8qak5I1lX4/1EC27nEejCmtuV7D10Fbv9I1/TMT jUA2m1OGz4GRIXSFF/Fk/QsgwSAdQHU6UhwA4= 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=jy7CgZicyeGhKGBp2uV1pJO87lURt3gu4HYMf+LnvLo=; b=Ow3/QaiJW3snLmO1+8ejNBDDfgZ96we8KK9S4b3UeK1uqhhtLg7PuGUIkVbbXnY37j ODlEcdWVTm9RUBXc27oOhpSOLtsK2PzMCiWKazv1ibDSAf7fhgFeSOGZvKZmVPdRiydq mtCV1Quz8W3tRjuUjwxAK8iwbHI4PYj8c0r4FcQyLCuJjPBz38SGGzQMJLekd0MDnouK wyJdHjVIyE9ubzaQqeHhr4ok+LSsi2mOVmbWp0KVUi24am048KVRuLsj+ktOSM6F29YK w8Js2Iwottbk+z8/6CvcHWB9GFyD841dCPZ2c1OHnOAbC9DkhzCx0bWUeFEJ3rwRrXBN t+vA== X-Gm-Message-State: APt69E2lhhJ3LegXStmtSIsUoPEuOV6LhGeBwQOAFqEV2mvSsCtR82Ov PZRIwmLZ0iIo1oOijH4ARKUu7grfnfk= X-Received: by 2002:a17:902:760e:: with SMTP id k14-v6mr12929490pll.310.1528599828857; Sat, 09 Jun 2018 20:03:48 -0700 (PDT) Received: from cloudburst.twiddle.net (rrcs-173-198-77-219.west.biz.rr.com. [173.198.77.219]) by smtp.gmail.com with ESMTPSA id y17-v6sm31712718pfe.33.2018.06.09.20.03.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:03:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:10 -1000 Message-Id: <20180610030220.3777-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180610030220.3777-1-richard.henderson@linaro.org> References: <20180610030220.3777-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 Subject: [Qemu-devel] [PATCH v2 038/108] linux-user: Split out mmap, mmap2, reboot, swapon 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" All targets define swapon; remove the ifdef. Add a comment noting the incorrect implementation of mmap2. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 142 ++++++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 61 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f1123479df..a3374955da 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8392,6 +8392,49 @@ IMPL(mknodat) return ret; } +#ifdef TARGET_NR_mmap +IMPL(mmap) +{ +# if (defined(TARGET_I386) && defined(TARGET_ABI32)) \ + || (defined(TARGET_ARM) && defined(TARGET_ABI32)) \ + || defined(TARGET_M68K) || defined(TARGET_CRIS) \ + || defined(TARGET_MICROBLAZE) || defined(TARGET_S390X) + abi_ulong orig_arg1 = arg1; + abi_ulong *v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1); + + if (!v) { + return -TARGET_EFAULT; + } + arg1 = tswapal(v[0]); + arg2 = tswapal(v[1]); + arg3 = tswapal(v[2]); + arg4 = tswapal(v[3]); + arg5 = tswapal(v[4]); + arg6 = tswapal(v[5]); + unlock_user(v, orig_arg1, 0); +# endif + return get_errno(target_mmap(arg1, arg2, arg3, + target_to_host_bitmask(arg4, mmap_flags_tbl), + arg5, arg6)); +} +#endif + +#ifdef TARGET_NR_mmap2 +IMPL(mmap2) +{ +#ifndef MMAP_SHIFT +#define MMAP_SHIFT 12 +#endif + /* ??? The argument to target_mmap is abi_ulong. Therefore this + * truncates the true offset for ABI32, which are the only users + * (and only point) of this syscall. + */ + return get_errno(target_mmap(arg1, arg2, arg3, + target_to_host_bitmask(arg4, mmap_flags_tbl), + arg5, arg6 << MMAP_SHIFT)); +} +#endif + IMPL(mount) { char *p1 = NULL, *p2, *p3 = NULL; @@ -8751,6 +8794,23 @@ IMPL(readlinkat) return do_readlinkat(arg1, arg2, arg3, arg4); } +IMPL(reboot) +{ + abi_long ret; + if (arg3 == LINUX_REBOOT_CMD_RESTART2) { + /* arg4 must be ignored in all other cases */ + char *p = lock_user_string(arg4); + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(reboot(arg1, arg2, arg3, p)); + unlock_user(p, arg4, 0); + } else { + ret = get_errno(reboot(arg1, arg2, arg3, NULL)); + } + return ret; +} + #ifdef TARGET_NR_rename IMPL(rename) { @@ -9370,6 +9430,19 @@ IMPL(stime) } #endif +IMPL(swapon) +{ + char *p = lock_user_string(arg1); + abi_long ret; + + if (!p) { + return -TARGET_EFAULT; + } + ret = get_errno(swapon(p, arg2)); + unlock_user(p, arg1, 0); + return ret; +} + #ifdef TARGET_NR_symlink IMPL(symlink) { @@ -9630,67 +9703,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_swapon - case TARGET_NR_swapon: - if (!(p = lock_user_string(arg1))) - return -TARGET_EFAULT; - ret = get_errno(swapon(p, arg2)); - unlock_user(p, arg1, 0); - return ret; -#endif - case TARGET_NR_reboot: - if (arg3 == LINUX_REBOOT_CMD_RESTART2) { - /* arg4 must be ignored in all other cases */ - p = lock_user_string(arg4); - if (!p) { - return -TARGET_EFAULT; - } - ret = get_errno(reboot(arg1, arg2, arg3, p)); - unlock_user(p, arg4, 0); - } else { - ret = get_errno(reboot(arg1, arg2, arg3, NULL)); - } - return ret; -#ifdef TARGET_NR_mmap - case TARGET_NR_mmap: -#if (defined(TARGET_I386) && defined(TARGET_ABI32)) || \ - (defined(TARGET_ARM) && defined(TARGET_ABI32)) || \ - defined(TARGET_M68K) || defined(TARGET_CRIS) || defined(TARGET_MICROBLAZE) \ - || defined(TARGET_S390X) - { - abi_ulong *v; - abi_ulong v1, v2, v3, v4, v5, v6; - if (!(v = lock_user(VERIFY_READ, arg1, 6 * sizeof(abi_ulong), 1))) - return -TARGET_EFAULT; - v1 = tswapal(v[0]); - v2 = tswapal(v[1]); - v3 = tswapal(v[2]); - v4 = tswapal(v[3]); - v5 = tswapal(v[4]); - v6 = tswapal(v[5]); - unlock_user(v, arg1, 0); - ret = get_errno(target_mmap(v1, v2, v3, - target_to_host_bitmask(v4, mmap_flags_tbl), - v5, v6)); - } -#else - ret = get_errno(target_mmap(arg1, arg2, arg3, - target_to_host_bitmask(arg4, mmap_flags_tbl), - arg5, - arg6)); -#endif - return ret; -#endif -#ifdef TARGET_NR_mmap2 - case TARGET_NR_mmap2: -#ifndef MMAP_SHIFT -#define MMAP_SHIFT 12 -#endif - ret = target_mmap(arg1, arg2, arg3, - target_to_host_bitmask(arg4, mmap_flags_tbl), - arg5, arg6 << MMAP_SHIFT); - return get_errno(ret); -#endif case TARGET_NR_munmap: return get_errno(target_munmap(arg1, arg2)); case TARGET_NR_mprotect: @@ -12743,6 +12755,12 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(mknod); #endif SYSCALL(mknodat); +#ifdef TARGET_NR_mmap + SYSCALL(mmap); +#endif +#ifdef TARGET_NR_mmap2 + SYSCALL(mmap2); +#endif SYSCALL(mount); #ifdef CONFIG_OPEN_BY_HANDLE SYSCALL(name_to_handle_at); @@ -12773,6 +12791,7 @@ static impl_fn *syscall_table(unsigned num) SYSCALL(readlink); #endif SYSCALL(readlinkat); + SYSCALL(reboot); #ifdef TARGET_NR_rename SYSCALL(rename); #endif @@ -12827,6 +12846,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_stime SYSCALL(stime); #endif + SYSCALL(swapon); #ifdef TARGET_NR_symlink SYSCALL(symlink); #endif