2024-12-02 10:19:48 +02:00
|
|
|
use core::mem::MaybeUninit;
|
|
|
|
|
2024-03-13 23:41:12 +02:00
|
|
|
pub(crate) use abi::{
|
|
|
|
error::Error,
|
|
|
|
io::{
|
2024-11-06 19:40:27 +02:00
|
|
|
DirectoryEntry, FileAttr, FileMode, MountOptions, OpenOptions, PipeOptions, PollControl,
|
|
|
|
RawFd, TerminalOptions, TerminalSize, TimerOptions, UnmountOptions,
|
2024-03-13 23:41:12 +02:00
|
|
|
},
|
2024-11-14 16:24:45 +02:00
|
|
|
mem::{MappingFlags, MappingSource},
|
2024-03-13 23:41:12 +02:00
|
|
|
net::SocketType,
|
2024-11-28 22:28:32 +02:00
|
|
|
process::{Signal, SignalEntryData, SpawnOptions, WaitFlags},
|
2024-03-13 23:41:12 +02:00
|
|
|
system::SystemInfo,
|
|
|
|
};
|
2024-04-01 17:23:12 +03:00
|
|
|
use abi::{
|
|
|
|
path::Path,
|
|
|
|
process::{ExecveOptions, ProcessId},
|
2024-12-02 10:19:48 +02:00
|
|
|
time::{ClockType, SystemTime},
|
2024-04-01 17:23:12 +03:00
|
|
|
};
|
2024-12-02 10:19:48 +02:00
|
|
|
use device_api::timer::RealTimeProviderDevice;
|
2024-04-01 17:23:12 +03:00
|
|
|
use libk::{module, random, task::thread::Thread};
|
2024-12-05 11:47:38 +02:00
|
|
|
use libk_device::monotonic_timestamp_provider;
|
2024-03-13 23:41:12 +02:00
|
|
|
use libk_mm::phys;
|
|
|
|
|
2024-12-02 10:19:48 +02:00
|
|
|
use crate::{device::timer::GLOBAL_TIME, fs};
|
2024-03-13 23:41:12 +02:00
|
|
|
|
|
|
|
use super::run_with_io;
|
|
|
|
|
2024-03-19 23:11:03 +02:00
|
|
|
pub(super) mod sys_debug;
|
2024-03-13 23:41:12 +02:00
|
|
|
pub(super) mod sys_io;
|
|
|
|
pub(super) mod sys_net;
|
|
|
|
pub(super) mod sys_process;
|
|
|
|
|
2024-03-19 23:11:03 +02:00
|
|
|
pub(super) use sys_debug::*;
|
2024-03-13 23:41:12 +02:00
|
|
|
pub(super) use sys_io::*;
|
|
|
|
pub(super) use sys_net::*;
|
|
|
|
pub(super) use sys_process::*;
|
|
|
|
|
|
|
|
// Misc
|
|
|
|
pub(crate) fn get_random(buffer: &mut [u8]) {
|
|
|
|
random::read(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn mount(options: &MountOptions<'_>) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
2024-07-30 17:46:50 +03:00
|
|
|
let fs_root = fs::create_filesystem(io.ioctx_mut(), options)?;
|
2024-03-13 23:41:12 +02:00
|
|
|
io.ioctx_mut().mount(options.target, fs_root)?;
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn unmount(_options: &UnmountOptions) -> Result<(), Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-12-02 10:19:48 +02:00
|
|
|
pub(crate) fn get_clock(ty: ClockType, value: &mut MaybeUninit<SystemTime>) -> Result<(), Error> {
|
|
|
|
let time = match ty {
|
|
|
|
ClockType::RealTime => GLOBAL_TIME.real_timestamp()?,
|
2024-12-05 11:47:38 +02:00
|
|
|
ClockType::Monotonic => {
|
|
|
|
let time = monotonic_timestamp_provider().monotonic_timestamp()?;
|
|
|
|
SystemTime {
|
|
|
|
seconds: time.as_secs(),
|
|
|
|
nanoseconds: time.subsec_nanos() as _,
|
|
|
|
}
|
|
|
|
}
|
2024-12-02 10:19:48 +02:00
|
|
|
};
|
|
|
|
value.write(time);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-03-13 23:41:12 +02:00
|
|
|
pub(crate) fn get_system_info(element: &mut SystemInfo) -> Result<(), Error> {
|
|
|
|
match element {
|
|
|
|
SystemInfo::MemoryStats(stats) => {
|
|
|
|
*stats = phys::stats();
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-01 17:23:12 +03:00
|
|
|
pub(crate) fn load_module(path: &str) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process();
|
|
|
|
|
|
|
|
let file = run_with_io(&process, |mut io| {
|
|
|
|
let path: &Path = path.as_ref();
|
|
|
|
if !path.is_absolute() {
|
2024-11-05 22:00:10 +02:00
|
|
|
return Err(Error::InvalidArgument);
|
2024-04-01 17:23:12 +03:00
|
|
|
}
|
|
|
|
io.ioctx_mut().open_executable(path)
|
|
|
|
})?;
|
|
|
|
|
|
|
|
module::load_and_execute(file)
|
|
|
|
}
|
|
|
|
|
2024-03-13 23:41:12 +02:00
|
|
|
// Handled outside
|
|
|
|
pub(crate) fn exit_signal(_frame: &SignalEntryData) -> ! {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn fork() -> Result<ProcessId, Error> {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn execve(_options: &ExecveOptions<'_>) -> Result<(), Error> {
|
|
|
|
unreachable!()
|
|
|
|
}
|