Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit 86c8ddf

Browse files
committed
[feat] Add axns for task
1 parent 0b59da2 commit 86c8ddf

File tree

9 files changed

+465
-21
lines changed

9 files changed

+465
-21
lines changed

Cargo.lock

Lines changed: 392 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ linkme = "0.3"
1212
axerrno = "0.1"
1313
memory_addr = "0.3"
1414
xmas-elf = "0.9"
15+
crate_interface = "0.1"
1516
bitflags = "2.6"
1617
kernel-elf-parser = "0.1.0"
1718
num_enum = { version = "0.7", default-features = false }
1819
syscalls = { version = "0.6", default-features = false }
1920

20-
axstd = { git = "https://github.com/arceos-org/arceos.git", features = ["paging"] }
21-
axhal = { git = "https://github.com/arceos-org/arceos.git", features = ["uspace"] }
22-
axmm = { git = "https://github.com/arceos-org/arceos.git" }
23-
axtask = { git = "https://github.com/arceos-org/arceos.git" }
24-
axsync = { git = "https://github.com/arceos-org/arceos.git" }
25-
axruntime = { git = "https://github.com/arceos-org/arceos.git", features = ["multitask"] }
26-
arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git" }
21+
axstd = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic", features = ["paging"] }
22+
axhal = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic", features = ["uspace"] }
23+
axmm = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic" }
24+
axtask = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic" }
25+
axsync = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic" }
26+
axruntime = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic", features = ["multitask"] }
27+
arceos_posix_api = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic", features = ["uspace"] }
28+
axns = { git = "https://github.com/arceos-org/arceos.git", branch = "monolithic", features = ["thread-local"] }
2729

2830
[target.'cfg(target_arch = "x86_64")'.dependencies]
2931
x86 = "0.52"

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ all: build
1515

1616
ax_root:
1717
@./scripts/set_ax_root.sh $(AX_ROOT)
18+
@make -C $(AX_ROOT) disk_img
1819

1920
user_apps:
2021
@make -C ./apps/$(AX_TESTCASE) ARCH=$(ARCH) build
@@ -23,7 +24,7 @@ test:
2324
@./scripts/app_test.sh
2425

2526
build run justrun debug disasm: ax_root
26-
@make -C $(AX_ROOT) A=$(PWD) FEATURES=$(FEATURES) $@
27+
@make -C $(AX_ROOT) A=$(PWD) FEATURES=$(FEATURES) BLK=y NET=y $@
2728

2829
clean: ax_root
2930
@make -C $(AX_ROOT) A=$(PWD) clean

apps/nimbos/expect_off.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ log_level = off
44

55
Hello world from user mode program!
66
Hello, world!
7-
Hello, I am process 2.
8-
Back in process 2, iteration 0.
9-
Back in process 2, iteration 1.
10-
Back in process 2, iteration 2.
11-
Back in process 2, iteration 3.
12-
Back in process 2, iteration 4.
7+
Hello, I am process 6.
8+
Back in process 6, iteration 0.
9+
Back in process 6, iteration 1.
10+
Back in process 6, iteration 2.
11+
Back in process 6, iteration 3.
12+
Back in process 6, iteration 4.
1313
yield passed!
1414
into sleep test!
1515
simple_sleep passed!

scripts/config.toml.temp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ axstd = { path = "%AX_ROOT%/ulib/axstd" }
33
arceos_posix_api = { path = "%AX_ROOT%/api/arceos_posix_api" }
44
axhal = { path = "%AX_ROOT%/modules/axhal" }
55
axmm = { path = "%AX_ROOT%/modules/axmm" }
6+
axns = { path = "%AX_ROOT%/modules/axns" }
67
axtask = { path = "%AX_ROOT%/modules/axtask" }
78
axsync = { path = "%AX_ROOT%/modules/axsync" }
89
axruntime = { path = "%AX_ROOT%/modules/axruntime" }

scripts/get_deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
AX_ROOT=.arceos
44

55
test ! -d "$AX_ROOT" && echo "Cloning repositories ..." || true
6-
test ! -d "$AX_ROOT" && git clone https://github.com/arceos-org/arceos -b monolithic "$AX_ROOT" --depth=1 || true
6+
test ! -d "$AX_ROOT" && git clone https://github.com/Azure-stars/Starry -b monolithic "$AX_ROOT" --depth=1 || true
77

88
$(dirname $0)/set_ax_root.sh $AX_ROOT

src/syscall_imp/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ fn handle_syscall(tf: &TrapFrame, syscall_num: usize) -> isize {
5454
Sysno::writev => sys_writev(tf.arg0() as _, tf.arg1() as _, tf.arg2() as _),
5555
Sysno::sched_yield => sys_sched_yield() as isize,
5656
Sysno::nanosleep => sys_nanosleep(tf.arg0() as _, tf.arg1() as _) as _,
57+
Sysno::clock_nanosleep => sys_clock_nanosleep(
58+
tf.arg0() as _,
59+
tf.arg1() as _,
60+
tf.arg2() as _,
61+
tf.arg3() as _,
62+
) as _,
5763
Sysno::getpid => sys_getpid() as isize,
5864
Sysno::exit => sys_exit(tf.arg0() as _),
5965
#[cfg(target_arch = "x86_64")]

src/syscall_imp/task/schedule.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
use arceos_posix_api as api;
1+
use arceos_posix_api::{
2+
self as api,
3+
ctypes::{clockid_t, timespec},
4+
};
5+
use axerrno::LinuxError;
26

37
pub(crate) fn sys_sched_yield() -> i32 {
48
api::sys_sched_yield()
59
}
610

7-
pub(crate) fn sys_nanosleep(
8-
req: *const api::ctypes::timespec,
9-
rem: *mut api::ctypes::timespec,
11+
pub(crate) fn sys_nanosleep(req: *const timespec, rem: *mut timespec) -> i32 {
12+
unsafe { api::sys_nanosleep(req, rem) }
13+
}
14+
15+
pub(crate) fn sys_clock_nanosleep(
16+
clock_id: clockid_t,
17+
flags: isize,
18+
req: *const timespec,
19+
rem: *mut timespec,
1020
) -> i32 {
21+
// CLOCK defaults to CLOCK_REALTIME
22+
// flags defaults to 0
23+
24+
if clock_id != api::ctypes::CLOCK_REALTIME as clockid_t {
25+
// For older linux headers, it does not define ENOTSUP, so we use EOPNOTSUPP instead
26+
return -LinuxError::EOPNOTSUPP.code();
27+
}
28+
29+
if flags != 0 {
30+
return -LinuxError::EOPNOTSUPP.code();
31+
}
32+
1133
unsafe { api::sys_nanosleep(req, rem) }
1234
}

src/task.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use alloc::sync::Arc;
21
use core::sync::atomic::AtomicU64;
32

3+
use alloc::sync::Arc;
4+
45
use axhal::arch::UspaceContext;
56
use axmm::AddrSpace;
7+
use axns::{AxNamespace, AxNamespaceIf};
68
use axsync::Mutex;
79
use axtask::{AxTaskRef, TaskExtRef, TaskInner};
810

@@ -20,15 +22,18 @@ pub struct TaskExt {
2022
pub uctx: UspaceContext,
2123
/// The virtual memory address space.
2224
pub aspace: Arc<Mutex<AddrSpace>>,
25+
/// The resource namespace
26+
pub ns: AxNamespace,
2327
}
2428

2529
impl TaskExt {
26-
pub const fn new(uctx: UspaceContext, aspace: Arc<Mutex<AddrSpace>>) -> Self {
30+
pub fn new(uctx: UspaceContext, aspace: Arc<Mutex<AddrSpace>>) -> Self {
2731
Self {
2832
proc_id: 233,
2933
uctx,
3034
clear_child_tid: AtomicU64::new(0),
3135
aspace,
36+
ns: AxNamespace::new_thread_local(),
3237
}
3338
}
3439

@@ -43,6 +48,21 @@ impl TaskExt {
4348
}
4449
}
4550

51+
struct AxNamespaceImpl;
52+
53+
#[crate_interface::impl_interface]
54+
impl AxNamespaceIf for AxNamespaceImpl {
55+
#[inline(never)]
56+
fn current_namespace_base() -> *mut u8 {
57+
let current = axtask::current();
58+
// Safety: We only check whether the task extended data is null and do not access it.
59+
if unsafe { current.task_ext_ptr() }.is_null() {
60+
return axns::AxNamespace::global().base();
61+
}
62+
current.task_ext().ns.base()
63+
}
64+
}
65+
4666
axtask::def_task_ext!(TaskExt);
4767

4868
pub fn spawn_user_task(aspace: Arc<Mutex<AddrSpace>>, uctx: UspaceContext) -> AxTaskRef {

0 commit comments

Comments
 (0)