Implement reading memory
This commit is contained in:
@@ -5,7 +5,7 @@ use alloc::string::String;
|
||||
use crate::{
|
||||
error::Errno,
|
||||
fs::File,
|
||||
header::{errno, fcntl, limits},
|
||||
header::{errno, fcntl, limits, sys_statvfs},
|
||||
io::Read,
|
||||
platform::{self, Pal, Sys, types::*},
|
||||
};
|
||||
@@ -65,8 +65,8 @@ pub(super) fn sysconf_impl(name: c_int) -> c_long {
|
||||
_SC_HOST_NAME_MAX => 64,
|
||||
_SC_NPROCESSORS_CONF => get_cpu_count().unwrap_or(None).unwrap_or(1),
|
||||
_SC_NPROCESSORS_ONLN => get_cpu_count().unwrap_or(None).unwrap_or(1),
|
||||
_SC_PHYS_PAGES => 262144,
|
||||
_SC_AVPHYS_PAGES => -1,
|
||||
_SC_PHYS_PAGES => get_mem_stat().map(|s| s.f_bsize).unwrap_or(-1),
|
||||
_SC_AVPHYS_PAGES => get_mem_stat().map(|s| s.f_bfree).unwrap_or(-1),
|
||||
_SC_SIGQUEUE_MAX => 32,
|
||||
_SC_REALTIME_SIGNALS => 202405,
|
||||
_ => {
|
||||
@@ -88,3 +88,15 @@ pub fn get_cpu_count() -> Result<Option<c_long>, Errno> {
|
||||
.and_then(|line| line.split(':').nth(1))
|
||||
.and_then(|num_str| num_str.trim().parse::<c_long>().ok()))
|
||||
}
|
||||
|
||||
pub fn get_mem_stat() -> Result<sys_statvfs::statvfs, Errno> {
|
||||
let fd = Sys::open(c"/scheme/memory".into(), fcntl::O_PATH, 0)?;
|
||||
if fd < 0 {
|
||||
return -1;
|
||||
}
|
||||
let buf = sys_statvfs::statvfs::default();
|
||||
let res = Sys::fstatvfs(fd, buf).map(|()| 0);
|
||||
Sys::close(fd);
|
||||
let res = res?;
|
||||
return Ok(buf);
|
||||
}
|
||||
|
||||
@@ -27,4 +27,6 @@ int main(void) {
|
||||
SC(HOST_NAME_MAX);
|
||||
SC(NPROCESSORS_CONF);
|
||||
SC(NPROCESSORS_ONLN);
|
||||
SC(PHYS_PAGES);
|
||||
SC(AVPHYS_PAGES);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user