xref: /DragonOS/kernel/src/syscall/misc.rs (revision edaf015400f83967c2fc940f07be0dbb5792246f)
1 use crate::arch::mm::LockedFrameAllocator;
2 
3 use super::{user_access::UserBufferWriter, Syscall, SystemError};
4 
5 #[repr(C)]
6 
7 /// 系统信息
8 ///
9 /// 参考 https://opengrok.ringotek.cn/xref/linux-6.1.9/include/uapi/linux/sysinfo.h#8
10 #[derive(Debug, Default, Copy, Clone)]
11 pub struct SysInfo {
12     uptime: u64,
13     loads: [u64; 3],
14     totalram: u64,
15     freeram: u64,
16     sharedram: u64,
17     bufferram: u64,
18     totalswap: u64,
19     freeswap: u64,
20     procs: u16,
21     pad: u16,
22     totalhigh: u64,
23     freehigh: u64,
24     mem_unit: u32,
25     // 这后面还有一小段,但是我们不需要
26 }
27 
28 impl Syscall {
29     pub fn sysinfo(info: *mut SysInfo) -> Result<usize, SystemError> {
30         let mut writer = UserBufferWriter::new(info, core::mem::size_of::<SysInfo>(), true)?;
31         let mut sysinfo = SysInfo::default();
32 
33         let mem = LockedFrameAllocator.get_usage();
34         sysinfo.uptime = 0;
35         sysinfo.loads = [0; 3];
36         sysinfo.totalram = mem.total().bytes() as u64;
37         sysinfo.freeram = mem.free().bytes() as u64;
38         sysinfo.sharedram = 0;
39         sysinfo.bufferram = 0;
40         sysinfo.totalswap = 0;
41         sysinfo.freeswap = 0;
42         sysinfo.procs = 0;
43         sysinfo.pad = 0;
44         sysinfo.totalhigh = 0;
45         sysinfo.freehigh = 0;
46         sysinfo.mem_unit = 0;
47 
48         writer.copy_one_to_user(&sysinfo, 0)?;
49 
50         return Ok(0);
51     }
52 
53     pub fn umask(_mask: u32) -> Result<usize, SystemError> {
54         kwarn!("SYS_UMASK has not yet been implemented\n");
55         return Ok(0o777);
56     }
57 }
58