From 15aa8e32ef0f3328dd9d48cc8ca02e148a362069 Mon Sep 17 00:00:00 2001 From: Ibuki Omatsu Date: Sat, 4 Oct 2025 14:54:47 +0000 Subject: [PATCH] Define GlobalSchemes. --- Cargo.toml | 2 +- src/arch/aarch64.rs | 2 ++ src/arch/riscv64.rs | 2 ++ src/arch/x86.rs | 2 ++ src/arch/x86_64.rs | 2 ++ src/call.rs | 61 +++++++++++++++++++++++++++++++++++++++++++-- src/data.rs | 56 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 124 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b224f2c3f..1090e6db43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "redox_syscall" -version = "0.5.17" +version = "0.5.18" description = "A Rust library to access raw Redox system calls" license = "MIT" authors = ["Jeremy Soller "] diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index 62ddbb92cc..a63ab385dd 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -7,6 +7,8 @@ use core::{ use super::error::{Error, Result}; pub const PAGE_SIZE: usize = 4096; +/// Size of the metadata region used to transfer information from the kernel to the bootstrapper. +pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE; #[cfg(feature = "userspace")] macro_rules! syscall { diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index 13f27afbe0..3341bb36a9 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -7,6 +7,8 @@ use core::{ }; pub const PAGE_SIZE: usize = 4096; +/// Size of the metadata region used to transfer information from the kernel to the bootstrapper. +pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE; #[cfg(feature = "userspace")] macro_rules! syscall { diff --git a/src/arch/x86.rs b/src/arch/x86.rs index c6159ac920..d9dba855d4 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -8,6 +8,8 @@ use core::{ use super::error::{Error, Result}; pub const PAGE_SIZE: usize = 4096; +/// Size of the metadata region used to transfer information from the kernel to the bootstrapper. +pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE; #[cfg(feature = "userspace")] macro_rules! syscall { diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 95f4a6e210..9872dff61a 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -5,6 +5,8 @@ use core::{ }; pub const PAGE_SIZE: usize = 4096; +/// Size of the metadata region used to transfer information from the kernel to the bootstrapper. +pub const KERNEL_METADATA_SIZE: usize = 4 * PAGE_SIZE; #[cfg(feature = "userspace")] macro_rules! syscall { diff --git a/src/call.rs b/src/call.rs index c7ad25ebf5..03e3425a10 100644 --- a/src/call.rs +++ b/src/call.rs @@ -181,9 +181,23 @@ pub fn open>(path: T, flags: usize) -> Result { } /// Open a file at a specific path -pub fn openat>(fd: usize, path: T, flags: usize, fcntl_flags: usize) -> Result { +pub fn openat>( + fd: usize, + path: T, + flags: usize, + fcntl_flags: usize, +) -> Result { let path = path.as_ref(); - unsafe { syscall5(SYS_OPENAT, fd, path.as_ptr() as usize, path.len(), flags, fcntl_flags) } + unsafe { + syscall5( + SYS_OPENAT, + fd, + path.as_ptr() as usize, + path.len(), + flags, + fcntl_flags, + ) + } } /// Read from a file descriptor into a buffer @@ -250,3 +264,46 @@ pub fn sendfd(receiver_socket: usize, fd: usize, flags: usize, arg: u64) -> Resu syscall4(SYS_SENDFD, receiver_socket, fd, flags, arg as usize) } } + +/// SYS_CALL interface, read-only variant +pub fn call_ro(fd: usize, payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result { + let combined_flags = flags | CallFlags::READ; + unsafe { + syscall5( + SYS_CALL, + fd, + payload.as_mut_ptr() as usize, + payload.len(), + metadata.len() | combined_flags.bits(), + metadata.as_ptr() as usize, + ) + } +} +/// SYS_CALL interface, write-only variant +pub fn call_wo(fd: usize, payload: &[u8], flags: CallFlags, metadata: &[u64]) -> Result { + let combined_flags = flags | CallFlags::WRITE; + unsafe { + syscall5( + SYS_CALL, + fd, + payload.as_ptr() as *mut u8 as usize, + payload.len(), + metadata.len() | combined_flags.bits(), + metadata.as_ptr() as usize, + ) + } +} +/// SYS_CALL interface, read-write variant +pub fn call_rw(fd: usize, payload: &mut [u8], flags: CallFlags, metadata: &[u64]) -> Result { + let combined_flags = flags | CallFlags::READ | CallFlags::WRITE; + unsafe { + syscall5( + SYS_CALL, + fd, + payload.as_mut_ptr() as usize, + payload.len(), + metadata.len() | combined_flags.bits(), + metadata.as_ptr() as usize, + ) + } +} diff --git a/src/data.rs b/src/data.rs index 90778a96f7..c7d8568c55 100644 --- a/src/data.rs +++ b/src/data.rs @@ -407,3 +407,59 @@ impl DerefMut for CtxtStsBuf { } } } + +#[repr(u8)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum GlobalSchemes { + Debug = 1, + Event = 2, + Memory = 3, + Pipe = 4, + Serio = 5, + Irq = 6, + Time = 7, + Sys = 8, + Proc = 9, + Acpi = 10, + Dtb = 11, +} +impl GlobalSchemes { + pub fn try_from_raw(raw: u8) -> Option { + match raw { + 1 => Some(Self::Debug), + 2 => Some(Self::Event), + 3 => Some(Self::Memory), + 4 => Some(Self::Pipe), + 5 => Some(Self::Serio), + 6 => Some(Self::Irq), + 7 => Some(Self::Time), + 8 => Some(Self::Sys), + 9 => Some(Self::Proc), + 10 => Some(Self::Acpi), + 11 => Some(Self::Dtb), + _ => None, + } + } + pub fn as_str(&self) -> &'static str { + match self { + Self::Debug => "debug", + Self::Event => "event", + Self::Memory => "memory", + Self::Pipe => "pipe", + Self::Serio => "serio", + Self::Irq => "irq", + Self::Time => "time", + Self::Sys => "sys", + Self::Proc => "kernel.proc", + Self::Acpi => "kernel.acpi", + Self::Dtb => "kernel.dtb", + } + } +} + +#[repr(C)] +#[derive(Debug, Clone, Copy, Default)] +pub struct KernelSchemeInfo { + pub scheme_id: u8, + pub fd: usize, +}