Merge branch 'mem-sysconf' into 'master'

Implement reading memory

See merge request redox-os/relibc!742
This commit is contained in:
Jeremy Soller
2025-10-09 08:36:10 -06:00
2 changed files with 15 additions and 3 deletions
+13 -3
View File
@@ -5,8 +5,9 @@ use alloc::string::String;
use crate::{
error::Errno,
fs::File,
header::{errno, fcntl, limits},
header::{errno, fcntl, limits, sys_statvfs},
io::Read,
out::Out,
platform::{self, Pal, Sys, types::*},
};
@@ -65,8 +66,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_blocks as c_long).unwrap_or(-1),
_SC_AVPHYS_PAGES => get_mem_stat().map(|s| s.f_bfree as c_long).unwrap_or(-1),
_SC_SIGQUEUE_MAX => 32,
_SC_REALTIME_SIGNALS => 202405,
_ => {
@@ -88,3 +89,12 @@ 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)?;
let mut buf = sys_statvfs::statvfs::default();
let res = Sys::fstatvfs(fd, Out::from_mut(&mut buf));
Sys::close(fd);
let _ = res?;
return Ok(buf);
}
+2
View File
@@ -27,4 +27,6 @@ int main(void) {
SC(HOST_NAME_MAX);
SC(NPROCESSORS_CONF);
SC(NPROCESSORS_ONLN);
SC(PHYS_PAGES);
SC(AVPHYS_PAGES);
}