Skip to content

Extended NetBSD API#4985

Open
antoncxx wants to merge 1 commit intorust-lang:mainfrom
antoncxx:netbsd-ext
Open

Extended NetBSD API#4985
antoncxx wants to merge 1 commit intorust-lang:mainfrom
antoncxx:netbsd-ext

Conversation

@antoncxx
Copy link
Contributor

@antoncxx antoncxx commented Feb 19, 2026

Description

This PR extends NetBSD support with updates to kernel information structures and file descriptor types.

1. Added kinfo_pcb

  • Constants:
    • PCB_SLOP
    • PCB_ALL

2. kinfo_file structure

  • Contants
    • KERN_FILE_BYFILE
    • KERN_FILE_BYPID
    • KERN_FILESLOP

3. File descriptor types

  • DTYPE_VNODE
  • DTYPE_SOCKET
  • DTYPE_PIPE
  • DTYPE_MISC
  • DTYPE_CRYPTO
  • DTYPE_MQUEUE
  • DTYPE_SEM
  • DTYPE_EVENTFD
  • DTYPE_TIMERFD

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated


Of all the file descriptor types, I’ve been having trouble with DTYPE_MEMFD. Even though it exists in the NetBSD source code, the corresponding header on an actual installation seems to be missing this definition. I’m not sure how to handle this properly—whether to ignore it during tests or not include it at all.

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2026

Some changes occurred in a NetBSD-like module

cc @semarie

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Feb 19, 2026
- added `kinfo_pcb` struct and related constants
- added `kinfo_file` struct and related constants
@semarie
Copy link
Contributor

semarie commented Feb 19, 2026

Some changes occurred in a NetBSD-like module

cc @semarie

just to note that the PR is properly rebased to NetBSD only 👍

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

The structs themselves look pretty fine, but a lot of the support bits can be dropped.

Also, please give PRs a more descriptive title. We get a lot of additions to NetBSD API and it is helpful to be able to narrow them down :)

View changes since this review

Comment on lines +877 to +904
impl Eq for __c_anonymous_pcb_sockaddr_src {}
impl PartialEq for __c_anonymous_pcb_sockaddr_src {
fn eq(&self, other: &__c_anonymous_pcb_sockaddr_src) -> bool {
unsafe { self._kis_src == other._kis_src || self._kis_pad == other._kis_pad }
}
}
impl hash::Hash for __c_anonymous_pcb_sockaddr_src {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
self._kis_src.hash(state);
self._kis_pad.hash(state);
}
}
}
impl Eq for __c_anonymous_pcb_sockaddr_dst {}
impl PartialEq for __c_anonymous_pcb_sockaddr_dst {
fn eq(&self, other: &__c_anonymous_pcb_sockaddr_dst) -> bool {
unsafe { self._kid_dst == other._kid_dst || self._kid_pad == other._kid_pad }
}
}
impl hash::Hash for __c_anonymous_pcb_sockaddr_dst {
fn hash<H: hash::Hasher>(&self, state: &mut H) {
unsafe {
self._kid_dst.hash(state);
self._kid_pad.hash(state);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

No more unsound trait impls please. Any new structs containing unions need to be in s_no_extra_traits

Comment on lines +1788 to +1798
// sys/file.h
pub const DTYPE_VNODE: c_int = 1;
pub const DTYPE_SOCKET: c_int = 2;
pub const DTYPE_PIPE: c_int = 3;
pub const DTYPE_KQUEUE: c_int = 4;
pub const DTYPE_MISC: c_int = 5;
pub const DTYPE_CRYPTO: c_int = 6;
pub const DTYPE_MQUEUE: c_int = 7;
pub const DTYPE_SEM: c_int = 8;
pub const DTYPE_EVENTFD: c_int = 9;
pub const DTYPE_TIMERFD: c_int = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

For anything that is a new header, could you instead add it as a new module in https://github.com/rust-lang/libc/blob/0a15ee8898875514c3f1e372d9e2c604ab721d27/src/new/netbsd/sys/mod.rs? We're trying to (slowly) migrate to a new structure

pub ki_pid: u32,
pub ki_fd: i32,
pub ki_ofileflags: u32,
pub _ki_padto64bits: u32,
Copy link
Contributor

Choose a reason for hiding this comment

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

Padding fields should be private and wrapped in Padding<...>

Comment on lines +134 to +150
impl kinfo_pcb {
pub unsafe fn ki_src(&self) -> crate::sockaddr {
self.ki_s._kis_src
}

pub unsafe fn ki_dst(&self) -> crate::sockaddr {
self.ki_d._kid_dst
}

pub unsafe fn ki_spad(&self) -> &[c_char; 256 + 8] {
&self.ki_s._kis_pad
}

pub unsafe fn ki_dpad(&self) -> &[c_char; 256 + 8] {
&self.ki_d._kid_pad
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these can be dropped. It's a bit unfortunate that we can't exactly match the source, but the fields aren't especially useful without *mut T setters (for use via MaybeUninit) which is more API than we provide elsewhere.

@rustbot
Copy link
Collaborator

rustbot commented Mar 2, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants