linux-user: Implement fchmodat2 syscall
PATCH 1/1 linux-user: Implement fchmodat2 syscall
The fchmodat2 syscall is new from Linux 6.6; it is like the existing fchmodat syscall except that it takes a flags parameter.
If we have the host fchmodat2 syscall, we implement it as a direct passthrough call; if we do not, then we can fall back to using the libc fchmodat() function. The fallback can handle the AT_SYMLINK_NOFOLLOW flag but won't be able to do anything about AT_EMPTY_PATH.
---
Tested very lightly (ran an fchmodat2 test from the Linux Test Project test suite).
You could argue that the fallback-to-libc-fchmodat here isn't worth bothering with, I guess.
linux-user/syscall.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
linux-user/syscall.c +20 -0
@@ -790,6 +790,10 @@ safe_syscall6(ssize_t, copy_file_range, int, infd, loff_t *, pinoff, int, outfd, loff_t *, poutoff, size_t, length, unsigned int, flags) #endif +#if defined(TARGET_NR_fchmodat2) && defined(__NR_fchmodat2) +safe_syscall4 (int ,fchmodat2 ,int ,dfd ,const char *,filename , + unsigned short, mode, unsigned int, flags) +#endif /* We do ioctl like this rather than via safe_syscall3 to preserve the * "third argument might be integer or pointer or not present" behaviour of
@@ -10713,6 +10717,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, ret =get_errno (fchmodat (arg1, p, arg3,0 ));unlock_user (p, arg2,0 );return ret; +#endif +#if defined(TARGET_NR_fchmodat2) +case TARGET_NR_fchmodat2: +if (!(p =lock_user_string (arg2))) +return -TARGET_EFAULT ; +#if defined(__NR_fchmodat2) + ret =get_errno (safe_fchmodat2 (arg1, p, arg3, arg4)); +#else +/* +* fall back to using libc function: this will work for +* flag AT_SYMLINK_NOFOLLOW but not AT_EMPTY_PATH. +*/ + ret =get_errno (fchmodat (arg1, p, arg3, arg4)); +#endif +unlock_user (p, arg2,0 ); +return ret;#endif case TARGET_NR_getpriority:/* Note that negative values are valid for getpriority, so we must
Signature · 1 line
2.43.0
Quoted 2 lines · Peter Maydell
You could argue that the fallback-to-libc-fchmodat here isn't worth bothering with, I guess.
Indeed not. Support for fchmodat2 is at least 2 years old already.
r~