diff --git a/Cargo.toml b/Cargo.toml index bb5f9253..dbbcdfe3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,19 +12,23 @@ linkme = "0.3" axerrno = "0.1" memory_addr = "0.3" xmas-elf = "0.9" +spin = "0.9" +crate_interface = "0.1" bitflags = "2.6" kernel-elf-parser = "0.1.0" num_enum = { version = "0.7", default-features = false } syscalls = { version = "0.6", default-features = false } +axfs = { git = "https://github.com/arceos-org/arceos.git", features = ["thread-local"] } axstd = { git = "https://github.com/arceos-org/arceos.git", features = ["paging"] } axhal = { git = "https://github.com/arceos-org/arceos.git", features = ["uspace"] } axmm = { git = "https://github.com/arceos-org/arceos.git" } axtask = { git = "https://github.com/arceos-org/arceos.git" } axsync = { git = "https://github.com/arceos-org/arceos.git" } axruntime = { git = "https://github.com/arceos-org/arceos.git", features = ["multitask"] } -arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git" } +arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git", features = ["uspace"] } +axns = { git = "https://github.com/arceos-org/arceos.git", features = ["thread-local"] } [target.'cfg(target_arch = "x86_64")'.dependencies] x86 = "0.52" diff --git a/apps/nimbos/test_cmd b/apps/nimbos/test_cmd index 38e7fc6c..c76fd4fe 100644 --- a/apps/nimbos/test_cmd +++ b/apps/nimbos/test_cmd @@ -1 +1 @@ -test_one "LOG=off" "expect_off.out" +test_one "LOG=info" "expect_off.out" diff --git a/scripts/config.toml.temp b/scripts/config.toml.temp index 9211c0ca..726cc465 100644 --- a/scripts/config.toml.temp +++ b/scripts/config.toml.temp @@ -6,3 +6,5 @@ axmm = { path = "%AX_ROOT%/modules/axmm" } axtask = { path = "%AX_ROOT%/modules/axtask" } axsync = { path = "%AX_ROOT%/modules/axsync" } axruntime = { path = "%AX_ROOT%/modules/axruntime" } +axns = { path = "%AX_ROOT%/modules/axns" } +axfs = { path = "%AX_ROOT%/modules/axfs" } \ No newline at end of file diff --git a/scripts/get_deps.sh b/scripts/get_deps.sh index 92011146..2ced3f39 100755 --- a/scripts/get_deps.sh +++ b/scripts/get_deps.sh @@ -3,6 +3,6 @@ AX_ROOT=.arceos test ! -d "$AX_ROOT" && echo "Cloning repositories ..." || true -test ! -d "$AX_ROOT" && git clone https://github.com/arceos-org/arceos -b monolithic "$AX_ROOT" --depth=1 || true +test ! -d "$AX_ROOT" && git clone https://github.com/Azure-stars/Starry -b monolithic "$AX_ROOT" --depth=1 || true $(dirname $0)/set_ax_root.sh $AX_ROOT diff --git a/src/syscall_imp/fs/mod.rs b/src/syscall_imp/fs/mod.rs index 3e925036..98b1e253 100644 --- a/src/syscall_imp/fs/mod.rs +++ b/src/syscall_imp/fs/mod.rs @@ -1,5 +1,7 @@ mod ctl; mod io; +mod path; pub(crate) use self::ctl::*; pub(crate) use self::io::*; +pub(crate) use self::path::*; diff --git a/src/syscall_imp/fs/path.rs b/src/syscall_imp/fs/path.rs new file mode 100644 index 00000000..ce9e8597 --- /dev/null +++ b/src/syscall_imp/fs/path.rs @@ -0,0 +1,12 @@ +use core::ffi::c_char; + +use crate::syscall_body; +use axerrno::LinuxError; + +pub(crate) fn sys_getcwd(buf: *mut c_char, size: usize) -> *mut c_char { + arceos_posix_api::sys_getcwd(buf, size) +} + +pub(crate) fn sys_chdir(path: *const c_char) -> i32 { + arceos_posix_api::sys_chdir(path) +} diff --git a/src/task.rs b/src/task.rs index 403dbacf..d4b5acb3 100644 --- a/src/task.rs +++ b/src/task.rs @@ -4,6 +4,7 @@ use alloc::sync::Arc; use axhal::arch::UspaceContext; use axmm::AddrSpace; +use axns::{AxNamespace, AxNamespaceIf}; use axsync::Mutex; use axtask::{AxTaskRef, TaskExtRef, TaskInner}; @@ -21,15 +22,18 @@ pub struct TaskExt { pub uctx: UspaceContext, /// The virtual memory address space. pub aspace: Arc>, + /// The resource namespace + pub ns: AxNamespace, } impl TaskExt { - pub const fn new(uctx: UspaceContext, aspace: Arc>) -> Self { + pub fn new(uctx: UspaceContext, aspace: Arc>) -> Self { Self { proc_id: 233, uctx, clear_child_tid: AtomicU64::new(0), aspace, + ns: AxNamespace::new_thread_local(), } } @@ -44,6 +48,21 @@ impl TaskExt { } } +struct AxNamespaceImpl; + +#[crate_interface::impl_interface] +impl AxNamespaceIf for AxNamespaceImpl { + #[inline(never)] + fn current_namespace_base() -> *mut u8 { + log::info!("current_namespace_base {}", axtask::current().id_name()); + let current = axtask::current(); + if current.name() == "main" { + return axns::AxNamespace::global().base(); + } + axtask::current().task_ext().ns.base() + } +} + axtask::def_task_ext!(TaskExt); pub fn spawn_user_task(aspace: Arc>, uctx: UspaceContext) -> AxTaskRef {