diff --git a/kernel/aster-nix/src/syscall/accept.rs b/kernel/aster-nix/src/syscall/accept.rs index 413f55d33..9c3734cd1 100644 --- a/kernel/aster-nix/src/syscall/accept.rs +++ b/kernel/aster-nix/src/syscall/accept.rs @@ -14,11 +14,11 @@ pub fn sys_accept( sockfd: FileDesc, sockaddr_ptr: Vaddr, addrlen_ptr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!("sockfd = {sockfd}, sockaddr_ptr = 0x{sockaddr_ptr:x}, addrlen_ptr = 0x{addrlen_ptr:x}"); - let fd = do_accept(sockfd, sockaddr_ptr, addrlen_ptr, Flags::empty())?; + let fd = do_accept(sockfd, sockaddr_ptr, addrlen_ptr, Flags::empty(), ctx)?; Ok(SyscallReturn::Return(fd as _)) } @@ -27,7 +27,7 @@ pub fn sys_accept4( sockaddr_ptr: Vaddr, addrlen_ptr: Vaddr, flags: u32, - _ctx: &Context, + ctx: &Context, ) -> Result { trace!("raw flags = 0x{:x}", flags); let flags = Flags::from_bits_truncate(flags); @@ -36,7 +36,7 @@ pub fn sys_accept4( sockfd, sockaddr_ptr, addrlen_ptr, flags ); - let fd = do_accept(sockfd, sockaddr_ptr, addrlen_ptr, flags)?; + let fd = do_accept(sockfd, sockaddr_ptr, addrlen_ptr, flags, ctx)?; Ok(SyscallReturn::Return(fd as _)) } @@ -45,6 +45,7 @@ fn do_accept( sockaddr_ptr: Vaddr, addrlen_ptr: Vaddr, flags: Flags, + ctx: &Context, ) -> Result { let (connected_socket, socket_addr) = { let socket = get_socket_from_fd(sockfd)?; @@ -66,8 +67,7 @@ fn do_accept( } let fd = { - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); file_table.insert(connected_socket, fd_flags) }; diff --git a/kernel/aster-nix/src/syscall/access.rs b/kernel/aster-nix/src/syscall/access.rs index 5ed0c8534..c0889bebe 100644 --- a/kernel/aster-nix/src/syscall/access.rs +++ b/kernel/aster-nix/src/syscall/access.rs @@ -14,20 +14,20 @@ pub fn sys_faccessat( dirfd: FileDesc, path_ptr: Vaddr, mode: u16, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "faccessat: dirfd = {}, path_ptr = {:#x}, mode = {:o}", dirfd, path_ptr, mode ); - do_faccessat(dirfd, path_ptr, mode, 0) + do_faccessat(dirfd, path_ptr, mode, 0, ctx) } -pub fn sys_access(path_ptr: Vaddr, mode: u16, _ctx: &Context) -> Result { +pub fn sys_access(path_ptr: Vaddr, mode: u16, ctx: &Context) -> Result { debug!("access: path_ptr = {:#x}, mode = {:o}", path_ptr, mode); - do_faccessat(AT_FDCWD, path_ptr, mode, 0) + do_faccessat(AT_FDCWD, path_ptr, mode, 0, ctx) } bitflags! { @@ -53,6 +53,7 @@ pub fn do_faccessat( path_ptr: Vaddr, mode: u16, flags: i32, + ctx: &Context, ) -> Result { let mode = AccessMode::from_bits(mode) .ok_or_else(|| Error::with_message(Errno::EINVAL, "Invalid mode"))?; @@ -65,11 +66,10 @@ pub fn do_faccessat( dirfd, path, mode, flags ); - let current = current!(); let dentry = { let path = path.to_string_lossy(); let fs_path = FsPath::new(dirfd, path.as_ref())?; - let fs = current.fs().read(); + let fs = ctx.process.fs().read(); if flags.contains(FaccessatFlags::AT_SYMLINK_NOFOLLOW) { fs.lookup_no_follow(&fs_path)? } else { diff --git a/kernel/aster-nix/src/syscall/alarm.rs b/kernel/aster-nix/src/syscall/alarm.rs index 9e115d984..c4ed3b57f 100644 --- a/kernel/aster-nix/src/syscall/alarm.rs +++ b/kernel/aster-nix/src/syscall/alarm.rs @@ -5,11 +5,10 @@ use core::time::Duration; use super::SyscallReturn; use crate::{prelude::*, time::timer::Timeout}; -pub fn sys_alarm(seconds: u32, _ctx: &Context) -> Result { +pub fn sys_alarm(seconds: u32, ctx: &Context) -> Result { debug!("seconds = {}", seconds); - let current = current!(); - let alarm_timer = current.timer_manager().alarm_timer(); + let alarm_timer = ctx.process.timer_manager().alarm_timer(); let remaining = alarm_timer.remain(); let mut remaining_secs = remaining.as_secs(); diff --git a/kernel/aster-nix/src/syscall/brk.rs b/kernel/aster-nix/src/syscall/brk.rs index 51c7cca29..80f96452c 100644 --- a/kernel/aster-nix/src/syscall/brk.rs +++ b/kernel/aster-nix/src/syscall/brk.rs @@ -3,15 +3,14 @@ use crate::{prelude::*, syscall::SyscallReturn}; /// expand the user heap to new heap end, returns the new heap end if expansion succeeds. -pub fn sys_brk(heap_end: u64, _ctx: &Context) -> Result { +pub fn sys_brk(heap_end: u64, ctx: &Context) -> Result { let new_heap_end = if heap_end == 0 { None } else { Some(heap_end as usize) }; debug!("new heap end = {:x?}", heap_end); - let current = current!(); - let user_heap = current.heap(); + let user_heap = ctx.process.heap(); let new_heap_end = user_heap.brk(new_heap_end)?; Ok(SyscallReturn::Return(new_heap_end as _)) diff --git a/kernel/aster-nix/src/syscall/chdir.rs b/kernel/aster-nix/src/syscall/chdir.rs index 6b4c9099a..730f9594b 100644 --- a/kernel/aster-nix/src/syscall/chdir.rs +++ b/kernel/aster-nix/src/syscall/chdir.rs @@ -7,12 +7,11 @@ use crate::{ syscall::constants::MAX_FILENAME_LEN, }; -pub fn sys_chdir(path_ptr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_chdir(path_ptr: Vaddr, ctx: &Context) -> Result { let path = CurrentUserSpace::get().read_cstring(path_ptr, MAX_FILENAME_LEN)?; debug!("path = {:?}", path); - let current = current!(); - let mut fs = current.fs().write(); + let mut fs = ctx.process.fs().write(); let dentry = { let path = path.to_string_lossy(); if path.is_empty() { @@ -28,12 +27,11 @@ pub fn sys_chdir(path_ptr: Vaddr, _ctx: &Context) -> Result { Ok(SyscallReturn::Return(0)) } -pub fn sys_fchdir(fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_fchdir(fd: FileDesc, ctx: &Context) -> Result { debug!("fd = {}", fd); - let current = current!(); let dentry = { - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let inode_handle = file .downcast_ref::() @@ -43,6 +41,6 @@ pub fn sys_fchdir(fd: FileDesc, _ctx: &Context) -> Result { if dentry.type_() != InodeType::Dir { return_errno_with_message!(Errno::ENOTDIR, "must be directory"); } - current.fs().write().set_cwd(dentry); + ctx.process.fs().write().set_cwd(dentry); Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/chmod.rs b/kernel/aster-nix/src/syscall/chmod.rs index 8c6f7a826..476ce3468 100644 --- a/kernel/aster-nix/src/syscall/chmod.rs +++ b/kernel/aster-nix/src/syscall/chmod.rs @@ -10,11 +10,10 @@ use crate::{ prelude::*, }; -pub fn sys_fchmod(fd: FileDesc, mode: u16, _ctx: &Context) -> Result { +pub fn sys_fchmod(fd: FileDesc, mode: u16, ctx: &Context) -> Result { debug!("fd = {}, mode = 0o{:o}", fd, mode); - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; file.set_mode(InodeMode::from_bits_truncate(mode))?; Ok(SyscallReturn::Return(0)) @@ -30,19 +29,18 @@ pub fn sys_fchmodat( path_ptr: Vaddr, mode: u16, /* flags: u32, */ - _ctx: &Context, + ctx: &Context, ) -> Result { let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?; debug!("dirfd = {}, path = {:?}, mode = 0o{:o}", dirfd, path, mode,); - let current = current!(); let dentry = { let path = path.to_string_lossy(); if path.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); } let fs_path = FsPath::new(dirfd, path.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; dentry.set_mode(InodeMode::from_bits_truncate(mode))?; Ok(SyscallReturn::Return(0)) diff --git a/kernel/aster-nix/src/syscall/chown.rs b/kernel/aster-nix/src/syscall/chown.rs index 2684bb415..9c08fc3d9 100644 --- a/kernel/aster-nix/src/syscall/chown.rs +++ b/kernel/aster-nix/src/syscall/chown.rs @@ -11,7 +11,7 @@ use crate::{ process::{Gid, Uid}, }; -pub fn sys_fchown(fd: FileDesc, uid: i32, gid: i32, _ctx: &Context) -> Result { +pub fn sys_fchown(fd: FileDesc, uid: i32, gid: i32, ctx: &Context) -> Result { debug!("fd = {}, uid = {}, gid = {}", fd, uid, gid); let uid = to_optional_id(uid, Uid::new)?; @@ -20,8 +20,7 @@ pub fn sys_fchown(fd: FileDesc, uid: i32, gid: i32, _ctx: &Context) -> Result Result { +pub fn sys_chroot(path_ptr: Vaddr, ctx: &Context) -> Result { let path = CurrentUserSpace::get().read_cstring(path_ptr, MAX_FILENAME_LEN)?; debug!("path = {:?}", path); - let current = current!(); - let mut fs = current.fs().write(); + let mut fs = ctx.process.fs().write(); let dentry = { let path = path.to_string_lossy(); if path.is_empty() { diff --git a/kernel/aster-nix/src/syscall/clock_gettime.rs b/kernel/aster-nix/src/syscall/clock_gettime.rs index e1609008a..20574f5e6 100644 --- a/kernel/aster-nix/src/syscall/clock_gettime.rs +++ b/kernel/aster-nix/src/syscall/clock_gettime.rs @@ -22,11 +22,11 @@ use crate::{ pub fn sys_clock_gettime( clockid: clockid_t, timespec_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!("clockid = {:?}", clockid); - let time_duration = read_clock(clockid)?; + let time_duration = read_clock(clockid, ctx)?; let timespec = timespec_t::from(time_duration); CurrentUserSpace::get().write_val(timespec_addr, ×pec)?; @@ -109,7 +109,7 @@ pub enum DynamicClockType { /// Reads the time of a clock specified by the input clock ID. /// /// If the clock ID does not support, this function will return `Err`. -pub fn read_clock(clockid: clockid_t) -> Result { +pub fn read_clock(clockid: clockid_t, ctx: &Context) -> Result { if clockid >= 0 { let clock_id = ClockId::try_from(clockid)?; match clock_id { @@ -119,14 +119,8 @@ pub fn read_clock(clockid: clockid_t) -> Result { ClockId::CLOCK_REALTIME_COARSE => Ok(RealTimeCoarseClock::get().read_time()), ClockId::CLOCK_MONOTONIC_COARSE => Ok(MonotonicCoarseClock::get().read_time()), ClockId::CLOCK_BOOTTIME => Ok(BootTimeClock::get().read_time()), - ClockId::CLOCK_PROCESS_CPUTIME_ID => { - let process = current!(); - Ok(process.prof_clock().read_time()) - } - ClockId::CLOCK_THREAD_CPUTIME_ID => { - let thread = current_thread!(); - Ok(thread.as_posix_thread().unwrap().prof_clock().read_time()) - } + ClockId::CLOCK_PROCESS_CPUTIME_ID => Ok(ctx.process.prof_clock().read_time()), + ClockId::CLOCK_THREAD_CPUTIME_ID => Ok(ctx.posix_thread.prof_clock().read_time()), } } else { let dynamic_clockid_info = DynamicClockIdInfo::try_from(clockid)?; diff --git a/kernel/aster-nix/src/syscall/close.rs b/kernel/aster-nix/src/syscall/close.rs index b84d37e69..6ce27f93e 100644 --- a/kernel/aster-nix/src/syscall/close.rs +++ b/kernel/aster-nix/src/syscall/close.rs @@ -3,12 +3,11 @@ use super::SyscallReturn; use crate::{fs::file_table::FileDesc, prelude::*}; -pub fn sys_close(fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_close(fd: FileDesc, ctx: &Context) -> Result { debug!("fd = {}", fd); let file = { - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let _ = file_table.get_file(fd)?; file_table.close_file(fd).unwrap() }; diff --git a/kernel/aster-nix/src/syscall/dup.rs b/kernel/aster-nix/src/syscall/dup.rs index 54ff2ec1e..4b3765b1d 100644 --- a/kernel/aster-nix/src/syscall/dup.rs +++ b/kernel/aster-nix/src/syscall/dup.rs @@ -7,34 +7,32 @@ use crate::{ process::ResourceType, }; -pub fn sys_dup(old_fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_dup(old_fd: FileDesc, ctx: &Context) -> Result { debug!("old_fd = {}", old_fd); - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let new_fd = file_table.dup(old_fd, 0, FdFlags::empty())?; Ok(SyscallReturn::Return(new_fd as _)) } -pub fn sys_dup2(old_fd: FileDesc, new_fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_dup2(old_fd: FileDesc, new_fd: FileDesc, ctx: &Context) -> Result { debug!("old_fd = {}, new_fd = {}", old_fd, new_fd); if old_fd == new_fd { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let _ = file_table.get_file(old_fd)?; return Ok(SyscallReturn::Return(new_fd as _)); } - do_dup3(old_fd, new_fd, FdFlags::empty()) + do_dup3(old_fd, new_fd, FdFlags::empty(), ctx) } pub fn sys_dup3( old_fd: FileDesc, new_fd: FileDesc, flags: u32, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!("old_fd = {}, new_fd = {}", old_fd, new_fd); @@ -44,15 +42,20 @@ pub fn sys_dup3( _ => return_errno_with_message!(Errno::EINVAL, "flags must be O_CLOEXEC or 0"), }; - do_dup3(old_fd, new_fd, fdflag) + do_dup3(old_fd, new_fd, fdflag, ctx) } -fn do_dup3(old_fd: FileDesc, new_fd: FileDesc, flags: FdFlags) -> Result { +fn do_dup3( + old_fd: FileDesc, + new_fd: FileDesc, + flags: FdFlags, + ctx: &Context, +) -> Result { if old_fd == new_fd { return_errno!(Errno::EINVAL); } - let current = current!(); + let current = ctx.process; if new_fd >= current .resource_limits() diff --git a/kernel/aster-nix/src/syscall/epoll.rs b/kernel/aster-nix/src/syscall/epoll.rs index d5b95e010..af406bc65 100644 --- a/kernel/aster-nix/src/syscall/epoll.rs +++ b/kernel/aster-nix/src/syscall/epoll.rs @@ -21,7 +21,7 @@ pub fn sys_epoll_create(size: i32, ctx: &Context) -> Result { sys_epoll_create1(0, ctx) } -pub fn sys_epoll_create1(flags: u32, _ctx: &Context) -> Result { +pub fn sys_epoll_create1(flags: u32, ctx: &Context) -> Result { debug!("flags = 0x{:x}", flags); let fd_flags = { @@ -37,9 +37,8 @@ pub fn sys_epoll_create1(flags: u32, _ctx: &Context) -> Result { } }; - let current = current!(); let epoll_file: Arc = EpollFile::new(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let fd = file_table.insert(epoll_file, fd_flags); Ok(SyscallReturn::Return(fd as _)) } @@ -49,7 +48,7 @@ pub fn sys_epoll_ctl( op: i32, fd: FileDesc, event_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "epfd = {}, op = {}, fd = {}, event_addr = 0x{:x}", @@ -77,9 +76,8 @@ pub fn sys_epoll_ctl( _ => return_errno_with_message!(Errno::EINVAL, "invalid op"), }; - let current = current!(); let file = { - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(epfd)?.clone() }; let epoll_file = file @@ -90,7 +88,12 @@ pub fn sys_epoll_ctl( Ok(SyscallReturn::Return(0 as _)) } -fn do_epoll_wait(epfd: FileDesc, max_events: i32, timeout: i32) -> Result> { +fn do_epoll_wait( + epfd: FileDesc, + max_events: i32, + timeout: i32, + ctx: &Context, +) -> Result> { let max_events = { if max_events <= 0 { return_errno_with_message!(Errno::EINVAL, "max_events is not positive"); @@ -103,8 +106,7 @@ fn do_epoll_wait(epfd: FileDesc, max_events: i32, timeout: i32) -> Result() @@ -129,14 +131,14 @@ pub fn sys_epoll_wait( events_addr: Vaddr, max_events: i32, timeout: i32, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "epfd = {}, events_addr = 0x{:x}, max_events = {}, timeout = {:?}", epfd, events_addr, max_events, timeout ); - let epoll_events = do_epoll_wait(epfd, max_events, timeout)?; + let epoll_events = do_epoll_wait(epfd, max_events, timeout, ctx)?; // Write back let mut write_addr = events_addr; @@ -184,7 +186,7 @@ pub fn sys_epoll_pwait( timeout: i32, sigmask: Vaddr, sigset_size: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "epfd = {}, events_addr = 0x{:x}, max_events = {}, timeout = {:?}, sigmask = 0x{:x}, sigset_size = {}", @@ -197,7 +199,7 @@ pub fn sys_epoll_pwait( let old_sig_mask_value = set_signal_mask(sigmask)?; - let ready_events = match do_epoll_wait(epfd, max_events, timeout) { + let ready_events = match do_epoll_wait(epfd, max_events, timeout, ctx) { Ok(events) => { restore_signal_mask(old_sig_mask_value); events diff --git a/kernel/aster-nix/src/syscall/eventfd.rs b/kernel/aster-nix/src/syscall/eventfd.rs index 9be19f221..f9c16f1d2 100644 --- a/kernel/aster-nix/src/syscall/eventfd.rs +++ b/kernel/aster-nix/src/syscall/eventfd.rs @@ -30,30 +30,29 @@ use crate::{ time::clocks::RealTimeClock, }; -pub fn sys_eventfd(init_val: u64, _ctx: &Context) -> Result { +pub fn sys_eventfd(init_val: u64, ctx: &Context) -> Result { debug!("init_val = 0x{:x}", init_val); - let fd = do_sys_eventfd2(init_val, Flags::empty()); + let fd = do_sys_eventfd2(init_val, Flags::empty(), ctx); Ok(SyscallReturn::Return(fd as _)) } -pub fn sys_eventfd2(init_val: u64, flags: u32, _ctx: &Context) -> Result { +pub fn sys_eventfd2(init_val: u64, flags: u32, ctx: &Context) -> Result { trace!("raw flags = {}", flags); let flags = Flags::from_bits(flags) .ok_or_else(|| Error::with_message(Errno::EINVAL, "unknown flags"))?; debug!("init_val = 0x{:x}, flags = {:?}", init_val, flags); - let fd = do_sys_eventfd2(init_val, flags); + let fd = do_sys_eventfd2(init_val, flags, ctx); Ok(SyscallReturn::Return(fd as _)) } -fn do_sys_eventfd2(init_val: u64, flags: Flags) -> FileDesc { +fn do_sys_eventfd2(init_val: u64, flags: Flags, ctx: &Context) -> FileDesc { let event_file = EventFile::new(init_val, flags); let fd = { - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let fd_flags = if flags.contains(Flags::EFD_CLOEXEC) { FdFlags::CLOEXEC } else { diff --git a/kernel/aster-nix/src/syscall/execve.rs b/kernel/aster-nix/src/syscall/execve.rs index e94f36f19..ffc937f17 100644 --- a/kernel/aster-nix/src/syscall/execve.rs +++ b/kernel/aster-nix/src/syscall/execve.rs @@ -28,7 +28,7 @@ pub fn sys_execve( ) -> Result { let elf_file = { let executable_path = read_filename(filename_ptr)?; - lookup_executable_file(AT_FDCWD, executable_path, OpenFlags::empty())? + lookup_executable_file(AT_FDCWD, executable_path, OpenFlags::empty(), ctx)? }; do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_ctx)?; @@ -47,7 +47,7 @@ pub fn sys_execveat( let elf_file = { let flags = OpenFlags::from_bits_truncate(flags); let filename = read_filename(filename_ptr)?; - lookup_executable_file(dfd, filename, flags)? + lookup_executable_file(dfd, filename, flags, ctx)? }; do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_ctx)?; @@ -58,9 +58,9 @@ fn lookup_executable_file( dfd: FileDesc, filename: String, flags: OpenFlags, + ctx: &Context, ) -> Result> { - let current = current!(); - let fs_resolver = current.fs().read(); + let fs_resolver = ctx.process.fs().read(); let dentry = if flags.contains(OpenFlags::AT_EMPTY_PATH) && filename.is_empty() { fs_resolver.lookup_from_fd(dfd) } else { diff --git a/kernel/aster-nix/src/syscall/fallocate.rs b/kernel/aster-nix/src/syscall/fallocate.rs index 8edb4b5cb..00fe30b37 100644 --- a/kernel/aster-nix/src/syscall/fallocate.rs +++ b/kernel/aster-nix/src/syscall/fallocate.rs @@ -12,18 +12,17 @@ pub fn sys_fallocate( mode: u64, offset: i64, len: i64, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, mode = {}, offset = {}, len = {}", fd, mode, offset, len ); - check_offset_and_len(offset, len)?; + check_offset_and_len(offset, len, ctx)?; let file = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() }; @@ -36,7 +35,7 @@ pub fn sys_fallocate( Ok(SyscallReturn::Return(0)) } -fn check_offset_and_len(offset: i64, len: i64) -> Result<()> { +fn check_offset_and_len(offset: i64, len: i64, ctx: &Context) -> Result<()> { if offset < 0 || len <= 0 { return_errno_with_message!( Errno::EINVAL, @@ -48,8 +47,7 @@ fn check_offset_and_len(offset: i64, len: i64) -> Result<()> { } let max_file_size = { - let current = current!(); - let resource_limits = current.resource_limits().lock(); + let resource_limits = ctx.process.resource_limits().lock(); resource_limits .get_rlimit(ResourceType::RLIMIT_FSIZE) .get_cur() as usize diff --git a/kernel/aster-nix/src/syscall/fcntl.rs b/kernel/aster-nix/src/syscall/fcntl.rs index e70ba8c62..be914a022 100644 --- a/kernel/aster-nix/src/syscall/fcntl.rs +++ b/kernel/aster-nix/src/syscall/fcntl.rs @@ -10,24 +10,22 @@ use crate::{ process::Pid, }; -pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, _ctx: &Context) -> Result { +pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, ctx: &Context) -> Result { let fcntl_cmd = FcntlCmd::try_from(cmd)?; debug!("fd = {}, cmd = {:?}, arg = {}", fd, fcntl_cmd, arg); + let current = ctx.process; match fcntl_cmd { FcntlCmd::F_DUPFD => { - let current = current!(); let mut file_table = current.file_table().lock(); let new_fd = file_table.dup(fd, arg as FileDesc, FdFlags::empty())?; Ok(SyscallReturn::Return(new_fd as _)) } FcntlCmd::F_DUPFD_CLOEXEC => { - let current = current!(); let mut file_table = current.file_table().lock(); let new_fd = file_table.dup(fd, arg as FileDesc, FdFlags::CLOEXEC)?; Ok(SyscallReturn::Return(new_fd as _)) } FcntlCmd::F_GETFD => { - let current = current!(); let file_table = current.file_table().lock(); let entry = file_table.get_entry(fd)?; let fd_flags = entry.flags(); @@ -41,14 +39,12 @@ pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, _ctx: &Context) -> Result { - let current = current!(); let file = { let file_table = current.file_table().lock(); file_table.get_file(fd)?.clone() @@ -60,7 +56,6 @@ pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, _ctx: &Context) -> Result { - let current = current!(); let file = { let file_table = current.file_table().lock(); file_table.get_file(fd)?.clone() @@ -82,7 +77,6 @@ pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, _ctx: &Context) -> Result { - let current = current!(); let file_table = current.file_table().lock(); let file_entry = file_table.get_entry(fd)?; // A process ID is specified as a positive value; a process group ID is specified as a negative value. @@ -96,7 +90,6 @@ pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, _ctx: &Context) -> Result { - let current = current!(); let file_table = current.file_table().lock(); let file_entry = file_table.get_entry(fd)?; let pid = file_entry.owner().unwrap_or(0); diff --git a/kernel/aster-nix/src/syscall/fsync.rs b/kernel/aster-nix/src/syscall/fsync.rs index 112e66fac..4c3135c4d 100644 --- a/kernel/aster-nix/src/syscall/fsync.rs +++ b/kernel/aster-nix/src/syscall/fsync.rs @@ -6,12 +6,11 @@ use crate::{ prelude::*, }; -pub fn sys_fsync(fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_fsync(fd: FileDesc, ctx: &Context) -> Result { debug!("fd = {}", fd); let dentry = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let inode_handle = file .downcast_ref::() @@ -22,12 +21,11 @@ pub fn sys_fsync(fd: FileDesc, _ctx: &Context) -> Result { Ok(SyscallReturn::Return(0)) } -pub fn sys_fdatasync(fd: FileDesc, _ctx: &Context) -> Result { +pub fn sys_fdatasync(fd: FileDesc, ctx: &Context) -> Result { debug!("fd = {}", fd); let dentry = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let inode_handle = file .downcast_ref::() diff --git a/kernel/aster-nix/src/syscall/getdents64.rs b/kernel/aster-nix/src/syscall/getdents64.rs index 5d0f94e14..8c354cee3 100644 --- a/kernel/aster-nix/src/syscall/getdents64.rs +++ b/kernel/aster-nix/src/syscall/getdents64.rs @@ -16,7 +16,7 @@ pub fn sys_getdents( fd: FileDesc, buf_addr: Vaddr, buf_len: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, buf_addr = 0x{:x}, buf_len = 0x{:x}", @@ -24,8 +24,7 @@ pub fn sys_getdents( ); let file = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() }; let inode_handle = file @@ -46,7 +45,7 @@ pub fn sys_getdents64( fd: FileDesc, buf_addr: Vaddr, buf_len: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, buf_addr = 0x{:x}, buf_len = 0x{:x}", @@ -54,8 +53,7 @@ pub fn sys_getdents64( ); let file = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() }; let inode_handle = file diff --git a/kernel/aster-nix/src/syscall/getpgrp.rs b/kernel/aster-nix/src/syscall/getpgrp.rs index 911275c2a..58685ebc8 100644 --- a/kernel/aster-nix/src/syscall/getpgrp.rs +++ b/kernel/aster-nix/src/syscall/getpgrp.rs @@ -3,7 +3,6 @@ use super::SyscallReturn; use crate::prelude::*; -pub fn sys_getpgrp(_ctx: &Context) -> Result { - let current = current!(); - Ok(SyscallReturn::Return(current.pgid() as _)) +pub fn sys_getpgrp(ctx: &Context) -> Result { + Ok(SyscallReturn::Return(ctx.process.pgid() as _)) } diff --git a/kernel/aster-nix/src/syscall/getppid.rs b/kernel/aster-nix/src/syscall/getppid.rs index 8b7013267..7cfa33d32 100644 --- a/kernel/aster-nix/src/syscall/getppid.rs +++ b/kernel/aster-nix/src/syscall/getppid.rs @@ -3,9 +3,8 @@ use super::SyscallReturn; use crate::prelude::*; -pub fn sys_getppid(_ctx: &Context) -> Result { - let current = current!(); - let parent = current.parent(); +pub fn sys_getppid(ctx: &Context) -> Result { + let parent = ctx.process.parent(); match parent { None => Ok(SyscallReturn::Return(0)), Some(parent) => Ok(SyscallReturn::Return(parent.pid() as _)), diff --git a/kernel/aster-nix/src/syscall/getrusage.rs b/kernel/aster-nix/src/syscall/getrusage.rs index d7f1448b8..b82df6d51 100644 --- a/kernel/aster-nix/src/syscall/getrusage.rs +++ b/kernel/aster-nix/src/syscall/getrusage.rs @@ -3,7 +3,7 @@ use int_to_c_enum::TryFromInt; use super::SyscallReturn; -use crate::{prelude::*, process::posix_thread::PosixThreadExt, time::timeval_t}; +use crate::{prelude::*, time::timeval_t}; #[derive(Debug, Copy, Clone, TryFromInt, PartialEq)] #[repr(i32)] @@ -14,7 +14,7 @@ enum RusageTarget { Thread = 1, } -pub fn sys_getrusage(target: i32, rusage_addr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_getrusage(target: i32, rusage_addr: Vaddr, ctx: &Context) -> Result { let rusage_target = RusageTarget::try_from(target)?; debug!( @@ -25,7 +25,7 @@ pub fn sys_getrusage(target: i32, rusage_addr: Vaddr, _ctx: &Context) -> Result< if rusage_addr != 0 { let rusage = match rusage_target { RusageTarget::ForSelf => { - let process = current!(); + let process = ctx.process; rusage_t { ru_utime: process.prof_clock().user_clock().read_time().into(), ru_stime: process.prof_clock().kernel_clock().read_time().into(), @@ -33,8 +33,7 @@ pub fn sys_getrusage(target: i32, rusage_addr: Vaddr, _ctx: &Context) -> Result< } } RusageTarget::Thread => { - let thread = current_thread!(); - let posix_thread = thread.as_posix_thread().unwrap(); + let posix_thread = ctx.posix_thread; rusage_t { ru_utime: posix_thread.prof_clock().user_clock().read_time().into(), ru_stime: posix_thread.prof_clock().kernel_clock().read_time().into(), diff --git a/kernel/aster-nix/src/syscall/getsid.rs b/kernel/aster-nix/src/syscall/getsid.rs index 08b880661..cb84525a6 100644 --- a/kernel/aster-nix/src/syscall/getsid.rs +++ b/kernel/aster-nix/src/syscall/getsid.rs @@ -6,10 +6,10 @@ use crate::{ process::{process_table, Pid}, }; -pub fn sys_getsid(pid: Pid, _ctx: &Context) -> Result { +pub fn sys_getsid(pid: Pid, ctx: &Context) -> Result { debug!("pid = {}", pid); - let session = current!().session().unwrap(); + let session = ctx.process.session().unwrap(); let sid = session.sid(); if pid == 0 { diff --git a/kernel/aster-nix/src/syscall/ioctl.rs b/kernel/aster-nix/src/syscall/ioctl.rs index d1f92c591..4a36a122e 100644 --- a/kernel/aster-nix/src/syscall/ioctl.rs +++ b/kernel/aster-nix/src/syscall/ioctl.rs @@ -9,14 +9,13 @@ use crate::{ prelude::*, }; -pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, _ctx: &Context) -> Result { +pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, ctx: &Context) -> Result { let ioctl_cmd = IoctlCmd::try_from(cmd)?; debug!( "fd = {}, ioctl_cmd = {:?}, arg = 0x{:x}", fd, ioctl_cmd, arg ); - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let res = match ioctl_cmd { IoctlCmd::FIONBIO => { diff --git a/kernel/aster-nix/src/syscall/kill.rs b/kernel/aster-nix/src/syscall/kill.rs index 03f54587e..12082f894 100644 --- a/kernel/aster-nix/src/syscall/kill.rs +++ b/kernel/aster-nix/src/syscall/kill.rs @@ -29,10 +29,8 @@ pub fn sys_kill(process_filter: u64, sig_num: u64, ctx: &Context) -> Result, ctx: &Context) -> Result<()> { - let current = current!(); - let signal = sig_num.map(|sig_num| { - let pid = current.pid(); + let pid = ctx.process.pid(); let uid = ctx.posix_thread.credentials().ruid(); UserSignal::new(sig_num, UserSignalKind::Kill, pid, uid) }); diff --git a/kernel/aster-nix/src/syscall/link.rs b/kernel/aster-nix/src/syscall/link.rs index be592ac24..b8ad0fd0c 100644 --- a/kernel/aster-nix/src/syscall/link.rs +++ b/kernel/aster-nix/src/syscall/link.rs @@ -16,7 +16,7 @@ pub fn sys_linkat( new_dirfd: FileDesc, new_path_addr: Vaddr, flags: u32, - _ctx: &Context, + ctx: &Context, ) -> Result { let user_space = CurrentUserSpace::get(); @@ -29,7 +29,6 @@ pub fn sys_linkat( old_dirfd, old_path, new_dirfd, new_path, flags ); - let current = current!(); let (old_dentry, new_dir_dentry, new_name) = { let old_path = old_path.to_string_lossy(); if old_path.ends_with('/') { @@ -45,7 +44,7 @@ pub fn sys_linkat( let old_fs_path = FsPath::new(old_dirfd, old_path.as_ref())?; let new_fs_path = FsPath::new(new_dirfd, new_path.as_ref())?; - let fs = current.fs().read(); + let fs = ctx.process.fs().read(); let old_dentry = if flags.contains(LinkFlags::AT_SYMLINK_FOLLOW) { fs.lookup(&old_fs_path)? } else { diff --git a/kernel/aster-nix/src/syscall/lseek.rs b/kernel/aster-nix/src/syscall/lseek.rs index b9af9a939..6819a9c21 100644 --- a/kernel/aster-nix/src/syscall/lseek.rs +++ b/kernel/aster-nix/src/syscall/lseek.rs @@ -6,12 +6,7 @@ use crate::{ prelude::*, }; -pub fn sys_lseek( - fd: FileDesc, - offset: isize, - whence: u32, - _ctx: &Context, -) -> Result { +pub fn sys_lseek(fd: FileDesc, offset: isize, whence: u32, ctx: &Context) -> Result { debug!("fd = {}, offset = {}, whence = {}", fd, offset, whence); let seek_from = match whence { 0 => { @@ -24,8 +19,7 @@ pub fn sys_lseek( 2 => SeekFrom::End(offset), _ => return_errno!(Errno::EINVAL), }; - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let offset = file.seek(seek_from)?; Ok(SyscallReturn::Return(offset as _)) diff --git a/kernel/aster-nix/src/syscall/madvise.rs b/kernel/aster-nix/src/syscall/madvise.rs index eefd428fb..34734eaaf 100644 --- a/kernel/aster-nix/src/syscall/madvise.rs +++ b/kernel/aster-nix/src/syscall/madvise.rs @@ -7,7 +7,7 @@ pub fn sys_madvise( start: Vaddr, len: usize, behavior: i32, - _ctx: &Context, + ctx: &Context, ) -> Result { let behavior = MadviseBehavior::try_from(behavior)?; debug!( @@ -26,18 +26,17 @@ pub fn sys_madvise( MadviseBehavior::MADV_DONTNEED => { warn!("MADV_DONTNEED isn't implemented, do nothing for now."); } - MadviseBehavior::MADV_FREE => madv_free(start, len)?, + MadviseBehavior::MADV_FREE => madv_free(start, len, ctx)?, _ => todo!(), } Ok(SyscallReturn::Return(0)) } -fn madv_free(start: Vaddr, len: usize) -> Result<()> { +fn madv_free(start: Vaddr, len: usize, ctx: &Context) -> Result<()> { debug_assert!(start % PAGE_SIZE == 0); debug_assert!(len % PAGE_SIZE == 0); - let current = current!(); - let root_vmar = current.root_vmar(); + let root_vmar = ctx.process.root_vmar(); let advised_range = start..start + len; let _ = root_vmar.destroy(advised_range); diff --git a/kernel/aster-nix/src/syscall/mkdir.rs b/kernel/aster-nix/src/syscall/mkdir.rs index 1ac989649..844346462 100644 --- a/kernel/aster-nix/src/syscall/mkdir.rs +++ b/kernel/aster-nix/src/syscall/mkdir.rs @@ -15,12 +15,12 @@ pub fn sys_mkdirat( dirfd: FileDesc, path_addr: Vaddr, mode: u16, - _ctx: &Context, + ctx: &Context, ) -> Result { let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?; debug!("dirfd = {}, path = {:?}, mode = {}", dirfd, path, mode); - let current = current!(); + let current = ctx.process; let (dir_dentry, name) = { let path = path.to_string_lossy(); if path.is_empty() { diff --git a/kernel/aster-nix/src/syscall/mknod.rs b/kernel/aster-nix/src/syscall/mknod.rs index 2ecf368cb..cddbc886b 100644 --- a/kernel/aster-nix/src/syscall/mknod.rs +++ b/kernel/aster-nix/src/syscall/mknod.rs @@ -17,10 +17,10 @@ pub fn sys_mknodat( path_addr: Vaddr, mode: u16, dev: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?; - let current = current!(); + let current = ctx.process; let inode_mode = { let mask_mode = mode & !current.umask().read().get(); InodeMode::from_bits_truncate(mask_mode) diff --git a/kernel/aster-nix/src/syscall/mmap.rs b/kernel/aster-nix/src/syscall/mmap.rs index d888ab95f..aab6e0852 100644 --- a/kernel/aster-nix/src/syscall/mmap.rs +++ b/kernel/aster-nix/src/syscall/mmap.rs @@ -22,7 +22,7 @@ pub fn sys_mmap( flags: u64, fd: u64, offset: u64, - _ctx: &Context, + ctx: &Context, ) -> Result { let perms = VmPerms::from_posix_prot_bits(perms as u32).unwrap(); let option = MMapOptions::try_from(flags as u32)?; @@ -33,6 +33,7 @@ pub fn sys_mmap( option, fd as _, offset as usize, + ctx, )?; Ok(SyscallReturn::Return(res as _)) } @@ -44,6 +45,7 @@ fn do_sys_mmap( option: MMapOptions, fd: FileDesc, offset: usize, + ctx: &Context, ) -> Result { debug!( "addr = 0x{:x}, len = 0x{:x}, perms = {:?}, option = {:?}, fd = {}, offset = 0x{:x}", @@ -64,11 +66,10 @@ fn do_sys_mmap( } alloc_anonyous_vmo(len)? } else { - alloc_filebacked_vmo(fd, len, offset, &option)? + alloc_filebacked_vmo(fd, len, offset, &option, ctx)? }; - let current = current!(); - let root_vmar = current.root_vmar(); + let root_vmar = ctx.process.root_vmar(); let vm_map_options = { let mut options = root_vmar.new_map(vmo.to_dyn(), vm_perms)?; let flags = option.flags; @@ -101,10 +102,10 @@ fn alloc_filebacked_vmo( len: usize, offset: usize, option: &MMapOptions, + ctx: &Context, ) -> Result { - let current = current!(); let page_cache_vmo = { - let fs_resolver = current.fs().read(); + let fs_resolver = ctx.process.fs().read(); let dentry = fs_resolver.lookup_from_fd(fd)?; let inode = dentry.inode(); inode diff --git a/kernel/aster-nix/src/syscall/mount.rs b/kernel/aster-nix/src/syscall/mount.rs index 8c6d3f98f..89fc6c0f4 100644 --- a/kernel/aster-nix/src/syscall/mount.rs +++ b/kernel/aster-nix/src/syscall/mount.rs @@ -23,7 +23,7 @@ pub fn sys_mount( fstype_addr: Vaddr, flags: u64, data: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let user_space = CurrentUserSpace::get(); let devname = user_space.read_cstring(devname_addr, MAX_FILENAME_LEN)?; @@ -34,14 +34,13 @@ pub fn sys_mount( devname, dirname, fstype_addr, mount_flags, data, ); - let current = current!(); let dst_dentry = { let dirname = dirname.to_string_lossy(); if dirname.is_empty() { return_errno_with_message!(Errno::ENOENT, "dirname is empty"); } let fs_path = FsPath::new(AT_FDCWD, dirname.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; if mount_flags.contains(MountFlags::MS_REMOUNT) && mount_flags.contains(MountFlags::MS_BIND) { @@ -53,6 +52,7 @@ pub fn sys_mount( devname, dst_dentry, mount_flags.contains(MountFlags::MS_REC), + ctx, )?; } else if mount_flags.contains(MountFlags::MS_SHARED) | mount_flags.contains(MountFlags::MS_PRIVATE) @@ -61,7 +61,7 @@ pub fn sys_mount( { do_change_type()?; } else if mount_flags.contains(MountFlags::MS_MOVE) { - do_move_mount_old(devname, dst_dentry)?; + do_move_mount_old(devname, dst_dentry, ctx)?; } else { do_new_mount(devname, fstype_addr, dst_dentry)?; } @@ -81,15 +81,19 @@ fn do_remount() -> Result<()> { /// /// If recursive is true, then bind the mount recursively. /// Such as use user command `mount --rbind src dst`. -fn do_bind_mount(src_name: CString, dst_dentry: Arc, recursive: bool) -> Result<()> { - let current = current!(); +fn do_bind_mount( + src_name: CString, + dst_dentry: Arc, + recursive: bool, + ctx: &Context, +) -> Result<()> { let src_dentry = { let src_name = src_name.to_string_lossy(); if src_name.is_empty() { return_errno_with_message!(Errno::ENOENT, "src_name is empty"); } let fs_path = FsPath::new(AT_FDCWD, src_name.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; if src_dentry.type_() != InodeType::Dir { @@ -105,15 +109,14 @@ fn do_change_type() -> Result<()> { } /// Move a mount from src location to dst location. -fn do_move_mount_old(src_name: CString, dst_dentry: Arc) -> Result<()> { - let current = current!(); +fn do_move_mount_old(src_name: CString, dst_dentry: Arc, ctx: &Context) -> Result<()> { let src_dentry = { let src_name = src_name.to_string_lossy(); if src_name.is_empty() { return_errno_with_message!(Errno::ENOENT, "src_name is empty"); } let fs_path = FsPath::new(AT_FDCWD, src_name.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; if !src_dentry.is_root_of_mount() { diff --git a/kernel/aster-nix/src/syscall/mprotect.rs b/kernel/aster-nix/src/syscall/mprotect.rs index da0e258ac..c06348b98 100644 --- a/kernel/aster-nix/src/syscall/mprotect.rs +++ b/kernel/aster-nix/src/syscall/mprotect.rs @@ -5,14 +5,13 @@ use align_ext::AlignExt; use super::SyscallReturn; use crate::{prelude::*, vm::perms::VmPerms}; -pub fn sys_mprotect(addr: Vaddr, len: usize, perms: u64, _ctx: &Context) -> Result { +pub fn sys_mprotect(addr: Vaddr, len: usize, perms: u64, ctx: &Context) -> Result { let vm_perms = VmPerms::from_bits_truncate(perms as u32); debug!( "addr = 0x{:x}, len = 0x{:x}, perms = {:?}", addr, len, vm_perms ); - let current = current!(); - let root_vmar = current.root_vmar(); + let root_vmar = ctx.process.root_vmar(); debug_assert!(addr % PAGE_SIZE == 0); let len = len.align_up(PAGE_SIZE); let range = addr..(addr + len); diff --git a/kernel/aster-nix/src/syscall/munmap.rs b/kernel/aster-nix/src/syscall/munmap.rs index b057365be..7823c3c07 100644 --- a/kernel/aster-nix/src/syscall/munmap.rs +++ b/kernel/aster-nix/src/syscall/munmap.rs @@ -5,10 +5,9 @@ use align_ext::AlignExt; use super::SyscallReturn; use crate::prelude::*; -pub fn sys_munmap(addr: Vaddr, len: usize, _ctx: &Context) -> Result { +pub fn sys_munmap(addr: Vaddr, len: usize, ctx: &Context) -> Result { debug!("addr = 0x{:x}, len = {}", addr, len); - let current = current!(); - let root_vmar = current.root_vmar(); + let root_vmar = ctx.process.root_vmar(); let len = len.align_up(PAGE_SIZE); debug!("unmap range = 0x{:x} - 0x{:x}", addr, addr + len); root_vmar.destroy(addr..addr + len)?; diff --git a/kernel/aster-nix/src/syscall/nanosleep.rs b/kernel/aster-nix/src/syscall/nanosleep.rs index e2b01161a..f430ade23 100644 --- a/kernel/aster-nix/src/syscall/nanosleep.rs +++ b/kernel/aster-nix/src/syscall/nanosleep.rs @@ -12,7 +12,7 @@ use crate::{ pub fn sys_nanosleep( request_timespec_addr: Vaddr, remain_timespec_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let clockid = ClockId::CLOCK_MONOTONIC; @@ -21,6 +21,7 @@ pub fn sys_nanosleep( false, request_timespec_addr, remain_timespec_addr, + ctx, ) } @@ -29,7 +30,7 @@ pub fn sys_clock_nanosleep( flags: i32, request_timespec_addr: Vaddr, remain_timespec_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let is_abs_time = if flags == 0 { false @@ -44,6 +45,7 @@ pub fn sys_clock_nanosleep( is_abs_time, request_timespec_addr, remain_timespec_addr, + ctx, ) } @@ -52,6 +54,7 @@ fn do_clock_nanosleep( is_abs_time: bool, request_timespec_addr: Vaddr, remain_timespec_addr: Vaddr, + ctx: &Context, ) -> Result { let request_time = { let timespec = CurrentUserSpace::get().read_val::(request_timespec_addr)?; @@ -63,7 +66,7 @@ fn do_clock_nanosleep( clockid, is_abs_time, request_time, remain_timespec_addr ); - let start_time = read_clock(clockid)?; + let start_time = read_clock(clockid, ctx)?; let timeout = if is_abs_time { if request_time < start_time { return Ok(SyscallReturn::Return(0)); @@ -82,7 +85,7 @@ fn do_clock_nanosleep( match res { Err(e) if e.error() == Errno::ETIME => Ok(SyscallReturn::Return(0)), Err(e) if e.error() == Errno::EINTR => { - let end_time = read_clock(clockid)?; + let end_time = read_clock(clockid, ctx)?; if end_time >= start_time + timeout { return Ok(SyscallReturn::Return(0)); diff --git a/kernel/aster-nix/src/syscall/open.rs b/kernel/aster-nix/src/syscall/open.rs index 6c8e7e0e3..f66ade271 100644 --- a/kernel/aster-nix/src/syscall/open.rs +++ b/kernel/aster-nix/src/syscall/open.rs @@ -16,7 +16,7 @@ pub fn sys_openat( path_addr: Vaddr, flags: u32, mode: u16, - _ctx: &Context, + ctx: &Context, ) -> Result { let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?; debug!( @@ -24,7 +24,7 @@ pub fn sys_openat( dirfd, path, flags, mode ); - let current = current!(); + let current = ctx.process; let file_handle = { let path = path.to_string_lossy(); let fs_path = FsPath::new(dirfd, path.as_ref())?; diff --git a/kernel/aster-nix/src/syscall/pipe.rs b/kernel/aster-nix/src/syscall/pipe.rs index 9fd74f316..a3556620e 100644 --- a/kernel/aster-nix/src/syscall/pipe.rs +++ b/kernel/aster-nix/src/syscall/pipe.rs @@ -10,7 +10,7 @@ use crate::{ prelude::*, }; -pub fn sys_pipe2(fds: Vaddr, flags: u32, _ctx: &Context) -> Result { +pub fn sys_pipe2(fds: Vaddr, flags: u32, ctx: &Context) -> Result { debug!("flags: {:?}", flags); let (pipe_reader, pipe_writer) = { @@ -30,8 +30,7 @@ pub fn sys_pipe2(fds: Vaddr, flags: u32, _ctx: &Context) -> Result Result { +pub fn sys_poll(fds: Vaddr, nfds: u64, timeout: i32, ctx: &Context) -> Result { let user_space = CurrentUserSpace::get(); let poll_fds = { let mut read_addr = fds; @@ -31,7 +31,7 @@ pub fn sys_poll(fds: Vaddr, nfds: u64, timeout: i32, _ctx: &Context) -> Result Result) -> Result { +pub fn do_poll(poll_fds: &[PollFd], timeout: Option, ctx: &Context) -> Result { // The main loop of polling let mut poller = Poller::new(); loop { @@ -59,9 +59,8 @@ pub fn do_poll(poll_fds: &[PollFd], timeout: Option) -> Result }; // Poll the file - let current = current!(); let file = { - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() }; let need_poller = if num_revents == 0 { diff --git a/kernel/aster-nix/src/syscall/prctl.rs b/kernel/aster-nix/src/syscall/prctl.rs index 72dcbd56c..763624b6b 100644 --- a/kernel/aster-nix/src/syscall/prctl.rs +++ b/kernel/aster-nix/src/syscall/prctl.rs @@ -15,7 +15,7 @@ pub fn sys_prctl( arg3: u64, arg4: u64, arg5: u64, - _ctx: &Context, + ctx: &Context, ) -> Result { let prctl_cmd = PrctlCmd::from_args(option, arg2, arg3, arg4, arg5)?; debug!("prctl cmd = {:x?}", prctl_cmd); @@ -23,14 +23,11 @@ pub fn sys_prctl( let posix_thread = current_thread.as_posix_thread().unwrap(); match prctl_cmd { PrctlCmd::PR_SET_PDEATHSIG(signum) => { - let current = current!(); - current.set_parent_death_signal(signum); + ctx.process.set_parent_death_signal(signum); } PrctlCmd::PR_GET_PDEATHSIG(write_to_addr) => { let write_val = { - let current = current!(); - - match current.parent_death_signal() { + match ctx.process.parent_death_signal() { None => 0i32, Some(signum) => signum.as_u8() as i32, } diff --git a/kernel/aster-nix/src/syscall/pread64.rs b/kernel/aster-nix/src/syscall/pread64.rs index a2caf2fc1..9c058bd25 100644 --- a/kernel/aster-nix/src/syscall/pread64.rs +++ b/kernel/aster-nix/src/syscall/pread64.rs @@ -8,7 +8,7 @@ pub fn sys_pread64( user_buf_ptr: Vaddr, user_buf_len: usize, offset: i64, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, buf = 0x{:x}, user_buf_len = 0x{:x}, offset = 0x{:x}", @@ -19,8 +19,7 @@ pub fn sys_pread64( return_errno_with_message!(Errno::EINVAL, "offset cannot be negative"); } let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; // TODO: Check (f.file->f_mode & FMODE_PREAD); We don't have f_mode in our FileLike trait diff --git a/kernel/aster-nix/src/syscall/preadv.rs b/kernel/aster-nix/src/syscall/preadv.rs index d1b07686a..42209e30b 100644 --- a/kernel/aster-nix/src/syscall/preadv.rs +++ b/kernel/aster-nix/src/syscall/preadv.rs @@ -11,9 +11,9 @@ pub fn sys_readv( fd: FileDesc, io_vec_ptr: Vaddr, io_vec_count: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { - let res = do_sys_readv(fd, io_vec_ptr, io_vec_count)?; + let res = do_sys_readv(fd, io_vec_ptr, io_vec_count, ctx)?; Ok(SyscallReturn::Return(res as _)) } @@ -22,9 +22,9 @@ pub fn sys_preadv( io_vec_ptr: Vaddr, io_vec_count: usize, offset: i64, - _ctx: &Context, + ctx: &Context, ) -> Result { - let res = do_sys_preadv(fd, io_vec_ptr, io_vec_count, offset, RWFFlag::empty())?; + let res = do_sys_preadv(fd, io_vec_ptr, io_vec_count, offset, RWFFlag::empty(), ctx)?; Ok(SyscallReturn::Return(res as _)) } @@ -34,16 +34,16 @@ pub fn sys_preadv2( io_vec_count: usize, offset: i64, flags: u32, - _ctx: &Context, + ctx: &Context, ) -> Result { let flags = match RWFFlag::from_bits(flags) { Some(flags) => flags, None => return_errno_with_message!(Errno::EINVAL, "invalid flags"), }; let res = if offset == -1 { - do_sys_readv(fd, io_vec_ptr, io_vec_count)? + do_sys_readv(fd, io_vec_ptr, io_vec_count, ctx)? } else { - do_sys_preadv(fd, io_vec_ptr, io_vec_count, offset, flags)? + do_sys_preadv(fd, io_vec_ptr, io_vec_count, offset, flags, ctx)? }; Ok(SyscallReturn::Return(res as _)) } @@ -54,6 +54,7 @@ fn do_sys_preadv( io_vec_count: usize, offset: i64, _flags: RWFFlag, + ctx: &Context, ) -> Result { debug!( "preadv: fd = {}, io_vec_ptr = 0x{:x}, io_vec_counter = 0x{:x}, offset = 0x{:x}", @@ -65,8 +66,7 @@ fn do_sys_preadv( } let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; @@ -125,15 +125,19 @@ fn do_sys_preadv( Ok(total_len) } -fn do_sys_readv(fd: FileDesc, io_vec_ptr: Vaddr, io_vec_count: usize) -> Result { +fn do_sys_readv( + fd: FileDesc, + io_vec_ptr: Vaddr, + io_vec_count: usize, + ctx: &Context, +) -> Result { debug!( "fd = {}, io_vec_ptr = 0x{:x}, io_vec_counter = 0x{:x}", fd, io_vec_ptr, io_vec_count ); let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; diff --git a/kernel/aster-nix/src/syscall/prlimit64.rs b/kernel/aster-nix/src/syscall/prlimit64.rs index a7d4df467..d83b5e180 100644 --- a/kernel/aster-nix/src/syscall/prlimit64.rs +++ b/kernel/aster-nix/src/syscall/prlimit64.rs @@ -11,15 +11,14 @@ pub fn sys_prlimit64( resource: u32, new_rlim_addr: Vaddr, old_rlim_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let resource = ResourceType::try_from(resource)?; debug!( "pid = {}, resource = {:?}, new_rlim_addr = 0x{:x}, old_rlim_addr = 0x{:x}", pid, resource, new_rlim_addr, old_rlim_addr ); - let current = current!(); - let mut resource_limits = current.resource_limits().lock(); + let mut resource_limits = ctx.process.resource_limits().lock(); if old_rlim_addr != 0 { let rlimit = resource_limits.get_rlimit(resource); CurrentUserSpace::get().write_val(old_rlim_addr, rlimit)?; diff --git a/kernel/aster-nix/src/syscall/pselect6.rs b/kernel/aster-nix/src/syscall/pselect6.rs index 4f8160247..c409babcc 100644 --- a/kernel/aster-nix/src/syscall/pselect6.rs +++ b/kernel/aster-nix/src/syscall/pselect6.rs @@ -4,10 +4,7 @@ use core::{sync::atomic::Ordering, time::Duration}; use super::{select::do_sys_select, SyscallReturn}; use crate::{ - fs::file_table::FileDesc, - prelude::*, - process::{posix_thread::PosixThreadExt, signal::sig_mask::SigMask}, - time::timespec_t, + fs::file_table::FileDesc, prelude::*, process::signal::sig_mask::SigMask, time::timespec_t, }; pub fn sys_pselect6( @@ -17,11 +14,8 @@ pub fn sys_pselect6( exceptfds_addr: Vaddr, timespec_addr: Vaddr, sigmask_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { - let current_thread = current_thread!(); - let posix_thread = current_thread.as_posix_thread().unwrap(); - let user_space = CurrentUserSpace::get(); let old_simask = if sigmask_addr != 0 { let sigmask_with_size: SigMaskWithSize = user_space.read_val(sigmask_addr)?; @@ -29,7 +23,8 @@ pub fn sys_pselect6( if !sigmask_with_size.is_valid() { return_errno_with_message!(Errno::EINVAL, "sigmask size is invalid") } - let old_sigmask = posix_thread + let old_sigmask = ctx + .posix_thread .sig_mask() .swap(sigmask_with_size.sigmask, Ordering::Relaxed); @@ -45,10 +40,19 @@ pub fn sys_pselect6( None }; - let res = do_sys_select(nfds, readfds_addr, writefds_addr, exceptfds_addr, timeout); + let res = do_sys_select( + nfds, + readfds_addr, + writefds_addr, + exceptfds_addr, + timeout, + ctx, + ); if let Some(old_mask) = old_simask { - posix_thread.sig_mask().store(old_mask, Ordering::Relaxed); + ctx.posix_thread + .sig_mask() + .store(old_mask, Ordering::Relaxed); } res diff --git a/kernel/aster-nix/src/syscall/pwrite64.rs b/kernel/aster-nix/src/syscall/pwrite64.rs index 76e7177b0..335545b7a 100644 --- a/kernel/aster-nix/src/syscall/pwrite64.rs +++ b/kernel/aster-nix/src/syscall/pwrite64.rs @@ -8,7 +8,7 @@ pub fn sys_pwrite64( user_buf_ptr: Vaddr, user_buf_len: usize, offset: i64, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, user_buf_ptr = 0x{:x}, user_buf_len = 0x{:x}, offset = 0x{:x}", @@ -18,8 +18,7 @@ pub fn sys_pwrite64( return_errno_with_message!(Errno::EINVAL, "offset cannot be negative"); } let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; // TODO: Check (f.file->f_mode & FMODE_PWRITE); We don't have f_mode in our FileLike trait diff --git a/kernel/aster-nix/src/syscall/pwritev.rs b/kernel/aster-nix/src/syscall/pwritev.rs index a0b7113ca..833025a45 100644 --- a/kernel/aster-nix/src/syscall/pwritev.rs +++ b/kernel/aster-nix/src/syscall/pwritev.rs @@ -7,9 +7,9 @@ pub fn sys_writev( fd: FileDesc, io_vec_ptr: Vaddr, io_vec_count: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { - let res = do_sys_writev(fd, io_vec_ptr, io_vec_count)?; + let res = do_sys_writev(fd, io_vec_ptr, io_vec_count, ctx)?; Ok(SyscallReturn::Return(res as _)) } @@ -18,9 +18,9 @@ pub fn sys_pwritev( io_vec_ptr: Vaddr, io_vec_count: usize, offset: i64, - _ctx: &Context, + ctx: &Context, ) -> Result { - let res = do_sys_pwritev(fd, io_vec_ptr, io_vec_count, offset, RWFFlag::empty())?; + let res = do_sys_pwritev(fd, io_vec_ptr, io_vec_count, offset, RWFFlag::empty(), ctx)?; Ok(SyscallReturn::Return(res as _)) } @@ -30,16 +30,16 @@ pub fn sys_pwritev2( io_vec_count: usize, offset: i64, flags: u32, - _ctx: &Context, + ctx: &Context, ) -> Result { let flags = match RWFFlag::from_bits(flags) { Some(flags) => flags, None => return_errno_with_message!(Errno::EINVAL, "invalid flags"), }; let res = if offset == -1 { - do_sys_writev(fd, io_vec_ptr, io_vec_count)? + do_sys_writev(fd, io_vec_ptr, io_vec_count, ctx)? } else { - do_sys_pwritev(fd, io_vec_ptr, io_vec_count, offset, flags)? + do_sys_pwritev(fd, io_vec_ptr, io_vec_count, offset, flags, ctx)? }; Ok(SyscallReturn::Return(res as _)) } @@ -50,6 +50,7 @@ fn do_sys_pwritev( io_vec_count: usize, offset: i64, _flags: RWFFlag, + ctx: &Context, ) -> Result { // TODO: Implement flags support debug!( @@ -60,8 +61,7 @@ fn do_sys_pwritev( return_errno_with_message!(Errno::EINVAL, "offset cannot be negative"); } let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; // TODO: Check (f.file->f_mode & FMODE_PREAD); We don't have f_mode in our FileLike trait @@ -110,14 +110,18 @@ fn do_sys_pwritev( Ok(total_len) } -fn do_sys_writev(fd: FileDesc, io_vec_ptr: Vaddr, io_vec_count: usize) -> Result { +fn do_sys_writev( + fd: FileDesc, + io_vec_ptr: Vaddr, + io_vec_count: usize, + ctx: &Context, +) -> Result { debug!( "fd = {}, io_vec_ptr = 0x{:x}, io_vec_counter = 0x{:x}", fd, io_vec_ptr, io_vec_count ); let file = { - let current = current!(); - let filetable = current.file_table().lock(); + let filetable = ctx.process.file_table().lock(); filetable.get_file(fd)?.clone() }; let mut total_len = 0; diff --git a/kernel/aster-nix/src/syscall/read.rs b/kernel/aster-nix/src/syscall/read.rs index 1a5af9d4d..502bc2aa8 100644 --- a/kernel/aster-nix/src/syscall/read.rs +++ b/kernel/aster-nix/src/syscall/read.rs @@ -9,7 +9,7 @@ pub fn sys_read( fd: FileDesc, user_buf_addr: Vaddr, buf_len: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, user_buf_ptr = 0x{:x}, buf_len = 0x{:x}", @@ -17,8 +17,7 @@ pub fn sys_read( ); let file = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() }; diff --git a/kernel/aster-nix/src/syscall/readlink.rs b/kernel/aster-nix/src/syscall/readlink.rs index 317183758..365f743f5 100644 --- a/kernel/aster-nix/src/syscall/readlink.rs +++ b/kernel/aster-nix/src/syscall/readlink.rs @@ -15,7 +15,7 @@ pub fn sys_readlinkat( path_addr: Vaddr, usr_buf_addr: Vaddr, usr_buf_len: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { let user_space = CurrentUserSpace::get(); let path = user_space.read_cstring(path_addr, MAX_FILENAME_LEN)?; @@ -24,14 +24,13 @@ pub fn sys_readlinkat( dirfd, path, usr_buf_addr, usr_buf_len ); - let current = current!(); let dentry = { let path = path.to_string_lossy(); if path.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); } let fs_path = FsPath::new(dirfd, path.as_ref())?; - current.fs().read().lookup_no_follow(&fs_path)? + ctx.process.fs().read().lookup_no_follow(&fs_path)? }; let linkpath = dentry.inode().read_link()?; let bytes = linkpath.as_bytes(); diff --git a/kernel/aster-nix/src/syscall/rename.rs b/kernel/aster-nix/src/syscall/rename.rs index 10dd1aae2..5a117d604 100644 --- a/kernel/aster-nix/src/syscall/rename.rs +++ b/kernel/aster-nix/src/syscall/rename.rs @@ -16,7 +16,7 @@ pub fn sys_renameat( old_path_addr: Vaddr, new_dirfd: FileDesc, new_path_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let user_space = CurrentUserSpace::get(); let old_path = user_space.read_cstring(old_path_addr, MAX_FILENAME_LEN)?; @@ -26,8 +26,7 @@ pub fn sys_renameat( old_dirfd, old_path, new_dirfd, new_path ); - let current = current!(); - let fs = current.fs().read(); + let fs = ctx.process.fs().read(); let (old_dir_dentry, old_name) = { let old_path = old_path.to_string_lossy(); diff --git a/kernel/aster-nix/src/syscall/rmdir.rs b/kernel/aster-nix/src/syscall/rmdir.rs index a780dc996..f3c3af86b 100644 --- a/kernel/aster-nix/src/syscall/rmdir.rs +++ b/kernel/aster-nix/src/syscall/rmdir.rs @@ -17,19 +17,18 @@ pub fn sys_rmdir(path_addr: Vaddr, ctx: &Context) -> Result { pub(super) fn sys_rmdirat( dirfd: FileDesc, path_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let path_addr = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?; debug!("dirfd = {}, path_addr = {:?}", dirfd, path_addr); - let current = current!(); let (dir_dentry, name) = { let path_addr = path_addr.to_string_lossy(); if path_addr == "/" { return_errno_with_message!(Errno::EBUSY, "is root directory"); } let fs_path = FsPath::new(dirfd, path_addr.as_ref())?; - current.fs().read().lookup_dir_and_base_name(&fs_path)? + ctx.process.fs().read().lookup_dir_and_base_name(&fs_path)? }; dir_dentry.rmdir(name.trim_end_matches('/'))?; Ok(SyscallReturn::Return(0)) diff --git a/kernel/aster-nix/src/syscall/rt_sigaction.rs b/kernel/aster-nix/src/syscall/rt_sigaction.rs index 86c55383f..30ed34078 100644 --- a/kernel/aster-nix/src/syscall/rt_sigaction.rs +++ b/kernel/aster-nix/src/syscall/rt_sigaction.rs @@ -11,7 +11,7 @@ pub fn sys_rt_sigaction( sig_action_addr: Vaddr, old_sig_action_addr: Vaddr, sigset_size: u64, - _ctx: &Context, + ctx: &Context, ) -> Result { let sig_num = SigNum::try_from(sig_num)?; debug!( @@ -21,8 +21,7 @@ pub fn sys_rt_sigaction( old_sig_action_addr, sigset_size ); - let current = current!(); - let mut sig_dispositions = current.sig_dispositions().lock(); + let mut sig_dispositions = ctx.process.sig_dispositions().lock(); let old_action = sig_dispositions.get(sig_num); let old_action_c = old_action.as_c_type(); if old_sig_action_addr != 0 { diff --git a/kernel/aster-nix/src/syscall/select.rs b/kernel/aster-nix/src/syscall/select.rs index 4ae5a8edb..f708c5e75 100644 --- a/kernel/aster-nix/src/syscall/select.rs +++ b/kernel/aster-nix/src/syscall/select.rs @@ -14,7 +14,7 @@ pub fn sys_select( writefds_addr: Vaddr, exceptfds_addr: Vaddr, timeval_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let timeout = if timeval_addr == 0 { None @@ -23,7 +23,14 @@ pub fn sys_select( Some(Duration::from(timeval)) }; - do_sys_select(nfds, readfds_addr, writefds_addr, exceptfds_addr, timeout) + do_sys_select( + nfds, + readfds_addr, + writefds_addr, + exceptfds_addr, + timeout, + ctx, + ) } pub fn do_sys_select( @@ -32,6 +39,7 @@ pub fn do_sys_select( writefds_addr: Vaddr, exceptfds_addr: Vaddr, timeout: Option, + ctx: &Context, ) -> Result { if nfds < 0 || nfds as usize > FD_SETSIZE { return_errno_with_message!(Errno::EINVAL, "nfds is negative or exceeds the FD_SETSIZE"); @@ -62,6 +70,7 @@ pub fn do_sys_select( writefds.as_mut(), exceptfds.as_mut(), timeout, + ctx, )?; // FIXME: The Linux select() and pselect6() system call @@ -89,6 +98,7 @@ fn do_select( mut writefds: Option<&mut FdSet>, mut exceptfds: Option<&mut FdSet>, timeout: Option, + ctx: &Context, ) -> Result { // Convert the FdSet to an array of PollFd let poll_fds = { @@ -123,7 +133,7 @@ fn do_select( } // Do the poll syscall that is equivalent to the select syscall - let num_revents = do_poll(&poll_fds, timeout)?; + let num_revents = do_poll(&poll_fds, timeout, ctx)?; if num_revents == 0 { return Ok(0); } diff --git a/kernel/aster-nix/src/syscall/sendfile.rs b/kernel/aster-nix/src/syscall/sendfile.rs index 24031c78b..74de7fa41 100644 --- a/kernel/aster-nix/src/syscall/sendfile.rs +++ b/kernel/aster-nix/src/syscall/sendfile.rs @@ -8,7 +8,7 @@ pub fn sys_sendfile( in_fd: FileDesc, offset_ptr: Vaddr, count: isize, - _ctx: &Context, + ctx: &Context, ) -> Result { trace!("raw offset ptr = 0x{:x}", offset_ptr); @@ -34,8 +34,7 @@ pub fn sys_sendfile( }; let (out_file, in_file) = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let out_file = file_table.get_file(out_fd)?.clone(); // FIXME: the in_file must support mmap-like operations (i.e., it cannot be a socket). let in_file = file_table.get_file(in_fd)?.clone(); diff --git a/kernel/aster-nix/src/syscall/set_get_priority.rs b/kernel/aster-nix/src/syscall/set_get_priority.rs index 7d3ee8452..4c359c117 100644 --- a/kernel/aster-nix/src/syscall/set_get_priority.rs +++ b/kernel/aster-nix/src/syscall/set_get_priority.rs @@ -9,8 +9,8 @@ use crate::{ sched::nice::Nice, }; -pub fn sys_set_priority(which: i32, who: u32, prio: i32, _ctx: &Context) -> Result { - let prio_target = PriorityTarget::new(which, who)?; +pub fn sys_set_priority(which: i32, who: u32, prio: i32, ctx: &Context) -> Result { + let prio_target = PriorityTarget::new(which, who, ctx)?; let new_nice = { let norm_prio = prio.clamp(i8::MIN as i32, i8::MAX as i32) as i8; Nice::new(norm_prio) @@ -29,8 +29,8 @@ pub fn sys_set_priority(which: i32, who: u32, prio: i32, _ctx: &Context) -> Resu Ok(SyscallReturn::Return(0)) } -pub fn sys_get_priority(which: i32, who: u32, _ctx: &Context) -> Result { - let prio_target = PriorityTarget::new(which, who)?; +pub fn sys_get_priority(which: i32, who: u32, ctx: &Context) -> Result { + let prio_target = PriorityTarget::new(which, who, ctx)?; debug!("get_priority prio_target: {:?}", prio_target); let processes = get_processes(prio_target)?; @@ -98,13 +98,13 @@ enum PriorityTarget { } impl PriorityTarget { - fn new(which: i32, who: u32) -> Result { + fn new(which: i32, who: u32, ctx: &Context) -> Result { let which = Which::try_from(which) .map_err(|_| Error::with_message(Errno::EINVAL, "invalid which value"))?; Ok(match which { Which::PRIO_PROCESS => { let pid = if who == 0 { - current!().pid() + ctx.process.pid() } else { who as Pid }; @@ -112,7 +112,7 @@ impl PriorityTarget { } Which::PRIO_PGRP => { let pgid = if who == 0 { - current!().pgid() + ctx.process.pgid() } else { who as Pgid }; @@ -120,11 +120,7 @@ impl PriorityTarget { } Which::PRIO_USER => { let uid = if who == 0 { - current_thread!() - .as_posix_thread() - .unwrap() - .credentials() - .ruid() + ctx.posix_thread.credentials().ruid() } else { Uid::new(who) }; diff --git a/kernel/aster-nix/src/syscall/setitimer.rs b/kernel/aster-nix/src/syscall/setitimer.rs index 380b66d8d..0b1ea7d72 100644 --- a/kernel/aster-nix/src/syscall/setitimer.rs +++ b/kernel/aster-nix/src/syscall/setitimer.rs @@ -22,7 +22,7 @@ pub fn sys_setitimer( itimer_type: i32, new_itimerval_addr: Vaddr, old_itimerval_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "itimer_type = {}, new_itimerval_addr = 0x{:x}, old_itimerval_addr = 0x{:x}, ", @@ -32,13 +32,12 @@ pub fn sys_setitimer( if new_itimerval_addr == 0 { return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value"); } - let current = current!(); let user_space = CurrentUserSpace::get(); let new_itimerval = user_space.read_val::(new_itimerval_addr)?; let interval = Duration::from(new_itimerval.it_interval); let expire_time = Duration::from(new_itimerval.it_value); - let process_timer_manager = current.timer_manager(); + let process_timer_manager = ctx.process.timer_manager(); let timer = match ItimerType::try_from(itimer_type)? { ItimerType::ITIMER_REAL => process_timer_manager.alarm_timer(), ItimerType::ITIMER_VIRTUAL => process_timer_manager.virtual_timer(), @@ -69,7 +68,7 @@ pub fn sys_setitimer( pub fn sys_getitimer( itimer_type: i32, itimerval_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "itimer_type = {}, itimerval_addr = 0x{:x}", @@ -80,8 +79,7 @@ pub fn sys_getitimer( return_errno_with_message!(Errno::EINVAL, "invalid pointer to itimerval"); } - let current = current!(); - let process_timer_manager = current.timer_manager(); + let process_timer_manager = ctx.process.timer_manager(); let timer = match ItimerType::try_from(itimer_type)? { ItimerType::ITIMER_REAL => process_timer_manager.alarm_timer(), ItimerType::ITIMER_VIRTUAL => process_timer_manager.virtual_timer(), diff --git a/kernel/aster-nix/src/syscall/setpgid.rs b/kernel/aster-nix/src/syscall/setpgid.rs index 6afd2bd82..991538a41 100644 --- a/kernel/aster-nix/src/syscall/setpgid.rs +++ b/kernel/aster-nix/src/syscall/setpgid.rs @@ -6,8 +6,8 @@ use crate::{ process::{process_table, Pgid, Pid}, }; -pub fn sys_setpgid(pid: Pid, pgid: Pgid, _ctx: &Context) -> Result { - let current = current!(); +pub fn sys_setpgid(pid: Pid, pgid: Pgid, ctx: &Context) -> Result { + let current = ctx.process; // if pid is 0, pid should be the pid of current process let pid = if pid == 0 { current.pid() } else { pid }; // if pgid is 0, pgid should be pid diff --git a/kernel/aster-nix/src/syscall/socket.rs b/kernel/aster-nix/src/syscall/socket.rs index d01d138e4..9bc51756c 100644 --- a/kernel/aster-nix/src/syscall/socket.rs +++ b/kernel/aster-nix/src/syscall/socket.rs @@ -12,7 +12,7 @@ use crate::{ util::net::{CSocketAddrFamily, Protocol, SockFlags, SockType, SOCK_TYPE_MASK}, }; -pub fn sys_socket(domain: i32, type_: i32, protocol: i32, _ctx: &Context) -> Result { +pub fn sys_socket(domain: i32, type_: i32, protocol: i32, ctx: &Context) -> Result { let domain = CSocketAddrFamily::try_from(domain)?; let sock_type = SockType::try_from(type_ & SOCK_TYPE_MASK)?; let sock_flags = SockFlags::from_bits_truncate(type_ & !SOCK_TYPE_MASK); @@ -43,8 +43,7 @@ pub fn sys_socket(domain: i32, type_: i32, protocol: i32, _ctx: &Context) -> Res _ => return_errno_with_message!(Errno::EAFNOSUPPORT, "unsupported domain"), }; let fd = { - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let fd_flags = if sock_flags.contains(SockFlags::SOCK_CLOEXEC) { FdFlags::CLOEXEC } else { diff --git a/kernel/aster-nix/src/syscall/socketpair.rs b/kernel/aster-nix/src/syscall/socketpair.rs index 921c10864..9ec9fa272 100644 --- a/kernel/aster-nix/src/syscall/socketpair.rs +++ b/kernel/aster-nix/src/syscall/socketpair.rs @@ -13,7 +13,7 @@ pub fn sys_socketpair( type_: i32, protocol: i32, sv: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let domain = CSocketAddrFamily::try_from(domain)?; let sock_type = SockType::try_from(type_ & SOCK_TYPE_MASK)?; @@ -37,8 +37,7 @@ pub fn sys_socketpair( }; let socket_fds = { - let current = current!(); - let mut file_table = current.file_table().lock(); + let mut file_table = ctx.process.file_table().lock(); let fd_flags = if sock_flags.contains(SockFlags::SOCK_CLOEXEC) { FdFlags::CLOEXEC } else { diff --git a/kernel/aster-nix/src/syscall/stat.rs b/kernel/aster-nix/src/syscall/stat.rs index 69b2c9ce4..136c93e5f 100644 --- a/kernel/aster-nix/src/syscall/stat.rs +++ b/kernel/aster-nix/src/syscall/stat.rs @@ -12,11 +12,10 @@ use crate::{ time::timespec_t, }; -pub fn sys_fstat(fd: FileDesc, stat_buf_ptr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_fstat(fd: FileDesc, stat_buf_ptr: Vaddr, ctx: &Context) -> Result { debug!("fd = {}, stat_buf_addr = 0x{:x}", fd, stat_buf_ptr); - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let stat = Stat::from(file.metadata()); CurrentUserSpace::get().write_val(stat_buf_ptr, &stat)?; @@ -61,11 +60,10 @@ pub fn sys_fstatat( return self::sys_fstat(dirfd, stat_buf_ptr, ctx); } - let current = current!(); let dentry = { let filename = filename.to_string_lossy(); let fs_path = FsPath::new(dirfd, filename.as_ref())?; - let fs = current.fs().read(); + let fs = ctx.process.fs().read(); if flags.contains(StatFlags::AT_SYMLINK_NOFOLLOW) { fs.lookup_no_follow(&fs_path)? } else { diff --git a/kernel/aster-nix/src/syscall/statfs.rs b/kernel/aster-nix/src/syscall/statfs.rs index 0228821b2..65d5d2014 100644 --- a/kernel/aster-nix/src/syscall/statfs.rs +++ b/kernel/aster-nix/src/syscall/statfs.rs @@ -11,27 +11,25 @@ use crate::{ prelude::*, }; -pub fn sys_statfs(path_ptr: Vaddr, statfs_buf_ptr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_statfs(path_ptr: Vaddr, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result { let user_space = CurrentUserSpace::get(); let path = user_space.read_cstring(path_ptr, PATH_MAX)?; debug!("path = {:?}, statfs_buf_ptr = 0x{:x}", path, statfs_buf_ptr,); - let current = current!(); let dentry = { let path = path.to_string_lossy(); let fs_path = FsPath::try_from(path.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; let statfs = Statfs::from(dentry.fs().sb()); user_space.write_val(statfs_buf_ptr, &statfs)?; Ok(SyscallReturn::Return(0)) } -pub fn sys_fstatfs(fd: FileDesc, statfs_buf_ptr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_fstatfs(fd: FileDesc, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result { debug!("fd = {}, statfs_buf_addr = 0x{:x}", fd, statfs_buf_ptr); - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; let inode_handle = file .downcast_ref::() diff --git a/kernel/aster-nix/src/syscall/symlink.rs b/kernel/aster-nix/src/syscall/symlink.rs index 0aeec9b75..e020f698e 100644 --- a/kernel/aster-nix/src/syscall/symlink.rs +++ b/kernel/aster-nix/src/syscall/symlink.rs @@ -15,7 +15,7 @@ pub fn sys_symlinkat( target_addr: Vaddr, dirfd: FileDesc, linkpath_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let user_space = CurrentUserSpace::get(); let target = user_space.read_cstring(target_addr, MAX_FILENAME_LEN)?; @@ -25,7 +25,6 @@ pub fn sys_symlinkat( target, dirfd, linkpath ); - let current = current!(); let target = target.to_string_lossy(); if target.is_empty() { return_errno_with_message!(Errno::ENOENT, "target is empty"); @@ -36,7 +35,7 @@ pub fn sys_symlinkat( return_errno_with_message!(Errno::ENOENT, "linkpath is empty"); } let fs_path = FsPath::new(dirfd, linkpath.as_ref())?; - current + ctx.process .fs() .read() .lookup_dir_and_new_basename(&fs_path, false)? diff --git a/kernel/aster-nix/src/syscall/tgkill.rs b/kernel/aster-nix/src/syscall/tgkill.rs index 24a88b739..15b7c9f39 100644 --- a/kernel/aster-nix/src/syscall/tgkill.rs +++ b/kernel/aster-nix/src/syscall/tgkill.rs @@ -24,7 +24,7 @@ pub fn sys_tgkill(tgid: Pid, tid: Tid, sig_num: u8, ctx: &Context) -> Result Result { if new_itimerspec_addr == 0 { return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value"); @@ -24,8 +24,7 @@ pub fn sys_timer_settime( let interval = Duration::try_from(new_itimerspec.it_interval)?; let expire_time = Duration::try_from(new_itimerspec.it_value)?; - let current_process = current!(); - let Some(timer) = current_process.timer_manager().find_posix_timer(timer_id) else { + let Some(timer) = ctx.process.timer_manager().find_posix_timer(timer_id) else { return_errno_with_message!(Errno::EINVAL, "invalid timer ID"); }; @@ -60,13 +59,12 @@ pub fn sys_timer_settime( pub fn sys_timer_gettime( timer_id: usize, itimerspec_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { if itimerspec_addr == 0 { return_errno_with_message!(Errno::EINVAL, "invalid pointer to return value"); } - let current_process = current!(); - let Some(timer) = current_process.timer_manager().find_posix_timer(timer_id) else { + let Some(timer) = ctx.process.timer_manager().find_posix_timer(timer_id) else { return_errno_with_message!(Errno::EINVAL, "invalid timer ID"); }; diff --git a/kernel/aster-nix/src/syscall/truncate.rs b/kernel/aster-nix/src/syscall/truncate.rs index ab4141c41..136f6a6ce 100644 --- a/kernel/aster-nix/src/syscall/truncate.rs +++ b/kernel/aster-nix/src/syscall/truncate.rs @@ -11,46 +11,43 @@ use crate::{ process::ResourceType, }; -pub fn sys_ftruncate(fd: FileDesc, len: isize, _ctx: &Context) -> Result { +pub fn sys_ftruncate(fd: FileDesc, len: isize, ctx: &Context) -> Result { debug!("fd = {}, lentgh = {}", fd, len); - check_length(len)?; + check_length(len, ctx)?; - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); let file = file_table.get_file(fd)?; file.resize(len as usize)?; Ok(SyscallReturn::Return(0)) } -pub fn sys_truncate(path_ptr: Vaddr, len: isize, _ctx: &Context) -> Result { +pub fn sys_truncate(path_ptr: Vaddr, len: isize, ctx: &Context) -> Result { let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?; debug!("path = {:?}, length = {}", path, len); - check_length(len)?; + check_length(len, ctx)?; - let current = current!(); let dir_dentry = { let path = path.to_string_lossy(); if path.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); } let fs_path = FsPath::new(AT_FDCWD, path.as_ref())?; - current.fs().read().lookup(&fs_path)? + ctx.process.fs().read().lookup(&fs_path)? }; dir_dentry.resize(len as usize)?; Ok(SyscallReturn::Return(0)) } #[inline] -fn check_length(len: isize) -> Result<()> { +fn check_length(len: isize, ctx: &Context) -> Result<()> { if len < 0 { return_errno_with_message!(Errno::EINVAL, "length is negative"); } let max_file_size = { - let current = current!(); - let resource_limits = current.resource_limits().lock(); + let resource_limits = ctx.process.resource_limits().lock(); resource_limits .get_rlimit(ResourceType::RLIMIT_FSIZE) .get_cur() as usize diff --git a/kernel/aster-nix/src/syscall/umask.rs b/kernel/aster-nix/src/syscall/umask.rs index 1429e333c..d9df5d3bd 100644 --- a/kernel/aster-nix/src/syscall/umask.rs +++ b/kernel/aster-nix/src/syscall/umask.rs @@ -3,9 +3,8 @@ use super::SyscallReturn; use crate::prelude::*; -pub fn sys_umask(mask: u16, _ctx: &Context) -> Result { +pub fn sys_umask(mask: u16, ctx: &Context) -> Result { debug!("mask = 0o{:o}", mask); - let current = current!(); - let old_mask = current.umask().write().set(mask); + let old_mask = ctx.process.umask().write().set(mask); Ok(SyscallReturn::Return(old_mask as _)) } diff --git a/kernel/aster-nix/src/syscall/umount.rs b/kernel/aster-nix/src/syscall/umount.rs index 22b991274..630b28460 100644 --- a/kernel/aster-nix/src/syscall/umount.rs +++ b/kernel/aster-nix/src/syscall/umount.rs @@ -7,14 +7,13 @@ use crate::{ syscall::constants::MAX_FILENAME_LEN, }; -pub fn sys_umount(path_addr: Vaddr, flags: u64, _ctx: &Context) -> Result { +pub fn sys_umount(path_addr: Vaddr, flags: u64, ctx: &Context) -> Result { let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?; let umount_flags = UmountFlags::from_bits_truncate(flags as u32); debug!("path = {:?}, flags = {:?}", path, umount_flags); umount_flags.check_unsupported_flags()?; - let current = current!(); let path = path.to_string_lossy(); if path.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); @@ -22,9 +21,9 @@ pub fn sys_umount(path_addr: Vaddr, flags: u64, _ctx: &Context) -> Result Result { debug!( "utimensat: dirfd: {}, pathname_ptr: {:#x}, timespecs_ptr: {:#x}, flags: {:#x}", @@ -41,7 +41,7 @@ pub fn sys_utimensat( } else { None }; - do_utimes(dirfd, pathname_ptr, times, flags) + do_utimes(dirfd, pathname_ptr, times, flags, ctx) } /// The 'sys_futimesat' system call sets the access and modification times of a file. @@ -51,32 +51,28 @@ pub fn sys_futimesat( dirfd: FileDesc, pathname_ptr: Vaddr, timeval_ptr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "futimesat: dirfd: {}, pathname_ptr: {:#x}, timeval_ptr: {:#x}", dirfd, pathname_ptr, timeval_ptr ); - do_futimesat(dirfd, pathname_ptr, timeval_ptr) + do_futimesat(dirfd, pathname_ptr, timeval_ptr, ctx) } /// The 'sys_utimes' system call sets the access and modification times of a file. /// It receives time values in the form of timeval structures like 'sys_futimesat', /// but it uses the current working directory as the base directory. -pub fn sys_utimes( - pathname_ptr: Vaddr, - timeval_ptr: Vaddr, - _ctx: &Context, -) -> Result { +pub fn sys_utimes(pathname_ptr: Vaddr, timeval_ptr: Vaddr, ctx: &Context) -> Result { debug!( "utimes: pathname_ptr: {:#x}, timeval_ptr: {:#x}", pathname_ptr, timeval_ptr ); - do_futimesat(AT_FDCWD, pathname_ptr, timeval_ptr) + do_futimesat(AT_FDCWD, pathname_ptr, timeval_ptr, ctx) } /// The 'sys_utime' system call is similar to 'sys_utimes' but uses the older 'utimbuf' structure to specify times. -pub fn sys_utime(pathname_ptr: Vaddr, utimbuf_ptr: Vaddr, _ctx: &Context) -> Result { +pub fn sys_utime(pathname_ptr: Vaddr, utimbuf_ptr: Vaddr, ctx: &Context) -> Result { debug!( "utime: pathname_ptr: {:#x}, utimbuf_ptr: {:#x}", pathname_ptr, utimbuf_ptr @@ -95,7 +91,7 @@ pub fn sys_utime(pathname_ptr: Vaddr, utimbuf_ptr: Vaddr, _ctx: &Context) -> Res } else { None }; - do_utimes(AT_FDCWD, pathname_ptr, times, 0) + do_utimes(AT_FDCWD, pathname_ptr, times, 0, ctx) } // Structure to hold access and modification times @@ -156,6 +152,7 @@ fn do_utimes( pathname_ptr: Vaddr, times: Option, flags: u32, + ctx: &Context, ) -> Result { let flags = UtimensFlags::from_bits(flags) .ok_or(Error::with_message(Errno::EINVAL, "invalid flags"))?; @@ -166,11 +163,10 @@ fn do_utimes( let cstring = CurrentUserSpace::get().read_cstring(pathname_ptr, MAX_FILENAME_LEN)?; cstring.to_string_lossy().into_owned() }; - let current = current!(); let dentry = { // Determine the file system path and the corresponding entry let fs_path = FsPath::new(dirfd, pathname.as_ref())?; - let fs = current.fs().read(); + let fs = ctx.process.fs().read(); if flags.contains(UtimensFlags::AT_SYMLINK_NOFOLLOW) { fs.lookup_no_follow(&fs_path)? } else { @@ -183,7 +179,12 @@ fn do_utimes( // Sets the access and modification times for a file, // specified by a pathname relative to the directory file descriptor `dirfd`. -fn do_futimesat(dirfd: FileDesc, pathname_ptr: Vaddr, timeval_ptr: Vaddr) -> Result { +fn do_futimesat( + dirfd: FileDesc, + pathname_ptr: Vaddr, + timeval_ptr: Vaddr, + ctx: &Context, +) -> Result { let times = if timeval_ptr != 0 { let (autime, mutime) = read_time_from_user::(timeval_ptr)?; if autime.usec >= 1000000 || autime.usec < 0 || mutime.usec >= 1000000 || mutime.usec < 0 { @@ -197,7 +198,7 @@ fn do_futimesat(dirfd: FileDesc, pathname_ptr: Vaddr, timeval_ptr: Vaddr) -> Res } else { None }; - do_utimes(dirfd, pathname_ptr, times, 0) + do_utimes(dirfd, pathname_ptr, times, 0, ctx) } fn read_time_from_user(time_ptr: Vaddr) -> Result<(T, T)> { diff --git a/kernel/aster-nix/src/syscall/wait4.rs b/kernel/aster-nix/src/syscall/wait4.rs index 52828e48a..c0d4f413d 100644 --- a/kernel/aster-nix/src/syscall/wait4.rs +++ b/kernel/aster-nix/src/syscall/wait4.rs @@ -11,7 +11,7 @@ pub fn sys_wait4( exit_status_ptr: u64, wait_options: u32, rusage_addr: Vaddr, - _ctx: &Context, + ctx: &Context, ) -> Result { let wait_options = WaitOptions::from_bits(wait_options) .ok_or_else(|| Error::with_message(Errno::EINVAL, "unknown wait option"))?; @@ -19,7 +19,7 @@ pub fn sys_wait4( "pid = {}, exit_status_ptr = {}, wait_options: {:?}", wait_pid as i32, exit_status_ptr, wait_options ); - debug!("wait4 current pid = {}", current!().pid()); + debug!("wait4 current pid = {}", ctx.process.pid()); let process_filter = ProcessFilter::from_id(wait_pid as _); let waited_process = wait_child_exit(process_filter, wait_options)?; diff --git a/kernel/aster-nix/src/syscall/write.rs b/kernel/aster-nix/src/syscall/write.rs index bed036ad7..992a6e240 100644 --- a/kernel/aster-nix/src/syscall/write.rs +++ b/kernel/aster-nix/src/syscall/write.rs @@ -7,7 +7,7 @@ pub fn sys_write( fd: FileDesc, user_buf_ptr: Vaddr, user_buf_len: usize, - _ctx: &Context, + ctx: &Context, ) -> Result { debug!( "fd = {}, user_buf_ptr = 0x{:x}, user_buf_len = 0x{:x}", @@ -15,8 +15,7 @@ pub fn sys_write( ); let file = { - let current = current!(); - let file_table = current.file_table().lock(); + let file_table = ctx.process.file_table().lock(); file_table.get_file(fd)?.clone() };