summaryrefslogtreecommitdiffstats
path: root/vendor/redox_syscall/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/redox_syscall/src')
-rw-r--r--vendor/redox_syscall/src/call.rs15
-rw-r--r--vendor/redox_syscall/src/data.rs59
-rw-r--r--vendor/redox_syscall/src/error.rs6
-rw-r--r--vendor/redox_syscall/src/flag.rs40
-rw-r--r--vendor/redox_syscall/src/io/mmio.rs129
-rw-r--r--vendor/redox_syscall/src/number.rs20
-rwxr-xr-xvendor/redox_syscall/src/scheme/generate.sh2
-rw-r--r--vendor/redox_syscall/src/scheme/mod.rs50
-rw-r--r--vendor/redox_syscall/src/scheme/scheme.rs72
-rw-r--r--vendor/redox_syscall/src/scheme/scheme_block.rs72
-rw-r--r--vendor/redox_syscall/src/scheme/scheme_block_mut.rs72
-rw-r--r--vendor/redox_syscall/src/scheme/scheme_mut.rs72
-rw-r--r--vendor/redox_syscall/src/tests.rs26
13 files changed, 418 insertions, 217 deletions
diff --git a/vendor/redox_syscall/src/call.rs b/vendor/redox_syscall/src/call.rs
index bc1af0dc2..87ba8a980 100644
--- a/vendor/redox_syscall/src/call.rs
+++ b/vendor/redox_syscall/src/call.rs
@@ -264,21 +264,6 @@ pub unsafe fn physmap(physical_address: usize, size: usize, flags: PhysmapFlags)
syscall3(SYS_PHYSMAP, physical_address, size, flags.bits())
}
-/// Unmap previously mapped physical memory
-///
-/// # Errors
-///
-/// * `EPERM` - `uid != 0`
-/// * `EFAULT` - `virtual_address` has not been mapped
-pub unsafe fn physunmap(virtual_address: usize) -> Result<usize> {
- syscall1(SYS_PHYSUNMAP, virtual_address)
-}
-
-/// Create a pair of file descriptors referencing the read and write ends of a pipe
-pub fn pipe2(fds: &mut [usize; 2], flags: usize) -> Result<usize> {
- unsafe { syscall2(SYS_PIPE2, fds.as_ptr() as usize, flags) }
-}
-
/// Read from a file descriptor into a buffer
pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
unsafe { syscall3(SYS_READ, fd, buf.as_mut_ptr() as usize, buf.len()) }
diff --git a/vendor/redox_syscall/src/data.rs b/vendor/redox_syscall/src/data.rs
index 45d2dd862..c93869793 100644
--- a/vendor/redox_syscall/src/data.rs
+++ b/vendor/redox_syscall/src/data.rs
@@ -149,6 +149,24 @@ pub struct SigAction {
pub sa_mask: [u64; 2],
pub sa_flags: SigActionFlags,
}
+impl Deref for SigAction {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const SigAction as *const u8,
+ mem::size_of::<SigAction>())
+ }
+ }
+}
+
+impl DerefMut for SigAction {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut SigAction as *mut u8,
+ mem::size_of::<SigAction>())
+ }
+ }
+}
#[allow(dead_code)]
unsafe fn _assert_size_of_function_is_sane() {
@@ -295,3 +313,44 @@ macro_rules! ptrace_event {
}
}
}
+
+bitflags::bitflags! {
+ #[derive(Default)]
+ pub struct GrantFlags: usize {
+ const GRANT_READ = 0x0000_0001;
+ const GRANT_WRITE = 0x0000_0002;
+ const GRANT_EXEC = 0x0000_0004;
+
+ const GRANT_SHARED = 0x0000_0008;
+ const GRANT_LAZY = 0x0000_0010;
+ const GRANT_SCHEME = 0x0000_0020;
+ const GRANT_PHYS = 0x0000_0040;
+ const GRANT_PINNED = 0x0000_0080;
+ }
+}
+
+#[derive(Clone, Copy, Debug, Default)]
+#[repr(C)]
+pub struct GrantDesc {
+ pub base: usize,
+ pub size: usize,
+ pub flags: GrantFlags,
+ pub offset: u64,
+}
+
+impl Deref for GrantDesc {
+ type Target = [u8];
+ fn deref(&self) -> &[u8] {
+ unsafe {
+ slice::from_raw_parts(self as *const GrantDesc as *const u8, mem::size_of::<GrantDesc>())
+ }
+ }
+}
+
+impl DerefMut for GrantDesc {
+ fn deref_mut(&mut self) -> &mut [u8] {
+ unsafe {
+ slice::from_raw_parts_mut(self as *mut GrantDesc as *mut u8, mem::size_of::<GrantDesc>())
+ }
+ }
+}
diff --git a/vendor/redox_syscall/src/error.rs b/vendor/redox_syscall/src/error.rs
index 9a4b0b5ad..5cc0bfc33 100644
--- a/vendor/redox_syscall/src/error.rs
+++ b/vendor/redox_syscall/src/error.rs
@@ -176,8 +176,9 @@ 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 static STR_ERROR: [&'static str; 132] = ["Success",
+pub static STR_ERROR: [&'static str; 133] = ["Success",
"Operation not permitted",
"No such file or directory",
"No such process",
@@ -308,4 +309,5 @@ pub static STR_ERROR: [&'static str; 132] = ["Success",
"Key has been revoked",
"Key was rejected by service",
"Owner died",
- "State not recoverable"];
+ "State not recoverable",
+ "Scheme-kernel message code"];
diff --git a/vendor/redox_syscall/src/flag.rs b/vendor/redox_syscall/src/flag.rs
index 341104856..45a6e42e8 100644
--- a/vendor/redox_syscall/src/flag.rs
+++ b/vendor/redox_syscall/src/flag.rs
@@ -54,9 +54,18 @@ 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;
+
bitflags! {
pub struct MapFlags: usize {
+ // TODO: Downgrade PROT_NONE to global constant? (bitflags specifically states zero flags
+ // can cause buggy behavior).
const PROT_NONE = 0x0000_0000;
+
const PROT_EXEC = 0x0001_0000;
const PROT_WRITE = 0x0002_0000;
const PROT_READ = 0x0004_0000;
@@ -64,9 +73,30 @@ bitflags! {
const MAP_SHARED = 0x0001;
const MAP_PRIVATE = 0x0002;
- /// Only accepted for mmap2(2).
const MAP_FIXED = 0x0004;
const MAP_FIXED_NOREPLACE = 0x000C;
+
+ /// For *userspace-backed mmaps*, return from the mmap call before all pages have been
+ /// provided by the scheme. This requires the scheme to be trusted, as the current context
+ /// can block indefinitely, if the scheme does not respond to the page fault handler's
+ /// request, as it tries to map the page by requesting it from the scheme.
+ ///
+ /// In some cases however, such as the program loader, the data needs to be trusted as much
+ /// with or without MAP_LAZY, and if so, mapping lazily will not cause insecureness by
+ /// itself.
+ ///
+ /// For kernel-backed mmaps, this flag has no effect at all. It is unspecified whether
+ /// kernel mmaps are lazy or not.
+ const MAP_LAZY = 0x0010;
+ }
+}
+bitflags! {
+ pub struct MunmapFlags: usize {
+ /// Indicates whether the funmap call must implicitly do an msync, for the changes to
+ /// become visible later.
+ ///
+ /// This flag will currently be set if and only if MAP_SHARED | PROT_WRITE are set.
+ const NEEDS_SYNC = 1;
}
}
@@ -334,3 +364,11 @@ pub fn wexitstatus(status: usize) -> usize {
pub fn wcoredump(status: usize) -> bool {
(status & 0x80) != 0
}
+
+bitflags! {
+ pub struct MremapFlags: usize {
+ const FIXED = 1;
+ const FIXED_REPLACE = 3;
+ // TODO: MAYMOVE, DONTUNMAP
+ }
+}
diff --git a/vendor/redox_syscall/src/io/mmio.rs b/vendor/redox_syscall/src/io/mmio.rs
index 3966ab454..ef8f60391 100644
--- a/vendor/redox_syscall/src/io/mmio.rs
+++ b/vendor/redox_syscall/src/io/mmio.rs
@@ -1,5 +1,6 @@
-use core::ptr::{read_volatile, write_volatile, addr_of, addr_of_mut};
use core::mem::MaybeUninit;
+use core::ptr;
+#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
use core::ops::{BitAnd, BitOr, Not};
use super::io::Io;
@@ -32,14 +33,136 @@ impl<T> Mmio<T> {
}
}
+// Generic implementation (WARNING: requires aligned pointers!)
+#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
impl<T> Io for Mmio<T> where T: Copy + PartialEq + BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
type Value = T;
fn read(&self) -> T {
- unsafe { read_volatile(addr_of!(self.value).cast::<T>()) }
+ unsafe { ptr::read_volatile(ptr::addr_of!(self.value).cast::<T>()) }
}
fn write(&mut self, value: T) {
- unsafe { write_volatile(addr_of_mut!(self.value).cast::<T>(), value) };
+ unsafe { ptr::write_volatile(ptr::addr_of_mut!(self.value).cast::<T>(), value) };
+ }
+}
+
+// x86 u8 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u8> {
+ type Value = u8;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {}, [{}]",
+ out(reg_byte) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {}",
+ in(reg) ptr,
+ in(reg_byte) value,
+ );
+ }
+ }
+}
+
+// x86 u16 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u16> {
+ type Value = u16;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:x}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:x}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
+ }
+}
+
+// x86 u32 implementation
+#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
+impl Io for Mmio<u32> {
+ type Value = u32;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:e}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:e}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
+ }
+}
+
+// x86 u64 implementation (x86_64 only)
+#[cfg(target_arch = "x86_64")]
+impl Io for Mmio<u64> {
+ type Value = u64;
+
+ fn read(&self) -> Self::Value {
+ unsafe {
+ let value: Self::Value;
+ let ptr: *const Self::Value = ptr::addr_of!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov {:r}, [{}]",
+ out(reg) value,
+ in(reg) ptr
+ );
+ value
+ }
+ }
+
+ fn write(&mut self, value: Self::Value) {
+ unsafe {
+ let ptr: *mut Self::Value = ptr::addr_of_mut!(self.value).cast::<Self::Value>();
+ core::arch::asm!(
+ "mov [{}], {:r}",
+ in(reg) ptr,
+ in(reg) value,
+ );
+ }
}
}
diff --git a/vendor/redox_syscall/src/number.rs b/vendor/redox_syscall/src/number.rs
index 2b9205a26..056cfc76a 100644
--- a/vendor/redox_syscall/src/number.rs
+++ b/vendor/redox_syscall/src/number.rs
@@ -25,10 +25,16 @@ pub const SYS_FCHMOD: usize = SYS_CLASS_FILE | 94;
pub const SYS_FCHOWN: usize = SYS_CLASS_FILE | 207;
pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55;
pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927;
+
+// 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;
+
pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928;
pub const SYS_FRENAME: usize = SYS_CLASS_FILE | SYS_ARG_PATH | 38;
pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28;
@@ -37,6 +43,18 @@ 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;
+
pub const SYS_CLOCK_GETTIME: usize = 265;
pub const SYS_EXIT: usize = 1;
pub const SYS_FUTEX: usize = 240;
@@ -58,9 +76,7 @@ pub const SYS_PHYSALLOC: usize =945;
pub const SYS_PHYSALLOC3: usize=9453;
pub const SYS_PHYSFREE: usize = 946;
pub const SYS_PHYSMAP: usize = 947;
-pub const SYS_PHYSUNMAP: usize =948;
pub const SYS_VIRTTOPHYS: usize=949;
-pub const SYS_PIPE2: usize = 331;
pub const SYS_SETPGID: usize = 57;
pub const SYS_SETREGID: usize = 204;
pub const SYS_SETRENS: usize = 952;
diff --git a/vendor/redox_syscall/src/scheme/generate.sh b/vendor/redox_syscall/src/scheme/generate.sh
index a877cda92..be851f57b 100755
--- a/vendor/redox_syscall/src/scheme/generate.sh
+++ b/vendor/redox_syscall/src/scheme/generate.sh
@@ -15,6 +15,8 @@ sed 's/trait Scheme/trait SchemeBlock/' scheme.rs \
| 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"
diff --git a/vendor/redox_syscall/src/scheme/mod.rs b/vendor/redox_syscall/src/scheme/mod.rs
index f65d1e2c0..61655dabf 100644
--- a/vendor/redox_syscall/src/scheme/mod.rs
+++ b/vendor/redox_syscall/src/scheme/mod.rs
@@ -1,5 +1,7 @@
use core::{slice, str};
+use crate::{Error, Result, EOPNOTSUPP, ESKMSG, Packet, SKMSG_FRETURNFD};
+
pub use self::scheme::Scheme;
pub use self::scheme_mut::SchemeMut;
pub use self::scheme_block::SchemeBlock;
@@ -16,3 +18,51 @@ mod scheme_mut;
mod scheme_block;
mod scheme_block_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,
+ }
+ }
+}
diff --git a/vendor/redox_syscall/src/scheme/scheme.rs b/vendor/redox_syscall/src/scheme/scheme.rs
index 6bf36172c..ee09d697b 100644
--- a/vendor/redox_syscall/src/scheme/scheme.rs
+++ b/vendor/redox_syscall/src/scheme/scheme.rs
@@ -1,17 +1,20 @@
use core::{mem, slice};
+use crate::CallerCtx;
+use crate::OpenResult;
use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
-use crate::scheme::str_from_raw_parts;
+use crate::scheme::*;
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 {
+ 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) } {
@@ -25,7 +28,7 @@ pub trait Scheme {
Err(Error::new(EINVAL))
},
- SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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),
@@ -33,18 +36,6 @@ pub trait Scheme {
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)
@@ -69,6 +60,10 @@ pub trait Scheme {
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))
};
@@ -81,6 +76,10 @@ pub trait Scheme {
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> {
@@ -104,6 +103,11 @@ pub trait Scheme {
}
#[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))
}
@@ -139,32 +143,6 @@ pub trait Scheme {
}
#[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))
}
@@ -203,4 +181,14 @@ pub trait Scheme {
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))
+ }
}
diff --git a/vendor/redox_syscall/src/scheme/scheme_block.rs b/vendor/redox_syscall/src/scheme/scheme_block.rs
index 3b3de4bc9..e74e3b7e2 100644
--- a/vendor/redox_syscall/src/scheme/scheme_block.rs
+++ b/vendor/redox_syscall/src/scheme/scheme_block.rs
@@ -1,17 +1,20 @@
use core::{mem, slice};
+use crate::CallerCtx;
+use crate::OpenResult;
use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
-use crate::scheme::str_from_raw_parts;
+use crate::scheme::*;
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 {
+ 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) } {
@@ -25,7 +28,7 @@ pub trait SchemeBlock {
Err(Error::new(EINVAL))
},
- SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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)),
@@ -33,18 +36,6 @@ pub trait SchemeBlock {
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)
@@ -69,6 +60,10 @@ pub trait SchemeBlock {
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))
};
@@ -81,6 +76,10 @@ pub trait SchemeBlock {
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>> {
@@ -104,6 +103,11 @@ pub trait SchemeBlock {
}
#[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))
}
@@ -139,32 +143,6 @@ pub trait SchemeBlock {
}
#[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))
}
@@ -203,4 +181,14 @@ pub trait SchemeBlock {
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))
+ }
}
diff --git a/vendor/redox_syscall/src/scheme/scheme_block_mut.rs b/vendor/redox_syscall/src/scheme/scheme_block_mut.rs
index 1fae3a0e5..fd2c59069 100644
--- a/vendor/redox_syscall/src/scheme/scheme_block_mut.rs
+++ b/vendor/redox_syscall/src/scheme/scheme_block_mut.rs
@@ -1,17 +1,20 @@
use core::{mem, slice};
+use crate::CallerCtx;
+use crate::OpenResult;
use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
-use crate::scheme::str_from_raw_parts;
+use crate::scheme::*;
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 {
+ 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) } {
@@ -25,7 +28,7 @@ pub trait SchemeBlockMut {
Err(Error::new(EINVAL))
},
- SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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)),
@@ -33,18 +36,6 @@ pub trait SchemeBlockMut {
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)
@@ -69,6 +60,10 @@ pub trait SchemeBlockMut {
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))
};
@@ -81,6 +76,10 @@ pub trait SchemeBlockMut {
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>> {
@@ -104,6 +103,11 @@ pub trait SchemeBlockMut {
}
#[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))
}
@@ -139,32 +143,6 @@ pub trait SchemeBlockMut {
}
#[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))
}
@@ -203,4 +181,14 @@ pub trait SchemeBlockMut {
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))
+ }
}
diff --git a/vendor/redox_syscall/src/scheme/scheme_mut.rs b/vendor/redox_syscall/src/scheme/scheme_mut.rs
index b364b62aa..2eea4dcbc 100644
--- a/vendor/redox_syscall/src/scheme/scheme_mut.rs
+++ b/vendor/redox_syscall/src/scheme/scheme_mut.rs
@@ -1,17 +1,20 @@
use core::{mem, slice};
+use crate::CallerCtx;
+use crate::OpenResult;
use crate::data::*;
use crate::error::*;
use crate::flag::*;
use crate::number::*;
-use crate::scheme::str_from_raw_parts;
+use crate::scheme::*;
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 {
+ 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) } {
@@ -25,7 +28,7 @@ pub trait SchemeMut {
Err(Error::new(EINVAL))
},
- SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }),
+ 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),
@@ -33,18 +36,6 @@ pub trait SchemeMut {
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)
@@ -69,6 +60,10 @@ pub trait SchemeMut {
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))
};
@@ -81,6 +76,10 @@ pub trait SchemeMut {
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> {
@@ -104,6 +103,11 @@ pub trait SchemeMut {
}
#[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))
}
@@ -139,32 +143,6 @@ pub trait SchemeMut {
}
#[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))
}
@@ -203,4 +181,14 @@ pub trait SchemeMut {
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))
+ }
}
diff --git a/vendor/redox_syscall/src/tests.rs b/vendor/redox_syscall/src/tests.rs
index fdff89b4b..06a3c011b 100644
--- a/vendor/redox_syscall/src/tests.rs
+++ b/vendor/redox_syscall/src/tests.rs
@@ -287,32 +287,6 @@ fn nanosleep() {
//TODO: physunmap
-#[test]
-fn pipe2() {
- let mut fds = [0, 0];
- assert_eq!(dbg!(crate::pipe2(&mut fds, crate::O_CLOEXEC)), Ok(0));
- assert_ne!(dbg!(fds), [0, 0]);
-
- {
- let mut buf = [0; 256];
- for i in 0..buf.len() {
- buf[i] = i as u8;
- }
- assert_eq!(dbg!(crate::write(fds[1], &buf)), Ok(buf.len()));
- }
-
- {
- let mut buf = [0; 256];
- assert_eq!(dbg!(crate::read(fds[0], &mut buf)), Ok(buf.len()));
- for i in 0..buf.len() {
- assert_eq!(buf[i], i as u8);
- }
- }
-
- assert_eq!(dbg!(crate::close(fds[0])), Ok(0));
- assert_eq!(dbg!(crate::close(fds[1])), Ok(0));
-}
-
//TODO: read
#[test]