Add syscall faccessat2

Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
This commit is contained in:
Zhenchen Wang 2025-04-11 14:29:14 +00:00 committed by Tate, Hongliang Tian
parent 17e5108c17
commit 9e729593e8
4 changed files with 25 additions and 3 deletions

View File

@ -342,6 +342,7 @@ provided by Linux on x86-64 architecture.
| 328 | pwritev2 | ✅ |
| 332 | statx | ✅ |
| 435 | clone3 | ✅ |
| 439 | faccessat2 | ✅ |
## File Systems

View File

@ -30,8 +30,23 @@ pub fn sys_access(path_ptr: Vaddr, mode: u16, ctx: &Context) -> Result<SyscallRe
do_faccessat(AT_FDCWD, path_ptr, mode, 0, ctx)
}
pub fn sys_faccessat2(
dirfd: FileDesc,
path_ptr: Vaddr,
mode: u16,
flags: u32,
ctx: &Context,
) -> Result<SyscallReturn> {
debug!(
"faccessat2: dirfd = {}, path_ptr = {:#x}, mode = {:o}, flags = {}",
dirfd, path_ptr, mode, flags
);
do_faccessat(dirfd, path_ptr, mode, flags, ctx)
}
bitflags! {
struct FaccessatFlags: i32 {
struct FaccessatFlags: u32 {
const AT_EACCESS = 0x200;
const AT_SYMLINK_NOFOLLOW = 0x100;
const AT_EMPTY_PATH = 0x1000;
@ -52,7 +67,7 @@ pub fn do_faccessat(
dirfd: FileDesc,
path_ptr: Vaddr,
mode: u16,
flags: i32,
flags: u32,
ctx: &Context,
) -> Result<SyscallReturn> {
let mode = AccessMode::from_bits(mode)
@ -66,6 +81,10 @@ pub fn do_faccessat(
dirfd, path, mode, flags
);
if path.is_empty() && !flags.contains(FaccessatFlags::AT_EMPTY_PATH) {
return_errno_with_message!(Errno::ENOENT, "path is empty");
}
let dentry = {
let path = path.to_string_lossy();
let fs_path = FsPath::new(dirfd, path.as_ref())?;

View File

@ -296,4 +296,5 @@ impl_syscall_nums_and_dispatch_fn! {
SYS_UTIMENSAT = 412 => sys_utimensat(args[..4]);
SYS_SEMTIMEDOP = 420 => sys_semtimedop(args[..4]);
SYS_CLONE3 = 435 => sys_clone3(args[..2], &user_ctx);
SYS_FACCESSAT2 = 439 => sys_faccessat2(arg[..4]);
}

View File

@ -2,7 +2,7 @@
use crate::syscall::{
accept::{sys_accept, sys_accept4},
access::{sys_access, sys_faccessat},
access::{sys_access, sys_faccessat, sys_faccessat2},
alarm::sys_alarm,
arch_prctl::sys_arch_prctl,
bind::sys_bind,
@ -362,4 +362,5 @@ impl_syscall_nums_and_dispatch_fn! {
SYS_PWRITEV2 = 328 => sys_pwritev2(args[..5]);
SYS_STATX = 332 => sys_statx(args[..5]);
SYS_CLONE3 = 435 => sys_clone3(args[..2], &user_ctx);
SYS_FACCESSAT2 = 439 => sys_faccessat2(args[..4]);
}