Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ axns = { git = "https://github.com/oscomp/arceos.git", features = [
] }
axsync = { git = "https://github.com/oscomp/arceos.git" }
axtask = { git = "https://github.com/oscomp/arceos.git" }
axptr = { git = "https://github.com/Starry-OS/axptr.git" }
axsignal = { git = "https://github.com/Starry-OS/axsignal.git" }


axerrno = "0.1"
bitflags = "2.6"
Expand Down
4 changes: 3 additions & 1 deletion api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ axlog.workspace = true
axsync.workspace = true
axtask.workspace = true
arceos_posix_api.workspace = true
axptr.workspace = true
axsignal.workspace = true

axerrno.workspace = true
bitflags.workspace = true
memory_addr.workspace = true
linkme.workspace = true

starry-core.workspace = true

macro_rules_attribute = "0.2"
num_enum = { version = "0.7", default-features = false }
static_assertions = "1.1"

Expand Down
38 changes: 18 additions & 20 deletions api/src/imp/fs/ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ use core::ffi::{c_char, c_void};
use alloc::string::ToString;
use arceos_posix_api::AT_FDCWD;
use axerrno::{AxError, LinuxError, LinuxResult};
use macro_rules_attribute::apply;

use crate::{
ptr::{PtrWrapper, UserConstPtr, UserPtr},
syscall_instrument,
};
use axptr::{UserConstPtr, UserPtr};
use axtask::{TaskExtRef, current};

/// The ioctl() system call manipulates the underlying device parameters
/// of special files.
Expand All @@ -18,22 +14,21 @@ use crate::{
/// * `op` - The request code. It is of type unsigned long in glibc and BSD,
/// and of type int in musl and other UNIX systems.
/// * `argp` - The argument to the request. It is a pointer to a memory location
#[apply(syscall_instrument)]
pub fn sys_ioctl(_fd: i32, _op: usize, _argp: UserPtr<c_void>) -> LinuxResult<isize> {
warn!("Unimplemented syscall: SYS_IOCTL");
Ok(0)
}

pub fn sys_chdir(path: UserConstPtr<c_char>) -> LinuxResult<isize> {
let path = path.get_as_str()?;
let path = path.get_as_str(current().task_ext())?;
axfs::api::set_current_dir(path).map(|_| 0).map_err(|err| {
warn!("Failed to change directory: {err:?}");
err.into()
})
}

pub fn sys_mkdirat(dirfd: i32, path: UserConstPtr<c_char>, mode: u32) -> LinuxResult<isize> {
let path = path.get_as_str()?;
let path = path.get_as_str(current().task_ext())?;

if !path.starts_with("/") && dirfd != AT_FDCWD as i32 {
warn!("unsupported.");
Expand Down Expand Up @@ -142,8 +137,9 @@ impl<'a> DirBuffer<'a> {
}
}

pub fn sys_getdents64(fd: i32, buf: UserPtr<c_void>, len: usize) -> LinuxResult<isize> {
let buf = buf.get_as_bytes(len)?;
pub fn sys_getdents64(fd: i32, mut buf: UserPtr<u8>, len: usize) -> LinuxResult<isize> {
let buf_address = buf.address().as_usize();
let buf = buf.get_as_slice(current().task_ext(), len)?;

if len < DirEnt::FIXED_SIZE {
warn!("Buffer size too small: {len}");
Expand All @@ -158,14 +154,15 @@ pub fn sys_getdents64(fd: i32, buf: UserPtr<c_void>, len: usize) -> LinuxResult<
}
};

let mut buffer =
unsafe { DirBuffer::new(core::slice::from_raw_parts_mut(buf as *mut u8, len)) };
let mut buffer = DirBuffer::new(buf);

let (initial_offset, count) = unsafe {
let (initial_offset, count) = {
let mut buf_offset = 0;
let mut count = 0;
while buf_offset + DirEnt::FIXED_SIZE <= len {
let dir_ent = *(buf.add(buf_offset) as *const DirEnt);
let dir_ent: UserConstPtr<DirEnt> = (buf_address + buf_offset).into();
let dir_ent = dir_ent.get(current().task_ext())?;

if dir_ent.d_reclen == 0 {
break;
}
Expand Down Expand Up @@ -226,8 +223,8 @@ pub fn sys_linkat(
new_path: UserConstPtr<c_char>,
flags: i32,
) -> LinuxResult<isize> {
let old_path = old_path.get_as_null_terminated()?;
let new_path = new_path.get_as_null_terminated()?;
let old_path = old_path.get_as_null_terminated(current().task_ext())?;
let new_path = new_path.get_as_null_terminated(current().task_ext())?;

if flags != 0 {
warn!("Unsupported flags: {flags}");
Expand Down Expand Up @@ -262,7 +259,7 @@ pub fn sys_linkat(
/// flags: can be 0 or AT_REMOVEDIR
/// return 0 when success, else return -1
pub fn sys_unlinkat(dir_fd: isize, path: UserConstPtr<c_char>, flags: usize) -> LinuxResult<isize> {
let path = path.get_as_null_terminated()?;
let path = path.get_as_null_terminated(current().task_ext())?;

const AT_REMOVEDIR: usize = 0x200;

Expand Down Expand Up @@ -293,6 +290,7 @@ pub fn sys_unlinkat(dir_fd: isize, path: UserConstPtr<c_char>, flags: usize) ->
.map_err(|err| err.into())
}

pub fn sys_getcwd(buf: UserPtr<c_char>, size: usize) -> LinuxResult<isize> {
Ok(arceos_posix_api::sys_getcwd(buf.get_as_null_terminated()?.as_ptr() as _, size) as _)
pub fn sys_getcwd(mut buf: UserPtr<c_char>, size: usize) -> LinuxResult<isize> {
let buf = buf.get_as_slice(current().task_ext(), size + 1)?;
Ok(arceos_posix_api::sys_getcwd(buf.as_mut_ptr() as _, size) as _)
}
24 changes: 12 additions & 12 deletions api/src/imp/fs/io.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
use core::ffi::{c_char, c_void};
use core::ffi::c_char;

use arceos_posix_api::{self as api, ctypes::mode_t};
use axerrno::LinuxResult;
use axptr::{UserConstPtr, UserPtr};
use axtask::{TaskExtRef, current};

use crate::ptr::{PtrWrapper, UserConstPtr, UserPtr};

pub fn sys_read(fd: i32, buf: UserPtr<c_void>, count: usize) -> LinuxResult<isize> {
let buf = buf.get_as_bytes(count)?;
Ok(api::sys_read(fd, buf, count))
pub fn sys_read(fd: i32, mut buf: UserPtr<u8>, count: usize) -> LinuxResult<isize> {
let buf = buf.get_as_slice(current().task_ext(), count)?;
Ok(api::sys_read(fd, buf.as_mut_ptr().cast(), count))
}

pub fn sys_write(fd: i32, buf: UserConstPtr<c_void>, count: usize) -> LinuxResult<isize> {
let buf = buf.get_as_bytes(count)?;
Ok(api::sys_write(fd, buf, count))
pub fn sys_write(fd: i32, buf: UserConstPtr<u8>, count: usize) -> LinuxResult<isize> {
let buf = buf.get_as_slice(current().task_ext(), count)?;
Ok(api::sys_write(fd, buf.as_ptr().cast(), count))
}

pub fn sys_writev(
fd: i32,
iov: UserConstPtr<api::ctypes::iovec>,
iocnt: i32,
) -> LinuxResult<isize> {
let iov = iov.get_as_bytes(iocnt as _)?;
unsafe { Ok(api::sys_writev(fd, iov, iocnt)) }
let iov = iov.get_as_slice(current().task_ext(), iocnt as _)?;
unsafe { Ok(api::sys_writev(fd, iov.as_ptr().cast(), iocnt)) }
}

pub fn sys_openat(
Expand All @@ -30,7 +30,7 @@ pub fn sys_openat(
flags: i32,
modes: mode_t,
) -> LinuxResult<isize> {
let path = path.get_as_null_terminated()?;
let path = path.get_as_str(current().task_ext())?;
Ok(api::sys_openat(dirfd, path.as_ptr(), flags, modes) as _)
}

Expand Down
15 changes: 8 additions & 7 deletions api/src/imp/fs/mount.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use alloc::vec::Vec;
use arceos_posix_api::{AT_FDCWD, FilePath, handle_file_path};
use axerrno::{LinuxError, LinuxResult};
use axptr::UserConstPtr;
use axsync::Mutex;
use axtask::{TaskExtRef, current};
use core::ffi::{c_char, c_void};

use crate::ptr::UserConstPtr;

pub fn sys_mount(
source: UserConstPtr<c_char>,
target: UserConstPtr<c_char>,
Expand All @@ -14,9 +14,10 @@ pub fn sys_mount(
_data: UserConstPtr<c_void>,
) -> LinuxResult<isize> {
info!("sys_mount");
let source = source.get_as_null_terminated()?;
let target = target.get_as_null_terminated()?;
let fs_type = fs_type.get_as_str()?;
let curr = current();
let source = source.get_as_null_terminated(curr.task_ext())?;
let target = target.get_as_null_terminated(curr.task_ext())?;
let fs_type = fs_type.get_as_str(curr.task_ext())?;
let device_path = handle_file_path(AT_FDCWD, Some(source.as_ptr() as _), false)?;
let mount_path = handle_file_path(AT_FDCWD, Some(target.as_ptr() as _), true)?;
info!(
Expand Down Expand Up @@ -48,8 +49,8 @@ pub fn sys_mount(

pub fn sys_umount2(target: UserConstPtr<c_char>, flags: i32) -> LinuxResult<isize> {
info!("sys_umount2");
let target = target.get_as_null_terminated()?;
let mount_path = handle_file_path(AT_FDCWD, Some(target.as_ptr() as _), true)?;
let target = target.get_as_str(current().task_ext())?;
let mount_path = handle_file_path(AT_FDCWD, Some(target.as_ptr()), true)?;
if flags != 0 {
debug!("flags unimplemented");
return Err(LinuxError::EPERM);
Expand Down
11 changes: 5 additions & 6 deletions api/src/imp/fs/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use core::ffi::c_int;

use arceos_posix_api as api;
use axerrno::LinuxResult;
use axptr::UserPtr;
use axtask::{current, TaskExtRef};

use crate::ptr::{PtrWrapper, UserPtr};

pub fn sys_pipe2(fds: UserPtr<i32>) -> LinuxResult<isize> {
let fds = fds.get_as_array(2)?;
let fds_slice: &mut [c_int] = unsafe { core::slice::from_raw_parts_mut(fds, 2) };
Ok(api::sys_pipe(fds_slice) as _)
pub fn sys_pipe2(mut fds: UserPtr<c_int>) -> LinuxResult<isize> {
let fds = fds.get_as_slice(current().task_ext(), 2)?;
Ok(api::sys_pipe(fds) as _)
}
Loading
Loading