Skip to content

Commit 959d1c7

Browse files
authored
Merge pull request arceos-org#224 from arceos-org/monolithic
[feat] Add Support for Monolithic kernel
2 parents bb52cf1 + f542419 commit 959d1c7

File tree

51 files changed

+1826
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1826
-218
lines changed

Cargo.lock

Lines changed: 44 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ members = [
1212
"modules/axmm",
1313
"modules/axdma",
1414
"modules/axnet",
15+
"modules/axns",
1516
"modules/axruntime",
1617
"modules/axsync",
1718
"modules/axtask",
@@ -58,6 +59,7 @@ axhal = { path = "modules/axhal" }
5859
axlog = { path = "modules/axlog" }
5960
axmm = { path = "modules/axmm" }
6061
axnet = { path = "modules/axnet" }
62+
axns = { path = "modules/axns" }
6163
axruntime = { path = "modules/axruntime" }
6264
axsync = { path = "modules/axsync" }
6365
axtask = { path = "modules/axtask" }

api/arceos_posix_api/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ smp = ["axfeat/smp"]
2323
irq = ["axfeat/irq"]
2424
alloc = ["dep:axalloc", "axfeat/alloc"]
2525
multitask = ["axtask/multitask", "axfeat/multitask", "axsync/multitask"]
26-
fd = ["alloc"]
26+
fd = ["alloc", "dep:axns"]
2727
fs = ["dep:axfs", "axfeat/fs", "fd"]
2828
net = ["dep:axnet", "axfeat/net", "fd"]
2929
pipe = ["fd"]
3030
select = ["fd"]
3131
epoll = ["fd"]
32+
uspace = ["axns/thread-local"]
3233

3334
[dependencies]
3435
# ArceOS modules
@@ -42,6 +43,7 @@ axalloc = { workspace = true, optional = true }
4243
axtask = { workspace = true, optional = true }
4344
axfs = { workspace = true, optional = true }
4445
axnet = { workspace = true, optional = true }
46+
axns = { workspace = true, optional = true }
4547

4648
# Other crates
4749
axio = "0.1"
@@ -50,6 +52,7 @@ flatten_objects = "0.2"
5052
static_assertions = "1.1.0"
5153
spin = { version = "0.9" }
5254
lazy_static = { version = "1.5", features = ["spin_no_std"] }
55+
ctor_bare = "0.2"
5356

5457
[build-dependencies]
5558
bindgen ={ version = "0.69" }

api/arceos_posix_api/src/imp/fd_ops.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ use core::ffi::c_int;
33

44
use axerrno::{LinuxError, LinuxResult};
55
use axio::PollState;
6+
use axns::{ResArc, def_resource};
67
use flatten_objects::FlattenObjects;
78
use spin::RwLock;
89

9-
use super::stdio::{stdin, stdout};
1010
use crate::ctypes;
11+
use crate::imp::stdio::{stdin, stdout};
1112

1213
pub const AX_FILE_LIMIT: usize = 1024;
1314

@@ -21,14 +22,8 @@ pub trait FileLike: Send + Sync {
2122
fn set_nonblocking(&self, nonblocking: bool) -> LinuxResult;
2223
}
2324

24-
lazy_static::lazy_static! {
25-
static ref FD_TABLE: RwLock<FlattenObjects<Arc<dyn FileLike>, AX_FILE_LIMIT>> = {
26-
let mut fd_table = FlattenObjects::new();
27-
fd_table.add_at(0, Arc::new(stdin()) as _).unwrap_or_else(|_| panic!()); // stdin
28-
fd_table.add_at(1, Arc::new(stdout()) as _).unwrap_or_else(|_| panic!()); // stdout
29-
fd_table.add_at(2, Arc::new(stdout()) as _).unwrap_or_else(|_| panic!()); // stderr
30-
RwLock::new(fd_table)
31-
};
25+
def_resource! {
26+
pub(crate) static FD_TABLE: ResArc<RwLock<FlattenObjects<Arc<dyn FileLike>, AX_FILE_LIMIT>>> = ResArc::new();
3227
}
3328

3429
pub fn get_file_like(fd: c_int) -> LinuxResult<Arc<dyn FileLike>> {
@@ -127,3 +122,18 @@ pub fn sys_fcntl(fd: c_int, cmd: c_int, arg: usize) -> c_int {
127122
}
128123
})
129124
}
125+
126+
#[ctor_bare::register_ctor]
127+
fn init_stdio() {
128+
let mut fd_table = flatten_objects::FlattenObjects::new();
129+
fd_table
130+
.add_at(0, Arc::new(stdin()) as _)
131+
.unwrap_or_else(|_| panic!()); // stdin
132+
fd_table
133+
.add_at(1, Arc::new(stdout()) as _)
134+
.unwrap_or_else(|_| panic!()); // stdout
135+
fd_table
136+
.add_at(2, Arc::new(stdout()) as _)
137+
.unwrap_or_else(|_| panic!()); // stderr
138+
FD_TABLE.init_new(spin::RwLock::new(fd_table));
139+
}

api/arceos_posix_api/src/imp/io_mpx/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ pub unsafe fn sys_select(
153153
unsafe fn zero_fd_set(fds: *mut ctypes::fd_set, nfds: usize) {
154154
if !fds.is_null() {
155155
let nfds_usizes = nfds.div_ceil(BITS_PER_USIZE);
156-
let dst = &mut (*fds).fds_bits[..nfds_usizes];
156+
let dst = &mut unsafe { *fds }.fds_bits[..nfds_usizes];
157157
dst.fill(0);
158158
}
159159
}
160160

161161
unsafe fn set_fd_set(fds: *mut ctypes::fd_set, fd: usize) {
162162
if !fds.is_null() {
163-
(*fds).fds_bits[fd / BITS_PER_USIZE] |= 1 << (fd % BITS_PER_USIZE);
163+
unsafe { *fds }.fds_bits[fd / BITS_PER_USIZE] |= 1 << (fd % BITS_PER_USIZE);
164164
}
165165
}

api/arceos_posix_api/src/imp/net.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,10 @@ pub unsafe fn sys_freeaddrinfo(res: *mut ctypes::addrinfo) {
525525
return;
526526
}
527527
let aibuf_ptr = res as *mut ctypes::aibuf;
528-
let len = (*aibuf_ptr).ref_ as usize;
529-
assert!((*aibuf_ptr).slot == 0);
528+
let len = unsafe { *aibuf_ptr }.ref_ as usize;
529+
assert!(unsafe { *aibuf_ptr }.slot == 0);
530530
assert!(len > 0);
531-
let vec = Vec::from_raw_parts(aibuf_ptr, len, len); // TODO: lock
531+
let vec = unsafe { Vec::from_raw_parts(aibuf_ptr, len, len) }; // TODO: lock
532532
drop(vec);
533533
}
534534

modules/axfs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ crate_interface = { version = "0.1", optional = true }
3434
axsync = { workspace = true }
3535
axdriver = { workspace = true, features = ["block"] }
3636
axdriver_block = { git = "https://github.com/arceos-org/axdriver_crates.git", tag = "v0.1.0" }
37+
axns = { workspace = true }
3738

3839
[dependencies.fatfs]
3940
git = "https://github.com/rafalh/rust-fatfs"

modules/axfs/src/root.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
use alloc::{string::String, sync::Arc, vec::Vec};
66
use axerrno::{AxError, AxResult, ax_err};
77
use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodeRef, VfsNodeType, VfsOps, VfsResult};
8+
use axns::{ResArc, def_resource};
89
use axsync::Mutex;
910
use lazyinit::LazyInit;
1011

1112
use crate::{api::FileType, fs, mounts};
1213

13-
static CURRENT_DIR_PATH: Mutex<String> = Mutex::new(String::new());
14-
static CURRENT_DIR: LazyInit<Mutex<VfsNodeRef>> = LazyInit::new();
14+
def_resource! {
15+
static CURRENT_DIR_PATH: ResArc<Mutex<String>> = ResArc::new();
16+
static CURRENT_DIR: ResArc<Mutex<VfsNodeRef>> = ResArc::new();
17+
}
1518

1619
struct MountPoint {
1720
path: &'static str,
@@ -180,8 +183,8 @@ pub(crate) fn init_rootfs(disk: crate::dev::Disk) {
180183
.expect("fail to mount sysfs at /sys");
181184

182185
ROOT_DIR.init_once(Arc::new(root_dir));
183-
CURRENT_DIR.init_once(Mutex::new(ROOT_DIR.clone()));
184-
*CURRENT_DIR_PATH.lock() = "/".into();
186+
CURRENT_DIR.init_new(Mutex::new(ROOT_DIR.clone()));
187+
CURRENT_DIR_PATH.init_new(Mutex::new("/".into()));
185188
}
186189

187190
fn parent_node_of(dir: Option<&VfsNodeRef>, path: &str) -> VfsNodeRef {

modules/axhal/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ paging = ["axalloc", "page_table_multiarch"]
1717
irq = []
1818
tls = ["alloc"]
1919
rtc = ["x86_rtc", "riscv_goldfish", "arm_pl031"]
20+
uspace = ["paging"]
2021
default = []
2122

2223
[dependencies]

modules/axhal/linker.lds.S

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,22 @@ SECTIONS
1616
_etext = .;
1717
}
1818

19+
_srodata = .;
1920
.rodata : ALIGN(4K) {
20-
_srodata = .;
2121
*(.rodata .rodata.*)
2222
*(.srodata .srodata.*)
2323
*(.sdata2 .sdata2.*)
24-
. = ALIGN(4K);
25-
_erodata = .;
2624
}
2725

26+
.init_array : ALIGN(0x10) {
27+
__init_array_start = .;
28+
*(.init_array .init_array.*)
29+
__init_array_end = .;
30+
}
31+
32+
. = ALIGN(4K);
33+
_erodata = .;
34+
2835
.data : ALIGN(4K) {
2936
_sdata = .;
3037
*(.data.boot_page_table)
@@ -87,5 +94,8 @@ SECTIONS {
8794
linkm2_IRQ : { *(linkm2_IRQ) }
8895
linkme_PAGE_FAULT : { *(linkme_PAGE_FAULT) }
8996
linkm2_PAGE_FAULT : { *(linkm2_PAGE_FAULT) }
97+
linkme_SYSCALL : { *(linkme_SYSCALL) }
98+
linkm2_SYSCALL : { *(linkm2_SYSCALL) }
99+
axns_resource : { *(axns_resource) }
90100
}
91101
INSERT AFTER .tbss;

0 commit comments

Comments
 (0)