From patchwork Sun Jun 10 03:01:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 138167 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp2610690lji; Sat, 9 Jun 2018 21:08:51 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLy7deiMzsR5CxSO0rpK/kSYMR0nAZHZyYk2srWdK2WwR6zqFWoPi+BvsKG43RDuacS5hDH X-Received: by 2002:ac8:1842:: with SMTP id n2-v6mr11601082qtk.124.1528603731641; Sat, 09 Jun 2018 21:08:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528603731; cv=none; d=google.com; s=arc-20160816; b=dhZhbqqTfnqW72AJa2fKHSgw6ewARxnKFMw0c4P/aUwcyboBhGBe24tNBg7yzn4Wdk pqfK9W24VvASk/8W/cfzOzeWO12DFQug5O+2QSIH57g9V02tyXUfIEam+OZHrCYF3qwm jVM3fyLuEe9LK+7edvfAhOafwzS6gP4K0uG7OCLmuHgJxwSyduY+USLfn8MiiylFObbw XJBNvEkKNB95Q0UK8ISnIXjQS3GKjmzQPPPC7j+DiYU2g1GnhT3rEr6rOJyR3MqIf3vT kCysqv7ZOTcF7MT+bNkBtjgfW3Z1/qWIKuzrH/UFR9cLWFqldefhT4g81m8gl4Yf9bX2 j/ww== 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=jJu66j4M4vMFwAAiOgcsW0pzqL3MDUUhI187vdBYAZk=; b=T8NemanCzSSa/Fqd35n9GhcciqnsGV5gkV7SFsfVq9whtXwBgn0qJ00S2jZGDn1rKA x5pzBPZI1kbHl10up25YwSkBgKvzwsOh6X+pii96Q/Qpqcgs6Lzbse2/uYxh9ydoEtiy h4+zXnd2MBgCMHtu9Bmhx+8eMOA5wMtSFJJyL8tNs3M2SmNxmxDZe39QsIlwPkfSySbu vGwQDYXf+qY730+S3UFux0AZsYrSCPXpPv8MOkgB8kUeCzrmxCM+oJ6lRHxUZNaSsSQQ Z7pymZ/Oemw7Wb2PAhN9FLQAIThJv5KQOF3Zl24r5Y+zKtlmZWkzuG54gxq8/4ioFUmt YbPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=aLpQ8Ze9; 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 p67-v6si4590047qkh.201.2018.06.09.21.08.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 09 Jun 2018 21:08:51 -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=aLpQ8Ze9; 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]:42542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRret-0003M4-34 for patch@linaro.org; Sun, 10 Jun 2018 00:08:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRqfU-000489-8o for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRqfR-0004Pj-2g for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:24 -0400 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]:44846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fRqfQ-0004OE-R0 for qemu-devel@nongnu.org; Sat, 09 Jun 2018 23:05:20 -0400 Received: by mail-pg0-x242.google.com with SMTP id p21-v6so8128641pgd.11 for ; Sat, 09 Jun 2018 20:05:20 -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=jJu66j4M4vMFwAAiOgcsW0pzqL3MDUUhI187vdBYAZk=; b=aLpQ8Ze9s58xHR8gKPSx8KG4i0+lHMYx5FXAXJiE28zDguS2TGt+inQIHyUQnrXf8h OgH2/xppAxgFF8ddFdeAnu8ODpCVFwlptBftufKycQIrMTfxsZGmV/t3Zyzn2tkNa+kK mRTnEtDsxX+eLEoKI8710ZJEB4/JjI3UTpV78= 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=jJu66j4M4vMFwAAiOgcsW0pzqL3MDUUhI187vdBYAZk=; b=QQkhNn3LdVJamiQAIIYe1KHC56JnieZm742zPGYuztBBra+0iG9TGdgvzSflkdKmpF ig1dcWMFtDkHmioWTDGWLM2yoGH9BB4KslTCyxyXuAlWusf+T8qMpuIa9SpaQihtMELC qIow2uq+8ISWZCEiqjcL2EbEwqeGNFK3H2ydvQ8+agsKR17sYPucjxICaDHgU1OZ1N5Y xy9HEC4VjMHCdj3LWmgksvNu58iBHA+5qTl/RJ3HrSLrx2piw0NZbv7SBUZN/kyKXeTl CvA/e1Zxqyc48m+z+gd5nX9toVTkb6BH55sduRWI1ImnU9qtW7rZnUiXk+GWlN6DTcPB fIIw== X-Gm-Message-State: APt69E1mHHBZ8Li8NG9rPCopR6cTdpNoEqtHo7uuGcp4Lvd2fCyLLGzn EzcngIGNxfD/7IFk660T/GNJKgt0jTs= X-Received: by 2002:a65:6356:: with SMTP id p22-v6mr10457431pgv.20.1528599919552; Sat, 09 Jun 2018 20:05:19 -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.05.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 09 Jun 2018 20:05:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 9 Jun 2018 17:01:55 -1000 Message-Id: <20180610030220.3777-84-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:c05::242 Subject: [Qemu-devel] [PATCH v2 083/108] linux-user: Split out mincore 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 mincore; remove the ifdef. At the same time, fix two bugs in the implementation: (1) The pages to check need not be readable, only valid. (2) The third argument is an output vector, which (2a) needs to be writable, and (2b) sized properly. Signed-off-by: Richard Henderson --- linux-user/syscall.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index fc7f301519..afe6df5efa 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -9144,6 +9144,31 @@ IMPL(lstat64) } #endif +IMPL(mincore) +{ + void *a, *p; + size_t veclen; + abi_long ret; + + /* Note that this is not the same as VERIFY_WRITE or VERIFY_READ. + * Moreover, we want to test the exact pages of guest memory. + */ + if (page_check_range(arg1, arg2, PAGE_VALID)) { + return -TARGET_ENOMEM; + } + a = g2h(arg1); + + veclen = DIV_ROUND_UP(arg2, TARGET_PAGE_SIZE); + p = lock_user(VERIFY_WRITE, arg3, veclen, 0); + if (!p) { + return -TARGET_EFAULT; + } + + ret = get_errno(mincore(a, arg2, p)); + unlock_user(p, arg3, veclen); + return ret; +} + #ifdef TARGET_NR_mkdir IMPL(mkdir) { @@ -11986,24 +12011,6 @@ static abi_long do_syscall1(void *cpu_env, unsigned num, abi_long arg1, void *p; switch(num) { -#ifdef TARGET_NR_mincore - case TARGET_NR_mincore: - { - void *a = lock_user(VERIFY_READ, arg1, arg2, 0); - if (!a) { - return -TARGET_ENOMEM; - } - p = lock_user_string(arg3); - if (!p) { - ret = -TARGET_EFAULT; - } else { - ret = get_errno(mincore(a, arg2, p)); - unlock_user(p, arg3, ret); - } - unlock_user(a, arg1, 0); - } - return ret; -#endif #ifdef TARGET_NR_arm_fadvise64_64 case TARGET_NR_arm_fadvise64_64: /* arm_fadvise64_64 looks like fadvise64_64 but @@ -13328,6 +13335,7 @@ static impl_fn *syscall_table(unsigned num) #ifdef TARGET_NR_lstat64 SYSCALL(lstat64); #endif + SYSCALL(mincore); #ifdef TARGET_NR_mkdir SYSCALL(mkdir); #endif