diff --git a/Cargo.toml b/Cargo.toml index fb4bde326a..18788a02ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "redox_syscall" -version = "0.5.15" +version = "0.5.16" description = "A Rust library to access raw Redox system calls" license = "MIT" authors = ["Jeremy Soller "] diff --git a/src/flag.rs b/src/flag.rs index 2656602def..70b94a35a6 100644 --- a/src/flag.rs +++ b/src/flag.rs @@ -74,29 +74,64 @@ pub const SKMSG_FOBTAINFD: usize = 2; bitflags::bitflags! { #[derive(Clone, Copy, Debug)] pub struct SendFdFlags: usize { - /// If set, the kernel will enforce that the file descriptor is exclusively owned. + /// If set, the kernel will enforce that the file descriptors are exclusively owned. /// - /// That is, there will no longer exist any other reference to that FD when removed from - /// the file table (SYS_SENDFD always removes the FD from the file table, but without this - /// flag, it can be retained by SYS_DUPing it first). + /// That is, there will no longer exist any other reference to those FDs when removed from + /// the file table (sendfd always removes the FDs from the file table, but without this + /// flag, it can be retained by SYS_DUPing them first). const EXCLUSIVE = 1; + + /// If set, the file descriptors will be cloned and *not* removed from the sender's file table. + /// By default, `SYS_SENDFD` moves the file descriptors, removing them from the sender. + const CLONE = 2; } } bitflags::bitflags! { #[derive(Clone, Copy, Debug)] pub struct FobtainFdFlags: usize { - /// If set, `packet.c` specifies the destination file descriptor slot, otherwise the lowest - /// available slot will be selected, and placed in the usize pointed to by `packet.c`. + /// If set, the SYS_CALL payload specifies the destination file descriptor slots, otherwise the lowest + /// available slots will be selected, and placed in the usize pointed to by SYS_CALL + /// payload. const MANUAL_FD = 1; - // If set, the file descriptor received is guaranteed to be exclusively owned (by the file - // table the obtainer is running in). + /// If set, the file descriptors received are guaranteed to be exclusively owned (by the file + /// table the obtainer is running in). const EXCLUSIVE = 2; + /// If set, the file descriptors received will be placed into the *upper* file table. + const UPPER_TBL = 4; + // No, cloexec won't be stored in the kernel in the future, when the stable ABI is moved to // relibc, so no flag for that! } } +bitflags::bitflags! { + #[derive(Clone, Copy, Debug)] + pub struct RecvFdFlags: usize { + /// If set, the SYS_CALL payload specifies the destination file descriptor slots, otherwise the lowest + /// available slots will be selected, and placed in the usize pointed to by SYS_CALL + /// payload. + const MANUAL_FD = 1; + + /// If set, the file descriptors received will be placed into the *upper* file table. + const UPPER_TBL = 2; + } +} +bitflags::bitflags! { + #[derive(Clone, Copy, Debug)] + pub struct FmoveFdFlags: usize { + /// If set, the kernel will enforce that the file descriptors are exclusively owned. + /// + /// That is, there will no longer exist any other reference to those FDs when removed from + /// the file table (SYS_CALL always removes the FDs from the file table, but without this + /// flag, it can be retained by SYS_DUPing them first). + const EXCLUSIVE = 1; + + /// If set, the file descriptors will be cloned and *not* removed from the sender's file table. + /// By default, sendfd moves the file descriptors, removing them from the sender. + const CLONE = 2; + } +} bitflags! { pub struct MapFlags: usize { @@ -221,6 +256,22 @@ impl ProcSchemeVerb { } } +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[repr(usize)] +pub enum SchemeSocketCall { + ObtainFd = 0, + MoveFd = 1, +} +impl SchemeSocketCall { + pub fn try_from_raw(raw: usize) -> Option { + Some(match raw { + 0 => Self::ObtainFd, + 1 => Self::MoveFd, + _ => return None, + }) + } +} + #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[repr(usize)] #[non_exhaustive] @@ -338,5 +389,15 @@ bitflags! { /// Remove the fd from the caller's file table before sending the message. const CONSUME = 1 << 8; + + const WRITE = 1 << 9; + const READ = 1 << 10; + + /// Indicates the request is a bulk fd passing request. + const FD = 1 << 11; + /// Flags for the fd passing request. + const FD_EXCLUSIVE = 1 << 12; + const FD_CLONE = 1 << 13; + const FD_UPPER = 1 << 14; } } diff --git a/src/schemev2.rs b/src/schemev2.rs index bc662694e8..1849fa88e1 100644 --- a/src/schemev2.rs +++ b/src/schemev2.rs @@ -41,7 +41,7 @@ bitflags! { #[repr(C)] #[derive(Clone, Copy, Debug, Default)] pub struct Cqe { - pub flags: u8, // bits 3:0 are CqeOpcode + pub flags: u8, // bits 2:0 are CqeOpcode pub extra_raw: [u8; 3], pub tag: u32, pub result: u64, @@ -79,6 +79,7 @@ pub enum CqeOpcode { RespondWithFd, SendFevent, // no tag ObtainFd, + RespondWithMultipleFds, // TODO: ProvideMmap } impl CqeOpcode { @@ -88,6 +89,7 @@ impl CqeOpcode { 1 => Self::RespondWithFd, 2 => Self::SendFevent, 3 => Self::ObtainFd, + 4 => Self::RespondWithMultipleFds, _ => return None, }) } @@ -132,6 +134,8 @@ pub enum Opcode { OpenAt = 29, // fd, buf_ptr, buf_len, flags Flink = 30, + + Recvfd = 31, } impl Opcode { @@ -175,6 +179,8 @@ impl Opcode { 29 => OpenAt, 30 => Flink, + 31 => Recvfd, + _ => return None, }) }