diff --git a/src/arch/arm64/exceptions/syscall.rs b/src/arch/arm64/exceptions/syscall.rs index 6fb3004..a6a5289 100644 --- a/src/arch/arm64/exceptions/syscall.rs +++ b/src/arch/arm64/exceptions/syscall.rs @@ -6,17 +6,8 @@ use crate::{ pipe::sys_pipe2, syscalls::{ at::{ - access::{sys_faccessat, sys_faccessat2}, - open::sys_openat, - stat::sys_newfstatat, - }, - close::sys_close, - ioctl::sys_ioctl, - iov::{sys_readv, sys_writev}, - rw::{sys_read, sys_write}, - seek::sys_lseek, - splice::sys_sendfile, - stat::sys_fstat, + access::{sys_faccessat, sys_faccessat2}, open::sys_openat, readlink::sys_readlinkat, stat::sys_newfstatat + }, chdir::sys_chdir, close::sys_close, ioctl::sys_ioctl, iov::{sys_readv, sys_writev}, rw::{sys_read, sys_write}, seek::sys_lseek, splice::sys_sendfile, stat::sys_fstat }, }, kernel::uname::sys_uname, @@ -36,12 +27,17 @@ use crate::{ }, sleep::sys_nanosleep, thread_group::{ - Pgid, pid::{sys_getpgid, sys_getpid, sys_getppid, sys_setpgid}, rsrc_lim::sys_prlimit64, signal::{ + Pgid, + pid::{sys_getpgid, sys_getpid, sys_getppid, sys_setpgid}, + rsrc_lim::sys_prlimit64, + signal::{ kill::{sys_kill, sys_tkill}, sigaction::sys_rt_sigaction, sigaltstack::sys_sigaltstack, sigprocmask::sys_rt_sigprocmask, - }, umask::sys_umask, wait::sys_wait4 + }, + umask::sys_umask, + wait::sys_wait4, }, threading::sys_set_tid_address, }, @@ -77,6 +73,7 @@ pub async fn handle_syscall() { 0x19 => sys_fcntl(arg1.into(), arg2 as _, arg3 as _).await, 0x1d => sys_ioctl(arg1.into(), arg2 as _, arg3 as _).await, 0x30 => sys_faccessat(arg1.into(), TUA::from_value(arg2 as _), arg3 as _).await, + 0x31 => sys_chdir(TUA::from_value(arg1 as _)).await, 0x38 => { sys_openat( arg1.into(), diff --git a/src/fs/syscalls/chdir.rs b/src/fs/syscalls/chdir.rs new file mode 100644 index 0000000..940443c --- /dev/null +++ b/src/fs/syscalls/chdir.rs @@ -0,0 +1,17 @@ +use crate::{fs::VFS, memory::uaccess::cstr::UserCStr, sched::current_task}; +use core::ffi::c_char; +use libkernel::{error::Result, fs::path::Path, memory::address::TUA}; + +pub async fn sys_chdir(path: TUA) -> Result { + let mut buf = [0; 1024]; + + let path = Path::new(UserCStr::from_ptr(path).copy_from_user(&mut buf).await?); + let task = current_task(); + let current_path = task.cwd.lock_save_irq().clone(); + + let node = VFS.resolve_path(path, current_path).await?; + + *task.cwd.lock_save_irq() = node; + + Ok(0) +} diff --git a/src/fs/syscalls/mod.rs b/src/fs/syscalls/mod.rs index 4153391..a50287b 100644 --- a/src/fs/syscalls/mod.rs +++ b/src/fs/syscalls/mod.rs @@ -1,4 +1,5 @@ pub mod at; +pub mod chdir; pub mod close; pub mod ioctl; pub mod iov;