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

Use more constants and functions from libc #368

Merged
merged 1 commit into from
Oct 27, 2024
Merged

Conversation

sunshowers
Copy link
Contributor

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).

@sunshowers
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Contributor Author

@sunshowers sunshowers Oct 18, 2024

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.

Copy link
Contributor Author

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.

Comment on lines +995 to +1023
// 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>()
Copy link
Member

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.

Copy link
Contributor Author

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).
@sunshowers
Copy link
Contributor Author

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.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

This seems reasonable.

@jdm jdm added this pull request to the merge queue Oct 27, 2024
Merged via the queue into servo:main with commit 97df9fd Oct 27, 2024
17 checks passed
@sunshowers sunshowers deleted the use-libc branch October 27, 2024 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants