use linux_api::sysinfo::sysinfo;
use shadow_shim_helper_rs::emulated_time::EmulatedTime;
use shadow_shim_helper_rs::syscall_types::ForeignPtr;
use crate::core::worker::Worker;
use crate::host::syscall::handler::{SyscallContext, SyscallHandler};
use crate::host::syscall::types::SyscallError;
impl SyscallHandler {
log_syscall!(
sysinfo,
std::ffi::c_int,
*const linux_api::sysinfo::sysinfo,
);
pub fn sysinfo(
ctx: &mut SyscallContext,
info_ptr: ForeignPtr<linux_api::sysinfo::sysinfo>,
) -> Result<(), SyscallError> {
let seconds = Worker::current_time()
.unwrap()
.duration_since(&EmulatedTime::SIMULATION_START)
.as_secs();
let mut info = shadow_pod::zeroed::<sysinfo>();
info.uptime = i64::try_from(seconds).unwrap_or(i64::MAX);
info.loads[0] = 1;
info.loads[1] = 1;
info.loads[2] = 1;
info.totalram = 32;
info.freeram = 24;
info.sharedram = 4;
info.bufferram = 4;
info.totalswap = 0;
info.freeswap = 0;
info.procs = 100;
info.totalhigh = 4;
info.freehigh = 3;
info.mem_unit = 1024 * 1024 * 1024; ctx.objs
.process
.memory_borrow_mut()
.write(info_ptr, &info)?;
Ok(())
}
}