diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/redox_syscall/src/scheme/mod.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/redox_syscall/src/scheme/mod.rs')
-rw-r--r-- | vendor/redox_syscall/src/scheme/mod.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/redox_syscall/src/scheme/mod.rs b/vendor/redox_syscall/src/scheme/mod.rs new file mode 100644 index 0000000..61655da --- /dev/null +++ b/vendor/redox_syscall/src/scheme/mod.rs @@ -0,0 +1,68 @@ +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; +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; + +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, + } + } +} |