mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
Prefer Context::get_user_space
than CurrentUserSpace::get
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
8cf7063150
commit
38b46f7ac3
@ -60,7 +60,7 @@ pub fn do_faccessat(
|
|||||||
let flags = FaccessatFlags::from_bits(flags)
|
let flags = FaccessatFlags::from_bits(flags)
|
||||||
.ok_or_else(|| Error::with_message(Errno::EINVAL, "Invalid flags"))?;
|
.ok_or_else(|| Error::with_message(Errno::EINVAL, "Invalid flags"))?;
|
||||||
|
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?;
|
let path = ctx.get_user_space().read_cstring(path_ptr, PATH_MAX)?;
|
||||||
debug!(
|
debug!(
|
||||||
"dirfd = {}, path = {:?}, mode = {:o}, flags = {:?}",
|
"dirfd = {}, path = {:?}, mode = {:o}, flags = {:?}",
|
||||||
dirfd, path, mode, flags
|
dirfd, path, mode, flags
|
||||||
|
@ -13,7 +13,7 @@ pub fn sys_capget(
|
|||||||
cap_user_data_addr: Vaddr,
|
cap_user_data_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let cap_user_header: cap_user_header_t =
|
let cap_user_header: cap_user_header_t =
|
||||||
user_space.read_val::<cap_user_header_t>(cap_user_header_addr)?;
|
user_space.read_val::<cap_user_header_t>(cap_user_header_addr)?;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub fn sys_capset(
|
|||||||
cap_user_data_addr: Vaddr,
|
cap_user_data_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let cap_user_header: cap_user_header_t =
|
let cap_user_header: cap_user_header_t =
|
||||||
user_space.read_val::<cap_user_header_t>(cap_user_header_addr)?;
|
user_space.read_val::<cap_user_header_t>(cap_user_header_addr)?;
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn sys_chdir(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_chdir(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
let mut fs = ctx.process.fs().write();
|
let mut fs = ctx.process.fs().write();
|
||||||
|
@ -31,7 +31,7 @@ pub fn sys_fchmodat(
|
|||||||
/* flags: u32, */
|
/* flags: u32, */
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?;
|
let path = ctx.get_user_space().read_cstring(path_ptr, PATH_MAX)?;
|
||||||
debug!("dirfd = {}, path = {:?}, mode = 0o{:o}", dirfd, path, mode,);
|
debug!("dirfd = {}, path = {:?}, mode = 0o{:o}", dirfd, path, mode,);
|
||||||
|
|
||||||
let dentry = {
|
let dentry = {
|
||||||
|
@ -54,7 +54,7 @@ pub fn sys_fchownat(
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?;
|
let path = ctx.get_user_space().read_cstring(path_ptr, PATH_MAX)?;
|
||||||
let flags = ChownFlags::from_bits(flags)
|
let flags = ChownFlags::from_bits(flags)
|
||||||
.ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid flags"))?;
|
.ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid flags"))?;
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -8,7 +8,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn sys_chroot(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_chroot(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
||||||
debug!("path = {:?}", path);
|
debug!("path = {:?}", path);
|
||||||
|
|
||||||
let mut fs = ctx.process.fs().write();
|
let mut fs = ctx.process.fs().write();
|
||||||
|
@ -29,7 +29,7 @@ pub fn sys_clock_gettime(
|
|||||||
let time_duration = read_clock(clockid, ctx)?;
|
let time_duration = read_clock(clockid, ctx)?;
|
||||||
|
|
||||||
let timespec = timespec_t::from(time_duration);
|
let timespec = timespec_t::from(time_duration);
|
||||||
CurrentUserSpace::get().write_val(timespec_addr, ×pec)?;
|
ctx.get_user_space().write_val(timespec_addr, ×pec)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ pub fn sys_clone3(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let clone_args = {
|
let clone_args = {
|
||||||
let args: Clone3Args = CurrentUserSpace::get().read_val(clong_args_addr)?;
|
let args: Clone3Args = ctx.get_user_space().read_val(clong_args_addr)?;
|
||||||
trace!("clone3 args = {:x?}", args);
|
trace!("clone3 args = {:x?}", args);
|
||||||
CloneArgs::from(args)
|
CloneArgs::from(args)
|
||||||
};
|
};
|
||||||
|
@ -61,14 +61,14 @@ pub fn sys_epoll_ctl(
|
|||||||
|
|
||||||
let cmd = match op {
|
let cmd = match op {
|
||||||
EPOLL_CTL_ADD => {
|
EPOLL_CTL_ADD => {
|
||||||
let c_epoll_event = CurrentUserSpace::get().read_val::<c_epoll_event>(event_addr)?;
|
let c_epoll_event = ctx.get_user_space().read_val::<c_epoll_event>(event_addr)?;
|
||||||
let event = EpollEvent::from(&c_epoll_event);
|
let event = EpollEvent::from(&c_epoll_event);
|
||||||
let flags = EpollFlags::from_bits_truncate(c_epoll_event.events);
|
let flags = EpollFlags::from_bits_truncate(c_epoll_event.events);
|
||||||
EpollCtl::Add(fd, event, flags)
|
EpollCtl::Add(fd, event, flags)
|
||||||
}
|
}
|
||||||
EPOLL_CTL_DEL => EpollCtl::Del(fd),
|
EPOLL_CTL_DEL => EpollCtl::Del(fd),
|
||||||
EPOLL_CTL_MOD => {
|
EPOLL_CTL_MOD => {
|
||||||
let c_epoll_event = CurrentUserSpace::get().read_val::<c_epoll_event>(event_addr)?;
|
let c_epoll_event = ctx.get_user_space().read_val::<c_epoll_event>(event_addr)?;
|
||||||
let event = EpollEvent::from(&c_epoll_event);
|
let event = EpollEvent::from(&c_epoll_event);
|
||||||
let flags = EpollFlags::from_bits_truncate(c_epoll_event.events);
|
let flags = EpollFlags::from_bits_truncate(c_epoll_event.events);
|
||||||
EpollCtl::Mod(fd, event, flags)
|
EpollCtl::Mod(fd, event, flags)
|
||||||
@ -142,7 +142,7 @@ pub fn sys_epoll_wait(
|
|||||||
|
|
||||||
// Write back
|
// Write back
|
||||||
let mut write_addr = events_addr;
|
let mut write_addr = events_addr;
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
for epoll_event in epoll_events.iter() {
|
for epoll_event in epoll_events.iter() {
|
||||||
let c_epoll_event = c_epoll_event::from(epoll_event);
|
let c_epoll_event = c_epoll_event::from(epoll_event);
|
||||||
user_space.write_val(write_addr, &c_epoll_event)?;
|
user_space.write_val(write_addr, &c_epoll_event)?;
|
||||||
@ -154,7 +154,7 @@ pub fn sys_epoll_wait(
|
|||||||
|
|
||||||
fn set_signal_mask(set_ptr: Vaddr, ctx: &Context) -> Result<SigMask> {
|
fn set_signal_mask(set_ptr: Vaddr, ctx: &Context) -> Result<SigMask> {
|
||||||
let new_mask: Option<SigMask> = if set_ptr != 0 {
|
let new_mask: Option<SigMask> = if set_ptr != 0 {
|
||||||
Some(CurrentUserSpace::get().read_val::<u64>(set_ptr)?.into())
|
Some(ctx.get_user_space().read_val::<u64>(set_ptr)?.into())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@ -210,7 +210,7 @@ pub fn sys_epoll_pwait(
|
|||||||
|
|
||||||
// Write back
|
// Write back
|
||||||
let mut write_addr = events_addr;
|
let mut write_addr = events_addr;
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
for event in ready_events.iter() {
|
for event in ready_events.iter() {
|
||||||
let c_event = c_epoll_event::from(event);
|
let c_event = c_epoll_event::from(event);
|
||||||
user_space.write_val(write_addr, &c_event)?;
|
user_space.write_val(write_addr, &c_event)?;
|
||||||
|
@ -24,14 +24,14 @@ pub fn sys_execve(
|
|||||||
argv_ptr_ptr: Vaddr,
|
argv_ptr_ptr: Vaddr,
|
||||||
envp_ptr_ptr: Vaddr,
|
envp_ptr_ptr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
user_ctx: &mut UserContext,
|
user_context: &mut UserContext,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let elf_file = {
|
let elf_file = {
|
||||||
let executable_path = read_filename(filename_ptr)?;
|
let executable_path = read_filename(filename_ptr, ctx)?;
|
||||||
lookup_executable_file(AT_FDCWD, executable_path, OpenFlags::empty(), ctx)?
|
lookup_executable_file(AT_FDCWD, executable_path, OpenFlags::empty(), ctx)?
|
||||||
};
|
};
|
||||||
|
|
||||||
do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_ctx)?;
|
do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_context)?;
|
||||||
Ok(SyscallReturn::NoReturn)
|
Ok(SyscallReturn::NoReturn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,15 +42,15 @@ pub fn sys_execveat(
|
|||||||
envp_ptr_ptr: Vaddr,
|
envp_ptr_ptr: Vaddr,
|
||||||
flags: u32,
|
flags: u32,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
user_ctx: &mut UserContext,
|
user_context: &mut UserContext,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let elf_file = {
|
let elf_file = {
|
||||||
let flags = OpenFlags::from_bits_truncate(flags);
|
let flags = OpenFlags::from_bits_truncate(flags);
|
||||||
let filename = read_filename(filename_ptr)?;
|
let filename = read_filename(filename_ptr, ctx)?;
|
||||||
lookup_executable_file(dfd, filename, flags, ctx)?
|
lookup_executable_file(dfd, filename, flags, ctx)?
|
||||||
};
|
};
|
||||||
|
|
||||||
do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_ctx)?;
|
do_execve(elf_file, argv_ptr_ptr, envp_ptr_ptr, ctx, user_context)?;
|
||||||
Ok(SyscallReturn::NoReturn)
|
Ok(SyscallReturn::NoReturn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ fn do_execve(
|
|||||||
argv_ptr_ptr: Vaddr,
|
argv_ptr_ptr: Vaddr,
|
||||||
envp_ptr_ptr: Vaddr,
|
envp_ptr_ptr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
user_ctx: &mut UserContext,
|
user_context: &mut UserContext,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let Context {
|
let Context {
|
||||||
process,
|
process,
|
||||||
@ -94,8 +94,8 @@ fn do_execve(
|
|||||||
} = ctx;
|
} = ctx;
|
||||||
|
|
||||||
let executable_path = elf_file.abs_path();
|
let executable_path = elf_file.abs_path();
|
||||||
let argv = read_cstring_vec(argv_ptr_ptr, MAX_ARGV_NUMBER, MAX_ARG_LEN)?;
|
let argv = read_cstring_vec(argv_ptr_ptr, MAX_ARGV_NUMBER, MAX_ARG_LEN, ctx)?;
|
||||||
let envp = read_cstring_vec(envp_ptr_ptr, MAX_ENVP_NUMBER, MAX_ENV_LEN)?;
|
let envp = read_cstring_vec(envp_ptr_ptr, MAX_ENVP_NUMBER, MAX_ENV_LEN, ctx)?;
|
||||||
debug!(
|
debug!(
|
||||||
"filename: {:?}, argv = {:?}, envp = {:?}",
|
"filename: {:?}, argv = {:?}, envp = {:?}",
|
||||||
executable_path, argv, envp
|
executable_path, argv, envp
|
||||||
@ -131,16 +131,16 @@ fn do_execve(
|
|||||||
process.set_executable_path(new_executable_path);
|
process.set_executable_path(new_executable_path);
|
||||||
// set signal disposition to default
|
// set signal disposition to default
|
||||||
process.sig_dispositions().lock().inherit();
|
process.sig_dispositions().lock().inherit();
|
||||||
// set cpu ctx to default
|
// set cpu context to default
|
||||||
let default_content = UserContext::default();
|
let default_content = UserContext::default();
|
||||||
*user_ctx.general_regs_mut() = *default_content.general_regs();
|
*user_context.general_regs_mut() = *default_content.general_regs();
|
||||||
user_ctx.set_tls_pointer(default_content.tls_pointer());
|
user_context.set_tls_pointer(default_content.tls_pointer());
|
||||||
*user_ctx.fp_regs_mut() = *default_content.fp_regs();
|
*user_context.fp_regs_mut() = *default_content.fp_regs();
|
||||||
// set new entry point
|
// set new entry point
|
||||||
user_ctx.set_instruction_pointer(elf_load_info.entry_point() as _);
|
user_context.set_instruction_pointer(elf_load_info.entry_point() as _);
|
||||||
debug!("entry_point: 0x{:x}", elf_load_info.entry_point());
|
debug!("entry_point: 0x{:x}", elf_load_info.entry_point());
|
||||||
// set new user stack top
|
// set new user stack top
|
||||||
user_ctx.set_stack_pointer(elf_load_info.user_stack_top() as _);
|
user_context.set_stack_pointer(elf_load_info.user_stack_top() as _);
|
||||||
debug!("user stack top: 0x{:x}", elf_load_info.user_stack_top());
|
debug!("user stack top: 0x{:x}", elf_load_info.user_stack_top());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -152,8 +152,10 @@ bitflags::bitflags! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_filename(filename_ptr: Vaddr) -> Result<String> {
|
fn read_filename(filename_ptr: Vaddr, ctx: &Context) -> Result<String> {
|
||||||
let filename = CurrentUserSpace::get().read_cstring(filename_ptr, MAX_FILENAME_LEN)?;
|
let filename = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(filename_ptr, MAX_FILENAME_LEN)?;
|
||||||
Ok(filename.into_string().unwrap())
|
Ok(filename.into_string().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,6 +163,7 @@ fn read_cstring_vec(
|
|||||||
array_ptr: Vaddr,
|
array_ptr: Vaddr,
|
||||||
max_string_number: usize,
|
max_string_number: usize,
|
||||||
max_string_len: usize,
|
max_string_len: usize,
|
||||||
|
ctx: &Context,
|
||||||
) -> Result<Vec<CString>> {
|
) -> Result<Vec<CString>> {
|
||||||
let mut res = Vec::new();
|
let mut res = Vec::new();
|
||||||
// On Linux, argv pointer and envp pointer can be specified as NULL.
|
// On Linux, argv pointer and envp pointer can be specified as NULL.
|
||||||
@ -169,7 +172,7 @@ fn read_cstring_vec(
|
|||||||
}
|
}
|
||||||
let mut read_addr = array_ptr;
|
let mut read_addr = array_ptr;
|
||||||
let mut find_null = false;
|
let mut find_null = false;
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
for _ in 0..max_string_number {
|
for _ in 0..max_string_number {
|
||||||
let cstring_ptr = user_space.read_val::<usize>(read_addr)?;
|
let cstring_ptr = user_space.read_val::<usize>(read_addr)?;
|
||||||
read_addr += 8;
|
read_addr += 8;
|
||||||
|
@ -3,11 +3,12 @@
|
|||||||
use super::SyscallReturn;
|
use super::SyscallReturn;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub fn sys_getcwd(buf: Vaddr, len: usize, _ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_getcwd(buf: Vaddr, len: usize, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
// TODO: getcwd only return a fake result now
|
// TODO: getcwd only return a fake result now
|
||||||
let fake_cwd = CString::new("/")?;
|
let fake_cwd = CString::new("/")?;
|
||||||
let bytes = fake_cwd.as_bytes_with_nul();
|
let bytes = fake_cwd.as_bytes_with_nul();
|
||||||
let write_len = len.min(bytes.len());
|
let write_len = len.min(bytes.len());
|
||||||
CurrentUserSpace::get().write_bytes(buf, &mut VmReader::from(&bytes[..write_len]))?;
|
ctx.get_user_space()
|
||||||
|
.write_bytes(buf, &mut VmReader::from(&bytes[..write_len]))?;
|
||||||
Ok(SyscallReturn::Return(write_len as _))
|
Ok(SyscallReturn::Return(write_len as _))
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,8 @@ pub fn sys_getdents(
|
|||||||
let mut reader = DirentBufferReader::<Dirent>::new(&mut buffer); // Use the non-64-bit reader
|
let mut reader = DirentBufferReader::<Dirent>::new(&mut buffer); // Use the non-64-bit reader
|
||||||
let _ = inode_handle.readdir(&mut reader)?;
|
let _ = inode_handle.readdir(&mut reader)?;
|
||||||
let read_len = reader.read_len();
|
let read_len = reader.read_len();
|
||||||
CurrentUserSpace::get().write_bytes(buf_addr, &mut VmReader::from(&buffer[..read_len]))?;
|
ctx.get_user_space()
|
||||||
|
.write_bytes(buf_addr, &mut VmReader::from(&buffer[..read_len]))?;
|
||||||
Ok(SyscallReturn::Return(read_len as _))
|
Ok(SyscallReturn::Return(read_len as _))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +67,8 @@ pub fn sys_getdents64(
|
|||||||
let mut reader = DirentBufferReader::<Dirent64>::new(&mut buffer);
|
let mut reader = DirentBufferReader::<Dirent64>::new(&mut buffer);
|
||||||
let _ = inode_handle.readdir(&mut reader)?;
|
let _ = inode_handle.readdir(&mut reader)?;
|
||||||
let read_len = reader.read_len();
|
let read_len = reader.read_len();
|
||||||
CurrentUserSpace::get().write_bytes(buf_addr, &mut VmReader::from(&buffer[..read_len]))?;
|
ctx.get_user_space()
|
||||||
|
.write_bytes(buf_addr, &mut VmReader::from(&buffer[..read_len]))?;
|
||||||
Ok(SyscallReturn::Return(read_len as _))
|
Ok(SyscallReturn::Return(read_len as _))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ pub fn sys_getgroups(size: i32, group_list_addr: Vaddr, ctx: &Context) -> Result
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
for (idx, gid) in groups.iter().enumerate() {
|
for (idx, gid) in groups.iter().enumerate() {
|
||||||
let addr = group_list_addr + idx * core::mem::size_of_val(gid);
|
let addr = group_list_addr + idx * core::mem::size_of_val(gid);
|
||||||
user_space.write_val(addr, gid)?;
|
user_space.write_val(addr, gid)?;
|
||||||
|
@ -3,12 +3,7 @@
|
|||||||
use super::SyscallReturn;
|
use super::SyscallReturn;
|
||||||
use crate::{device, prelude::*};
|
use crate::{device, prelude::*};
|
||||||
|
|
||||||
pub fn sys_getrandom(
|
pub fn sys_getrandom(buf: Vaddr, count: usize, flags: u32, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
buf: Vaddr,
|
|
||||||
count: usize,
|
|
||||||
flags: u32,
|
|
||||||
_ctx: &Context,
|
|
||||||
) -> Result<SyscallReturn> {
|
|
||||||
let flags = GetRandomFlags::from_bits_truncate(flags);
|
let flags = GetRandomFlags::from_bits_truncate(flags);
|
||||||
debug!(
|
debug!(
|
||||||
"buf = 0x{:x}, count = 0x{:x}, flags = {:?}",
|
"buf = 0x{:x}, count = 0x{:x}, flags = {:?}",
|
||||||
@ -22,7 +17,8 @@ pub fn sys_getrandom(
|
|||||||
} else {
|
} else {
|
||||||
device::Urandom::getrandom(&mut buffer)?
|
device::Urandom::getrandom(&mut buffer)?
|
||||||
};
|
};
|
||||||
CurrentUserSpace::get().write_bytes(buf, &mut VmReader::from(buffer.as_slice()))?;
|
ctx.get_user_space()
|
||||||
|
.write_bytes(buf, &mut VmReader::from(buffer.as_slice()))?;
|
||||||
Ok(SyscallReturn::Return(read_len as isize))
|
Ok(SyscallReturn::Return(read_len as isize))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ pub fn sys_getresgid(
|
|||||||
debug!("rgid_ptr = 0x{rgid_ptr:x}, egid_ptr = 0x{egid_ptr:x}, sgid_ptr = 0x{sgid_ptr:x}");
|
debug!("rgid_ptr = 0x{rgid_ptr:x}, egid_ptr = 0x{egid_ptr:x}, sgid_ptr = 0x{sgid_ptr:x}");
|
||||||
|
|
||||||
let credentials = ctx.posix_thread.credentials();
|
let credentials = ctx.posix_thread.credentials();
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
|
|
||||||
let rgid = credentials.rgid();
|
let rgid = credentials.rgid();
|
||||||
user_space.write_val(rgid_ptr, &rgid)?;
|
user_space.write_val(rgid_ptr, &rgid)?;
|
||||||
|
@ -12,7 +12,7 @@ pub fn sys_getresuid(
|
|||||||
debug!("ruid_ptr = 0x{ruid_ptr:x}, euid_ptr = 0x{euid_ptr:x}, suid_ptr = 0x{suid_ptr:x}");
|
debug!("ruid_ptr = 0x{ruid_ptr:x}, euid_ptr = 0x{euid_ptr:x}, suid_ptr = 0x{suid_ptr:x}");
|
||||||
|
|
||||||
let credentials = ctx.posix_thread.credentials();
|
let credentials = ctx.posix_thread.credentials();
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
|
|
||||||
let ruid = credentials.ruid();
|
let ruid = credentials.ruid();
|
||||||
user_space.write_val(ruid_ptr, &ruid)?;
|
user_space.write_val(ruid_ptr, &ruid)?;
|
||||||
|
@ -48,7 +48,7 @@ pub fn sys_getrusage(target: i32, rusage_addr: Vaddr, ctx: &Context) -> Result<S
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(rusage_addr, &rusage)?;
|
ctx.get_user_space().write_val(rusage_addr, &rusage)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
|
@ -13,13 +13,13 @@ pub fn sys_getsockopt(
|
|||||||
optname: i32,
|
optname: i32,
|
||||||
optval: Vaddr,
|
optval: Vaddr,
|
||||||
optlen_addr: Vaddr,
|
optlen_addr: Vaddr,
|
||||||
_ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let level = CSocketOptionLevel::try_from(level)?;
|
let level = CSocketOptionLevel::try_from(level)?;
|
||||||
if optval == 0 || optlen_addr == 0 {
|
if optval == 0 || optlen_addr == 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "optval or optlen_addr is null pointer");
|
return_errno_with_message!(Errno::EINVAL, "optval or optlen_addr is null pointer");
|
||||||
}
|
}
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
|
|
||||||
let optlen: u32 = user_space.read_val(optlen_addr)?;
|
let optlen: u32 = user_space.read_val(optlen_addr)?;
|
||||||
debug!("level = {level:?}, sockfd = {sockfd}, optname = {optname:?}, optlen = {optlen}");
|
debug!("level = {level:?}, sockfd = {sockfd}, optname = {optname:?}, optlen = {optlen}");
|
||||||
|
@ -10,7 +10,7 @@ use crate::{
|
|||||||
// Glibc sets the timezone_addr argument to NULL, so just ignore it.
|
// Glibc sets the timezone_addr argument to NULL, so just ignore it.
|
||||||
pub fn sys_gettimeofday(
|
pub fn sys_gettimeofday(
|
||||||
timeval_addr: Vaddr,
|
timeval_addr: Vaddr,
|
||||||
/* timezone_addr: Vaddr */ _ctx: &Context,
|
/* timezone_addr: Vaddr, */ ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
if timeval_addr == 0 {
|
if timeval_addr == 0 {
|
||||||
return Ok(SyscallReturn::Return(0));
|
return Ok(SyscallReturn::Return(0));
|
||||||
@ -21,7 +21,7 @@ pub fn sys_gettimeofday(
|
|||||||
let time_duration = now.duration_since(&SystemTime::UNIX_EPOCH)?;
|
let time_duration = now.duration_since(&SystemTime::UNIX_EPOCH)?;
|
||||||
timeval_t::from(time_duration)
|
timeval_t::from(time_duration)
|
||||||
};
|
};
|
||||||
CurrentUserSpace::get().write_val(timeval_addr, &time_val)?;
|
ctx.get_user_space().write_val(timeval_addr, &time_val)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, ctx: &Context) -> Result<Sy
|
|||||||
let file = file_table.get_file(fd)?;
|
let file = file_table.get_file(fd)?;
|
||||||
let res = match ioctl_cmd {
|
let res = match ioctl_cmd {
|
||||||
IoctlCmd::FIONBIO => {
|
IoctlCmd::FIONBIO => {
|
||||||
let is_nonblocking = CurrentUserSpace::get().read_val::<i32>(arg)? != 0;
|
let is_nonblocking = ctx.get_user_space().read_val::<i32>(arg)? != 0;
|
||||||
let mut flags = file.status_flags();
|
let mut flags = file.status_flags();
|
||||||
flags.set(StatusFlags::O_NONBLOCK, is_nonblocking);
|
flags.set(StatusFlags::O_NONBLOCK, is_nonblocking);
|
||||||
file.set_status_flags(flags)?;
|
file.set_status_flags(flags)?;
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
IoctlCmd::FIOASYNC => {
|
IoctlCmd::FIOASYNC => {
|
||||||
let is_async = CurrentUserSpace::get().read_val::<i32>(arg)? != 0;
|
let is_async = ctx.get_user_space().read_val::<i32>(arg)? != 0;
|
||||||
let mut flags = file.status_flags();
|
let mut flags = file.status_flags();
|
||||||
|
|
||||||
// Set `O_ASYNC` flags will send `SIGIO` signal to a process when
|
// Set `O_ASYNC` flags will send `SIGIO` signal to a process when
|
||||||
|
@ -18,7 +18,7 @@ pub fn sys_linkat(
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
|
|
||||||
let old_path = user_space.read_cstring(old_path_addr, MAX_FILENAME_LEN)?;
|
let old_path = user_space.read_cstring(old_path_addr, MAX_FILENAME_LEN)?;
|
||||||
let new_path = user_space.read_cstring(new_path_addr, MAX_FILENAME_LEN)?;
|
let new_path = user_space.read_cstring(new_path_addr, MAX_FILENAME_LEN)?;
|
||||||
|
@ -20,7 +20,7 @@ pub fn sys_madvise(
|
|||||||
| MadviseBehavior::MADV_WILLNEED => {
|
| MadviseBehavior::MADV_WILLNEED => {
|
||||||
// perform a read at first
|
// perform a read at first
|
||||||
let mut buffer = vec![0u8; len];
|
let mut buffer = vec![0u8; len];
|
||||||
CurrentUserSpace::get()
|
ctx.get_user_space()
|
||||||
.read_bytes(start, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
.read_bytes(start, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
||||||
}
|
}
|
||||||
MadviseBehavior::MADV_DONTNEED => {
|
MadviseBehavior::MADV_DONTNEED => {
|
||||||
|
@ -17,7 +17,9 @@ pub fn sys_mkdirat(
|
|||||||
mode: u16,
|
mode: u16,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!("dirfd = {}, path = {:?}, mode = {}", dirfd, path, mode);
|
debug!("dirfd = {}, path = {:?}, mode = {}", dirfd, path, mode);
|
||||||
|
|
||||||
let current = ctx.process;
|
let current = ctx.process;
|
||||||
|
@ -19,7 +19,9 @@ pub fn sys_mknodat(
|
|||||||
dev: usize,
|
dev: usize,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
let current = ctx.process;
|
let current = ctx.process;
|
||||||
let inode_mode = {
|
let inode_mode = {
|
||||||
let mask_mode = mode & !current.umask().read().get();
|
let mask_mode = mode & !current.umask().read().get();
|
||||||
|
@ -25,7 +25,7 @@ pub fn sys_mount(
|
|||||||
data: Vaddr,
|
data: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let devname = user_space.read_cstring(devname_addr, MAX_FILENAME_LEN)?;
|
let devname = user_space.read_cstring(devname_addr, MAX_FILENAME_LEN)?;
|
||||||
let dirname = user_space.read_cstring(dirname_addr, MAX_FILENAME_LEN)?;
|
let dirname = user_space.read_cstring(dirname_addr, MAX_FILENAME_LEN)?;
|
||||||
let mount_flags = MountFlags::from_bits_truncate(flags as u32);
|
let mount_flags = MountFlags::from_bits_truncate(flags as u32);
|
||||||
@ -63,7 +63,7 @@ pub fn sys_mount(
|
|||||||
} else if mount_flags.contains(MountFlags::MS_MOVE) {
|
} else if mount_flags.contains(MountFlags::MS_MOVE) {
|
||||||
do_move_mount_old(devname, dst_dentry, ctx)?;
|
do_move_mount_old(devname, dst_dentry, ctx)?;
|
||||||
} else {
|
} else {
|
||||||
do_new_mount(devname, fstype_addr, dst_dentry)?;
|
do_new_mount(devname, fstype_addr, dst_dentry, ctx)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
@ -132,12 +132,19 @@ fn do_move_mount_old(src_name: CString, dst_dentry: Arc<Dentry>, ctx: &Context)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Mount a new filesystem.
|
/// Mount a new filesystem.
|
||||||
fn do_new_mount(devname: CString, fs_type: Vaddr, target_dentry: Arc<Dentry>) -> Result<()> {
|
fn do_new_mount(
|
||||||
|
devname: CString,
|
||||||
|
fs_type: Vaddr,
|
||||||
|
target_dentry: Arc<Dentry>,
|
||||||
|
ctx: &Context,
|
||||||
|
) -> Result<()> {
|
||||||
if target_dentry.type_() != InodeType::Dir {
|
if target_dentry.type_() != InodeType::Dir {
|
||||||
return_errno_with_message!(Errno::ENOTDIR, "mountpoint must be directory");
|
return_errno_with_message!(Errno::ENOTDIR, "mountpoint must be directory");
|
||||||
};
|
};
|
||||||
|
|
||||||
let fs_type = CurrentUserSpace::get().read_cstring(fs_type, MAX_FILENAME_LEN)?;
|
let fs_type = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(fs_type, MAX_FILENAME_LEN)?;
|
||||||
if fs_type.is_empty() {
|
if fs_type.is_empty() {
|
||||||
return_errno_with_message!(Errno::EINVAL, "fs_type is empty");
|
return_errno_with_message!(Errno::EINVAL, "fs_type is empty");
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,9 @@ fn do_clock_nanosleep(
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let request_time = {
|
let request_time = {
|
||||||
let timespec = CurrentUserSpace::get().read_val::<timespec_t>(request_timespec_addr)?;
|
let timespec = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_val::<timespec_t>(request_timespec_addr)?;
|
||||||
Duration::try_from(timespec)?
|
Duration::try_from(timespec)?
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,7 +96,8 @@ fn do_clock_nanosleep(
|
|||||||
if remain_timespec_addr != 0 && !is_abs_time {
|
if remain_timespec_addr != 0 && !is_abs_time {
|
||||||
let remaining_duration = (start_time + timeout) - end_time;
|
let remaining_duration = (start_time + timeout) - end_time;
|
||||||
let remaining_timespec = timespec_t::from(remaining_duration);
|
let remaining_timespec = timespec_t::from(remaining_duration);
|
||||||
CurrentUserSpace::get().write_val(remain_timespec_addr, &remaining_timespec)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(remain_timespec_addr, &remaining_timespec)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
return_errno_with_message!(Errno::EINTR, "sleep was interrupted");
|
return_errno_with_message!(Errno::EINTR, "sleep was interrupted");
|
||||||
|
@ -18,7 +18,9 @@ pub fn sys_openat(
|
|||||||
mode: u16,
|
mode: u16,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!(
|
debug!(
|
||||||
"dirfd = {}, path = {:?}, flags = {}, mode = {}",
|
"dirfd = {}, path = {:?}, flags = {}, mode = {}",
|
||||||
dirfd, path, flags, mode
|
dirfd, path, flags, mode
|
||||||
|
@ -38,7 +38,7 @@ pub fn sys_pipe2(fds: Vaddr, flags: u32, ctx: &Context) -> Result<SyscallReturn>
|
|||||||
};
|
};
|
||||||
debug!("pipe_fds: {:?}", pipe_fds);
|
debug!("pipe_fds: {:?}", pipe_fds);
|
||||||
|
|
||||||
if let Err(err) = CurrentUserSpace::get().write_val(fds, &pipe_fds) {
|
if let Err(err) = ctx.get_user_space().write_val(fds, &pipe_fds) {
|
||||||
file_table.close_file(pipe_fds.reader_fd).unwrap();
|
file_table.close_file(pipe_fds.reader_fd).unwrap();
|
||||||
file_table.close_file(pipe_fds.writer_fd).unwrap();
|
file_table.close_file(pipe_fds.writer_fd).unwrap();
|
||||||
return Err(err);
|
return Err(err);
|
||||||
|
@ -6,7 +6,7 @@ use super::SyscallReturn;
|
|||||||
use crate::{events::IoEvents, fs::file_table::FileDesc, prelude::*, process::signal::Poller};
|
use crate::{events::IoEvents, fs::file_table::FileDesc, prelude::*, process::signal::Poller};
|
||||||
|
|
||||||
pub fn sys_poll(fds: Vaddr, nfds: u64, timeout: i32, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_poll(fds: Vaddr, nfds: u64, timeout: i32, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let poll_fds = {
|
let poll_fds = {
|
||||||
let mut read_addr = fds;
|
let mut read_addr = fds;
|
||||||
let mut poll_fds = Vec::with_capacity(nfds as _);
|
let mut poll_fds = Vec::with_capacity(nfds as _);
|
||||||
|
@ -28,7 +28,7 @@ pub fn sys_prctl(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(write_to_addr, &write_val)?;
|
ctx.get_user_space().write_val(write_to_addr, &write_val)?;
|
||||||
}
|
}
|
||||||
PrctlCmd::PR_GET_DUMPABLE => {
|
PrctlCmd::PR_GET_DUMPABLE => {
|
||||||
// TODO: when coredump is supported, return the actual value
|
// TODO: when coredump is supported, return the actual value
|
||||||
@ -45,7 +45,7 @@ pub fn sys_prctl(
|
|||||||
let thread_name = ctx.posix_thread.thread_name().lock();
|
let thread_name = ctx.posix_thread.thread_name().lock();
|
||||||
if let Some(thread_name) = &*thread_name {
|
if let Some(thread_name) = &*thread_name {
|
||||||
if let Some(thread_name) = thread_name.name()? {
|
if let Some(thread_name) = thread_name.name()? {
|
||||||
CurrentUserSpace::get().write_bytes(
|
ctx.get_user_space().write_bytes(
|
||||||
write_to_addr,
|
write_to_addr,
|
||||||
&mut VmReader::from(thread_name.to_bytes_with_nul()),
|
&mut VmReader::from(thread_name.to_bytes_with_nul()),
|
||||||
)?;
|
)?;
|
||||||
@ -55,8 +55,9 @@ pub fn sys_prctl(
|
|||||||
PrctlCmd::PR_SET_NAME(read_addr) => {
|
PrctlCmd::PR_SET_NAME(read_addr) => {
|
||||||
let mut thread_name = ctx.posix_thread.thread_name().lock();
|
let mut thread_name = ctx.posix_thread.thread_name().lock();
|
||||||
if let Some(thread_name) = &mut *thread_name {
|
if let Some(thread_name) = &mut *thread_name {
|
||||||
let new_thread_name =
|
let new_thread_name = ctx
|
||||||
CurrentUserSpace::get().read_cstring(read_addr, MAX_THREAD_NAME_LEN)?;
|
.get_user_space()
|
||||||
|
.read_cstring(read_addr, MAX_THREAD_NAME_LEN)?;
|
||||||
thread_name.set_name(&new_thread_name)?;
|
thread_name.set_name(&new_thread_name)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ pub fn sys_pread64(
|
|||||||
let read_len = {
|
let read_len = {
|
||||||
let mut buffer = vec![0u8; user_buf_len];
|
let mut buffer = vec![0u8; user_buf_len];
|
||||||
let read_len = file.read_at(offset as usize, &mut buffer)?;
|
let read_len = file.read_at(offset as usize, &mut buffer)?;
|
||||||
CurrentUserSpace::get()
|
ctx.get_user_space()
|
||||||
.write_bytes(user_buf_ptr, &mut VmReader::from(buffer.as_slice()))?;
|
.write_bytes(user_buf_ptr, &mut VmReader::from(buffer.as_slice()))?;
|
||||||
read_len
|
read_len
|
||||||
};
|
};
|
||||||
|
@ -21,10 +21,10 @@ pub fn sys_prlimit64(
|
|||||||
let mut resource_limits = ctx.process.resource_limits().lock();
|
let mut resource_limits = ctx.process.resource_limits().lock();
|
||||||
if old_rlim_addr != 0 {
|
if old_rlim_addr != 0 {
|
||||||
let rlimit = resource_limits.get_rlimit(resource);
|
let rlimit = resource_limits.get_rlimit(resource);
|
||||||
CurrentUserSpace::get().write_val(old_rlim_addr, rlimit)?;
|
ctx.get_user_space().write_val(old_rlim_addr, rlimit)?;
|
||||||
}
|
}
|
||||||
if new_rlim_addr != 0 {
|
if new_rlim_addr != 0 {
|
||||||
let new_rlimit = CurrentUserSpace::get().read_val(new_rlim_addr)?;
|
let new_rlimit = ctx.get_user_space().read_val(new_rlim_addr)?;
|
||||||
*resource_limits.get_rlimit_mut(resource) = new_rlimit;
|
*resource_limits.get_rlimit_mut(resource) = new_rlimit;
|
||||||
}
|
}
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
|
@ -16,7 +16,7 @@ pub fn sys_pselect6(
|
|||||||
sigmask_addr: Vaddr,
|
sigmask_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let old_simask = if sigmask_addr != 0 {
|
let old_simask = if sigmask_addr != 0 {
|
||||||
let sigmask_with_size: SigMaskWithSize = user_space.read_val(sigmask_addr)?;
|
let sigmask_with_size: SigMaskWithSize = user_space.read_val(sigmask_addr)?;
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ pub fn sys_pwrite64(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut buffer = vec![0u8; user_buf_len];
|
let mut buffer = vec![0u8; user_buf_len];
|
||||||
CurrentUserSpace::get().read_bytes(user_buf_ptr, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
ctx.get_user_space()
|
||||||
|
.read_bytes(user_buf_ptr, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
||||||
let write_len = file.write_at(offset as _, &buffer)?;
|
let write_len = file.write_at(offset as _, &buffer)?;
|
||||||
Ok(SyscallReturn::Return(write_len as _))
|
Ok(SyscallReturn::Return(write_len as _))
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ pub fn sys_read(
|
|||||||
let read_len = if buf_len != 0 {
|
let read_len = if buf_len != 0 {
|
||||||
let mut read_buf = vec![0u8; buf_len];
|
let mut read_buf = vec![0u8; buf_len];
|
||||||
let read_len = file.read(&mut read_buf)?;
|
let read_len = file.read(&mut read_buf)?;
|
||||||
CurrentUserSpace::get().write_bytes(
|
ctx.get_user_space().write_bytes(
|
||||||
user_buf_addr,
|
user_buf_addr,
|
||||||
&mut VmReader::from(&read_buf[..min(read_len, buf_len)]),
|
&mut VmReader::from(&read_buf[..min(read_len, buf_len)]),
|
||||||
)?;
|
)?;
|
||||||
|
@ -17,7 +17,7 @@ pub fn sys_readlinkat(
|
|||||||
usr_buf_len: usize,
|
usr_buf_len: usize,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let path = user_space.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = user_space.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!(
|
debug!(
|
||||||
"dirfd = {}, path = {:?}, usr_buf_addr = 0x{:x}, usr_buf_len = 0x{:x}",
|
"dirfd = {}, path = {:?}, usr_buf_addr = 0x{:x}, usr_buf_len = 0x{:x}",
|
||||||
|
@ -12,9 +12,9 @@ pub fn sys_recvmsg(
|
|||||||
sockfd: FileDesc,
|
sockfd: FileDesc,
|
||||||
user_msghdr_ptr: Vaddr,
|
user_msghdr_ptr: Vaddr,
|
||||||
flags: i32,
|
flags: i32,
|
||||||
_ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let c_user_msghdr: CUserMsgHdr = CurrentUserSpace::get().read_val(user_msghdr_ptr)?;
|
let c_user_msghdr: CUserMsgHdr = ctx.get_user_space().read_val(user_msghdr_ptr)?;
|
||||||
let flags = SendRecvFlags::from_bits_truncate(flags);
|
let flags = SendRecvFlags::from_bits_truncate(flags);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -18,7 +18,7 @@ pub fn sys_renameat(
|
|||||||
new_path_addr: Vaddr,
|
new_path_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let old_path = user_space.read_cstring(old_path_addr, MAX_FILENAME_LEN)?;
|
let old_path = user_space.read_cstring(old_path_addr, MAX_FILENAME_LEN)?;
|
||||||
let new_path = user_space.read_cstring(new_path_addr, MAX_FILENAME_LEN)?;
|
let new_path = user_space.read_cstring(new_path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -19,7 +19,9 @@ pub(super) fn sys_rmdirat(
|
|||||||
path_addr: Vaddr,
|
path_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let path_addr = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path_addr = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!("dirfd = {}, path_addr = {:?}", dirfd, path_addr);
|
debug!("dirfd = {}, path_addr = {:?}", dirfd, path_addr);
|
||||||
|
|
||||||
let (dir_dentry, name) = {
|
let (dir_dentry, name) = {
|
||||||
|
@ -25,10 +25,13 @@ pub fn sys_rt_sigaction(
|
|||||||
let old_action = sig_dispositions.get(sig_num);
|
let old_action = sig_dispositions.get(sig_num);
|
||||||
let old_action_c = old_action.as_c_type();
|
let old_action_c = old_action.as_c_type();
|
||||||
if old_sig_action_addr != 0 {
|
if old_sig_action_addr != 0 {
|
||||||
CurrentUserSpace::get().write_val(old_sig_action_addr, &old_action_c)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(old_sig_action_addr, &old_action_c)?;
|
||||||
}
|
}
|
||||||
if sig_action_addr != 0 {
|
if sig_action_addr != 0 {
|
||||||
let sig_action_c = CurrentUserSpace::get().read_val::<sigaction_t>(sig_action_addr)?;
|
let sig_action_c = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_val::<sigaction_t>(sig_action_addr)?;
|
||||||
let sig_action = SigAction::try_from(sig_action_c).unwrap();
|
let sig_action = SigAction::try_from(sig_action_c).unwrap();
|
||||||
trace!("sig action = {:?}", sig_action);
|
trace!("sig action = {:?}", sig_action);
|
||||||
sig_dispositions.set(sig_num, sig_action);
|
sig_dispositions.set(sig_num, sig_action);
|
||||||
|
@ -28,6 +28,7 @@ fn do_rt_sigpending(set_ptr: Vaddr, ctx: &Context) -> Result<()> {
|
|||||||
sig_mask_value & sig_pending_value
|
sig_mask_value & sig_pending_value
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(set_ptr, &u64::from(combined_signals))?;
|
ctx.get_user_space()
|
||||||
|
.write_val(set_ptr, &u64::from(combined_signals))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -39,12 +39,13 @@ fn do_rt_sigprocmask(
|
|||||||
let old_sig_mask_value = ctx.posix_thread.sig_mask().load(Ordering::Relaxed);
|
let old_sig_mask_value = ctx.posix_thread.sig_mask().load(Ordering::Relaxed);
|
||||||
debug!("old sig mask value: 0x{:x}", old_sig_mask_value);
|
debug!("old sig mask value: 0x{:x}", old_sig_mask_value);
|
||||||
if oldset_ptr != 0 {
|
if oldset_ptr != 0 {
|
||||||
CurrentUserSpace::get().write_val(oldset_ptr, &old_sig_mask_value)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(oldset_ptr, &old_sig_mask_value)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let sig_mask_ref = ctx.posix_thread.sig_mask();
|
let sig_mask_ref = ctx.posix_thread.sig_mask();
|
||||||
if set_ptr != 0 {
|
if set_ptr != 0 {
|
||||||
let mut read_mask = CurrentUserSpace::get().read_val::<SigMask>(set_ptr)?;
|
let mut read_mask = ctx.get_user_space().read_val::<SigMask>(set_ptr)?;
|
||||||
match mask_op {
|
match mask_op {
|
||||||
MaskOp::Block => {
|
MaskOp::Block => {
|
||||||
// According to man pages, "it is not possible to block SIGKILL or SIGSTOP.
|
// According to man pages, "it is not possible to block SIGKILL or SIGSTOP.
|
||||||
|
@ -24,7 +24,9 @@ pub fn sys_rt_sigreturn(ctx: &Context, user_ctx: &mut UserContext) -> Result<Sys
|
|||||||
// However, for most glibc applications, the restorer codes is provided by glibc and RESTORER flag is set.
|
// However, for most glibc applications, the restorer codes is provided by glibc and RESTORER flag is set.
|
||||||
debug_assert!(sig_context_addr == user_ctx.stack_pointer() as Vaddr);
|
debug_assert!(sig_context_addr == user_ctx.stack_pointer() as Vaddr);
|
||||||
|
|
||||||
let ucontext = CurrentUserSpace::get().read_val::<ucontext_t>(sig_context_addr)?;
|
let ucontext = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_val::<ucontext_t>(sig_context_addr)?;
|
||||||
|
|
||||||
// If the sig stack is active and used by current handler, decrease handler counter.
|
// If the sig stack is active and used by current handler, decrease handler counter.
|
||||||
if let Some(sig_stack) = posix_thread.sig_stack().lock().as_mut() {
|
if let Some(sig_stack) = posix_thread.sig_stack().lock().as_mut() {
|
||||||
|
@ -13,7 +13,7 @@ use crate::{
|
|||||||
pub fn sys_rt_sigsuspend(
|
pub fn sys_rt_sigsuspend(
|
||||||
sigmask_addr: Vaddr,
|
sigmask_addr: Vaddr,
|
||||||
sigmask_size: usize,
|
sigmask_size: usize,
|
||||||
_ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
debug!(
|
debug!(
|
||||||
"sigmask_addr = 0x{:x}, sigmask_size = {}",
|
"sigmask_addr = 0x{:x}, sigmask_size = {}",
|
||||||
@ -26,7 +26,7 @@ pub fn sys_rt_sigsuspend(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let sigmask = {
|
let sigmask = {
|
||||||
let mut mask: SigMask = CurrentUserSpace::get().read_val(sigmask_addr)?;
|
let mut mask: SigMask = ctx.get_user_space().read_val(sigmask_addr)?;
|
||||||
// It is not possible to block SIGKILL or SIGSTOP,
|
// It is not possible to block SIGKILL or SIGSTOP,
|
||||||
// specifying these signals in mask has no effect.
|
// specifying these signals in mask has no effect.
|
||||||
mask -= SIGKILL;
|
mask -= SIGKILL;
|
||||||
|
@ -18,7 +18,7 @@ pub fn sys_sched_getaffinity(
|
|||||||
pid: Pid,
|
pid: Pid,
|
||||||
cpuset_size: usize,
|
cpuset_size: usize,
|
||||||
cpu_set_ptr: Vaddr,
|
cpu_set_ptr: Vaddr,
|
||||||
_ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let num_cpus = get_num_cpus();
|
let num_cpus = get_num_cpus();
|
||||||
|
|
||||||
@ -41,7 +41,8 @@ pub fn sys_sched_getaffinity(
|
|||||||
|
|
||||||
let dummy_cpu_set = cpu_set_t::new(num_cpus);
|
let dummy_cpu_set = cpu_set_t::new(num_cpus);
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(cpu_set_ptr, &dummy_cpu_set)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(cpu_set_ptr, &dummy_cpu_set)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ pub fn sys_select(
|
|||||||
let timeout = if timeval_addr == 0 {
|
let timeout = if timeval_addr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let timeval = CurrentUserSpace::get().read_val::<timeval_t>(timeval_addr)?;
|
let timeval = ctx.get_user_space().read_val::<timeval_t>(timeval_addr)?;
|
||||||
Some(Duration::from(timeval))
|
Some(Duration::from(timeval))
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ pub fn do_sys_select(
|
|||||||
return_errno_with_message!(Errno::EINVAL, "nfds is negative or exceeds the FD_SETSIZE");
|
return_errno_with_message!(Errno::EINVAL, "nfds is negative or exceeds the FD_SETSIZE");
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let get_fdset = |fdset_addr: Vaddr| -> Result<Option<FdSet>> {
|
let get_fdset = |fdset_addr: Vaddr| -> Result<Option<FdSet>> {
|
||||||
let fdset = if fdset_addr == 0 {
|
let fdset = if fdset_addr == 0 {
|
||||||
None
|
None
|
||||||
|
@ -15,7 +15,7 @@ pub fn sys_sendfile(
|
|||||||
let offset = if offset_ptr == 0 {
|
let offset = if offset_ptr == 0 {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let offset: isize = CurrentUserSpace::get().read_val(offset_ptr)?;
|
let offset: isize = ctx.get_user_space().read_val(offset_ptr)?;
|
||||||
if offset < 0 {
|
if offset < 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "offset cannot be negative");
|
return_errno_with_message!(Errno::EINVAL, "offset cannot be negative");
|
||||||
}
|
}
|
||||||
@ -109,7 +109,8 @@ pub fn sys_sendfile(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(offset) = offset {
|
if let Some(offset) = offset {
|
||||||
CurrentUserSpace::get().write_val(offset_ptr, &(offset as isize))?;
|
ctx.get_user_space()
|
||||||
|
.write_val(offset_ptr, &(offset as isize))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(total_len as _))
|
Ok(SyscallReturn::Return(total_len as _))
|
||||||
|
@ -12,9 +12,9 @@ pub fn sys_sendmsg(
|
|||||||
sockfd: FileDesc,
|
sockfd: FileDesc,
|
||||||
user_msghdr_ptr: Vaddr,
|
user_msghdr_ptr: Vaddr,
|
||||||
flags: i32,
|
flags: i32,
|
||||||
_ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let c_user_msghdr: CUserMsgHdr = CurrentUserSpace::get().read_val(user_msghdr_ptr)?;
|
let c_user_msghdr: CUserMsgHdr = ctx.get_user_space().read_val(user_msghdr_ptr)?;
|
||||||
let flags = SendRecvFlags::from_bits_truncate(flags);
|
let flags = SendRecvFlags::from_bits_truncate(flags);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -18,8 +18,7 @@ pub fn sys_set_robust_list(
|
|||||||
"The len is not equal to the size of robust list head"
|
"The len is not equal to the size of robust list head"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let robust_list_head: RobustListHead =
|
let robust_list_head: RobustListHead = ctx.get_user_space().read_val(robust_list_head_ptr)?;
|
||||||
CurrentUserSpace::get().read_val(robust_list_head_ptr)?;
|
|
||||||
debug!("{:x?}", robust_list_head);
|
debug!("{:x?}", robust_list_head);
|
||||||
let mut robust_list = ctx.posix_thread.robust_list().lock();
|
let mut robust_list = ctx.posix_thread.robust_list().lock();
|
||||||
*robust_list = Some(robust_list_head);
|
*robust_list = Some(robust_list_head);
|
||||||
|
@ -15,7 +15,7 @@ pub fn sys_setgroups(size: usize, group_list_addr: Vaddr, ctx: &Context) -> Resu
|
|||||||
let mut new_groups = BTreeSet::new();
|
let mut new_groups = BTreeSet::new();
|
||||||
for idx in 0..size {
|
for idx in 0..size {
|
||||||
let addr = group_list_addr + idx * core::mem::size_of::<Gid>();
|
let addr = group_list_addr + idx * core::mem::size_of::<Gid>();
|
||||||
let gid = CurrentUserSpace::get().read_val(addr)?;
|
let gid = ctx.get_user_space().read_val(addr)?;
|
||||||
new_groups.insert(gid);
|
new_groups.insert(gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ pub fn sys_setitimer(
|
|||||||
if new_itimerval_addr == 0 {
|
if new_itimerval_addr == 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value");
|
return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value");
|
||||||
}
|
}
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let new_itimerval = user_space.read_val::<itimerval_t>(new_itimerval_addr)?;
|
let new_itimerval = user_space.read_val::<itimerval_t>(new_itimerval_addr)?;
|
||||||
let interval = Duration::from(new_itimerval.it_interval);
|
let interval = Duration::from(new_itimerval.it_interval);
|
||||||
let expire_time = Duration::from(new_itimerval.it_value);
|
let expire_time = Duration::from(new_itimerval.it_value);
|
||||||
@ -92,7 +92,7 @@ pub fn sys_getitimer(
|
|||||||
it_interval: interval,
|
it_interval: interval,
|
||||||
it_value: remain,
|
it_value: remain,
|
||||||
};
|
};
|
||||||
CurrentUserSpace::get().write_val(itimerval_addr, &itimerval)?;
|
ctx.get_user_space().write_val(itimerval_addr, &itimerval)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,17 @@ pub fn sys_sigaltstack(
|
|||||||
sig_stack.clone()
|
sig_stack.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
get_old_stack(old_sig_stack_addr, old_stack.as_ref())?;
|
get_old_stack(old_sig_stack_addr, old_stack.as_ref(), ctx)?;
|
||||||
set_new_stack(sig_stack_addr, old_stack.as_ref(), ctx)?;
|
set_new_stack(sig_stack_addr, old_stack.as_ref(), ctx)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_old_stack(old_sig_stack_addr: Vaddr, old_stack: Option<&SigStack>) -> Result<()> {
|
fn get_old_stack(
|
||||||
|
old_sig_stack_addr: Vaddr,
|
||||||
|
old_stack: Option<&SigStack>,
|
||||||
|
ctx: &Context,
|
||||||
|
) -> Result<()> {
|
||||||
if old_sig_stack_addr == 0 {
|
if old_sig_stack_addr == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@ -39,7 +43,7 @@ fn get_old_stack(old_sig_stack_addr: Vaddr, old_stack: Option<&SigStack>) -> Res
|
|||||||
debug!("old stack = {:?}", old_stack);
|
debug!("old stack = {:?}", old_stack);
|
||||||
|
|
||||||
let stack = stack_t::from(old_stack.clone());
|
let stack = stack_t::from(old_stack.clone());
|
||||||
CurrentUserSpace::get().write_val(old_sig_stack_addr, &stack)
|
ctx.get_user_space().write_val(old_sig_stack_addr, &stack)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>, ctx: &Context) -> Result<()> {
|
fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>, ctx: &Context) -> Result<()> {
|
||||||
@ -54,7 +58,7 @@ fn set_new_stack(sig_stack_addr: Vaddr, old_stack: Option<&SigStack>, ctx: &Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
let new_stack = {
|
let new_stack = {
|
||||||
let stack = CurrentUserSpace::get().read_val::<stack_t>(sig_stack_addr)?;
|
let stack = ctx.get_user_space().read_val::<stack_t>(sig_stack_addr)?;
|
||||||
SigStack::try_from(stack)?
|
SigStack::try_from(stack)?
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ pub fn sys_socketpair(
|
|||||||
SocketFds(fd_a, fd_b)
|
SocketFds(fd_a, fd_b)
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(sv, &socket_fds)?;
|
ctx.get_user_space().write_val(sv, &socket_fds)?;
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub fn sys_fstat(fd: FileDesc, stat_buf_ptr: Vaddr, ctx: &Context) -> Result<Sys
|
|||||||
let file_table = ctx.process.file_table().lock();
|
let file_table = ctx.process.file_table().lock();
|
||||||
let file = file_table.get_file(fd)?;
|
let file = file_table.get_file(fd)?;
|
||||||
let stat = Stat::from(file.metadata());
|
let stat = Stat::from(file.metadata());
|
||||||
CurrentUserSpace::get().write_val(stat_buf_ptr, &stat)?;
|
ctx.get_user_space().write_val(stat_buf_ptr, &stat)?;
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ pub fn sys_fstatat(
|
|||||||
flags: u32,
|
flags: u32,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let filename = user_space.read_cstring(filename_ptr, MAX_FILENAME_LEN)?;
|
let filename = user_space.read_cstring(filename_ptr, MAX_FILENAME_LEN)?;
|
||||||
let flags =
|
let flags =
|
||||||
StatFlags::from_bits(flags).ok_or(Error::with_message(Errno::EINVAL, "invalid flags"))?;
|
StatFlags::from_bits(flags).ok_or(Error::with_message(Errno::EINVAL, "invalid flags"))?;
|
||||||
|
@ -12,7 +12,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn sys_statfs(path_ptr: Vaddr, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_statfs(path_ptr: Vaddr, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let path = user_space.read_cstring(path_ptr, PATH_MAX)?;
|
let path = user_space.read_cstring(path_ptr, PATH_MAX)?;
|
||||||
debug!("path = {:?}, statfs_buf_ptr = 0x{:x}", path, statfs_buf_ptr,);
|
debug!("path = {:?}, statfs_buf_ptr = 0x{:x}", path, statfs_buf_ptr,);
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ pub fn sys_fstatfs(fd: FileDesc, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result
|
|||||||
.ok_or(Error::with_message(Errno::EBADF, "not inode"))?;
|
.ok_or(Error::with_message(Errno::EBADF, "not inode"))?;
|
||||||
let dentry = inode_handle.dentry();
|
let dentry = inode_handle.dentry();
|
||||||
let statfs = Statfs::from(dentry.fs().sb());
|
let statfs = Statfs::from(dentry.fs().sb());
|
||||||
CurrentUserSpace::get().write_val(statfs_buf_ptr, &statfs)?;
|
ctx.get_user_space().write_val(statfs_buf_ptr, &statfs)?;
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ pub fn sys_symlinkat(
|
|||||||
linkpath_addr: Vaddr,
|
linkpath_addr: Vaddr,
|
||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let target = user_space.read_cstring(target_addr, MAX_FILENAME_LEN)?;
|
let target = user_space.read_cstring(target_addr, MAX_FILENAME_LEN)?;
|
||||||
let linkpath = user_space.read_cstring(linkpath_addr, MAX_FILENAME_LEN)?;
|
let linkpath = user_space.read_cstring(linkpath_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!(
|
debug!(
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
use super::SyscallReturn;
|
use super::SyscallReturn;
|
||||||
use crate::{prelude::*, time::SystemTime};
|
use crate::{prelude::*, time::SystemTime};
|
||||||
|
|
||||||
pub fn sys_time(tloc: Vaddr, _ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_time(tloc: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
debug!("tloc = 0x{tloc:x}");
|
debug!("tloc = 0x{tloc:x}");
|
||||||
|
|
||||||
let now_as_secs = {
|
let now_as_secs = {
|
||||||
@ -12,7 +12,7 @@ pub fn sys_time(tloc: Vaddr, _ctx: &Context) -> Result<SyscallReturn> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if tloc != 0 {
|
if tloc != 0 {
|
||||||
CurrentUserSpace::get().write_val(tloc, &now_as_secs)?;
|
ctx.get_user_space().write_val(tloc, &now_as_secs)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(now_as_secs as _))
|
Ok(SyscallReturn::Return(now_as_secs as _))
|
||||||
|
@ -51,7 +51,7 @@ pub fn sys_timer_create(
|
|||||||
})
|
})
|
||||||
// Determine the timeout action through `sigevent`.
|
// Determine the timeout action through `sigevent`.
|
||||||
} else {
|
} else {
|
||||||
let sig_event = CurrentUserSpace::get().read_val::<sigevent_t>(sigevent_addr)?;
|
let sig_event = ctx.get_user_space().read_val::<sigevent_t>(sigevent_addr)?;
|
||||||
let sigev_notify = SigNotify::try_from(sig_event.sigev_notify)?;
|
let sigev_notify = SigNotify::try_from(sig_event.sigev_notify)?;
|
||||||
let signo = sig_event.sigev_signo;
|
let signo = sig_event.sigev_signo;
|
||||||
match sigev_notify {
|
match sigev_notify {
|
||||||
@ -146,7 +146,7 @@ pub fn sys_timer_create(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let timer_id = process_timer_manager.add_posix_timer(timer);
|
let timer_id = process_timer_manager.add_posix_timer(timer);
|
||||||
CurrentUserSpace::get().write_val(timer_id_addr, &timer_id)?;
|
ctx.get_user_space().write_val(timer_id_addr, &timer_id)?;
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ pub fn sys_timer_settime(
|
|||||||
return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value");
|
return_errno_with_message!(Errno::EINVAL, "invalid pointer to new value");
|
||||||
}
|
}
|
||||||
|
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let new_itimerspec = user_space.read_val::<itimerspec_t>(new_itimerspec_addr)?;
|
let new_itimerspec = user_space.read_val::<itimerspec_t>(new_itimerspec_addr)?;
|
||||||
let interval = Duration::try_from(new_itimerspec.it_interval)?;
|
let interval = Duration::try_from(new_itimerspec.it_interval)?;
|
||||||
let expire_time = Duration::try_from(new_itimerspec.it_value)?;
|
let expire_time = Duration::try_from(new_itimerspec.it_value)?;
|
||||||
@ -74,7 +74,8 @@ pub fn sys_timer_gettime(
|
|||||||
it_interval: interval,
|
it_interval: interval,
|
||||||
it_value: remain,
|
it_value: remain,
|
||||||
};
|
};
|
||||||
CurrentUserSpace::get().write_val(itimerspec_addr, &itimerspec)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(itimerspec_addr, &itimerspec)?;
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ pub fn sys_ftruncate(fd: FileDesc, len: isize, ctx: &Context) -> Result<SyscallR
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_truncate(path_ptr: Vaddr, len: isize, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_truncate(path_ptr: Vaddr, len: isize, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_ptr, PATH_MAX)?;
|
let path = ctx.get_user_space().read_cstring(path_ptr, PATH_MAX)?;
|
||||||
debug!("path = {:?}, length = {}", path, len);
|
debug!("path = {:?}, length = {}", path, len);
|
||||||
|
|
||||||
check_length(len, ctx)?;
|
check_length(len, ctx)?;
|
||||||
|
@ -8,7 +8,9 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
pub fn sys_umount(path_addr: Vaddr, flags: u64, ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_umount(path_addr: Vaddr, flags: u64, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
let umount_flags = UmountFlags::from_bits_truncate(flags as u32);
|
let umount_flags = UmountFlags::from_bits_truncate(flags as u32);
|
||||||
debug!("path = {:?}, flags = {:?}", path, umount_flags);
|
debug!("path = {:?}, flags = {:?}", path, umount_flags);
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ fn copy_cstring_to_u8_slice(src: &CStr, dst: &mut [u8]) {
|
|||||||
dst[..len].copy_from_slice(&src[..len]);
|
dst[..len].copy_from_slice(&src[..len]);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_uname(old_uname_addr: Vaddr, _ctx: &Context) -> Result<SyscallReturn> {
|
pub fn sys_uname(old_uname_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||||
debug!("old uname addr = 0x{:x}", old_uname_addr);
|
debug!("old uname addr = 0x{:x}", old_uname_addr);
|
||||||
CurrentUserSpace::get().write_val(old_uname_addr, &*UTS_NAME)?;
|
ctx.get_user_space().write_val(old_uname_addr, &*UTS_NAME)?;
|
||||||
Ok(SyscallReturn::Return(0))
|
Ok(SyscallReturn::Return(0))
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,9 @@ pub fn sys_unlinkat(
|
|||||||
return super::rmdir::sys_rmdirat(dirfd, path_addr, ctx);
|
return super::rmdir::sys_rmdirat(dirfd, path_addr, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = CurrentUserSpace::get().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
let path = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||||
debug!("dirfd = {}, path = {:?}", dirfd, path);
|
debug!("dirfd = {}, path = {:?}", dirfd, path);
|
||||||
|
|
||||||
let (dir_dentry, name) = {
|
let (dir_dentry, name) = {
|
||||||
|
@ -30,7 +30,7 @@ pub fn sys_utimensat(
|
|||||||
dirfd, pathname_ptr, timespecs_ptr, flags
|
dirfd, pathname_ptr, timespecs_ptr, flags
|
||||||
);
|
);
|
||||||
let times = if timespecs_ptr != 0 {
|
let times = if timespecs_ptr != 0 {
|
||||||
let (autime, mutime) = read_time_from_user::<timespec_t>(timespecs_ptr)?;
|
let (autime, mutime) = read_time_from_user::<timespec_t>(timespecs_ptr, ctx)?;
|
||||||
if autime.is_utime_omit() && mutime.is_utime_omit() {
|
if autime.is_utime_omit() && mutime.is_utime_omit() {
|
||||||
return Ok(SyscallReturn::Return(0));
|
return Ok(SyscallReturn::Return(0));
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ pub fn sys_utime(pathname_ptr: Vaddr, utimbuf_ptr: Vaddr, ctx: &Context) -> Resu
|
|||||||
pathname_ptr, utimbuf_ptr
|
pathname_ptr, utimbuf_ptr
|
||||||
);
|
);
|
||||||
let times = if utimbuf_ptr != 0 {
|
let times = if utimbuf_ptr != 0 {
|
||||||
let utimbuf = CurrentUserSpace::get().read_val::<Utimbuf>(utimbuf_ptr)?;
|
let utimbuf = ctx.get_user_space().read_val::<Utimbuf>(utimbuf_ptr)?;
|
||||||
let atime = timespec_t {
|
let atime = timespec_t {
|
||||||
sec: utimbuf.actime,
|
sec: utimbuf.actime,
|
||||||
nsec: 0,
|
nsec: 0,
|
||||||
@ -160,7 +160,9 @@ fn do_utimes(
|
|||||||
let pathname = if pathname_ptr == 0 {
|
let pathname = if pathname_ptr == 0 {
|
||||||
String::new()
|
String::new()
|
||||||
} else {
|
} else {
|
||||||
let cstring = CurrentUserSpace::get().read_cstring(pathname_ptr, MAX_FILENAME_LEN)?;
|
let cstring = ctx
|
||||||
|
.get_user_space()
|
||||||
|
.read_cstring(pathname_ptr, MAX_FILENAME_LEN)?;
|
||||||
cstring.to_string_lossy().into_owned()
|
cstring.to_string_lossy().into_owned()
|
||||||
};
|
};
|
||||||
let dentry = {
|
let dentry = {
|
||||||
@ -186,7 +188,7 @@ fn do_futimesat(
|
|||||||
ctx: &Context,
|
ctx: &Context,
|
||||||
) -> Result<SyscallReturn> {
|
) -> Result<SyscallReturn> {
|
||||||
let times = if timeval_ptr != 0 {
|
let times = if timeval_ptr != 0 {
|
||||||
let (autime, mutime) = read_time_from_user::<timeval_t>(timeval_ptr)?;
|
let (autime, mutime) = read_time_from_user::<timeval_t>(timeval_ptr, ctx)?;
|
||||||
if autime.usec >= 1000000 || autime.usec < 0 || mutime.usec >= 1000000 || mutime.usec < 0 {
|
if autime.usec >= 1000000 || autime.usec < 0 || mutime.usec >= 1000000 || mutime.usec < 0 {
|
||||||
return_errno_with_message!(Errno::EINVAL, "Invalid time");
|
return_errno_with_message!(Errno::EINVAL, "Invalid time");
|
||||||
}
|
}
|
||||||
@ -201,9 +203,9 @@ fn do_futimesat(
|
|||||||
do_utimes(dirfd, pathname_ptr, times, 0, ctx)
|
do_utimes(dirfd, pathname_ptr, times, 0, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_time_from_user<T: Pod>(time_ptr: Vaddr) -> Result<(T, T)> {
|
fn read_time_from_user<T: Pod>(time_ptr: Vaddr, ctx: &Context) -> Result<(T, T)> {
|
||||||
let mut time_addr = time_ptr;
|
let mut time_addr = time_ptr;
|
||||||
let user_space = CurrentUserSpace::get();
|
let user_space = ctx.get_user_space();
|
||||||
let autime = user_space.read_val::<T>(time_addr)?;
|
let autime = user_space.read_val::<T>(time_addr)?;
|
||||||
time_addr += core::mem::size_of::<T>();
|
time_addr += core::mem::size_of::<T>();
|
||||||
let mutime = user_space.read_val::<T>(time_addr)?;
|
let mutime = user_space.read_val::<T>(time_addr)?;
|
||||||
|
@ -29,7 +29,8 @@ pub fn sys_wait4(
|
|||||||
|
|
||||||
let (return_pid, exit_code) = (process.pid(), process.exit_code().unwrap());
|
let (return_pid, exit_code) = (process.pid(), process.exit_code().unwrap());
|
||||||
if exit_status_ptr != 0 {
|
if exit_status_ptr != 0 {
|
||||||
CurrentUserSpace::get().write_val(exit_status_ptr as _, &exit_code)?;
|
ctx.get_user_space()
|
||||||
|
.write_val(exit_status_ptr as _, &exit_code)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if rusage_addr != 0 {
|
if rusage_addr != 0 {
|
||||||
@ -39,7 +40,7 @@ pub fn sys_wait4(
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
CurrentUserSpace::get().write_val(rusage_addr, &rusage)?;
|
ctx.get_user_space().write_val(rusage_addr, &rusage)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SyscallReturn::Return(return_pid as _))
|
Ok(SyscallReturn::Return(return_pid as _))
|
||||||
|
@ -24,7 +24,7 @@ pub fn sys_write(
|
|||||||
// the file discriptor. If no errors detected, return 0 successfully.
|
// the file discriptor. If no errors detected, return 0 successfully.
|
||||||
let write_len = if user_buf_len != 0 {
|
let write_len = if user_buf_len != 0 {
|
||||||
let mut buffer = vec![0u8; user_buf_len];
|
let mut buffer = vec![0u8; user_buf_len];
|
||||||
CurrentUserSpace::get()
|
ctx.get_user_space()
|
||||||
.read_bytes(user_buf_ptr, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
.read_bytes(user_buf_ptr, &mut VmWriter::from(buffer.as_mut_slice()))?;
|
||||||
debug!("write content = {:?}", buffer);
|
debug!("write content = {:?}", buffer);
|
||||||
file.write(&buffer)?
|
file.write(&buffer)?
|
||||||
|
Reference in New Issue
Block a user