From d3c40b54f8c3addcaf0b947ac13cd08c1de40c2a Mon Sep 17 00:00:00 2001 From: August Date: Mon, 16 Mar 2026 22:12:29 +0000 Subject: [PATCH] Stuff with syscall API --- libgila/src/syscall/mod.rs | 50 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/libgila/src/syscall/mod.rs b/libgila/src/syscall/mod.rs index 0a5fc63..3d5f69c 100644 --- a/libgila/src/syscall/mod.rs +++ b/libgila/src/syscall/mod.rs @@ -1,7 +1,13 @@ +use core::{error::Error, num::ParseIntError}; + use num_derive::FromPrimitive; use num_traits::FromPrimitive; use crate::arch; + +pub struct SyscallError { +} + #[repr(u32)] #[derive(FromPrimitive, Debug)] pub enum Syscall { @@ -15,11 +21,17 @@ pub enum Syscall { Pid = 1, /// Send a message to another process. Message = 2, + /// Map new pages. MemMap = 3, + /// Unmap existing pages. MemUnmap = 4, + /// Resolve a service name to a process. Resolve = 5, + /// Spawn a new process. Spawn = 6, + /// Access information about the kernel versioning. Version = 7, + /// Yield the remainder of quantum to another process. Yield = 8, } @@ -27,23 +39,33 @@ pub enum Syscall { #[derive(FromPrimitive, Debug)] pub enum SyscallStatus { /// Syscall completed without any issues. - Success, + Success = 0, /// Issued a system call with the wrong call ID. - NoSuchCall, - NoSuchProcess, - NoSuchService, - SecurityFailure, - OutOfMemory, - Aborted, - Unspecified, - Unknown, - Unimplemented, - InvalidPage, + NoSuchCall = 1, + /// Issued a system call referencing a nonexistent process. + NoSuchProcess = 2, + /// Issued a system call referencing a nonexistent service name. + NoSuchService = 3, + /// System call was prevented by some security policy. + SecurityFailure = 4, + /// Could not allocate any more pages since there are none left. + OutOfMemory = 5, + /// System call failed to complete in constant time. + Aborted = 6, + /// Attempted to issue an unimplemented system call. + Unimplemented = 7, + /// Issued a system call with a malformed parameter. + InvalidParameter = 8, } -impl From for SyscallStatus { - fn from(value: u64) -> Self { - SyscallStatus::from_u64(value).unwrap_or(Self::Unknown) +impl TryFrom for SyscallStatus { + type Error = SyscallError; + fn try_from(value: u64) -> Result { + if let Some(status) = SyscallStatus::from_u64(value) { + Ok(status) + } else { + Err(SyscallError {}) + } } }