From patchwork Wed Aug 21 13:03:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 96229 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20E143865498 for ; Wed, 21 Aug 2024 13:05:15 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by sourceware.org (Postfix) with ESMTPS id 22271385DDCE for ; Wed, 21 Aug 2024 13:04:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22271385DDCE Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 22271385DDCE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2604:1380:4641:c500::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245442; cv=none; b=tXivCvL62QbMmPzsGFRcmR4kyIR973IDVrfA53FLrW6rfhCWKLlS7wdJx1xZQBT0ZS2UrsLPziuodSIovJ4Oz2kX7omorpcIccKEmRcY2rY8NKlFbfUgu48P8q2c18s+2AtVNdSQvvHdU/v5N55ZgrfWKWAbxHOFPekHQvUmw2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245442; c=relaxed/simple; bh=Tq3LBypRxFVFn8sDj6JPYFkmIxN9i12DeVg54phvTYU=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=gpXNIJ5Cnj7Bsz0mlj+DmV6qRmRGvQzM5ge/0BxHWd+vVDJU+v4zFgZJMnv883x14zT9TQGfM54To2UY3iyU+2U833uB72cIjRkYRlaj2yQ72HDi5WWEwMRH1oY255otLW1h1Zelp4CNg+CzQI4jZYpQ9+oiAyf5jsGuyJh9wjo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id BBCFE60FC3; Wed, 21 Aug 2024 13:03:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 6E084C4AF0E; Wed, 21 Aug 2024 13:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724245439; bh=Tq3LBypRxFVFn8sDj6JPYFkmIxN9i12DeVg54phvTYU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gVclh7CuHhbsIBJXLO9Czyyf7ZQO66KIJVHytHtKXrx7Kopn3b0UXOc3Uf9Fyd7T9 6nPQKDTMqXd1dP923xp5LwN1xjSAoY4eGM/cC6a+GTnKOZ5PPP57eaqV74jUlyPtWK k1CwRZ85I40KOb5xtG7rmK4IODglVKihI7Hr4/7W9/06nA+c/4q4z1BEMnfqfZJspd zQn6Vo+vDMTuHA5wEs2qEnAKawShmYuTI3xLrLarMH6Eyb4otYLmODYXq6zZkU9onQ nC6O9vnaI4HroFLX44SRbrzbBkT5WI/Mg9dFRI/x5wjz+LNwiC1mkUYAmiO3xuzlFg ffmuczSy0RRPw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C64AC5321D; Wed, 21 Aug 2024 13:03:59 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 21 Aug 2024 21:03:53 +0800 Subject: [PATCH v3 1/2] Loongarch: adapt for the re-introduction of fstat and newfstatat in 6.11 MIME-Version: 1.0 Message-Id: <20240821-loong-fstat-v3-1-0df9bd4f7ca6@gmail.com> References: <20240821-loong-fstat-v3-0-0df9bd4f7ca6@gmail.com> In-Reply-To: <20240821-loong-fstat-v3-0-0df9bd4f7ca6@gmail.com> To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Joseph Myers , Xi Ruoyao , b4-sent@kernel.org, Miao Wang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2575; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=w0nF466oMcnJ5XJ+d/1ta4U1NbS6zy8ZLg8X1f0LRsY=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBmxeW6qDhTKiMAyC3+fEHtRdCmrFVGSjgliEpbw +Lx9RuYo2GJAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZsXlugAKCRCwMePKe/7Z bmQ7EAC43sjqJpH9HQwlidDUEQ5mc02EYxXBkK8v1bv2iGgZdhTu2ZHWrx/xj24df4PGLpsRDrh 0GvrKOgkvy3bPf51gIUMimtr3iRXjUZxzC1nuPm7EUhT5ujukxmC3sjt64LYrVe5VTh9mQ17C2I tRkLs60HwNNuxbed9YHeV9gysZNbePMM1sYIKZfQnsPuXclZAGqe9CpD+ta4kqq7QfDkhSrnFXK 3UbcF9zfdHmR17HoEMTxt38GYrfu7AZ6xlBs8QFEtsOLljYzOeiIvf0kwXhvD9WmdjoJXYUX6cQ tFSmYc6CUscb7qjJQRFdJJMciPuhUny/838cdeE73eAZ9+u9yz44/rr3bYyeYbQgbld/C+s7vpS pQQyIB4xAvdXjOwzuXVedfofk7WXErOQuSnRv1EJZOY6iWJmyQrjZ8HjEAPQk9UTct3+TtkZUFB DwAq5BnVpX7faGqDgrPrGZ0qXM9fyrqYpI9ril6Jx7/oa7jGqB0hZuQCTAhqq6r5pCu6i2ovvWz 1hmQsGsYHsm827EDeA2xA4TQEmPy0McjXkudEwNOGp04BRrvdCGjmN3TelxgLV9waYeKJj1zNR7 uldeSRNVA9wRHPcWczsU/z8j4R4OnEKT1K8CfT+EPQ0e/UW8gj6Xc/aREs+PX8MoV6IF5BD1j2c 88ZoxhLkjSE7oMg== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: shankerwangmiao@gmail.com Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Miao Wang In Linux 6.11, fstat and newfstatat are added back. We need to include this change in kernel-features.h to avoid producing libraries incompatible with previous linux versions with new headers. The definition of the two syscalls will be removed when the targeted kernel version is below 6.10.6 in loongarch/sysdep.h, since the feature has already been backported to 6.10.6 in the stable tree. Signed-off-by: Miao Wang --- .../unix/sysv/linux/loongarch/kernel-features.h | 27 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/loongarch/sysdep.h | 5 ++++ 2 files changed, 32 insertions(+) diff --git a/sysdeps/unix/sysv/linux/loongarch/kernel-features.h b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h new file mode 100644 index 0000000000..8e2927c501 --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/kernel-features.h @@ -0,0 +1,27 @@ +/* Set flags signalling availability of kernel features based on given + kernel version number. Loongarch version. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include_next + +#define __ASSUME_LOONGARCH_NEWSTAT 1 + +/* No support for fstat or newfstatat before 6.10.6. */ +#if __LINUX_KERNEL_VERSION < 0x060a06 +# undef __ASSUME_LOONGARCH_NEWSTAT +#endif diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h index eb0ba790da..1fdf18197f 100644 --- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h @@ -109,6 +109,11 @@ #undef SYS_ify #define SYS_ify(syscall_name) __NR_##syscall_name +#ifndef __ASSUME_LOONGARCH_NEWSTAT +#undef __NR_fstat +#undef __NR_newfstatat +#endif + #ifndef __ASSEMBLER__ #define VDSO_NAME "LINUX_5.10" From patchwork Wed Aug 21 13:03:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Wang via B4 Relay X-Patchwork-Id: 96228 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D767386F805 for ; Wed, 21 Aug 2024 13:04:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by sourceware.org (Postfix) with ESMTPS id 7BE8E385DDD3 for ; Wed, 21 Aug 2024 13:04:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BE8E385DDD3 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7BE8E385DDD3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=147.75.193.91 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245442; cv=none; b=ZwCxAd5JKieH9GkdUV8Br4GoRNomR3EKzGfurB14aSnQeGjvmrW2j+YCrWuqgWLgrPMdffVVM8qxexPLLCbJ4VQO8MZscvFyKiraW4qReUodCvBQgl3NfKFHTRa07tYRsI4G3wTkIq1mkc1Vbwy9qacL47sGPgIOKfk5v2n2040= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724245442; c=relaxed/simple; bh=btyI8T71EIy09ksYFq62BqeoCCp596OC0kKCaag3RpE=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Dc4Cf1Ek5FWhi21M0cqsu6kuSp1mRZs/QBqNxZKERdbm+dOv59WTIgeZD4e7ZV18zjQExuOtTsnDEzC7oue9yMzS+DttKkYv+SPx5vro2f+kOjBMYIvIw6bnIpaknYMQAcEWGRJ1RNBcJqbYk8FJH8JG34PF4Fxm/CFlspAtyT8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 456C8A404D8; Wed, 21 Aug 2024 13:03:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPS id 86596C4AF11; Wed, 21 Aug 2024 13:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724245439; bh=btyI8T71EIy09ksYFq62BqeoCCp596OC0kKCaag3RpE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=orK9T8GCTliFdZKHAJi/zGusQRR272VB9nq47bP2Elmr9AH3z14BkUUC9THvcwvZR SN720mWJ+RlW+3OaeVttAfZyARQMDEeTL0Yg8ftk7xUegkGF+5mc5VJtnK4KhMysS5 xIiMy9WFUWnTPb4xGCYCAiu21cPIHI1VH/mO742wKN/sVs+1mr5TkF9Wym2PRESnH7 UZRq9BC9NWh8WnETjb0s1mdZ0XygjvQECVqqHRq0LU9vjOr4/uOCbSI66BSrdcy0DK KEfGBg4WcQqWte8AocwaPOGCZE+iVNlpqhyUeZnZAN3QSG4Y2VnDYLjSh8Ng9z3Tmr 7WCjDigfuPw7A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78CAEC52D7C; Wed, 21 Aug 2024 13:03:59 +0000 (UTC) From: Miao Wang via B4 Relay Date: Wed, 21 Aug 2024 21:03:54 +0800 Subject: [PATCH v3 2/2] linux: Add linux statx(fd, NULL, AT_EMPTY_PATH) support MIME-Version: 1.0 Message-Id: <20240821-loong-fstat-v3-2-0df9bd4f7ca6@gmail.com> References: <20240821-loong-fstat-v3-0-0df9bd4f7ca6@gmail.com> In-Reply-To: <20240821-loong-fstat-v3-0-0df9bd4f7ca6@gmail.com> To: libc-alpha@sourceware.org Cc: Adhemerval Zanella , Joseph Myers , Xi Ruoyao , b4-sent@kernel.org, Miao Wang X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=5366; i=shankerwangmiao@gmail.com; h=from:subject:message-id; bh=bxAtOdV2CcsHsYYlt1CZeGdi2yu2ZKIGWtpRN5Dm2bE=; b=owEBbQKS/ZANAwAKAbAx48p7/tluAcsmYgBmxeW6ARcX1QihOA2us2my54AG1BRxD8jmLebnt CvB2phVkU6JAjMEAAEKAB0WIQREqPWPgPJBxluezBOwMePKe/7ZbgUCZsXlugAKCRCwMePKe/7Z bgQgD/4+84CjQofUuuGH0G19E7CTEQ8sbjn6WHjDVhZh18gkAyyJbIh1zsRkbBM2pznYVf93vkO W+T0kVWR6hEhJDAFHDYYRpZzk1QkpR1GXpMf7rbIDln3tTBpGNV9fynF0W7P6OuW1qI69Iy0azl 1C7W7yRwvv1cYJChLenzdMeHlLefk29gffsP/ZG0HozTTRUz3PQyxARX9A4huumk4FaISzhBfCY BNmEVUYpI3IJvTdYItaA8dBobynomNxGr4CKIXqFTOASN63stB5VyuXutFSOtZy43r40CmwhOeL WXXL5Zc9Lk/ms9F0nx85VYyJPyhlBnkHIuRlV/87W8YngMmSloxDSQOkZMmRBKaXnOHun2SJfbu xY6d9o++IY5Ehggf/l91If1cq4SHcLRZo/guj/jYNAVuA6+A5svB0XT4qOW3mEyfIzY9FcntWxA u0bT7vcorL3PtP1nWpZ62ip1OL4OQglBTHXPaRq/bzEHWt2KzgKfNkGHOGCM9aSyjPWqx/umBjr 9Z81T+/145vEr/tm4X8TZmfQW5WZ3Ny86uIrw/Ef0la8hDyOGKvMRD3fRt+NiHRHyEr693Y94Se mpd1SXxmDrUYv03KYHhABtIr9xWR4lkCp/SQrjPxXlxV3f96h6Lx+p4b/okmRmaohDDPz6hq3tZ 0c2mOgRZptzZidw== X-Developer-Key: i=shankerwangmiao@gmail.com; a=openpgp; fpr=6FAEFF06B7D212A774C60BFDFA0D166D6632EF4A X-Endpoint-Received: by B4 Relay for shankerwangmiao@gmail.com/default with auth_id=189 X-Original-From: Miao Wang X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: shankerwangmiao@gmail.com Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org From: Miao Wang Linux supports passing NULL instead of an empty string as the second parameter when AT_EMPTY_PATH is set in the flags, starting from 6.11, which brings a performance gain since it is much more efficient to detect a NULL parameter than to detect an empty string in the kernel. We utilize this feature if statx is used for fstat, when glibc is compiled to target kernel versions afterwards, and dynamically probe the kernel support of it, when targeting previous versions. Signed-off-by: Miao Wang --- sysdeps/unix/sysv/linux/fstatat64.c | 9 +++-- sysdeps/unix/sysv/linux/fxstat64.c | 4 +-- sysdeps/unix/sysv/linux/kernel-features.h | 5 +++ sysdeps/unix/sysv/linux/statx_empty_path.h | 53 ++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index da496177c9..5b5ce7d9b5 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -39,6 +39,7 @@ _Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t), #endif #if FSTATAT_USE_STATX +#include static inline int fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, @@ -47,8 +48,12 @@ fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, /* 32-bit kABI with default 64-bit time_t, e.g. arc, riscv32. Also 64-bit time_t support is done through statx syscall. */ struct statx tmp; - int r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, - STATX_BASIC_STATS, &tmp); + int r; + if ((flag & AT_EMPTY_PATH) && (file == NULL || *file == '\0')) + r = __statx_empty_path (fd, AT_NO_AUTOMOUNT | flag, &tmp); + else + r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, + STATX_BASIC_STATS, &tmp); if (r != 0) return r; diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c index 230374cb22..9ed4530ca8 100644 --- a/sysdeps/unix/sysv/linux/fxstat64.c +++ b/sysdeps/unix/sysv/linux/fxstat64.c @@ -25,6 +25,7 @@ #include #include #include +#include #if LIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33) @@ -53,8 +54,7 @@ ___fxstat64 (int vers, int fd, struct stat64 *buf) # else /* New 32-bit kABIs with only 64-bit time_t support, e.g. arc, riscv32. */ struct statx tmp; - int r = INLINE_SYSCALL_CALL (statx, fd, "", AT_EMPTY_PATH, - STATX_BASIC_STATS, &tmp); + int r = __statx_empty_path (fd, AT_EMPTY_PATH, &tmp); if (r == 0) __cp_stat64_statx (buf, &tmp); return r; diff --git a/sysdeps/unix/sysv/linux/kernel-features.h b/sysdeps/unix/sysv/linux/kernel-features.h index a25cf07e9f..78aaf43a82 100644 --- a/sysdeps/unix/sysv/linux/kernel-features.h +++ b/sysdeps/unix/sysv/linux/kernel-features.h @@ -257,4 +257,9 @@ # define __ASSUME_FCHMODAT2 0 #endif +/* statx(fd, NULL, AT_EMPTY_PATH) was introduced in Linux 6.11. */ +#if __LINUX_KERNEL_VERSION >= 0x060b00 +# define __ASSUME_STATX_NULL_PATH 1 +#endif + #endif /* kernel-features.h */ diff --git a/sysdeps/unix/sysv/linux/statx_empty_path.h b/sysdeps/unix/sysv/linux/statx_empty_path.h new file mode 100644 index 0000000000..7c82311ffc --- /dev/null +++ b/sysdeps/unix/sysv/linux/statx_empty_path.h @@ -0,0 +1,53 @@ +/* Linux statx(fd, NULL, AT_EMPTY_PATH) support + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +#if FSTATAT_USE_STATX || XSTAT_IS_XSTAT64 + +static inline int +__statx_empty_path (int fd, int flag, struct statx *buf) +{ + flag |= AT_EMPTY_PATH; +#ifdef __ASSUME_STATX_NULL_PATH + return INTERNAL_SYSCALL_CALL (statx, fd, NULL, flag, STATX_BASIC_STATS, buf); +#else + static int statx_null_path_supported = -1; + int r; + int supported = atomic_load_relaxed (&statx_null_path_supported); + if (supported != 0) + { + r = INTERNAL_SYSCALL_CALL (statx, fd, NULL, flag, STATX_BASIC_STATS, buf); + if (__glibc_likely(supported == 1)) + return r; + if (r != -EFAULT) + { + if (r == 0) + atomic_store_relaxed (&statx_null_path_supported, 1); + return r; + } + atomic_store_relaxed (&statx_null_path_supported, 0); + } + return INTERNAL_SYSCALL_CALL (statx, fd, "", flag, STATX_BASIC_STATS, buf); +#endif +} + +#endif