-
Notifications
You must be signed in to change notification settings - Fork 131
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
Use more constants and functions from libc #368
Conversation
Oh whoops, forgot to use libc's memfd :) |
@@ -1096,7 +1099,7 @@ fn create_shmem(name: CString, length: usize) -> c_int { | |||
#[cfg(all(feature = "memfd", target_os = "linux"))] | |||
fn create_shmem(name: CString, length: usize) -> c_int { | |||
unsafe { | |||
let fd = memfd_create(name.as_ptr(), libc::MFD_CLOEXEC as usize); | |||
let fd = libc::memfd_create(name.as_ptr(), libc::MFD_CLOEXEC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh hmm, glibc support was only added in 2.27. Not sure what the glibc policy of ipc-channel is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I think the old call was incorrect, since it passed in a usize but the syscall is a cint: https://github.com/torvalds/linux/blob/4d939780b70592e0f4bc6c397e52e518f8fb7916/mm/memfd.c#L332
This worked presumably because of little-endianness, but it wasn't correct as far as I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like glibc 2.27 came out in 2018: https://sourceware.org/glibc/wiki/Release/2.27.
// determined by CMSG_SPACE. (On Linux this would the same as CMSG_ALIGN, but that isn't | ||
// exposed by libc. CMSG_SPACE(0) is the portable version of that.) | ||
(cmsg.cmsg_len() - CMSG_SPACE(0) as size_t) / mem::size_of::<c_int>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If CMSG_ALIGN
is not in libc we should add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CMSG_ALIGN isn't portable, though, which is the challenge. CMSG_SPACE(0)
should always be the same.
I've been trying to port ipc-channel to illumos for use in a downstream project, and I found that this code was using a local copy of several functions and constants that are in libc. In particular: * Some of the `CMSG_` functions were incorrect on illumos. * `SCM_RIGHTS` was also not correct. The correct versions of these functions are in libc, so use them. (I had to bump libc to 0.2.161 to pull in the definition of `POLLRDHUP` on FreeBSD.) This is an intermediate commit that should hopefully be uncontroversial. The full test suite still doesn't pass on illumos yet, but I'm still working on it (in my spare time).
Hey -- how can I help get this landed? I can revert the glibc change if 2.27 is too new, though note that it covers Ubuntu 18.04, CentOS 8 and Debian buster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable.
I've been trying to port ipc-channel to illumos for use in a downstream project, and I found that this code was using a local copy of several functions and constants that are in libc. In particular:
CMSG_
functions were incorrect on illumos.SCM_RIGHTS
was also not correct.The correct versions of these functions are in libc, so use them. (I had to bump libc to 0.2.161 to pull in the definition of
POLLRDHUP
on FreeBSD.)This is an intermediate commit that should hopefully be uncontroversial. The full test suite still doesn't pass on illumos yet, but I'm still working on it (in my spare time).