summaryrefslogtreecommitdiffstats
path: root/third_party/rust/redox_syscall/src/scheme
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/redox_syscall/src/scheme
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/redox_syscall/src/scheme')
-rwxr-xr-xthird_party/rust/redox_syscall/src/scheme/generate.sh23
-rw-r--r--third_party/rust/redox_syscall/src/scheme/mod.rs18
-rw-r--r--third_party/rust/redox_syscall/src/scheme/scheme.rs211
-rw-r--r--third_party/rust/redox_syscall/src/scheme/scheme_block.rs211
-rw-r--r--third_party/rust/redox_syscall/src/scheme/scheme_block_mut.rs211
-rw-r--r--third_party/rust/redox_syscall/src/scheme/scheme_mut.rs211
-rw-r--r--third_party/rust/redox_syscall/src/scheme/seek.rs33
7 files changed, 918 insertions, 0 deletions
diff --git a/third_party/rust/redox_syscall/src/scheme/generate.sh b/third_party/rust/redox_syscall/src/scheme/generate.sh
new file mode 100755
index 0000000000..a877cda921
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/generate.sh
@@ -0,0 +1,23 @@
+#!/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' \
+> 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
diff --git a/third_party/rust/redox_syscall/src/scheme/mod.rs b/third_party/rust/redox_syscall/src/scheme/mod.rs
new file mode 100644
index 0000000000..f65d1e2c06
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/mod.rs
@@ -0,0 +1,18 @@
+use core::{slice, str};
+
+pub use self::scheme::Scheme;
+pub use self::scheme_mut::SchemeMut;
+pub use self::scheme_block::SchemeBlock;
+pub use self::scheme_block_mut::SchemeBlockMut;
+pub use self::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_mut;
+mod scheme_block;
+mod scheme_block_mut;
+mod seek;
diff --git a/third_party/rust/redox_syscall/src/scheme/scheme.rs b/third_party/rust/redox_syscall/src/scheme/scheme.rs
new file mode 100644
index 0000000000..249d28c6e2
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/scheme.rs
@@ -0,0 +1,211 @@
+use core::{mem, slice};
+
+use crate::data::*;
+use crate::error::*;
+use crate::flag::*;
+use crate::number::*;
+use crate::scheme::str_from_raw_parts;
+
+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) } {
+ self.open(path, packet.d, packet.uid, packet.gid)
+ } else {
+ Err(Error::new(EINVAL))
+ },
+ SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
+ self.chmod(path, packet.d as u16, packet.uid, packet.gid)
+ } 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 => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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_FMAP_OLD => if packet.d >= mem::size_of::<OldMap>() {
+ self.fmap_old(packet.b, unsafe { &*(packet.c as *const OldMap) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
+ self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FUNMAP_OLD => self.funmap_old(packet.b),
+ SYS_FUNMAP => self.funmap(packet.b, packet.c),
+ 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),
+ _ => 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 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 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 fmap_old(&self, id: usize, map: &OldMap) -> Result<usize> {
+ Err(Error::new(EBADF))
+ }
+ #[allow(unused_variables)]
+ fn fmap(&self, id: usize, map: &Map) -> Result<usize> {
+ if map.flags.contains(MapFlags::MAP_FIXED) {
+ return Err(Error::new(EINVAL));
+ }
+ self.fmap_old(id, &OldMap {
+ offset: map.offset,
+ size: map.size,
+ flags: map.flags,
+ })
+ }
+
+ #[allow(unused_variables)]
+ fn funmap_old(&self, address: usize) -> Result<usize> {
+ Ok(0)
+ }
+
+ #[allow(unused_variables)]
+ fn funmap(&self, address: usize, length: usize) -> Result<usize> {
+ Ok(0)
+ }
+
+ #[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))
+ }
+}
diff --git a/third_party/rust/redox_syscall/src/scheme/scheme_block.rs b/third_party/rust/redox_syscall/src/scheme/scheme_block.rs
new file mode 100644
index 0000000000..e22535e0fd
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/scheme_block.rs
@@ -0,0 +1,211 @@
+use core::{mem, slice};
+
+use crate::data::*;
+use crate::error::*;
+use crate::flag::*;
+use crate::number::*;
+use crate::scheme::str_from_raw_parts;
+
+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) } {
+ self.open(path, packet.d, packet.uid, packet.gid)
+ } else {
+ Err(Error::new(EINVAL))
+ },
+ SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
+ self.chmod(path, packet.d as u16, packet.uid, packet.gid)
+ } 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 => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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_FMAP_OLD => if packet.d >= mem::size_of::<OldMap>() {
+ self.fmap_old(packet.b, unsafe { &*(packet.c as *const OldMap) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
+ self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FUNMAP_OLD => self.funmap_old(packet.b),
+ SYS_FUNMAP => self.funmap(packet.b, packet.c),
+ 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),
+ _ => 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 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 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 fmap_old(&self, id: usize, map: &OldMap) -> Result<Option<usize>> {
+ Err(Error::new(EBADF))
+ }
+ #[allow(unused_variables)]
+ fn fmap(&self, id: usize, map: &Map) -> Result<Option<usize>> {
+ if map.flags.contains(MapFlags::MAP_FIXED) {
+ return Err(Error::new(EINVAL));
+ }
+ self.fmap_old(id, &OldMap {
+ offset: map.offset,
+ size: map.size,
+ flags: map.flags,
+ })
+ }
+
+ #[allow(unused_variables)]
+ fn funmap_old(&self, address: usize) -> Result<Option<usize>> {
+ Ok(Some(0))
+ }
+
+ #[allow(unused_variables)]
+ fn funmap(&self, address: usize, length: usize) -> Result<Option<usize>> {
+ Ok(Some(0))
+ }
+
+ #[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))
+ }
+}
diff --git a/third_party/rust/redox_syscall/src/scheme/scheme_block_mut.rs b/third_party/rust/redox_syscall/src/scheme/scheme_block_mut.rs
new file mode 100644
index 0000000000..c1e54351a3
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/scheme_block_mut.rs
@@ -0,0 +1,211 @@
+use core::{mem, slice};
+
+use crate::data::*;
+use crate::error::*;
+use crate::flag::*;
+use crate::number::*;
+use crate::scheme::str_from_raw_parts;
+
+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) } {
+ self.open(path, packet.d, packet.uid, packet.gid)
+ } else {
+ Err(Error::new(EINVAL))
+ },
+ SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
+ self.chmod(path, packet.d as u16, packet.uid, packet.gid)
+ } 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 => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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_FMAP_OLD => if packet.d >= mem::size_of::<OldMap>() {
+ self.fmap_old(packet.b, unsafe { &*(packet.c as *const OldMap) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
+ self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FUNMAP_OLD => self.funmap_old(packet.b),
+ SYS_FUNMAP => self.funmap(packet.b, packet.c),
+ 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),
+ _ => 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 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 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 fmap_old(&mut self, id: usize, map: &OldMap) -> Result<Option<usize>> {
+ Err(Error::new(EBADF))
+ }
+ #[allow(unused_variables)]
+ fn fmap(&mut self, id: usize, map: &Map) -> Result<Option<usize>> {
+ if map.flags.contains(MapFlags::MAP_FIXED) {
+ return Err(Error::new(EINVAL));
+ }
+ self.fmap_old(id, &OldMap {
+ offset: map.offset,
+ size: map.size,
+ flags: map.flags,
+ })
+ }
+
+ #[allow(unused_variables)]
+ fn funmap_old(&mut self, address: usize) -> Result<Option<usize>> {
+ Ok(Some(0))
+ }
+
+ #[allow(unused_variables)]
+ fn funmap(&mut self, address: usize, length: usize) -> Result<Option<usize>> {
+ Ok(Some(0))
+ }
+
+ #[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))
+ }
+}
diff --git a/third_party/rust/redox_syscall/src/scheme/scheme_mut.rs b/third_party/rust/redox_syscall/src/scheme/scheme_mut.rs
new file mode 100644
index 0000000000..deb1483664
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/scheme_mut.rs
@@ -0,0 +1,211 @@
+use core::{mem, slice};
+
+use crate::data::*;
+use crate::error::*;
+use crate::flag::*;
+use crate::number::*;
+use crate::scheme::str_from_raw_parts;
+
+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) } {
+ self.open(path, packet.d, packet.uid, packet.gid)
+ } else {
+ Err(Error::new(EINVAL))
+ },
+ SYS_CHMOD => if let Some(path) = unsafe { str_from_raw_parts(packet.b as *const u8, packet.c) } {
+ self.chmod(path, packet.d as u16, packet.uid, packet.gid)
+ } 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 => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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_FMAP_OLD => if packet.d >= mem::size_of::<OldMap>() {
+ self.fmap_old(packet.b, unsafe { &*(packet.c as *const OldMap) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FMAP => if packet.d >= mem::size_of::<Map>() {
+ self.fmap(packet.b, unsafe { &*(packet.c as *const Map) })
+ } else {
+ Err(Error::new(EFAULT))
+ },
+ SYS_FUNMAP_OLD => self.funmap_old(packet.b),
+ SYS_FUNMAP => self.funmap(packet.b, packet.c),
+ 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),
+ _ => 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 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 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 fmap_old(&mut self, id: usize, map: &OldMap) -> Result<usize> {
+ Err(Error::new(EBADF))
+ }
+ #[allow(unused_variables)]
+ fn fmap(&mut self, id: usize, map: &Map) -> Result<usize> {
+ if map.flags.contains(MapFlags::MAP_FIXED) {
+ return Err(Error::new(EINVAL));
+ }
+ self.fmap_old(id, &OldMap {
+ offset: map.offset,
+ size: map.size,
+ flags: map.flags,
+ })
+ }
+
+ #[allow(unused_variables)]
+ fn funmap_old(&mut self, address: usize) -> Result<usize> {
+ Ok(0)
+ }
+
+ #[allow(unused_variables)]
+ fn funmap(&mut self, address: usize, length: usize) -> Result<usize> {
+ Ok(0)
+ }
+
+ #[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))
+ }
+}
diff --git a/third_party/rust/redox_syscall/src/scheme/seek.rs b/third_party/rust/redox_syscall/src/scheme/seek.rs
new file mode 100644
index 0000000000..09a45186ac
--- /dev/null
+++ b/third_party/rust/redox_syscall/src/scheme/seek.rs
@@ -0,0 +1,33 @@
+use core::cmp;
+use core::convert::TryFrom;
+use crate::error::*;
+use crate::flag::*;
+
+/// 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))
+ }
+} \ No newline at end of file