Implementation of uptime for sysinfo

This commit is contained in:
Roman Korostinskiy
2024-12-11 00:03:45 +03:00
committed by Tate, Hongliang Tian
parent b4ebd6e87f
commit 4f653acfa3
3 changed files with 31 additions and 3 deletions

View File

@ -1,11 +1,34 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn; use super::SyscallReturn;
use crate::prelude::*;
use aster_time::read_monotonic_time;
#[derive(Debug, Default, Clone, Copy, Pod)]
#[repr(C)]
pub struct sysinfo {
uptime: i64,
loads: [u64; 3],
totalram: u64,
freeram: u64,
sharedram: u64,
bufferram: u64,
totalswap: u64,
freeswap: u64,
procs: u16,
totalhigh: u64,
freehigh: u64,
mem_unit: u32
}
pub fn sys_sysinfo( pub fn sys_sysinfo(
sysinfo_addr: Vaddr, sysinfo_addr: Vaddr,
ctx: &Context, ctx: &Context,
) -> Result<SyscallReturn> { ) -> Result<SyscallReturn> {
unimplemented!("sysinfo implementation in process"); let info = sysinfo {
Ok(SyscallReturn::Return(-1)) uptime: read_monotonic_time().as_secs() as i64,
} ..Default::default() // TODO: add other system information
};
ctx.user_space().write_val(sysinfo_addr, &info)?;
Ok(SyscallReturn::Return(0))
}

View File

@ -47,6 +47,7 @@ TESTS ?= \
statfs_test \ statfs_test \
symlink_test \ symlink_test \
sync_test \ sync_test \
sysinfo_test \
timers_test \ timers_test \
truncate_test \ truncate_test \
uidgid_test \ uidgid_test \

View File

@ -0,0 +1,4 @@
SysinfoTest.TotalRamSaneValue
SysinfoTest.MemunitSet
SysinfoTest.FreeRamSaneValue
SysinfoTest.NumProcsSaneValue