From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: laurent@vivier.eu
Subject: [PATCH] linux-user: Implement faccessat2
Date: Fri, 29 Jul 2022 13:14:14 -0700 [thread overview]
Message-ID: <20220729201414.29869-1-richard.henderson@linaro.org> (raw)
Split out do_faccessat2 helper, and use it for
accessat and faccessat as well.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
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:
--
2.34.1
next reply other threads:[~2022-07-29 20:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-29 20:14 Richard Henderson [this message]
2022-07-31 15:38 ` [PATCH] linux-user: Implement faccessat2 Richard Henderson
2022-10-09 6:08 WANG Xuerui
2022-10-10 8:53 ` Helge Deller
2022-10-18 9:58 ` Michael Tokarev
2022-10-18 13:05 ` Luca Bonissi
2022-10-21 15:37 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220729201414.29869-1-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).