1 | //! POSIX shared memory |
2 | |
3 | use crate::fd::OwnedFd; |
4 | use crate::{backend, io, path}; |
5 | |
6 | pub use crate::backend::fs::types::Mode; |
7 | pub use crate::backend::shm::types::ShmOFlags; |
8 | |
9 | /// `shm_open(name, oflags, mode)`—Opens a shared memory object. |
10 | /// |
11 | /// For portability, `name` should begin with a slash, contain no other |
12 | /// slashes, and be no longer than an implementation-defined limit (255 on |
13 | /// Linux). |
14 | /// |
15 | /// Exactly one of [`ShmOFlags::RDONLY`] and [`ShmOFlags::RDWR`] should be |
16 | /// passed. The file descriptor will be opened with `FD_CLOEXEC` set. |
17 | /// |
18 | /// # References |
19 | /// - [POSIX] |
20 | /// - [Linux] |
21 | /// |
22 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html |
23 | /// [Linux]: https://man7.org/linux/man-pages/man3/shm_open.3.html |
24 | #[inline ] |
25 | pub fn shm_open<P: path::Arg>(name: P, flags: ShmOFlags, mode: Mode) -> io::Result<OwnedFd> { |
26 | name.into_with_c_str(|name: &CStr| backend::shm::syscalls::shm_open(name, oflags:flags, mode)) |
27 | } |
28 | |
29 | /// `shm_unlink(name)`—Unlinks a shared memory object. |
30 | /// |
31 | /// # References |
32 | /// - [POSIX] |
33 | /// - [Linux] |
34 | /// |
35 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_unlink.html |
36 | /// [Linux]: https://man7.org/linux/man-pages/man3/shm_unlink.3.html |
37 | #[inline ] |
38 | pub fn shm_unlink<P: path::Arg>(name: P) -> io::Result<()> { |
39 | name.into_with_c_str(backend::shm::syscalls::shm_unlink) |
40 | } |
41 | |