Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate old shared memory fd creation #374

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave the feature with a comment saying it's deprecated. This will allow us to put off having to make a semver-major version change.

Copy link
Contributor Author

@Mikopet Mikopet Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort of makes sense, but because its major is <1, semver allows to do anything.
It could be minor or patch version dump too.

However, (I just realize) memfd feature is used in the GHA workflow atm, and that also needs some care.
I'd vote for removing memfd feature completely therefore decreasing unnecessary complexity.

what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to bump anyway, given that this internal change removes support for some old systems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That position is reasonable. I'll merge this as-is.

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