Skip to content

Commit

Permalink
Deprecate old shared memory fd creation (#374)
Browse files Browse the repository at this point in the history
* deprecate shm_open

* fixing dangling references to removed memfd feature
  • Loading branch information
Mikopet authored Dec 3, 2024
1 parent 7476ff0 commit 6b8619f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 39 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ jobs:
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: i686-pc-windows-msvc, os: windows-latest }
features: ["", "force-inprocess", "async"]
include:
- features: ""
platform: { target: x86_64-pc-windows-msvc, os: windows-latest }
- features: ""
platform: { target: i686-pc-windows-msvc, os: windows-latest }
- features: "memfd"
platform: { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
steps:
- uses: actions/checkout@v4

Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ harness = false
[features]
default = []
force-inprocess = []
memfd = []
async = ["futures", "futures-test"]
win32-trace = []

Expand Down
13 changes: 1 addition & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,21 @@
//! The `inprocess` backend is a dummy back-end, that behaves like the real ones,
//! but doesn't actually work between processes.
//!
//! ## `memfd`
//!
//! Use [memfd_create] to back [OsIpcSharedMemory] on Linux. [memfd_create] was
//! introduced in kernel version 3.17. __WARNING:__ Enabling this feature with kernel
//! version less than 3.17 will cause panics on any use of [IpcSharedMemory].
//!
//! ## `unstable`
//!
//! [IpcReceiver]: ipc/struct.IpcReceiver.html
//! [IpcSender]: ipc/struct.IpcSender.html
//! [IpcReceiverSet]: ipc/struct.IpcReceiverSet.html
//! [IpcSharedMemory]: ipc/struct.IpcSharedMemory.html
//! [OsIpcSharedMemory]: platform/struct.OsIpcSharedMemory.html
//! [memfd_create]: http://man7.org/linux/man-pages/man2/memfd_create.2.html
#[cfg(any(
feature = "force-inprocess",
target_os = "windows",
target_os = "android",
target_os = "ios"
))]
#[cfg(all(
feature = "memfd",
not(feature = "force-inprocess"),
target_os = "linux"
))]
#[cfg(all(not(feature = "force-inprocess"), target_os = "linux"))]
#[cfg(feature = "async")]
use futures;

Expand Down
20 changes: 1 addition & 19 deletions src/platform/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,29 +1120,11 @@ fn new_msghdr(iovec: &mut [iovec], cmsg_buffer: *mut cmsghdr, cmsg_space: MsgCon
msghdr
}

#[cfg(not(all(target_os = "linux", feature = "memfd")))]
fn create_shmem(name: CString, length: usize) -> c_int {
unsafe {
// NB: the FreeBSD man page for shm_unlink states that it requires
// write permissions, but testing shows that read-write is required.
let fd = libc::shm_open(
name.as_ptr(),
libc::O_CREAT | libc::O_RDWR | libc::O_EXCL,
0o600,
);
assert!(fd >= 0);
assert!(libc::shm_unlink(name.as_ptr()) == 0);
assert!(libc::ftruncate(fd, length as off_t) == 0);
fd
}
}

#[cfg(all(feature = "memfd", target_os = "linux"))]
fn create_shmem(name: CString, length: usize) -> c_int {
unsafe {
let fd = libc::memfd_create(name.as_ptr(), libc::MFD_CLOEXEC);
assert!(fd >= 0);
assert!(libc::ftruncate(fd, length as off_t) == 0);
assert_eq!(libc::ftruncate(fd, length as off_t), 0);
fd
}
}
Expand Down

0 comments on commit 6b8619f

Please sign in to comment.