arceos_posix_api/imp/
sys.rs1use core::ffi::{c_int, c_long};
2
3use crate::ctypes;
4
5const PAGE_SIZE_4K: usize = 4096;
6
7pub fn sys_sysconf(name: c_int) -> c_long {
11 debug!("sys_sysconf <= {}", name);
12
13 syscall_body!(sys_sysconf, {
14 match name as u32 {
15 ctypes::_SC_PAGE_SIZE => Ok(PAGE_SIZE_4K),
17 ctypes::_SC_NPROCESSORS_ONLN => Ok(axconfig::plat::CPU_NUM),
19 ctypes::_SC_PHYS_PAGES => Ok(axhal::mem::total_ram_size() / PAGE_SIZE_4K),
21 ctypes::_SC_AVPHYS_PAGES => {
23 #[cfg(feature = "alloc")]
24 {
25 Ok(axalloc::global_allocator().available_pages())
26 }
27 #[cfg(not(feature = "alloc"))]
28 {
29 let total_pages = axhal::mem::total_ram_size() / PAGE_SIZE_4K;
30 let reserved_pages = axhal::mem::reserved_phys_ram_ranges()
31 .iter()
32 .map(|range| range.1 / PAGE_SIZE_4K)
33 .sum::<usize>();
34 Ok(total_pages - reserved_pages)
35 }
36 }
37 #[cfg(feature = "fd")]
39 ctypes::_SC_OPEN_MAX => Ok(super::fd_ops::AX_FILE_LIMIT),
40 _ => Ok(0),
41 }
42 })
43}