diff --git a/kernel/src/process/process_table.rs b/kernel/src/process/process_table.rs index 6bf19efbe..5a6ec3804 100644 --- a/kernel/src/process/process_table.rs +++ b/kernel/src/process/process_table.rs @@ -28,6 +28,11 @@ pub fn process_table_mut() -> MutexGuard<'static, ProcessTable> { PROCESS_TABLE.lock() } +/// Returns the number of current processes. +pub fn process_num() -> usize { + PROCESS_TABLE.lock().inner.len() +} + /// Process Table. pub struct ProcessTable { inner: BTreeMap>, diff --git a/kernel/src/syscall/sysinfo.rs b/kernel/src/syscall/sysinfo.rs index dad7ed620..a6f26c10b 100644 --- a/kernel/src/syscall/sysinfo.rs +++ b/kernel/src/syscall/sysinfo.rs @@ -3,11 +3,11 @@ use aster_time::read_monotonic_time; use super::SyscallReturn; -use crate::prelude::*; +use crate::{prelude::*, process::process_table}; #[derive(Debug, Default, Clone, Copy, Pod)] #[repr(C)] -pub struct sysinfo { +struct SysInfo { uptime: i64, /* Seconds since boot */ loads: [u64; 3], /* 1, 5, and 15 minute load averages */ totalram: u64, /* Total usable main memory size */ @@ -23,10 +23,14 @@ pub struct sysinfo { } pub fn sys_sysinfo(sysinfo_addr: Vaddr, ctx: &Context) -> Result { - let info = sysinfo { + let info = SysInfo { uptime: read_monotonic_time().as_secs() as i64, totalram: crate::vm::mem_total() as u64, freeram: osdk_frame_allocator::load_total_free_size() as u64, + procs: process_table::process_num() as u16, + // `mem_unit` will always be 1 byte since Asterinas only supports + // 64-bit CPU architectures. + mem_unit: 1, ..Default::default() // TODO: add other system information }; ctx.user_space().write_val(sysinfo_addr, &info)?; diff --git a/test/src/syscall/gvisor/blocklists/sysinfo_test b/test/src/syscall/gvisor/blocklists/sysinfo_test deleted file mode 100644 index a5f258fa6..000000000 --- a/test/src/syscall/gvisor/blocklists/sysinfo_test +++ /dev/null @@ -1,2 +0,0 @@ -SysinfoTest.MemunitSet -SysinfoTest.NumProcsSaneValue \ No newline at end of file