summaryrefslogtreecommitdiff
path: root/vendor/rustix/src/backend/libc/shm
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/rustix/src/backend/libc/shm
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/rustix/src/backend/libc/shm')
-rw-r--r--vendor/rustix/src/backend/libc/shm/mod.rs2
-rw-r--r--vendor/rustix/src/backend/libc/shm/syscalls.rs25
-rw-r--r--vendor/rustix/src/backend/libc/shm/types.rs30
3 files changed, 57 insertions, 0 deletions
diff --git a/vendor/rustix/src/backend/libc/shm/mod.rs b/vendor/rustix/src/backend/libc/shm/mod.rs
new file mode 100644
index 0000000..1e0181a
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/shm/mod.rs
@@ -0,0 +1,2 @@
+pub(crate) mod syscalls;
+pub(crate) mod types;
diff --git a/vendor/rustix/src/backend/libc/shm/syscalls.rs b/vendor/rustix/src/backend/libc/shm/syscalls.rs
new file mode 100644
index 0000000..b0d907f
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/shm/syscalls.rs
@@ -0,0 +1,25 @@
+use crate::ffi::CStr;
+
+use crate::backend::c;
+use crate::backend::conv::{c_str, ret, ret_owned_fd};
+use crate::fd::OwnedFd;
+use crate::fs::Mode;
+use crate::io;
+use crate::shm::ShmOFlags;
+
+pub(crate) fn shm_open(name: &CStr, oflags: ShmOFlags, mode: Mode) -> io::Result<OwnedFd> {
+ // On this platforms, `mode_t` is `u16` and can't be passed directly to a
+ // variadic function.
+ #[cfg(apple)]
+ let mode: c::c_uint = mode.bits().into();
+
+ // Otherwise, cast to `mode_t` as that's what `open` is documented to take.
+ #[cfg(not(apple))]
+ let mode: c::mode_t = mode.bits() as _;
+
+ unsafe { ret_owned_fd(c::shm_open(c_str(name), bitflags_bits!(oflags), mode)) }
+}
+
+pub(crate) fn shm_unlink(name: &CStr) -> io::Result<()> {
+ unsafe { ret(c::shm_unlink(c_str(name))) }
+}
diff --git a/vendor/rustix/src/backend/libc/shm/types.rs b/vendor/rustix/src/backend/libc/shm/types.rs
new file mode 100644
index 0000000..6575ef5
--- /dev/null
+++ b/vendor/rustix/src/backend/libc/shm/types.rs
@@ -0,0 +1,30 @@
+use crate::backend::c;
+use bitflags::bitflags;
+
+bitflags! {
+ /// `O_*` constants for use with [`shm_open`].
+ ///
+ /// [`shm_open`]: crate:shm::shm_open
+ #[repr(transparent)]
+ #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
+ pub struct ShmOFlags: u32 {
+ /// `O_CREAT`
+ #[doc(alias = "CREAT")]
+ const CREATE = bitcast!(c::O_CREAT);
+
+ /// `O_EXCL`
+ const EXCL = bitcast!(c::O_EXCL);
+
+ /// `O_RDONLY`
+ const RDONLY = bitcast!(c::O_RDONLY);
+
+ /// `O_RDWR`
+ const RDWR = bitcast!(c::O_RDWR);
+
+ /// `O_TRUNC`
+ const TRUNC = bitcast!(c::O_TRUNC);
+
+ /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>
+ const _ = !0;
+ }
+}