Skip to content

Expose mknodat/mkfifoat on Apple targets#1625

Open
mattsu2020 wants to merge 4 commits into
bytecodealliance:mainfrom
mattsu2020:mknodat_macos
Open

Expose mknodat/mkfifoat on Apple targets#1625
mattsu2020 wants to merge 4 commits into
bytecodealliance:mainfrom
mattsu2020:mknodat_macos

Conversation

@mattsu2020
Copy link
Copy Markdown

@mattsu2020 mattsu2020 commented May 16, 2026

Summary

  • Expose rustix::fs::{mknodat, mkfifoat} on Apple targets, which were previously gated out with cfg(not(apple))
  • macOS 13 added mknodat/mkfifoat system calls;
  • mkfifoat works automatically as it delegates to mknodat

macOS 13 added mknodat/mkfifoat system calls. Use the same weak-linking
pattern as linkat/unlinkat/renameat: resolve the symbol at runtime via
dlsym, and fall back to mknod/mkfifo when the symbol is unavailable
and dirfd == AT_FDCWD.
macOS 13 and earlier are EOL. Use c::mknodat directly via libc
without weak-linking, matching other platforms.
The use declarations for Dev and FileType were gated with
cfg(not(apple)), causing compilation failures when mknodat became
available on Apple. Remove apple from the exclusion list.
@xtqqczze
Copy link
Copy Markdown
Contributor

xtqqczze commented May 17, 2026

I think a fallback is needed for macOS ≤ 13 since Apple macOS targets are supported as far back as macOS 10.12, and there are also additional Apple platforms to consider such as tvOS and watchOS.

It would also be good to add references for the newly exposed functions on Apple targets. For example, https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2

@oech3
Copy link
Copy Markdown

oech3 commented May 17, 2026

Or add non-*at too for macOS?

@xtqqczze
Copy link
Copy Markdown
Contributor

Right, the POSIX mknod and mkfifo are currently absent from all platforms.

@mattsu2020
Copy link
Copy Markdown
Author

I'll revise this PR to restore weak-linking/runtime detection. When the symbol is unavailable, I'll only fall back to mknod/mkfifo for the AT_FDCWD case, and otherwise return an unsupported/error result. I'll also add Apple man page references for these functions.

@xtqqczze
Copy link
Copy Markdown
Contributor

On second thoughts, we probably don't need to implement a fallback for the libc backend. We can just return the appropriate Err and let callers handle it.

Comment on lines +1225 to +1229
// If we have `mknodat`, use it.
if let Some(libc_mknodat) = mknodat.get() {
return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev));
}
Err(io::Errno::NOSYS)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If we have `mknodat`, use it.
if let Some(libc_mknodat) = mknodat.get() {
return ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev));
}
Err(io::Errno::NOSYS)
let libc_mknodat = mknodat.get().ok_or(io::Errno::NOSYS)?;
ret(libc_mknodat(borrowed_fd(dirfd), c_str(path), mode, dev))

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