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

refactor: change name arg of memfd_create() to &NixPath #2431

Merged
merged 6 commits into from
Jun 8, 2024

Conversation

SteveLauC
Copy link
Member

@SteveLauC SteveLauC commented Jun 8, 2024

What does this PR do

  1. Change the type of the name argument of memfd_create() from &CStr to &NixPath.
  2. Add a test for memfd_create(). (Update: The test was removed because the symbol memfd_create is not available under our QEMU test and I cannot find a way to stop the linker from involving it)

Checklist:

  • I have read CONTRIBUTING.md
  • I have written necessary tests and rustdoc comments
  • A change log has been added if this PR modifies nix's API

Breaking changes

This is not a breaking change, since CStr has NixPath implemented.

@SteveLauC SteveLauC added this pull request to the merge queue Jun 8, 2024
@SteveLauC SteveLauC removed this pull request from the merge queue due to a manual request Jun 8, 2024
@SteveLauC SteveLauC added this pull request to the merge queue Jun 8, 2024
Merged via the queue into nix-rust:master with commit 13248d4 Jun 8, 2024
36 checks passed
@SteveLauC SteveLauC deleted the refactor/memfd_create_NixPath branch June 8, 2024 09:27
Comment on lines +103 to +105
libc::memfd_create(cstr.as_ptr(), flags.bits())
} else {
libc::syscall(libc::SYS_memfd_create, name.as_ptr(), flags.bits())
libc::syscall(libc::SYS_memfd_create, cstr.as_ptr(), flags.bits())
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible we always use the else branch? Or does it have any drawback?

From tokio-rs/tracing#1879 I'm afraid that using libc::memfd_create may fail on some old GNU toolchain.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, because the glibc wrapper may only be available since a specific version, and if you are using an older glibc and this Nix wrapper, the code won't compile. But raw syscalls are inherently unsafe, Nix tries to avoid it if possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly, this kind of thing has always been bothering me. I just created a tracking issue #2538 for these interfaces. May I ask about the issue you encountered with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

the issue you encountered with this?

Not in real-world, but a blocker I don't use nix at fast/logforth#80 (memfd.rs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps we should wrap the raw syscall. 😪

If we want to discuss this further, let's discuss it there #2538.

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.

2 participants