Skip to content
Draft
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
81 changes: 70 additions & 11 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ spin = "0.10"
starry-process = "0.2"
starry-signal = { version = "0.2", git = "https://github.com/Starry-OS/starry-signal.git", tag = "dev-v02" }
starry-vm = "0.2"
starry-vdso = { git = "https://github.com/Starry-OS/starry-vdso.git", rev = "dab20cc" }

starry-core = { path = "./core" }
starry-api = { path = "./api" }
Expand Down Expand Up @@ -127,6 +128,7 @@ starry-signal.workspace = true

starry-core.workspace = true
starry-api.workspace = true
starry-vdso.workspace = true

[dependencies.axplat-riscv64-visionfive2]
version = "0.3"
Expand Down
1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ spin.workspace = true
starry-process.workspace = true
starry-signal.workspace = true
starry-vm.workspace = true
starry-vdso.workspace = true
syscalls = { git = "https://github.com/Starry-OS/syscalls.git", rev = "efac241", default-features = false }
zerocopy = { version = "0.8.26", features = ["derive"] }

Expand Down
4 changes: 4 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ pub fn init() {
info!("Initialize VFS...");
vfs::mount_all().expect("Failed to mount vfs");

info!("Initialize vDSO data...");
starry_vdso::vdso::init_vdso_data();

info!("Initialize /proc/interrupts...");
axtask::register_timer_callback(|_| {
time::inc_irq_cnt();
starry_vdso::vdso::update_vdso_data();
});

info!("Initialize alarm...");
Expand Down
3 changes: 3 additions & 0 deletions api/src/syscall/task/clone.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::sync::atomic::Ordering;

use alloc::sync::Arc;

use axerrno::{AxError, AxResult};
Expand Down Expand Up @@ -180,6 +182,7 @@ pub fn sys_clone(
aspace,
signal_actions,
exit_signal,
old_proc_data.signal.default_restorer.load(Ordering::Relaxed),
);
proc_data.set_umask(old_proc_data.umask());

Expand Down
6 changes: 5 additions & 1 deletion api/src/syscall/task/execve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ pub fn sys_execve(
}

let mut aspace = proc_data.aspace.lock();
let (entry_point, user_stack_base) =
let (entry_point, user_stack_base, auxv) =
load_user_app(&mut aspace, Some(path.as_str()), &args, &envs)?;
drop(aspace);

let trampoline = starry_vdso::vdso::get_trampoline_addr(&auxv)
.unwrap_or(starry_core::config::SIGNAL_TRAMPOLINE);
proc_data.signal.set_default_restorer(trampoline);

let loc = FS_CONTEXT.lock().resolve(&path)?;
curr.set_name(loc.name());

Expand Down
21 changes: 21 additions & 0 deletions apps/vdso_test/test_getcpu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::println;

fn main() {
println!("test_getcpu: calling init_vdso_getcpu(cpu=1, node=0)");

// Call the vDSO getcpu initializer from the library.
// This may require appropriate privileges on the running machine.
// If running on a non-x86_64 platform this binary will not call the
// x86_64 implementation because the crate exposes platform modules
// conditionally.
if cfg!(target_arch = "x86_64") {
// Use the crate name with hyphen turned to underscore
use starry_vdso::x86_64::getcpu::init_vdso_getcpu;

// Example values; adjust as needed for your test environment.
init_vdso_getcpu(1u32, 0u32);
println!("init_vdso_getcpu returned (check kernel/log output for details)");
} else {
println!("Skipping init_vdso_getcpu: not x86_64 target");
}
}
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ spin.workspace = true
starry-process.workspace = true
starry-signal.workspace = true
starry-vm.workspace = true
starry-vdso.workspace = true
strum = { version = "0.27.2", default-features = false, features = ["derive"] }
uluru = "3.1.0"
weak-map = "0.1.1"
Expand Down
51 changes: 48 additions & 3 deletions core/src/mm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,55 @@ impl ElfLoader {
ldso.as_ref()
.map_or_else(|| elf.entry(), |ldso| ldso.entry()),
);
let auxv = elf
let mut auxv = elf
.aux_vector(PAGE_SIZE_4K, ldso.map(|elf| elf.base()))
.collect::<Vec<_>>();

{
let uspace = core::cell::RefCell::new(&mut *uspace);
starry_vdso::vdso::load_vdso_data(
&mut auxv,
|map_user_start, vdso_paddr_page, vdso_size| {
uspace
.borrow_mut()
.map_linear(
map_user_start.into(),
vdso_paddr_page,
vdso_size,
MappingFlags::READ | MappingFlags::EXECUTE | MappingFlags::USER,
)
.map_err(|_| AxError::InvalidExecutable)
},
|vvar_user_addr, vvar_paddr| {
uspace
.borrow_mut()
.map_linear(
vvar_user_addr.into(),
vvar_paddr.into(),
starry_vdso::config::VVAR_PAGES * PAGE_SIZE_4K,
MappingFlags::READ | MappingFlags::USER,
)
.map_err(|_| AxError::InvalidExecutable)
},
|seg_user_start, seg_paddr, seg_align_size, ph| {
let mut flags = MappingFlags::USER;
if ph.flags.is_read() {
flags |= MappingFlags::READ;
}
if ph.flags.is_write() {
flags |= MappingFlags::WRITE;
}
if ph.flags.is_execute() {
flags |= MappingFlags::EXECUTE;
}
uspace
.borrow_mut()
.map_linear(seg_user_start.into(), seg_paddr, seg_align_size, flags)
.map_err(|_| AxError::InvalidExecutable)
},
)?;
}

Ok(Ok((entry, auxv)))
}
}
Expand Down Expand Up @@ -280,7 +325,7 @@ pub fn load_user_app(
path: Option<&str>,
args: &[String],
envs: &[String],
) -> AxResult<(VirtAddr, VirtAddr)> {
) -> AxResult<(VirtAddr, VirtAddr, Vec<AuxEntry>)> {
let path = path
.or_else(|| args.first().map(String::as_str))
.ok_or(AxError::InvalidInput)?;
Expand Down Expand Up @@ -347,7 +392,7 @@ pub fn load_user_app(
Backend::new_alloc(heap_start, PageSize::Size4K),
)?;

Ok((entry, user_sp))
Ok((entry, user_sp, auxv))
}

static ACCESSING_USER_MEM: AtomicBool = AtomicBool::new(false);
Expand Down
3 changes: 2 additions & 1 deletion core/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ impl ProcessData {
aspace: Arc<Mutex<AddrSpace>>,
signal_actions: Arc<SpinNoIrq<SignalActions>>,
exit_signal: Option<Signo>,
trampoline: usize,
) -> Arc<Self> {
Arc::new(Self {
proc,
Expand All @@ -238,7 +239,7 @@ impl ProcessData {

signal: Arc::new(ProcessSignalManager::new(
signal_actions,
crate::config::SIGNAL_TRAMPOLINE,
trampoline,
)),

futex_table: Arc::new(FutexTable::new()),
Expand Down
Loading