Define GlobalSchemes.
This commit is contained in:
committed by
Jacob Lorentzon
parent
aedadf4d5c
commit
15aa8e32ef
+1
-1
@@ -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 <jackpot51@gmail.com>"]
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+59
-2
@@ -181,9 +181,23 @@ pub fn open<T: AsRef<str>>(path: T, flags: usize) -> Result<usize> {
|
||||
}
|
||||
|
||||
/// Open a file at a specific path
|
||||
pub fn openat<T: AsRef<str>>(fd: usize, path: T, flags: usize, fcntl_flags: usize) -> Result<usize> {
|
||||
pub fn openat<T: AsRef<str>>(
|
||||
fd: usize,
|
||||
path: T,
|
||||
flags: usize,
|
||||
fcntl_flags: usize,
|
||||
) -> Result<usize> {
|
||||
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<usize> {
|
||||
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<usize> {
|
||||
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<usize> {
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+56
@@ -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<Self> {
|
||||
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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user