From patchwork Fri Jul 29 20:14:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 594367 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1645652maz; Fri, 29 Jul 2022 13:14:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vc8AGh5dmfbR43yNp9r61MoLjqzW++x0/g3S+N9EUMx2I2eVOaOo7/8zy6m8Tk/OSIqjv5 X-Received: by 2002:a05:620a:254f:b0:6a6:313:3ccc with SMTP id s15-20020a05620a254f00b006a603133cccmr4090790qko.716.1659125689068; Fri, 29 Jul 2022 13:14:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659125689; cv=none; d=google.com; s=arc-20160816; b=Gh6wwXBiFFpL0iHQp+fEOo6MNBskwvDGRO7e2GqjpcBsCBuNx5RjhOVfXWkdpaEUM0 mWf30C+mgWQTGVTz8z+Xfd8MG0L+hWqE3XVgAzggpY0k8JYuNB+mn1/a/ePl6zWiGEdI kwFxZ9qcii6PRRb27W2kfYzPnIBNCryYq3hAaFHIqYQll6aUi0vTIvsRcHo/E2HL3JcH N9XFTWdF0npujOvUUiCpVO/qPpWEWHVr1CtKTUJqkzxE24itFHCEgNRVhE8t0eUd5DQL dNcZKhL3NW1ZDuN7Mq9CFc8IX9r86tIFj0Xp9xcsJNZ36OiETu+I6etn3wbbDgvP/elV Sh9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=5FfBgNZsEiZ6EuArh07NVhiDMbZUBp97lGu6eNi5woU=; b=IOmHQSW4FV/nx5rXpyYv+F1xC12vF6kAYveLOESuVNeAUzsOxXHW731IzV1ga77jcT BnMiF8IsHF3U/G19BG+PXbswX3Zeh6RI+Er0K2In1te3u2PgWaxeKbDLvJ5VvEa2H4ZS dscu2TeMDo5KQ/Cvvj53eg7r+sNnAnO453Gd5UcfRnOTeZwcNefKjrA0szVclkI/VbP4 9R1WgUPceFOjUoIQ2haKjlROYovEkLb+dyBfFfu/8MSfVyZ+NAie5G1bIbihPQhjkapI vSjVwHhwO15eyhHOuK+B36UJynpC5XuMNEXT9tjmDR3AGkLPUELzhW4O/DblBDC0350W dF2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=u3TgDmz+; 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=pass (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 t16-20020a05622a149000b0031eb4a685besi2915788qtx.733.2022.07.29.13.14.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 Jul 2022 13:14:49 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=u3TgDmz+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oHWNk-0004GF-Mm for patch@linaro.org; Fri, 29 Jul 2022 16:14:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oHWNI-0004G3-U4 for qemu-devel@nongnu.org; Fri, 29 Jul 2022 16:14:20 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:35518) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oHWNH-00007Q-Bf for qemu-devel@nongnu.org; Fri, 29 Jul 2022 16:14:20 -0400 Received: by mail-pf1-x436.google.com with SMTP id c139so5557305pfc.2 for ; Fri, 29 Jul 2022 13:14:18 -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:mime-version :content-transfer-encoding; bh=5FfBgNZsEiZ6EuArh07NVhiDMbZUBp97lGu6eNi5woU=; b=u3TgDmz+xisgJcxD1cR088e1uS/Ui5qd4Evf6tAKmRrYXGy31FxuKQZhq6McRkqF1Q zcbH3odJtahuCGGEyWAFBiBOAy3FpNPMy37MRJ8zXTplQ7Ax2cnJSbtRN4Wi2jMKeczM vfaxvKIFxrKdH12bA64Ek2pyAxUdwVgw1IDGpHxmpLba6m7B+iczwiSPO08u9Rj9lBg1 P978GQgdpVb+MSpOkxFMWB55KV5e79V7fEduBExY7Xlr0u+hPrpeiI+1tj0XKPmKrySs 0cmwlF4kFIMFt9kaKnMVhb1ph3MCWLRb9EyAQjYcznLjcY4JhDFOlWwtwSrLlNWZZml1 y3+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5FfBgNZsEiZ6EuArh07NVhiDMbZUBp97lGu6eNi5woU=; b=n4lelmCSgnkoNy3OSkcOoP/eAJj029LRLWZmgYlOESjoECU8PSpw2aB6dT9yHp1P4z X3MirtGT0SaR1EIwo5NC2W4L14n3PtO03vDcOcLXvfh7upFLByB5Ub1QYnFR5itk2S4Q CMQ0X2A3J71Ve1gQnUKXgsAFaGSh7pry772k6QmK+TYV0O6iRjI0ownn8OIWUbYgOZfv RzPpXuNf/12fUpJmln8+wEnG7I3XfqB7Q7WdcY3Ad2afjEFOMunCQWLn7woe3F1JbgEr E6HAyZQpOJXtwJJ3D76XCTqMisLAqGwXXJtsOXTtiNqCtclRGsSq8xDzeRr0O1be+IAI U6BA== X-Gm-Message-State: AJIora9nl+yk6ZO5RAwxevsUOkRXMCmrc3fMeNZZdvfBckcIF5MpdlKB 0SHL/JgW07OxDxZ9+QrGchYLkdytJsutDA== X-Received: by 2002:a63:1f58:0:b0:41a:27e8:d669 with SMTP id q24-20020a631f58000000b0041a27e8d669mr4280555pgm.74.1659125657326; Fri, 29 Jul 2022 13:14:17 -0700 (PDT) Received: from stoup.. ([2602:ae:1549:801:a427:660:88d4:8559]) by smtp.gmail.com with ESMTPSA id d65-20020a621d44000000b00517c84fd24asm3367153pfd.172.2022.07.29.13.14.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 13:14:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu Subject: [PATCH] linux-user: Implement faccessat2 Date: Fri, 29 Jul 2022 13:14:14 -0700 Message-Id: <20220729201414.29869-1-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Split out do_faccessat2 helper, and use it for accessat and faccessat as well. Signed-off-by: Richard Henderson --- Will we ever have a system libc for which __NR_faccessat2 is present, but faccessat() does not try faccessat2 first? r~ --- linux-user/syscall.c | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index b27a6552aa..acd8452048 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -8530,6 +8530,30 @@ static int do_getdents64(abi_long dirfd, abi_long arg2, abi_long count) _syscall2(int, pivot_root, const char *, new_root, const char *, put_old) #endif +static int do_faccessat2(int dirfd, abi_ptr pathname, int mode, int flags) +{ + char *p = lock_user_string(pathname); + bool nosys = true; + int ret; + + if (!p) { + return -TARGET_EFAULT; + } + + /* Use the raw host syscall if possible, in case we have an old libc. */ +#ifdef __NR_faccessat2 + ret = syscall(__NR_faccessat2, dirfd, p, mode, flags); + nosys = ret < 0 && errno == ENOSYS; +#endif + /* If we don't have the syscall, defer to libc emulation. */ + if (nosys) { + ret = faccessat(dirfd, p, mode, flags); + } + + unlock_user(p, pathname, 0); + return get_errno(ret); +} + /* This is an internal helper for do_syscall so that it is easier * to have a single return point, so that actions, such as logging * of syscall results, can be performed. @@ -9058,21 +9082,15 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, #endif #ifdef TARGET_NR_access case TARGET_NR_access: - if (!(p = lock_user_string(arg1))) { - return -TARGET_EFAULT; - } - ret = get_errno(access(path(p), arg2)); - unlock_user(p, arg1, 0); - return ret; + return do_faccessat2(AT_FDCWD, arg1, arg2, 0); #endif -#if defined(TARGET_NR_faccessat) && defined(__NR_faccessat) +#ifdef TARGET_NR_faccessat case TARGET_NR_faccessat: - if (!(p = lock_user_string(arg2))) { - return -TARGET_EFAULT; - } - ret = get_errno(faccessat(arg1, p, arg3, 0)); - unlock_user(p, arg2, 0); - return ret; + return do_faccessat2(arg1, arg2, arg3, 0); +#endif +#ifdef TARGET_NR_faccessat2 + case TARGET_NR_faccessat2: + return do_faccessat2(arg1, arg2, arg3, arg4); #endif #ifdef TARGET_NR_nice /* not on alpha */ case TARGET_NR_nice: