Skip to content

Commit 6b8619f

Browse files
authored
Deprecate old shared memory fd creation (#374)
* deprecate shm_open * fixing dangling references to removed memfd feature
1 parent 7476ff0 commit 6b8619f

File tree

4 files changed

+2
-39
lines changed

4 files changed

+2
-39
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ jobs:
2323
- { target: x86_64-pc-windows-msvc, os: windows-latest }
2424
- { target: i686-pc-windows-msvc, os: windows-latest }
2525
features: ["", "force-inprocess", "async"]
26-
include:
27-
- features: ""
28-
platform: { target: x86_64-pc-windows-msvc, os: windows-latest }
29-
- features: ""
30-
platform: { target: i686-pc-windows-msvc, os: windows-latest }
31-
- features: "memfd"
32-
platform: { target: x86_64-unknown-linux-gnu, os: ubuntu-latest }
3326
steps:
3427
- uses: actions/checkout@v4
3528

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ harness = false
2626
[features]
2727
default = []
2828
force-inprocess = []
29-
memfd = []
3029
async = ["futures", "futures-test"]
3130
win32-trace = []
3231

src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,21 @@
1919
//! The `inprocess` backend is a dummy back-end, that behaves like the real ones,
2020
//! but doesn't actually work between processes.
2121
//!
22-
//! ## `memfd`
23-
//!
24-
//! Use [memfd_create] to back [OsIpcSharedMemory] on Linux. [memfd_create] was
25-
//! introduced in kernel version 3.17. __WARNING:__ Enabling this feature with kernel
26-
//! version less than 3.17 will cause panics on any use of [IpcSharedMemory].
27-
//!
2822
//! ## `unstable`
2923
//!
3024
//! [IpcReceiver]: ipc/struct.IpcReceiver.html
3125
//! [IpcSender]: ipc/struct.IpcSender.html
3226
//! [IpcReceiverSet]: ipc/struct.IpcReceiverSet.html
3327
//! [IpcSharedMemory]: ipc/struct.IpcSharedMemory.html
3428
//! [OsIpcSharedMemory]: platform/struct.OsIpcSharedMemory.html
35-
//! [memfd_create]: http://man7.org/linux/man-pages/man2/memfd_create.2.html
3629
3730
#[cfg(any(
3831
feature = "force-inprocess",
3932
target_os = "windows",
4033
target_os = "android",
4134
target_os = "ios"
4235
))]
43-
#[cfg(all(
44-
feature = "memfd",
45-
not(feature = "force-inprocess"),
46-
target_os = "linux"
47-
))]
36+
#[cfg(all(not(feature = "force-inprocess"), target_os = "linux"))]
4837
#[cfg(feature = "async")]
4938
use futures;
5039

src/platform/unix/mod.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,29 +1120,11 @@ fn new_msghdr(iovec: &mut [iovec], cmsg_buffer: *mut cmsghdr, cmsg_space: MsgCon
11201120
msghdr
11211121
}
11221122

1123-
#[cfg(not(all(target_os = "linux", feature = "memfd")))]
1124-
fn create_shmem(name: CString, length: usize) -> c_int {
1125-
unsafe {
1126-
// NB: the FreeBSD man page for shm_unlink states that it requires
1127-
// write permissions, but testing shows that read-write is required.
1128-
let fd = libc::shm_open(
1129-
name.as_ptr(),
1130-
libc::O_CREAT | libc::O_RDWR | libc::O_EXCL,
1131-
0o600,
1132-
);
1133-
assert!(fd >= 0);
1134-
assert!(libc::shm_unlink(name.as_ptr()) == 0);
1135-
assert!(libc::ftruncate(fd, length as off_t) == 0);
1136-
fd
1137-
}
1138-
}
1139-
1140-
#[cfg(all(feature = "memfd", target_os = "linux"))]
11411123
fn create_shmem(name: CString, length: usize) -> c_int {
11421124
unsafe {
11431125
let fd = libc::memfd_create(name.as_ptr(), libc::MFD_CLOEXEC);
11441126
assert!(fd >= 0);
1145-
assert!(libc::ftruncate(fd, length as off_t) == 0);
1127+
assert_eq!(libc::ftruncate(fd, length as off_t), 0);
11461128
fd
11471129
}
11481130
}

0 commit comments

Comments
 (0)