2023-07-18 18:03:45 +03:00
|
|
|
//! System function call handlers
|
2024-03-12 13:46:24 +02:00
|
|
|
|
|
|
|
use abi::{error::Error, io::RawFd, SyscallFunction};
|
2024-02-05 12:35:09 +02:00
|
|
|
use libk_util::sync::IrqSafeSpinlockGuard;
|
2024-03-12 13:46:24 +02:00
|
|
|
use vfs::NodeRef;
|
|
|
|
|
|
|
|
use crate::{proc::io::ProcessIoImpl, task::process::ProcessImpl};
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2023-07-20 11:59:53 +03:00
|
|
|
mod arg;
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-02-12 12:09:53 +02:00
|
|
|
fn run_with_io<T, F: FnOnce(IrqSafeSpinlockGuard<ProcessIoImpl>) -> T>(
|
|
|
|
proc: &ProcessImpl,
|
|
|
|
f: F,
|
|
|
|
) -> T {
|
2023-12-05 10:27:56 +02:00
|
|
|
let io = proc.io.lock();
|
|
|
|
f(io)
|
|
|
|
}
|
|
|
|
|
2024-02-12 12:09:53 +02:00
|
|
|
fn run_with_io_at<
|
|
|
|
T,
|
|
|
|
F: FnOnce(NodeRef, IrqSafeSpinlockGuard<ProcessIoImpl>) -> Result<T, Error>,
|
|
|
|
>(
|
|
|
|
proc: &ProcessImpl,
|
2023-12-05 10:27:56 +02:00
|
|
|
at: Option<RawFd>,
|
|
|
|
f: F,
|
|
|
|
) -> Result<T, Error> {
|
2024-01-15 18:17:16 +02:00
|
|
|
let mut io = proc.io.lock();
|
2023-12-05 10:27:56 +02:00
|
|
|
let at = at
|
|
|
|
.map(|fd| {
|
2023-12-22 11:24:47 +02:00
|
|
|
io.files
|
|
|
|
.file(fd)
|
2023-12-05 10:27:56 +02:00
|
|
|
.and_then(|f| f.node().ok_or(Error::InvalidFile).cloned())
|
|
|
|
})
|
2024-01-15 18:17:16 +02:00
|
|
|
.transpose()?
|
|
|
|
// at = None
|
2024-02-12 12:09:53 +02:00
|
|
|
.unwrap_or_else(|| io.ioctx_mut().cwd().clone());
|
2023-12-05 10:27:56 +02:00
|
|
|
|
|
|
|
f(at, io)
|
|
|
|
}
|
2023-07-22 18:27:40 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
mod impls {
|
|
|
|
pub(crate) use abi::{
|
|
|
|
error::Error,
|
|
|
|
io::{
|
|
|
|
DeviceRequest, DirectoryEntry, FileAttr, FileMetadataUpdate, FileMode,
|
|
|
|
MessageDestination, MountOptions, OpenOptions, PollControl, RawFd,
|
|
|
|
ReceivedMessageMetadata, SeekFrom, SentMessage, TerminalOptions, TerminalSize,
|
|
|
|
UnmountOptions,
|
|
|
|
},
|
|
|
|
mem::MappingSource,
|
|
|
|
net::{SocketOption, SocketType},
|
|
|
|
process::{ExitCode, MutexOperation, Signal, SignalEntryData, SpawnOptions},
|
|
|
|
system::SystemInfo,
|
|
|
|
};
|
2024-03-12 14:46:54 +02:00
|
|
|
use abi::{
|
|
|
|
io::ChannelPublisherId,
|
|
|
|
process::{ExecveOptions, ProcessId, SpawnOption},
|
|
|
|
};
|
2024-03-12 13:46:24 +02:00
|
|
|
use alloc::{boxed::Box, sync::Arc};
|
|
|
|
use libk::{block, runtime};
|
|
|
|
use vfs::{File, IoContext, MessagePayload, Read, Seek, Write};
|
|
|
|
use ygg_driver_net_core::socket::{RawSocket, TcpListener, TcpSocket, UdpSocket};
|
|
|
|
|
|
|
|
use core::{
|
|
|
|
mem::MaybeUninit, net::SocketAddr, num::NonZeroUsize, sync::atomic::AtomicU32,
|
|
|
|
time::Duration,
|
|
|
|
};
|
|
|
|
|
|
|
|
use libk_mm::{
|
|
|
|
phys,
|
|
|
|
process::VirtualRangeBacking,
|
|
|
|
table::{EntryLevelExt, MapAttributes},
|
|
|
|
};
|
|
|
|
use libk_thread::{
|
|
|
|
process::{Process, ProcessManager},
|
|
|
|
thread::Thread,
|
|
|
|
};
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
use crate::{
|
|
|
|
arch::L3,
|
|
|
|
debug::LogLevel,
|
|
|
|
fs,
|
|
|
|
proc::{self, random},
|
|
|
|
task::process::ProcessManagerImpl,
|
|
|
|
};
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
use super::{run_with_io, run_with_io_at};
|
|
|
|
|
|
|
|
// Misc
|
|
|
|
pub(crate) fn debug_trace(message: &str) {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
log_print_raw!(
|
|
|
|
LogLevel::Debug,
|
|
|
|
"[{}:{}] TRACE: {}\n",
|
|
|
|
process.id(),
|
|
|
|
thread.id,
|
|
|
|
message
|
|
|
|
);
|
2024-01-08 18:44:55 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
|
|
|
|
pub(crate) fn get_random(buffer: &mut [u8]) {
|
|
|
|
random::read(buffer);
|
2024-01-08 18:44:55 +02:00
|
|
|
}
|
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn mount(options: &MountOptions<'_>) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let fs_root = fs::create_filesystem(options)?;
|
|
|
|
io.ioctx_mut().mount(options.target, fs_root)?;
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
2023-11-21 14:16:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn unmount(_options: &UnmountOptions) -> Result<(), Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
2023-11-21 14:16:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// Memory management
|
|
|
|
pub(crate) fn map_memory(
|
|
|
|
_hint: Option<NonZeroUsize>,
|
|
|
|
len: usize,
|
|
|
|
source: &MappingSource,
|
|
|
|
) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
let space = thread.address_space();
|
|
|
|
|
|
|
|
let len = len.page_align_up::<L3>();
|
|
|
|
|
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let backing = match source {
|
|
|
|
MappingSource::Anonymous => VirtualRangeBacking::anonymous(),
|
|
|
|
&MappingSource::File(fd, offset) => {
|
|
|
|
let file = io.files.file(fd)?;
|
|
|
|
VirtualRangeBacking::file(offset, file.clone())?
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
space.allocate(
|
|
|
|
None,
|
|
|
|
len,
|
|
|
|
backing,
|
|
|
|
MapAttributes::USER_WRITE | MapAttributes::USER_READ | MapAttributes::NON_GLOBAL,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2023-11-21 14:16:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn unmap_memory(address: usize, len: usize) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let space = thread.address_space();
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
if len & 0xFFF != 0 {
|
|
|
|
todo!();
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
space.unmap(address, len)?;
|
2023-12-05 12:23:44 +02:00
|
|
|
}
|
2023-11-23 10:41:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn get_system_info(element: &mut SystemInfo) -> Result<(), Error> {
|
|
|
|
match element {
|
|
|
|
SystemInfo::MemoryStats(stats) => {
|
|
|
|
*stats = phys::stats();
|
|
|
|
Ok(())
|
2023-11-23 10:41:27 +02:00
|
|
|
}
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
}
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// Process/thread management
|
|
|
|
pub(crate) fn exit_process(code: ExitCode) -> ! {
|
|
|
|
let thread = Thread::current();
|
|
|
|
thread.exit_process::<ProcessManagerImpl>(code)
|
|
|
|
}
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 14:46:54 +02:00
|
|
|
pub(crate) fn spawn_process(options: &SpawnOptions<'_>) -> Result<ProcessId, Error> {
|
2024-03-12 13:46:24 +02:00
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
// Setup a new process from the file
|
|
|
|
let (child_process, child_main) = proc::load_binary(
|
|
|
|
io.ioctx_mut(),
|
|
|
|
Some(Arc::downgrade(&process)),
|
|
|
|
options.program,
|
|
|
|
options.arguments,
|
|
|
|
options.environment,
|
|
|
|
)?;
|
2024-03-12 14:46:54 +02:00
|
|
|
let pid = child_process.id();
|
2024-03-12 13:46:24 +02:00
|
|
|
|
|
|
|
// Inherit group and session from the creator
|
|
|
|
child_process.inherit(&process)?;
|
|
|
|
|
|
|
|
// Inherit root from the creator
|
|
|
|
// let child_ioctx = IoContext::new(io.ioctx().root().clone());
|
|
|
|
let child_ioctx = IoContext::inherit(io.ioctx_mut());
|
|
|
|
let mut child_io = child_process.io.lock();
|
|
|
|
child_io.set_ioctx(child_ioctx);
|
|
|
|
|
|
|
|
for opt in options.optional {
|
|
|
|
match opt {
|
|
|
|
&SpawnOption::InheritFile { source, child } => {
|
|
|
|
if let Ok(src_file) = io.files.file(source) {
|
|
|
|
child_io.files.set_file(child, src_file.clone())?;
|
|
|
|
}
|
2023-12-31 12:50:16 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
&SpawnOption::SetProcessGroup(pgroup) => {
|
2024-03-12 14:46:54 +02:00
|
|
|
let pgroup = if pgroup.into_raw() == 0 {
|
2024-03-12 13:46:24 +02:00
|
|
|
child_process.id()
|
|
|
|
} else {
|
2024-03-12 14:46:54 +02:00
|
|
|
pgroup
|
2024-03-12 13:46:24 +02:00
|
|
|
};
|
|
|
|
child_process.set_group_id(pgroup);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
if let Some(fd) = options.optional.iter().find_map(|item| {
|
|
|
|
if let &SpawnOption::GainTerminal(fd) = item {
|
|
|
|
Some(fd)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}) {
|
|
|
|
debugln!("{} requested terminal {:?}", pid, fd);
|
|
|
|
let file = child_io.files.file(fd)?;
|
|
|
|
// let node = file.node().ok_or(Error::InvalidFile)?;
|
2024-03-13 01:54:00 +02:00
|
|
|
let mut req = DeviceRequest::SetTerminalGroup(child_process.group_id());
|
2024-03-12 13:46:24 +02:00
|
|
|
file.device_request(&mut req)?;
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
if let Some(node) = file.node() {
|
|
|
|
child_process.set_session_terminal(node.clone());
|
|
|
|
}
|
|
|
|
// node.device_request(&mut req)?;
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
drop(child_io);
|
|
|
|
child_main.enqueue();
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(pid as _)
|
|
|
|
})
|
|
|
|
}
|
2023-11-21 14:16:18 +02:00
|
|
|
|
2024-03-12 14:46:54 +02:00
|
|
|
pub(crate) fn wait_process(pid: ProcessId, status: &mut ExitCode) -> Result<(), Error> {
|
2024-03-12 13:46:24 +02:00
|
|
|
let target = ProcessManagerImpl::get(pid).ok_or(Error::DoesNotExist)?;
|
|
|
|
*status = block!(target.wait_for_exit().await)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-11-21 14:16:18 +02:00
|
|
|
|
2024-03-12 14:46:54 +02:00
|
|
|
pub(crate) fn get_pid() -> ProcessId {
|
2024-03-12 13:46:24 +02:00
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-03-12 14:46:54 +02:00
|
|
|
process.id()
|
2024-03-12 13:46:24 +02:00
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn nanosleep(duration: &Duration) {
|
|
|
|
block! {
|
|
|
|
runtime::sleep(*duration).await
|
2023-12-05 10:27:56 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
.unwrap();
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn set_signal_entry(ip: usize, sp: usize) {
|
|
|
|
let thread = Thread::current();
|
|
|
|
thread.set_signal_entry(ip, sp);
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 14:46:54 +02:00
|
|
|
pub(crate) fn send_signal(pid: ProcessId, signal: Signal) -> Result<(), Error> {
|
2024-03-12 13:46:24 +02:00
|
|
|
let target = ProcessManagerImpl::get(pid).ok_or(Error::DoesNotExist)?;
|
|
|
|
target.raise_signal(signal);
|
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn mutex(mutex: &AtomicU32, op: &MutexOperation) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
let mutex = process.get_or_insert_mutex((mutex as *const AtomicU32).addr());
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
match op {
|
|
|
|
&MutexOperation::Wait(value, _timeout) => block! { mutex.wait(value).await }.unwrap(),
|
|
|
|
MutexOperation::Wake => mutex.wake(),
|
|
|
|
MutexOperation::WakeAll => mutex.wake_all(),
|
|
|
|
}
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn start_session() -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
let session_terminal = process.clear_session_terminal();
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
if let Some(ctty) = session_terminal {
|
|
|
|
// Drop all FDs referring to the old session terminal
|
2024-02-12 12:09:53 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
2024-03-12 13:46:24 +02:00
|
|
|
io.files.retain(|_, f| {
|
|
|
|
f.node()
|
|
|
|
.map(|node| !Arc::ptr_eq(node, &ctty))
|
|
|
|
.unwrap_or(true)
|
|
|
|
});
|
|
|
|
});
|
2023-12-05 10:27:56 +02:00
|
|
|
}
|
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
process.set_session_id(process.id());
|
|
|
|
process.set_group_id(process.id());
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// I/O
|
|
|
|
pub(crate) fn open(
|
|
|
|
at: Option<RawFd>,
|
|
|
|
path: &str,
|
|
|
|
opts: OpenOptions,
|
|
|
|
mode: FileMode,
|
|
|
|
) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io_at(&process, at, |at, mut io| {
|
|
|
|
let file = io.ioctx_mut().open(Some(at), path, opts, mode)?;
|
|
|
|
|
|
|
|
// TODO NO_CTTY?
|
|
|
|
if process.session_terminal().is_none()
|
|
|
|
&& let Some(node) = file.node()
|
|
|
|
&& node.is_terminal()
|
|
|
|
{
|
|
|
|
debugln!("Session terminal set for #{}: {}", process.id(), path);
|
|
|
|
process.set_session_terminal(node.clone());
|
|
|
|
}
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn close(fd: RawFd) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let res = io.files.close_file(fd);
|
2023-12-14 18:45:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
if res == Err(Error::InvalidFile) {
|
|
|
|
warnln!("Double close of fd {:?} in process {}", fd, process.id());
|
|
|
|
}
|
2023-12-22 11:24:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
res
|
|
|
|
})
|
|
|
|
}
|
2023-12-22 11:24:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn write(fd: RawFd, buffer: &[u8]) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-22 11:24:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| io.files.file(fd)?.write(buffer))
|
|
|
|
}
|
2023-12-22 11:24:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn read(fd: RawFd, buffer: &mut [u8]) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-22 11:24:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| io.files.file(fd)?.read(buffer))
|
|
|
|
}
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn seek(fd: RawFd, pos: SeekFrom) -> Result<u64, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| io.files.file(fd)?.seek(pos))
|
|
|
|
}
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn open_directory(at: Option<RawFd>, path: &str) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io_at(&process, at, |at, mut io| {
|
|
|
|
let node = io.ioctx_mut().find(Some(at), path, true, true)?;
|
|
|
|
let access = io.ioctx_mut().check_access(vfs::Action::Read, &node)?;
|
|
|
|
let file = node.open_directory(access)?;
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn read_directory_entries(
|
|
|
|
fd: RawFd,
|
|
|
|
entries: &mut [MaybeUninit<DirectoryEntry>],
|
|
|
|
) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |io| io.files.file(fd)?.read_dir(entries))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn create_directory(
|
|
|
|
at: Option<RawFd>,
|
|
|
|
path: &str,
|
|
|
|
mode: FileMode,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io_at(&process, at, |at, mut io| {
|
|
|
|
io.ioctx_mut().create_directory(Some(at), path, mode)?;
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn remove_directory(_at: Option<RawFd>, _path: &str) -> Result<(), Error> {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn remove(at: Option<RawFd>, path: &str) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io_at(&process, at, |at, mut io| {
|
|
|
|
io.ioctx_mut().remove_file(Some(at), path)?;
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn clone_fd(source_fd: RawFd, target_fd: Option<RawFd>) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = io.files.file(source_fd)?.clone();
|
|
|
|
|
|
|
|
let fd = match target_fd {
|
|
|
|
Some(target_fd) => {
|
|
|
|
io.files.set_file(target_fd, file)?;
|
|
|
|
target_fd
|
2023-12-31 01:53:43 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
None => io.files.place_file(file, true)?,
|
|
|
|
};
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn update_metadata(
|
|
|
|
at: Option<RawFd>,
|
|
|
|
_path: &str,
|
|
|
|
_update: &FileMetadataUpdate,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-26 22:12:47 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io_at(&process, at, |_at, _io| {
|
|
|
|
todo!();
|
|
|
|
})
|
|
|
|
}
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn get_metadata(
|
|
|
|
at: Option<RawFd>,
|
|
|
|
path: &str,
|
|
|
|
buffer: &mut MaybeUninit<FileAttr>,
|
|
|
|
follow: bool,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io_at(&process, at, |at, mut io| {
|
|
|
|
let node = if path.is_empty() {
|
|
|
|
at
|
|
|
|
// at.ok_or(Error::InvalidArgument)?
|
|
|
|
} else {
|
|
|
|
io.ioctx_mut().find(Some(at), path, follow, true)?
|
|
|
|
};
|
|
|
|
|
|
|
|
let metadata = node.metadata()?;
|
|
|
|
let size = node.size()?;
|
|
|
|
|
|
|
|
buffer.write(FileAttr {
|
|
|
|
size,
|
|
|
|
ty: node.ty(),
|
|
|
|
mode: metadata.mode,
|
|
|
|
uid: metadata.uid,
|
|
|
|
gid: metadata.gid,
|
|
|
|
});
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
2023-12-28 22:32:33 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn device_request(fd: RawFd, req: &mut DeviceRequest) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| io.files.file(fd)?.device_request(req))
|
|
|
|
}
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// Misc I/O
|
|
|
|
pub(crate) fn open_channel(name: &str, subscribe: bool) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = File::new_message_channel(name, subscribe);
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-31 01:53:43 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn create_timer(repeat: bool) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-02 14:01:33 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = File::new_timer(repeat);
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2024-01-04 21:22:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn create_pty(
|
|
|
|
options: &TerminalOptions,
|
|
|
|
size: &TerminalSize,
|
|
|
|
output: &mut [MaybeUninit<RawFd>; 2],
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-04 21:22:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let (master, slave) = File::new_pseudo_terminal(*options, *size)?;
|
|
|
|
let master_fd = io.files.place_file(master, true)?;
|
|
|
|
let slave_fd = io.files.place_file(slave, true)?;
|
2024-01-04 21:22:18 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
output[0].write(master_fd);
|
|
|
|
output[1].write(slave_fd);
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn create_shared_memory(size: usize) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = File::new_shared_memory(size)?;
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2024-01-27 23:35:39 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn create_poll_channel() -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let poll = File::new_poll_channel();
|
|
|
|
let fd = io.files.place_file(poll, true)?;
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn create_pipe(ends: &mut [MaybeUninit<RawFd>; 2]) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let (read, write) = File::new_pipe_pair(256);
|
|
|
|
|
|
|
|
let read_fd = io.files.place_file(read, true)?;
|
|
|
|
let write_fd = io.files.place_file(write, true)?;
|
|
|
|
|
|
|
|
ends[0].write(read_fd);
|
|
|
|
ends[1].write(write_fd);
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn poll_channel_wait(
|
|
|
|
poll_fd: RawFd,
|
|
|
|
timeout: &Option<Duration>,
|
|
|
|
output: &mut Option<(RawFd, Result<(), Error>)>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-11-24 13:30:26 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let poll_file = io.files.file(poll_fd)?;
|
|
|
|
let poll = poll_file.as_poll_channel()?;
|
2023-11-24 13:30:26 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
*output = block! {
|
|
|
|
poll.wait(*timeout).await
|
|
|
|
}?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn poll_channel_control(
|
|
|
|
poll_fd: RawFd,
|
|
|
|
control: PollControl,
|
|
|
|
fd: RawFd,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let poll_file = io.files.file(poll_fd)?;
|
|
|
|
let poll = poll_file.as_poll_channel()?;
|
|
|
|
|
|
|
|
match control {
|
|
|
|
PollControl::AddFd => {
|
|
|
|
let polled_file = io.files.file(fd)?.clone();
|
|
|
|
poll.add(fd, polled_file);
|
2023-11-24 13:30:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
2023-11-26 15:05:16 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn send_message(
|
|
|
|
fd: RawFd,
|
|
|
|
message: &SentMessage<'_>,
|
|
|
|
destination: MessageDestination,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-11-23 10:41:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let file = io.files.file(fd)?;
|
|
|
|
let channel = file.as_message_channel()?;
|
2023-11-23 10:41:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
match message {
|
|
|
|
&SentMessage::File(fd) => {
|
|
|
|
let sent_file = io.files.file(fd)?;
|
2024-01-31 19:56:49 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
channel.send_message(MessagePayload::File(sent_file.clone()), destination)?;
|
2024-01-31 19:56:49 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
&SentMessage::Data(data) => {
|
|
|
|
channel.send_message(MessagePayload::Data(Box::from(data)), destination)?;
|
|
|
|
}
|
|
|
|
}
|
2024-01-31 19:56:49 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn receive_message(
|
|
|
|
fd: RawFd,
|
|
|
|
metadata: &mut MaybeUninit<ReceivedMessageMetadata>,
|
|
|
|
buf: &mut [u8],
|
2024-03-12 14:46:54 +02:00
|
|
|
from: &mut MaybeUninit<ChannelPublisherId>,
|
2024-03-12 13:46:24 +02:00
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = io.files.file(fd)?;
|
|
|
|
let channel = file.as_message_channel()?;
|
|
|
|
|
|
|
|
let message = channel.receive_message()?;
|
|
|
|
|
|
|
|
from.write(message.source);
|
|
|
|
|
|
|
|
match &message.payload {
|
|
|
|
MessagePayload::Data(data) => {
|
|
|
|
// TODO allow truncated messages?
|
|
|
|
let len = data.len();
|
|
|
|
if buf.len() < len {
|
|
|
|
return Err(Error::MissingData);
|
|
|
|
}
|
|
|
|
|
|
|
|
metadata.write(ReceivedMessageMetadata::Data(len));
|
|
|
|
buf[..len].copy_from_slice(data);
|
|
|
|
|
|
|
|
Ok(())
|
2024-01-31 19:56:49 +02:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
MessagePayload::File(file) => {
|
|
|
|
let fd = io.files.place_file(file.clone(), true)?;
|
|
|
|
|
|
|
|
metadata.write(ReceivedMessageMetadata::File(fd));
|
2024-01-31 19:56:49 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
Ok(())
|
2024-01-31 19:56:49 +02:00
|
|
|
}
|
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
})
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// Network
|
|
|
|
pub(crate) fn connect_socket(
|
|
|
|
socket_fd: Option<RawFd>,
|
|
|
|
remote: &SocketAddr,
|
|
|
|
ty: SocketType,
|
|
|
|
local_result: &mut MaybeUninit<SocketAddr>,
|
|
|
|
) -> Result<RawFd, Error> {
|
|
|
|
assert!(socket_fd.is_none());
|
|
|
|
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let (local, file) = match ty {
|
|
|
|
SocketType::TcpStream => {
|
|
|
|
let (local, socket) = TcpSocket::connect((*remote).into())?;
|
|
|
|
(local, File::from_stream_socket(socket))
|
|
|
|
}
|
|
|
|
_ => return Err(Error::InvalidArgument),
|
|
|
|
};
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
local_result.write(local.into());
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-12-05 10:27:56 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn bind_socket(listen: &SocketAddr, ty: SocketType) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2023-07-27 16:24:52 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = match ty {
|
|
|
|
SocketType::UdpPacket => {
|
|
|
|
File::from_packet_socket(UdpSocket::bind((*listen).into())?)
|
|
|
|
}
|
|
|
|
SocketType::RawPacket => File::from_packet_socket(RawSocket::bind()?),
|
|
|
|
SocketType::TcpStream => {
|
|
|
|
File::from_listener_socket(TcpListener::bind((*listen).into())?)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let fd = io.files.place_file(file, true)?;
|
|
|
|
Ok(fd)
|
|
|
|
})
|
|
|
|
}
|
2023-07-27 16:24:52 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn accept(
|
|
|
|
socket_fd: RawFd,
|
|
|
|
remote_result: &mut MaybeUninit<SocketAddr>,
|
|
|
|
) -> Result<RawFd, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |mut io| {
|
|
|
|
let file = io.files.file(socket_fd)?;
|
|
|
|
let mut remote = MaybeUninit::uninit();
|
|
|
|
let accepted_file = file.accept(&mut remote)?;
|
|
|
|
let accepted_fd = io.files.place_file(accepted_file, true)?;
|
|
|
|
unsafe {
|
|
|
|
remote_result.write(remote.assume_init().into());
|
|
|
|
}
|
|
|
|
Ok(accepted_fd)
|
|
|
|
})
|
|
|
|
}
|
2023-07-27 16:24:52 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn send_to(
|
|
|
|
socket_fd: RawFd,
|
|
|
|
buffer: &[u8],
|
|
|
|
recepient: &Option<SocketAddr>,
|
|
|
|
) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let file = io.files.file(socket_fd)?;
|
2024-01-20 19:40:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
file.send_to(buffer, recepient.map(Into::into))
|
|
|
|
})
|
|
|
|
}
|
2024-01-25 13:10:01 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn receive_from(
|
|
|
|
socket_fd: RawFd,
|
|
|
|
buffer: &mut [u8],
|
|
|
|
remote_result: &mut MaybeUninit<SocketAddr>,
|
|
|
|
) -> Result<usize, Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let file = io.files.file(socket_fd)?;
|
|
|
|
let mut remote = MaybeUninit::uninit();
|
|
|
|
let len = file.receive_from(buffer, &mut remote)?;
|
|
|
|
remote_result.write(unsafe { remote.assume_init() }.into());
|
|
|
|
Ok(len)
|
|
|
|
})
|
|
|
|
}
|
2024-01-25 13:10:01 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn set_socket_option(socket_fd: RawFd, option: &SocketOption) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
2024-01-20 19:40:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let file = io.files.file(socket_fd)?;
|
|
|
|
let socket = file.as_socket()?;
|
|
|
|
socket.set_option(option)
|
|
|
|
})
|
|
|
|
}
|
2024-01-20 19:40:27 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
pub(crate) fn get_socket_option(
|
|
|
|
socket_fd: RawFd,
|
|
|
|
option: &mut SocketOption,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
let thread = Thread::current();
|
|
|
|
let process = thread.process::<ProcessManagerImpl>();
|
|
|
|
|
|
|
|
run_with_io(&process, |io| {
|
|
|
|
let file = io.files.file(socket_fd)?;
|
|
|
|
let socket = file.as_socket()?;
|
|
|
|
socket.get_option(option)
|
|
|
|
})
|
|
|
|
}
|
2024-01-24 17:48:09 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
// Handled outside
|
|
|
|
pub(crate) fn exit_signal(_frame: &SignalEntryData) -> ! {
|
|
|
|
unreachable!()
|
|
|
|
}
|
2024-01-20 19:40:27 +02:00
|
|
|
|
2024-03-12 14:46:54 +02:00
|
|
|
pub(crate) fn fork() -> Result<ProcessId, Error> {
|
2024-03-12 13:46:24 +02:00
|
|
|
unreachable!()
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|
2024-03-12 13:46:24 +02:00
|
|
|
|
|
|
|
pub(crate) fn execve(_options: &ExecveOptions<'_>) -> Result<(), Error> {
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mod generated {
|
|
|
|
#![allow(unreachable_code)]
|
|
|
|
|
2024-03-13 14:25:02 +02:00
|
|
|
use abi::{
|
|
|
|
io::ChannelPublisherId,
|
|
|
|
process::{ExecveOptions, ProcessId},
|
|
|
|
SyscallFunction,
|
|
|
|
};
|
2024-03-12 13:46:24 +02:00
|
|
|
use abi_lib::SyscallRegister;
|
|
|
|
|
|
|
|
use super::{
|
|
|
|
arg,
|
|
|
|
impls::{self, *},
|
|
|
|
};
|
|
|
|
|
|
|
|
include!(concat!(env!("OUT_DIR"), "/generated_dispatcher.rs"));
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Entrypoint for system calls that takes raw argument values
|
|
|
|
pub fn raw_syscall_handler(func: u64, args: &[u64]) -> u64 {
|
|
|
|
let Ok(func) = SyscallFunction::try_from(func as usize) else {
|
|
|
|
todo!("Undefined syscall: {}", func);
|
|
|
|
};
|
2024-03-12 13:46:24 +02:00
|
|
|
let args = unsafe { core::mem::transmute(args) };
|
2023-07-18 18:03:45 +03:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
let result = generated::handle_syscall(func, args);
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
let value = match result {
|
|
|
|
Ok(value) => value,
|
|
|
|
Err(e) => (-(e as u32 as isize)) as usize,
|
|
|
|
};
|
2024-01-08 18:44:55 +02:00
|
|
|
|
2024-03-12 13:46:24 +02:00
|
|
|
value as _
|
2023-07-18 18:03:45 +03:00
|
|
|
}
|