Remove remnants of the old packet format.
This commit is contained in:
-30
@@ -112,36 +112,6 @@ impl DerefMut for Map {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
#[repr(C)]
|
||||
pub struct Packet {
|
||||
pub id: u64,
|
||||
pub pid: usize,
|
||||
pub uid: u32,
|
||||
pub gid: u32,
|
||||
pub a: usize,
|
||||
pub b: usize,
|
||||
pub c: usize,
|
||||
pub d: usize,
|
||||
}
|
||||
|
||||
impl Deref for Packet {
|
||||
type Target = [u8];
|
||||
fn deref(&self) -> &[u8] {
|
||||
unsafe {
|
||||
slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::<Packet>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for Packet {
|
||||
fn deref_mut(&mut self) -> &mut [u8] {
|
||||
unsafe {
|
||||
slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::<Packet>())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
#[repr(C)]
|
||||
pub struct Stat {
|
||||
|
||||
@@ -72,7 +72,6 @@ impl DirentKind {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct DirentIter<'a>(&'a [u8]);
|
||||
|
||||
impl<'a> DirentIter<'a> {
|
||||
|
||||
+2
-2
@@ -188,7 +188,7 @@ pub const EKEYREVOKED: i32 = 128; /* Key has been revoked */
|
||||
pub const EKEYREJECTED: i32 = 129; /* Key was rejected by service */
|
||||
pub const EOWNERDEAD: i32 = 130; /* Owner died */
|
||||
pub const ENOTRECOVERABLE: i32 = 131; /* State not recoverable */
|
||||
pub const ESKMSG: i32 = 132; /* Scheme-kernel message code */
|
||||
pub const ERSVD: i32 = 132; /* Reserved (formerly "scheme-kernel message code") */
|
||||
|
||||
pub static STR_ERROR: [&'static str; 133] = [
|
||||
"Success",
|
||||
@@ -323,5 +323,5 @@ pub static STR_ERROR: [&'static str; 133] = [
|
||||
"Key was rejected by service",
|
||||
"Owner died",
|
||||
"State not recoverable",
|
||||
"Scheme-kernel message code",
|
||||
"Reserved (formerly scheme-kernel message code)",
|
||||
];
|
||||
|
||||
@@ -62,15 +62,6 @@ pub const FUTEX_WAKE: usize = 1;
|
||||
pub const FUTEX_REQUEUE: usize = 2;
|
||||
pub const FUTEX_WAIT64: usize = 3;
|
||||
|
||||
// packet.c = fd
|
||||
pub const SKMSG_FRETURNFD: usize = 0;
|
||||
|
||||
// packet.uid:packet.gid = offset, packet.c = base address, packet.d = page count
|
||||
pub const SKMSG_PROVIDE_MMAP: usize = 1;
|
||||
|
||||
// packet.id provides state, packet.c = dest fd or pointer to dest fd, packet.d = flags
|
||||
pub const SKMSG_FOBTAINFD: usize = 2;
|
||||
|
||||
// TODO: Split SendFdFlags into caller flags and flags that the scheme receives?
|
||||
bitflags::bitflags! {
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
||||
@@ -51,6 +51,3 @@ pub mod sigabi;
|
||||
|
||||
/// V2 scheme format
|
||||
pub mod schemev2;
|
||||
|
||||
pub mod scheme;
|
||||
pub use scheme::*;
|
||||
|
||||
+1
-18
@@ -29,17 +29,15 @@ pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55;
|
||||
pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
|
||||
|
||||
// SYS_CALL, fd, inout buf ptr, inout buf len, flags, metadata buf ptr, metadata buf len
|
||||
// TODO: new number for SYS_CALL where flags are sent as 6th argument (using syscall6)
|
||||
pub const SYS_CALL: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | SYS_ARG_MSLICE | 0xCA11;
|
||||
|
||||
pub const SYS_SENDFD: usize = SYS_CLASS_FILE | 34;
|
||||
pub const SYS_GETDENTS: usize = SYS_CLASS_FILE | 43;
|
||||
|
||||
// TODO: Rename FMAP/FUNMAP to MMAP/MUNMAP
|
||||
pub const SYS_FMAP_OLD: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 90;
|
||||
pub const SYS_FMAP: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 900;
|
||||
// TODO: SYS_FUNMAP should be SYS_CLASS_FILE
|
||||
// TODO: Remove FMAP/FMAP_OLD
|
||||
pub const SYS_FUNMAP_OLD: usize = SYS_CLASS_FILE | 91;
|
||||
pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 92;
|
||||
pub const SYS_MREMAP: usize = 155;
|
||||
|
||||
@@ -52,21 +50,6 @@ pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118;
|
||||
pub const SYS_FTRUNCATE: usize = SYS_CLASS_FILE | 93;
|
||||
pub const SYS_FUTIMENS: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 320;
|
||||
|
||||
// b = file, c = flags, d = required_page_count, uid:gid = offset
|
||||
pub const KSMSG_MMAP: usize = SYS_CLASS_FILE | 72;
|
||||
|
||||
// b = file, c = flags, d = page_count, uid:gid = offset
|
||||
pub const KSMSG_MSYNC: usize = SYS_CLASS_FILE | 73;
|
||||
|
||||
// b = file, c = page_count, uid:gid = offset
|
||||
pub const KSMSG_MUNMAP: usize = SYS_CLASS_FILE | 74;
|
||||
|
||||
// b = file, c = flags, d = page_count, uid:gid = offset
|
||||
pub const KSMSG_MMAP_PREP: usize = SYS_CLASS_FILE | 75;
|
||||
|
||||
// b = target_packetid_lo32, c = target_packetid_hi32
|
||||
pub const KSMSG_CANCEL: usize = SYS_CLASS_FILE | 76;
|
||||
|
||||
pub const SYS_CLOCK_GETTIME: usize = 265;
|
||||
pub const SYS_FUTEX: usize = 240;
|
||||
pub const SYS_MPROTECT: usize = 125;
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "Generating SchemeMut from Scheme"
|
||||
sed 's/trait Scheme/trait SchemeMut/' scheme.rs \
|
||||
| sed 's/\&self/\&mut self/g' \
|
||||
> scheme_mut.rs
|
||||
|
||||
echo "Generating SchemeBlock from Scheme"
|
||||
sed 's/trait Scheme/trait SchemeBlock/' scheme.rs \
|
||||
| sed 's/fn handle(\&self, packet: \&mut Packet)/fn handle(\&self, packet: \&Packet) -> Option<usize>/' \
|
||||
| sed 's/packet.a = Error::mux(res);/res.transpose().map(Error::mux)/' \
|
||||
| sed 's/\.map(|f| f\.bits())/\.map(|f| f.map(|f| f.bits()))/' \
|
||||
| sed 's/\.map(|o| o as usize)/.map(|o| o.map(|o| o as usize))/' \
|
||||
| sed 's/Ok(0)/Ok(Some(0))/g' \
|
||||
| sed 's/Result<\([^>]\+\)>/Result<Option<\1>>/g' \
|
||||
| sed 's/convert_to_this_scheme/convert_to_this_scheme_block/g' \
|
||||
| sed 's/convert_in_scheme_handle/convert_in_scheme_handle_block/g' \
|
||||
> scheme_block.rs
|
||||
|
||||
echo "Generating SchemeBlockMut from SchemeBlock"
|
||||
sed 's/trait SchemeBlock/trait SchemeBlockMut/' scheme_block.rs \
|
||||
| sed 's/\&self/\&mut self/g' \
|
||||
> scheme_block_mut.rs
|
||||
@@ -1,73 +0,0 @@
|
||||
use core::{slice, str};
|
||||
|
||||
use crate::{Error, Packet, Result, EOPNOTSUPP, ESKMSG, SKMSG_FRETURNFD};
|
||||
|
||||
pub use self::{
|
||||
scheme::Scheme, scheme_block::SchemeBlock, scheme_block_mut::SchemeBlockMut,
|
||||
scheme_mut::SchemeMut, seek::*,
|
||||
};
|
||||
|
||||
unsafe fn str_from_raw_parts(ptr: *const u8, len: usize) -> Option<&'static str> {
|
||||
let slice = slice::from_raw_parts(ptr, len);
|
||||
str::from_utf8(slice).ok()
|
||||
}
|
||||
|
||||
mod scheme;
|
||||
mod scheme_block;
|
||||
mod scheme_block_mut;
|
||||
mod scheme_mut;
|
||||
mod seek;
|
||||
|
||||
pub struct CallerCtx {
|
||||
pub pid: usize,
|
||||
pub uid: u32,
|
||||
pub gid: u32,
|
||||
}
|
||||
|
||||
pub enum OpenResult {
|
||||
ThisScheme { number: usize },
|
||||
OtherScheme { fd: usize },
|
||||
}
|
||||
|
||||
// TODO: Find a better solution than generate.sh
|
||||
pub(crate) fn convert_to_this_scheme(r: Result<usize>) -> Result<OpenResult> {
|
||||
r.map(|number| OpenResult::ThisScheme { number })
|
||||
}
|
||||
pub(crate) fn convert_to_this_scheme_block(r: Result<Option<usize>>) -> Result<Option<OpenResult>> {
|
||||
r.map(|o| o.map(|number| OpenResult::ThisScheme { number }))
|
||||
}
|
||||
pub(crate) fn convert_in_scheme_handle_block(
|
||||
_: &Packet,
|
||||
result: Result<Option<OpenResult>>,
|
||||
) -> Result<Option<usize>> {
|
||||
match result {
|
||||
Ok(Some(OpenResult::ThisScheme { number })) => Ok(Some(number)),
|
||||
Ok(Some(OpenResult::OtherScheme { .. })) => Err(Error::new(EOPNOTSUPP)),
|
||||
Ok(None) => Ok(None),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
pub(crate) fn convert_in_scheme_handle(
|
||||
packet: &mut Packet,
|
||||
result: Result<OpenResult>,
|
||||
) -> Result<usize> {
|
||||
match result {
|
||||
Ok(OpenResult::ThisScheme { number }) => Ok(number),
|
||||
Ok(OpenResult::OtherScheme { fd }) => {
|
||||
packet.b = SKMSG_FRETURNFD;
|
||||
packet.c = fd;
|
||||
Err(Error::new(ESKMSG))
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
impl CallerCtx {
|
||||
pub fn from_packet(packet: &Packet) -> Self {
|
||||
Self {
|
||||
pid: packet.pid,
|
||||
uid: packet.uid,
|
||||
gid: packet.gid,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
use core::{mem, slice};
|
||||
|
||||
use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult};
|
||||
|
||||
pub trait Scheme {
|
||||
fn handle(&self, packet: &mut Packet) {
|
||||
let res = match packet.a {
|
||||
SYS_OPEN => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
convert_in_scheme_handle(
|
||||
packet,
|
||||
self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)),
|
||||
)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_RMDIR => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.rmdir(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_UNLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.unlink(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
|
||||
SYS_DUP => convert_in_scheme_handle(
|
||||
packet,
|
||||
self.xdup(
|
||||
packet.b,
|
||||
unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) },
|
||||
&CallerCtx::from_packet(&packet),
|
||||
),
|
||||
),
|
||||
SYS_READ => self.read(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_WRITE => self.write(packet.b, unsafe {
|
||||
slice::from_raw_parts(packet.c as *const u8, packet.d)
|
||||
}),
|
||||
SYS_LSEEK => self
|
||||
.seek(packet.b, packet.c as isize, packet.d)
|
||||
.map(|o| o as usize),
|
||||
SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
|
||||
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
|
||||
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
|
||||
SYS_FEVENT => self
|
||||
.fevent(packet.b, EventFlags::from_bits_truncate(packet.c))
|
||||
.map(|f| f.bits()),
|
||||
SYS_FLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.flink(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FPATH => self.fpath(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_FRENAME => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.frename(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FSTAT => {
|
||||
if packet.d >= mem::size_of::<Stat>() {
|
||||
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSTATVFS => {
|
||||
if packet.d >= mem::size_of::<StatVfs>() {
|
||||
self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSYNC => self.fsync(packet.b),
|
||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
||||
SYS_FUTIMENS => {
|
||||
if packet.d >= mem::size_of::<TimeSpec>() {
|
||||
self.futimens(packet.b, unsafe {
|
||||
slice::from_raw_parts(
|
||||
packet.c as *const TimeSpec,
|
||||
packet.d / mem::size_of::<TimeSpec>(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_CLOSE => self.close(packet.b),
|
||||
|
||||
KSMSG_MMAP_PREP => self.mmap_prep(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
KSMSG_MUNMAP => self.munmap(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MunmapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
|
||||
_ => Err(Error::new(ENOSYS)),
|
||||
};
|
||||
|
||||
packet.a = Error::mux(res);
|
||||
}
|
||||
|
||||
/* Scheme operations */
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn open(&self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
fn xopen(&self, path: &str, flags: usize, ctx: &CallerCtx) -> Result<OpenResult> {
|
||||
convert_to_this_scheme(self.open(path, flags, ctx.uid, ctx.gid))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn chmod(&self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn rmdir(&self, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn unlink(&self, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
#[allow(unused_variables)]
|
||||
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn xdup(&self, old_id: usize, buf: &[u8], ctx: &CallerCtx) -> Result<OpenResult> {
|
||||
convert_to_this_scheme(self.dup(old_id, buf))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn read(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn write(&self, id: usize, buf: &[u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn seek(&self, id: usize, pos: isize, whence: usize) -> Result<isize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchmod(&self, id: usize, mode: u16) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchown(&self, id: usize, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fevent(&self, id: usize, flags: EventFlags) -> Result<EventFlags> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn flink(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn frename(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fsync(&self, id: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn ftruncate(&self, id: usize, len: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn futimens(&self, id: usize, times: &[TimeSpec]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn close(&self, id: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn mmap_prep(&self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<usize> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn munmap(&self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<usize> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
use core::{mem, slice};
|
||||
|
||||
use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult};
|
||||
|
||||
pub trait SchemeBlock {
|
||||
fn handle(&self, packet: &Packet) -> Option<usize> {
|
||||
let res = match packet.a {
|
||||
SYS_OPEN => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
convert_in_scheme_handle_block(
|
||||
packet,
|
||||
self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)),
|
||||
)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_RMDIR => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.rmdir(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_UNLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.unlink(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
|
||||
SYS_DUP => convert_in_scheme_handle_block(
|
||||
packet,
|
||||
self.xdup(
|
||||
packet.b,
|
||||
unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) },
|
||||
&CallerCtx::from_packet(&packet),
|
||||
),
|
||||
),
|
||||
SYS_READ => self.read(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_WRITE => self.write(packet.b, unsafe {
|
||||
slice::from_raw_parts(packet.c as *const u8, packet.d)
|
||||
}),
|
||||
SYS_LSEEK => self
|
||||
.seek(packet.b, packet.c as isize, packet.d)
|
||||
.map(|o| o.map(|o| o as usize)),
|
||||
SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
|
||||
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
|
||||
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
|
||||
SYS_FEVENT => self
|
||||
.fevent(packet.b, EventFlags::from_bits_truncate(packet.c))
|
||||
.map(|f| f.map(|f| f.bits())),
|
||||
SYS_FLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.flink(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FPATH => self.fpath(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_FRENAME => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.frename(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FSTAT => {
|
||||
if packet.d >= mem::size_of::<Stat>() {
|
||||
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSTATVFS => {
|
||||
if packet.d >= mem::size_of::<StatVfs>() {
|
||||
self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSYNC => self.fsync(packet.b),
|
||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
||||
SYS_FUTIMENS => {
|
||||
if packet.d >= mem::size_of::<TimeSpec>() {
|
||||
self.futimens(packet.b, unsafe {
|
||||
slice::from_raw_parts(
|
||||
packet.c as *const TimeSpec,
|
||||
packet.d / mem::size_of::<TimeSpec>(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_CLOSE => self.close(packet.b),
|
||||
|
||||
KSMSG_MMAP_PREP => self.mmap_prep(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
KSMSG_MUNMAP => self.munmap(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MunmapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
|
||||
_ => Err(Error::new(ENOSYS)),
|
||||
};
|
||||
|
||||
res.transpose().map(Error::mux)
|
||||
}
|
||||
|
||||
/* Scheme operations */
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn open(&self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
fn xopen(&self, path: &str, flags: usize, ctx: &CallerCtx) -> Result<Option<OpenResult>> {
|
||||
convert_to_this_scheme_block(self.open(path, flags, ctx.uid, ctx.gid))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn chmod(&self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn rmdir(&self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn unlink(&self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
#[allow(unused_variables)]
|
||||
fn dup(&self, old_id: usize, buf: &[u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn xdup(&self, old_id: usize, buf: &[u8], ctx: &CallerCtx) -> Result<Option<OpenResult>> {
|
||||
convert_to_this_scheme_block(self.dup(old_id, buf))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn read(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn write(&self, id: usize, buf: &[u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn seek(&self, id: usize, pos: isize, whence: usize) -> Result<Option<isize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchmod(&self, id: usize, mode: u16) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchown(&self, id: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fevent(&self, id: usize, flags: EventFlags) -> Result<Option<EventFlags>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn flink(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fpath(&self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn frename(&self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstat(&self, id: usize, stat: &mut Stat) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fsync(&self, id: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn ftruncate(&self, id: usize, len: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn futimens(&self, id: usize, times: &[TimeSpec]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn close(&self, id: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn mmap_prep(&self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<Option<usize>> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn munmap(&self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<Option<usize>> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
use core::{mem, slice};
|
||||
|
||||
use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult};
|
||||
|
||||
pub trait SchemeBlockMut {
|
||||
fn handle(&mut self, packet: &Packet) -> Option<usize> {
|
||||
let res = match packet.a {
|
||||
SYS_OPEN => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
convert_in_scheme_handle_block(
|
||||
packet,
|
||||
self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)),
|
||||
)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_RMDIR => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.rmdir(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_UNLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.unlink(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
|
||||
SYS_DUP => convert_in_scheme_handle_block(
|
||||
packet,
|
||||
self.xdup(
|
||||
packet.b,
|
||||
unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) },
|
||||
&CallerCtx::from_packet(&packet),
|
||||
),
|
||||
),
|
||||
SYS_READ => self.read(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_WRITE => self.write(packet.b, unsafe {
|
||||
slice::from_raw_parts(packet.c as *const u8, packet.d)
|
||||
}),
|
||||
SYS_LSEEK => self
|
||||
.seek(packet.b, packet.c as isize, packet.d)
|
||||
.map(|o| o.map(|o| o as usize)),
|
||||
SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
|
||||
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
|
||||
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
|
||||
SYS_FEVENT => self
|
||||
.fevent(packet.b, EventFlags::from_bits_truncate(packet.c))
|
||||
.map(|f| f.map(|f| f.bits())),
|
||||
SYS_FLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.flink(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FPATH => self.fpath(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_FRENAME => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.frename(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FSTAT => {
|
||||
if packet.d >= mem::size_of::<Stat>() {
|
||||
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSTATVFS => {
|
||||
if packet.d >= mem::size_of::<StatVfs>() {
|
||||
self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSYNC => self.fsync(packet.b),
|
||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
||||
SYS_FUTIMENS => {
|
||||
if packet.d >= mem::size_of::<TimeSpec>() {
|
||||
self.futimens(packet.b, unsafe {
|
||||
slice::from_raw_parts(
|
||||
packet.c as *const TimeSpec,
|
||||
packet.d / mem::size_of::<TimeSpec>(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_CLOSE => self.close(packet.b),
|
||||
|
||||
KSMSG_MMAP_PREP => self.mmap_prep(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
KSMSG_MUNMAP => self.munmap(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MunmapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
|
||||
_ => Err(Error::new(ENOSYS)),
|
||||
};
|
||||
|
||||
res.transpose().map(Error::mux)
|
||||
}
|
||||
|
||||
/* Scheme operations */
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn open(&mut self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
fn xopen(&mut self, path: &str, flags: usize, ctx: &CallerCtx) -> Result<Option<OpenResult>> {
|
||||
convert_to_this_scheme_block(self.open(path, flags, ctx.uid, ctx.gid))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn chmod(&mut self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn rmdir(&mut self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn unlink(&mut self, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
#[allow(unused_variables)]
|
||||
fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn xdup(&mut self, old_id: usize, buf: &[u8], ctx: &CallerCtx) -> Result<Option<OpenResult>> {
|
||||
convert_to_this_scheme_block(self.dup(old_id, buf))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn write(&mut self, id: usize, buf: &[u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn seek(&mut self, id: usize, pos: isize, whence: usize) -> Result<Option<isize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchmod(&mut self, id: usize, mode: u16) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchown(&mut self, id: usize, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fevent(&mut self, id: usize, flags: EventFlags) -> Result<Option<EventFlags>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn flink(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn frename(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstatvfs(&mut self, id: usize, stat: &mut StatVfs) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fsync(&mut self, id: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn ftruncate(&mut self, id: usize, len: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn futimens(&mut self, id: usize, times: &[TimeSpec]) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn close(&mut self, id: usize) -> Result<Option<usize>> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<Option<usize>> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn munmap(&mut self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<Option<usize>> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
use core::{mem, slice};
|
||||
|
||||
use crate::{data::*, error::*, flag::*, number::*, scheme::*, CallerCtx, OpenResult};
|
||||
|
||||
pub trait SchemeMut {
|
||||
fn handle(&mut self, packet: &mut Packet) {
|
||||
let res = match packet.a {
|
||||
SYS_OPEN => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
convert_in_scheme_handle(
|
||||
packet,
|
||||
self.xopen(path, packet.d, &CallerCtx::from_packet(&packet)),
|
||||
)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_RMDIR => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.rmdir(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_UNLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
|
||||
self.unlink(path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
|
||||
SYS_DUP => convert_in_scheme_handle(
|
||||
packet,
|
||||
self.xdup(
|
||||
packet.b,
|
||||
unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) },
|
||||
&CallerCtx::from_packet(&packet),
|
||||
),
|
||||
),
|
||||
SYS_READ => self.read(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_WRITE => self.write(packet.b, unsafe {
|
||||
slice::from_raw_parts(packet.c as *const u8, packet.d)
|
||||
}),
|
||||
SYS_LSEEK => self
|
||||
.seek(packet.b, packet.c as isize, packet.d)
|
||||
.map(|o| o as usize),
|
||||
SYS_FCHMOD => self.fchmod(packet.b, packet.c as u16),
|
||||
SYS_FCHOWN => self.fchown(packet.b, packet.c as u32, packet.d as u32),
|
||||
SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d),
|
||||
SYS_FEVENT => self
|
||||
.fevent(packet.b, EventFlags::from_bits_truncate(packet.c))
|
||||
.map(|f| f.bits()),
|
||||
SYS_FLINK => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.flink(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FPATH => self.fpath(packet.b, unsafe {
|
||||
slice::from_raw_parts_mut(packet.c as *mut u8, packet.d)
|
||||
}),
|
||||
SYS_FRENAME => {
|
||||
if let Some(path) = unsafe { str_from_raw_parts(packet.c as *const u8, packet.d) } {
|
||||
self.frename(packet.b, path, packet.uid, packet.gid)
|
||||
} else {
|
||||
Err(Error::new(EINVAL))
|
||||
}
|
||||
}
|
||||
SYS_FSTAT => {
|
||||
if packet.d >= mem::size_of::<Stat>() {
|
||||
self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSTATVFS => {
|
||||
if packet.d >= mem::size_of::<StatVfs>() {
|
||||
self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) })
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_FSYNC => self.fsync(packet.b),
|
||||
SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c),
|
||||
SYS_FUTIMENS => {
|
||||
if packet.d >= mem::size_of::<TimeSpec>() {
|
||||
self.futimens(packet.b, unsafe {
|
||||
slice::from_raw_parts(
|
||||
packet.c as *const TimeSpec,
|
||||
packet.d / mem::size_of::<TimeSpec>(),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
Err(Error::new(EFAULT))
|
||||
}
|
||||
}
|
||||
SYS_CLOSE => self.close(packet.b),
|
||||
|
||||
KSMSG_MMAP_PREP => self.mmap_prep(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
KSMSG_MUNMAP => self.munmap(
|
||||
packet.b,
|
||||
u64::from(packet.uid) | (u64::from(packet.gid) << 32),
|
||||
packet.c,
|
||||
MunmapFlags::from_bits_truncate(packet.d),
|
||||
),
|
||||
|
||||
_ => Err(Error::new(ENOSYS)),
|
||||
};
|
||||
|
||||
packet.a = Error::mux(res);
|
||||
}
|
||||
|
||||
/* Scheme operations */
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn open(&mut self, path: &str, flags: usize, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
#[allow(unused_variables)]
|
||||
fn xopen(&mut self, path: &str, flags: usize, ctx: &CallerCtx) -> Result<OpenResult> {
|
||||
convert_to_this_scheme(self.open(path, flags, ctx.uid, ctx.gid))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn chmod(&mut self, path: &str, mode: u16, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn rmdir(&mut self, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn unlink(&mut self, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(ENOENT))
|
||||
}
|
||||
|
||||
/* Resource operations */
|
||||
#[allow(unused_variables)]
|
||||
fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn xdup(&mut self, old_id: usize, buf: &[u8], ctx: &CallerCtx) -> Result<OpenResult> {
|
||||
convert_to_this_scheme(self.dup(old_id, buf))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn read(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn write(&mut self, id: usize, buf: &[u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn seek(&mut self, id: usize, pos: isize, whence: usize) -> Result<isize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchmod(&mut self, id: usize, mode: u16) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fchown(&mut self, id: usize, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fevent(&mut self, id: usize, flags: EventFlags) -> Result<EventFlags> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn flink(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn frename(&mut self, id: usize, path: &str, uid: u32, gid: u32) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fstatvfs(&mut self, id: usize, stat: &mut StatVfs) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn fsync(&mut self, id: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn ftruncate(&mut self, id: usize, len: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn futimens(&mut self, id: usize, times: &[TimeSpec]) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn close(&mut self, id: usize) -> Result<usize> {
|
||||
Err(Error::new(EBADF))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn mmap_prep(&mut self, id: usize, offset: u64, size: usize, flags: MapFlags) -> Result<usize> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn munmap(&mut self, id: usize, offset: u64, size: usize, flags: MunmapFlags) -> Result<usize> {
|
||||
Err(Error::new(EOPNOTSUPP))
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
use crate::{error::*, flag::*};
|
||||
use core::{cmp, convert::TryFrom};
|
||||
|
||||
/// Helper for seek calls
|
||||
/// In most cases it's easier to use a usize to track the offset and buffer size internally,
|
||||
/// but the seek interface uses isize. This wrapper ensures EOVERFLOW errors are returned
|
||||
/// as appropriate if the value in the usize can't fit in the isize.
|
||||
pub fn calc_seek_offset_usize(
|
||||
cur_offset: usize,
|
||||
pos: isize,
|
||||
whence: usize,
|
||||
buf_len: usize,
|
||||
) -> Result<isize> {
|
||||
let cur_offset = isize::try_from(cur_offset).or_else(|_| Err(Error::new(EOVERFLOW)))?;
|
||||
let buf_len = isize::try_from(buf_len).or_else(|_| Err(Error::new(EOVERFLOW)))?;
|
||||
calc_seek_offset_isize(cur_offset, pos, whence, buf_len)
|
||||
}
|
||||
|
||||
/// Helper for seek calls
|
||||
/// Result is guaranteed to be positive.
|
||||
/// EOVERFLOW returned if the arguments would cause an overflow.
|
||||
/// EINVAL returned if the new offset is out of bounds.
|
||||
pub fn calc_seek_offset_isize(
|
||||
cur_offset: isize,
|
||||
pos: isize,
|
||||
whence: usize,
|
||||
buf_len: isize,
|
||||
) -> Result<isize> {
|
||||
let new_offset = match whence {
|
||||
SEEK_CUR => pos.checked_add(cur_offset),
|
||||
SEEK_END => pos.checked_add(buf_len),
|
||||
SEEK_SET => Some(pos),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match new_offset {
|
||||
Some(new_offset) if new_offset < 0 => Err(Error::new(EINVAL)),
|
||||
Some(new_offset) => Ok(cmp::min(new_offset, buf_len)),
|
||||
None => Err(Error::new(EOVERFLOW)),
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,17 @@ use core::{
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
pub struct CallerCtx {
|
||||
pub pid: usize,
|
||||
pub uid: u32,
|
||||
pub gid: u32,
|
||||
}
|
||||
|
||||
pub enum OpenResult {
|
||||
ThisScheme { number: usize },
|
||||
OtherScheme { fd: usize },
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct Sqe {
|
||||
|
||||
Reference in New Issue
Block a user