From 7384817c389439fcd9d5db6a126addc115072595 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 21:54:12 +0800 Subject: [PATCH 1/9] dragonfly: correct existing ABI definitions Fix DragonFly type aliases and struct layouts to match current headers, including regex offsets, ifaddrs, pthread barriers, process sizing fields, and mcontext alignment. --- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 15 +++++++++------ src/unix/bsd/mod.rs | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 2545f1e0059b..5a1452c505f3 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -31,11 +31,11 @@ pub type cpu_set_t = cpumask_t; pub type register_t = c_long; pub type umtx_t = c_int; -pub type pthread_barrierattr_t = c_int; -pub type pthread_barrier_t = crate::uintptr_t; +pub type pthread_barrierattr_t = *mut __c_anonymous_pthread_barrierattr; +pub type pthread_barrier_t = *mut __c_anonymous_pthread_barrier; pub type pthread_spinlock_t = crate::uintptr_t; -pub type segsz_t = usize; +pub type segsz_t = isize; pub type vm_prot_t = u8; pub type vm_maptype_t = u8; @@ -50,6 +50,8 @@ pub type pmap = __c_anonymous_pmap; extern_ty! { pub type sem; + pub type __c_anonymous_pthread_barrier; + pub type __c_anonymous_pthread_barrierattr; } c_enum! { @@ -191,9 +193,9 @@ s! { pub ifm_msglen: c_ushort, pub ifm_version: c_uchar, pub ifm_type: c_uchar, - pub ifm_addrs: c_int, - pub ifm_flags: c_int, pub ifm_index: c_ushort, + pub ifm_flags: c_int, + pub ifm_addrs: c_int, pub ifm_data: if_data, } @@ -259,7 +261,7 @@ s! { pub cp_nice: u64, pub cp_sys: u64, pub cp_intr: u64, - pub cp_idel: u64, + pub cp_idle: u64, cp_unused01: Padding, cp_unused02: Padding, pub cp_sample_pc: u64, @@ -481,6 +483,7 @@ s! { __unused3: Padding<*mut c_void>, //actually a function pointer } + #[repr(align(64))] pub struct mcontext_t { pub mc_onstack: register_t, pub mc_rdi: register_t, diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 586a1e05aea1..7d68d18cc492 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -7,6 +7,9 @@ pub type socklen_t = u32; pub type sa_family_t = u8; pub type pthread_t = crate::uintptr_t; pub type nfds_t = c_uint; +#[cfg(target_os = "dragonfly")] +pub type regoff_t = c_int; +#[cfg(not(target_os = "dragonfly"))] pub type regoff_t = off_t; s! { @@ -57,7 +60,7 @@ s! { pub ifa_netmask: *mut crate::sockaddr, pub ifa_dstaddr: *mut crate::sockaddr, pub ifa_data: *mut c_void, - #[cfg(target_os = "netbsd")] + #[cfg(any(target_os = "dragonfly", target_os = "netbsd"))] pub ifa_addrflags: c_uint, } From 5af88b9ad959da329220bfe7d6ab8b2a8f70e645 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 21:58:18 +0800 Subject: [PATCH 2/9] bsd: move target-specific regex and getrandom constants --- src/unix/bsd/apple/mod.rs | 35 +++++++++++++++++++ src/unix/bsd/freebsdlike/dragonfly/mod.rs | 40 ++++++++++++++++++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 41 +++++++++++++++++++++++ src/unix/bsd/freebsdlike/mod.rs | 6 ---- src/unix/bsd/mod.rs | 35 ------------------- src/unix/bsd/netbsdlike/mod.rs | 35 +++++++++++++++++++ 6 files changed, 151 insertions(+), 41 deletions(-) diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index d5953478a27f..d757935ae85b 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -1850,6 +1850,41 @@ pub const ABMON_10: crate::nl_item = 42; pub const ABMON_11: crate::nl_item = 43; pub const ABMON_12: crate::nl_item = 44; +pub const REG_BASIC: c_int = 0o0000; +pub const REG_EXTENDED: c_int = 0o0001; +pub const REG_ICASE: c_int = 0o0002; +pub const REG_NOSUB: c_int = 0o0004; +pub const REG_NEWLINE: c_int = 0o0010; +pub const REG_NOSPEC: c_int = 0o0020; +pub const REG_PEND: c_int = 0o0040; +pub const REG_DUMP: c_int = 0o0200; + +pub const REG_NOMATCH: c_int = 1; +pub const REG_BADPAT: c_int = 2; +pub const REG_ECOLLATE: c_int = 3; +pub const REG_ECTYPE: c_int = 4; +pub const REG_EESCAPE: c_int = 5; +pub const REG_ESUBREG: c_int = 6; +pub const REG_EBRACK: c_int = 7; +pub const REG_EPAREN: c_int = 8; +pub const REG_EBRACE: c_int = 9; +pub const REG_BADBR: c_int = 10; +pub const REG_ERANGE: c_int = 11; +pub const REG_ESPACE: c_int = 12; +pub const REG_BADRPT: c_int = 13; +pub const REG_EMPTY: c_int = 14; +pub const REG_ASSERT: c_int = 15; +pub const REG_INVARG: c_int = 16; +pub const REG_ATOI: c_int = 255; +pub const REG_ITOA: c_int = 0o0400; + +pub const REG_NOTBOL: c_int = 0o00001; +pub const REG_NOTEOL: c_int = 0o00002; +pub const REG_STARTEND: c_int = 0o00004; +pub const REG_TRACE: c_int = 0o00400; +pub const REG_LARGE: c_int = 0o01000; +pub const REG_BACKR: c_int = 0o02000; + pub const CLOCK_REALTIME: crate::clockid_t = 0; pub const CLOCK_MONOTONIC_RAW: crate::clockid_t = 4; pub const CLOCK_MONOTONIC_RAW_APPROX: crate::clockid_t = 5; diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 5a1452c505f3..315c48d7db82 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -730,6 +730,42 @@ pub const CPUCTL_CPUID_COUNT: c_int = u32_cast_int(0xc0106307); pub const CPU_SETSIZE: size_t = size_of::() * 8; +pub const REG_BASIC: c_int = 0o0000; +pub const REG_EXTENDED: c_int = 0o0001; +pub const REG_ICASE: c_int = 0o0002; +pub const REG_NOSUB: c_int = 0x8; +pub const REG_NEWLINE: c_int = 0x4; +pub const REG_NOSPEC: c_int = 0o0020; +pub const REG_PEND: c_int = 0x80; +pub const REG_DUMP: c_int = 0o0200; + +pub const REG_NOMATCH: c_int = 1; +pub const REG_BADPAT: c_int = 2; +pub const REG_ECOLLATE: c_int = 3; +pub const REG_ECTYPE: c_int = 4; +pub const REG_EESCAPE: c_int = 5; +pub const REG_ESUBREG: c_int = 6; +pub const REG_EBRACK: c_int = 7; +pub const REG_EPAREN: c_int = 8; +pub const REG_EBRACE: c_int = 9; +pub const REG_BADBR: c_int = 10; +pub const REG_ERANGE: c_int = 11; +pub const REG_ESPACE: c_int = 12; +pub const REG_BADRPT: c_int = 13; +pub const REG_EMPTY: c_int = 14; +pub const REG_ASSERT: c_int = 15; +pub const REG_INVARG: c_int = 15; +pub const REG_ILLSEQ: c_int = 16; +pub const REG_ATOI: c_int = 255; +pub const REG_ITOA: c_int = 0o0400; + +pub const REG_NOTBOL: c_int = 0o00001; +pub const REG_NOTEOL: c_int = 0o00002; +pub const REG_STARTEND: c_int = 0o00004; +pub const REG_TRACE: c_int = 0o00400; +pub const REG_LARGE: c_int = 0o01000; +pub const REG_BACKR: c_int = 0x8; + pub const EVFILT_READ: i16 = -1; pub const EVFILT_WRITE: i16 = -2; pub const EVFILT_AIO: i16 = -3; @@ -1104,6 +1140,10 @@ pub const _UTX_USERSIZE: usize = 32; pub const _UTX_IDSIZE: usize = 4; pub const _UTX_HOSTSIZE: usize = 256; +pub const GRND_NONBLOCK: c_uint = 0x2; +pub const GRND_RANDOM: c_uint = 0x1; +pub const GRND_INSECURE: c_uint = 0x4; + pub const LC_COLLATE_MASK: c_int = 1 << 0; pub const LC_CTYPE_MASK: c_int = 1 << 1; pub const LC_MONETARY_MASK: c_int = 1 << 2; diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 705248176caf..88b8870bab6c 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -2079,6 +2079,47 @@ pub const POSIX_FADV_WILLNEED: c_int = 3; pub const POSIX_FADV_DONTNEED: c_int = 4; pub const POSIX_FADV_NOREUSE: c_int = 5; +pub const REG_BASIC: c_int = 0o0000; +pub const REG_EXTENDED: c_int = 0o0001; +pub const REG_ICASE: c_int = 0o0002; +pub const REG_NOSUB: c_int = 0o0004; +pub const REG_NEWLINE: c_int = 0o0010; +pub const REG_NOSPEC: c_int = 0o0020; +pub const REG_PEND: c_int = 0o0040; +pub const REG_DUMP: c_int = 0o0200; + +pub const REG_NOMATCH: c_int = 1; +pub const REG_BADPAT: c_int = 2; +pub const REG_ECOLLATE: c_int = 3; +pub const REG_ECTYPE: c_int = 4; +pub const REG_EESCAPE: c_int = 5; +pub const REG_ESUBREG: c_int = 6; +pub const REG_EBRACK: c_int = 7; +pub const REG_EPAREN: c_int = 8; +pub const REG_EBRACE: c_int = 9; +pub const REG_BADBR: c_int = 10; +pub const REG_ERANGE: c_int = 11; +pub const REG_ESPACE: c_int = 12; +pub const REG_BADRPT: c_int = 13; +pub const REG_EMPTY: c_int = 14; +pub const REG_ASSERT: c_int = 15; +pub const REG_INVARG: c_int = 16; +pub const REG_ILLSEQ: c_int = 17; +pub const REG_ATOI: c_int = 255; +pub const REG_ITOA: c_int = 0o0400; + +pub const REG_NOTBOL: c_int = 0o00001; +pub const REG_NOTEOL: c_int = 0o00002; +pub const REG_STARTEND: c_int = 0o00004; +pub const REG_TRACE: c_int = 0o00400; +pub const REG_LARGE: c_int = 0o01000; +pub const REG_BACKR: c_int = 0o02000; + +// For getrandom() +pub const GRND_NONBLOCK: c_uint = 0x1; +pub const GRND_RANDOM: c_uint = 0x2; +pub const GRND_INSECURE: c_uint = 0x4; + pub const POLLINIGNEOF: c_short = 0x2000; pub const POLLRDHUP: c_short = 0x4000; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 5bdc41be6e68..192db118d1aa 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -1398,7 +1398,6 @@ pub const TIME_WAIT: c_int = 4; pub const TIME_ERROR: c_int = 5; pub const REG_ENOSYS: c_int = -1; -pub const REG_ILLSEQ: c_int = 17; pub const IPC_PRIVATE: crate::key_t = 0; pub const IPC_CREAT: c_int = 0o1000; @@ -1441,11 +1440,6 @@ pub const RB_GDB: c_int = 0x8000; pub const RB_MUTE: c_int = 0x10000; pub const RB_SELFTEST: c_int = 0x20000; -// For getrandom() -pub const GRND_NONBLOCK: c_uint = 0x1; -pub const GRND_RANDOM: c_uint = 0x2; -pub const GRND_INSECURE: c_uint = 0x4; - pub const POSIX_SPAWN_RESETIDS: c_short = 0x01; pub const POSIX_SPAWN_SETPGROUP: c_short = 0x02; pub const POSIX_SPAWN_SETSCHEDPARAM: c_short = 0x04; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 7d68d18cc492..24774fec4855 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -409,41 +409,6 @@ cfg_if! { } } -pub const REG_BASIC: c_int = 0o0000; -pub const REG_EXTENDED: c_int = 0o0001; -pub const REG_ICASE: c_int = 0o0002; -pub const REG_NOSUB: c_int = 0o0004; -pub const REG_NEWLINE: c_int = 0o0010; -pub const REG_NOSPEC: c_int = 0o0020; -pub const REG_PEND: c_int = 0o0040; -pub const REG_DUMP: c_int = 0o0200; - -pub const REG_NOMATCH: c_int = 1; -pub const REG_BADPAT: c_int = 2; -pub const REG_ECOLLATE: c_int = 3; -pub const REG_ECTYPE: c_int = 4; -pub const REG_EESCAPE: c_int = 5; -pub const REG_ESUBREG: c_int = 6; -pub const REG_EBRACK: c_int = 7; -pub const REG_EPAREN: c_int = 8; -pub const REG_EBRACE: c_int = 9; -pub const REG_BADBR: c_int = 10; -pub const REG_ERANGE: c_int = 11; -pub const REG_ESPACE: c_int = 12; -pub const REG_BADRPT: c_int = 13; -pub const REG_EMPTY: c_int = 14; -pub const REG_ASSERT: c_int = 15; -pub const REG_INVARG: c_int = 16; -pub const REG_ATOI: c_int = 255; -pub const REG_ITOA: c_int = 0o0400; - -pub const REG_NOTBOL: c_int = 0o00001; -pub const REG_NOTEOL: c_int = 0o00002; -pub const REG_STARTEND: c_int = 0o00004; -pub const REG_TRACE: c_int = 0o00400; -pub const REG_LARGE: c_int = 0o01000; -pub const REG_BACKR: c_int = 0o02000; - pub const TIOCCBRK: c_uint = 0x2000747a; pub const TIOCSBRK: c_uint = 0x2000747b; diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index 27db17736ea3..522039f63b02 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -133,6 +133,41 @@ pub const CRNCYSTR: crate::nl_item = 50; pub const CODESET: crate::nl_item = 51; +pub const REG_BASIC: c_int = 0o0000; +pub const REG_EXTENDED: c_int = 0o0001; +pub const REG_ICASE: c_int = 0o0002; +pub const REG_NOSUB: c_int = 0o0004; +pub const REG_NEWLINE: c_int = 0o0010; +pub const REG_NOSPEC: c_int = 0o0020; +pub const REG_PEND: c_int = 0o0040; +pub const REG_DUMP: c_int = 0o0200; + +pub const REG_NOMATCH: c_int = 1; +pub const REG_BADPAT: c_int = 2; +pub const REG_ECOLLATE: c_int = 3; +pub const REG_ECTYPE: c_int = 4; +pub const REG_EESCAPE: c_int = 5; +pub const REG_ESUBREG: c_int = 6; +pub const REG_EBRACK: c_int = 7; +pub const REG_EPAREN: c_int = 8; +pub const REG_EBRACE: c_int = 9; +pub const REG_BADBR: c_int = 10; +pub const REG_ERANGE: c_int = 11; +pub const REG_ESPACE: c_int = 12; +pub const REG_BADRPT: c_int = 13; +pub const REG_EMPTY: c_int = 14; +pub const REG_ASSERT: c_int = 15; +pub const REG_INVARG: c_int = 16; +pub const REG_ATOI: c_int = 255; +pub const REG_ITOA: c_int = 0o0400; + +pub const REG_NOTBOL: c_int = 0o00001; +pub const REG_NOTEOL: c_int = 0o00002; +pub const REG_STARTEND: c_int = 0o00004; +pub const REG_TRACE: c_int = 0o00400; +pub const REG_LARGE: c_int = 0o01000; +pub const REG_BACKR: c_int = 0o02000; + pub const EXIT_FAILURE: c_int = 1; pub const EXIT_SUCCESS: c_int = 0; pub const RAND_MAX: c_int = 2147483647; From fc3c36cd37d0befb36bc960ca1cdbc8d26738a1a Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 22:00:30 +0800 Subject: [PATCH 3/9] dragonfly: add compatibility aliases for renamed constants --- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 315c48d7db82..65e80b5b557c 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -720,7 +720,9 @@ pub const CTL_P1003_1B_SIGQUEUE_MAX: c_int = 24; pub const CTL_P1003_1B_TIMER_MAX: c_int = 25; pub const CTL_P1003_1B_MAXID: c_int = 26; -pub const CPUCTL_RSMSR: c_int = u32_cast_int(0xc0106301); +pub const CPUCTL_RDMSR: c_int = u32_cast_int(0xc0106301); +#[deprecated(since = "0.2.187", note = "Replaced on DragonFly by CPUCTL_RDMSR")] +pub const CPUCTL_RSMSR: c_int = CPUCTL_RDMSR; pub const CPUCTL_WRMSR: c_int = u32_cast_int(0xc0106302); pub const CPUCTL_CPUID: c_int = u32_cast_int(0xc0106303); pub const CPUCTL_UPDATE: c_int = u32_cast_int(0xc0106304); @@ -1134,7 +1136,9 @@ pub const DOWNTIME: c_short = 11; // utmpx database types pub const UTX_DB_UTMPX: c_uint = 0; pub const UTX_DB_WTMPX: c_uint = 1; -pub const UTX_DB_LASTLOG: c_uint = 2; +pub const UTX_DB_LASTLOGX: c_uint = 2; +#[deprecated(since = "0.2.187", note = "Replaced on DragonFly by UTX_DB_LASTLOGX")] +pub const UTX_DB_LASTLOG: c_uint = UTX_DB_LASTLOGX; pub const _UTX_LINESIZE: usize = 32; pub const _UTX_USERSIZE: usize = 32; pub const _UTX_IDSIZE: usize = 4; From 436188987b0cd3b71f1c9d23f831cec90bb2ff24 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 22:01:06 +0800 Subject: [PATCH 4/9] dragonfly: correct existing constant values --- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 8 ++++---- src/unix/mod.rs | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 65e80b5b557c..0b2a0a1307f1 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -724,11 +724,11 @@ pub const CPUCTL_RDMSR: c_int = u32_cast_int(0xc0106301); #[deprecated(since = "0.2.187", note = "Replaced on DragonFly by CPUCTL_RDMSR")] pub const CPUCTL_RSMSR: c_int = CPUCTL_RDMSR; pub const CPUCTL_WRMSR: c_int = u32_cast_int(0xc0106302); -pub const CPUCTL_CPUID: c_int = u32_cast_int(0xc0106303); +pub const CPUCTL_CPUID: c_int = u32_cast_int(0xc0146303); pub const CPUCTL_UPDATE: c_int = u32_cast_int(0xc0106304); pub const CPUCTL_MSRSBIT: c_int = u32_cast_int(0xc0106305); pub const CPUCTL_MSRCBIT: c_int = u32_cast_int(0xc0106306); -pub const CPUCTL_CPUID_COUNT: c_int = u32_cast_int(0xc0106307); +pub const CPUCTL_CPUID_COUNT: c_int = u32_cast_int(0xc0186307); pub const CPU_SETSIZE: size_t = size_of::() * 8; @@ -791,8 +791,8 @@ pub const EV_NODATA: u16 = 0x1000; pub const EV_FLAG1: u16 = 0x2000; pub const EV_ERROR: u16 = 0x4000; pub const EV_EOF: u16 = 0x8000; -pub const EV_HUP: u16 = 0x8000; -pub const EV_SYSFLAGS: u16 = 0xf000; +pub const EV_HUP: u16 = 0x0800; +pub const EV_SYSFLAGS: u16 = 0xF800; pub const FIODNAME: c_ulong = 0x80106678; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 18156b29d188..8dcc5ca8ebf4 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -395,6 +395,7 @@ cfg_if! { if #[cfg(any( target_os = "macos", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", target_os = "openbsd", target_os = "cygwin", @@ -410,6 +411,7 @@ cfg_if! { if #[cfg(any( target_os = "macos", target_os = "freebsd", + target_os = "dragonfly", target_os = "android", target_os = "openbsd", target_os = "netbsd", From 989cdfdd4bd666ad2b632944769c8a44faa74a5a Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 22:02:11 +0800 Subject: [PATCH 5/9] dragonfly: add missing constants --- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 38 +++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 0b2a0a1307f1..3826997ef1d4 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -543,10 +543,24 @@ pub const MADV_INVAL: c_int = 10; pub const MADV_SETMAP: c_int = 11; pub const O_CLOEXEC: c_int = 0x00020000; pub const O_DIRECTORY: c_int = 0x08000000; +pub const O_FBLOCKING: c_int = 0x00040000; +pub const O_FNONBLOCKING: c_int = 0x00080000; +pub const O_FAPPEND: c_int = 0x00100000; +pub const O_FOFFSET: c_int = 0x00200000; +pub const O_FSYNCWRITE: c_int = 0x00400000; +pub const O_FASYNCWRITE: c_int = 0x00800000; +pub const O_FMASK: c_int = + O_FBLOCKING | O_FNONBLOCKING | O_FAPPEND | O_FOFFSET | O_FSYNCWRITE | O_FASYNCWRITE; pub const F_GETLK: c_int = 7; pub const F_SETLK: c_int = 8; pub const F_SETLKW: c_int = 9; pub const F_GETPATH: c_int = 19; +pub const POSIX_FADV_NORMAL: c_int = 0; +pub const POSIX_FADV_SEQUENTIAL: c_int = 1; +pub const POSIX_FADV_RANDOM: c_int = 2; +pub const POSIX_FADV_WILLNEED: c_int = 3; +pub const POSIX_FADV_DONTNEED: c_int = 4; +pub const POSIX_FADV_NOREUSE: c_int = 5; pub const ENOMEDIUM: c_int = 93; pub const ENOTRECOVERABLE: c_int = 94; pub const EOWNERDEAD: c_int = 95; @@ -611,7 +625,8 @@ pub const KERN_USRSTACK: c_int = 33; pub const KERN_LOGSIGEXIT: c_int = 34; pub const KERN_IOV_MAX: c_int = 35; pub const KERN_MAXPOSIXLOCKSPERUID: c_int = 36; -pub const KERN_MAXID: c_int = 37; +pub const KERN_STATIC_TLS_EXTRA: c_int = 37; +pub const KERN_MAXID: c_int = 38; pub const KERN_PROC_ALL: c_int = 0; pub const KERN_PROC_PID: c_int = 1; pub const KERN_PROC_PGRP: c_int = 2; @@ -845,6 +860,7 @@ pub const IFF_NOARP: c_int = 0x80; // no address resolution protocol pub const IFF_PROMISC: c_int = 0x100; // receive all packets pub const IFF_ALLMULTI: c_int = 0x200; // receive all multicast packets pub const IFF_OACTIVE_COMPAT: c_int = 0x400; // was transmission in progress +pub const IFF_OACTIVE: c_int = IFF_OACTIVE_COMPAT; pub const IFF_SIMPLEX: c_int = 0x800; // can't hear own transmissions pub const IFF_LINK0: c_int = 0x1000; // per link layer defined bit pub const IFF_LINK1: c_int = 0x2000; // per link layer defined bit @@ -1092,8 +1108,10 @@ pub const TCP_FASTKEEP: c_int = 128; pub const AF_BLUETOOTH: c_int = 33; pub const AF_MPLS: c_int = 34; pub const AF_IEEE80211: c_int = 35; +pub const AF_ARP: c_int = 36; pub const PF_BLUETOOTH: c_int = AF_BLUETOOTH; +pub const PF_ARP: c_int = AF_ARP; pub const NET_RT_DUMP: c_int = 1; pub const NET_RT_FLAGS: c_int = 2; @@ -1144,10 +1162,24 @@ pub const _UTX_USERSIZE: usize = 32; pub const _UTX_IDSIZE: usize = 4; pub const _UTX_HOSTSIZE: usize = 256; +pub const EXTATTR_NAMESPACE_EMPTY: c_int = 0; +pub const EXTATTR_NAMESPACE_USER: c_int = 1; +pub const EXTATTR_NAMESPACE_SYSTEM: c_int = 2; + pub const GRND_NONBLOCK: c_uint = 0x2; pub const GRND_RANDOM: c_uint = 0x1; pub const GRND_INSECURE: c_uint = 0x4; +pub const NI_NOFQDN: c_int = 0x00000001; +pub const NI_NUMERICHOST: c_int = 0x00000002; +pub const NI_NAMEREQD: c_int = 0x00000004; +pub const NI_NUMERICSERV: c_int = 0x00000008; +pub const NI_DGRAM: c_int = 0x00000010; +pub const NI_NUMERICSCOPE: c_int = 0x00000040; + +pub const B460800: crate::speed_t = 460800; +pub const B921600: crate::speed_t = 921600; + pub const LC_COLLATE_MASK: c_int = 1 << 0; pub const LC_CTYPE_MASK: c_int = 1 << 1; pub const LC_MONETARY_MASK: c_int = 1 << 2; @@ -1171,6 +1203,8 @@ pub const TIOCMODG: c_ulong = 0x40047403; pub const TIOCMODS: c_ulong = 0x80047404; pub const TIOCREMOTE: c_ulong = 0x80047469; pub const TIOCTIMESTAMP: c_ulong = 0x40107459; +pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; +pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; // Constants used by "at" family of system calls. pub const AT_FDCWD: c_int = u32_cast_int(0xFFFAFDCD); // invalid file descriptor @@ -1184,8 +1218,6 @@ pub const VCHECKPT: usize = 19; pub const _PC_2_SYMLINKS: c_int = 22; pub const _PC_TIMESTAMP_RESOLUTION: c_int = 23; -pub const _CS_PATH: c_int = 1; - pub const _SC_V7_ILP32_OFF32: c_int = 122; pub const _SC_V7_ILP32_OFFBIG: c_int = 123; pub const _SC_V7_LP64_OFF64: c_int = 124; From 5d28b33fd45ab7119ce475c5501d8ff99c720290 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 22:02:30 +0800 Subject: [PATCH 6/9] dragonfly: add missing libc functions --- src/unix/bsd/freebsdlike/dragonfly/mod.rs | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 3826997ef1d4..62a633a18032 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1389,6 +1389,7 @@ extern "C" { pub fn statfs(path: *const c_char, buf: *mut statfs) -> c_int; pub fn fstatfs(fd: c_int, buf: *mut statfs) -> c_int; + pub fn fdatasync(fd: c_int) -> c_int; pub fn uname(buf: *mut crate::utsname) -> c_int; pub fn memmem( haystack: *const c_void, @@ -1396,12 +1397,36 @@ extern "C" { needle: *const c_void, needlelen: size_t, ) -> *mut c_void; + pub fn dlvsym( + handle: *mut c_void, + symbol: *const c_char, + version: *const c_char, + ) -> *mut c_void; + pub fn reallocarray(ptr: *mut c_void, nmemb: size_t, size: size_t) -> *mut c_void; + pub fn qsort_r( + base: *mut c_void, + num: size_t, + size: size_t, + arg: *mut c_void, + compar: Option c_int>, + ); pub fn pthread_spin_init(lock: *mut pthread_spinlock_t, pshared: c_int) -> c_int; pub fn pthread_spin_destroy(lock: *mut pthread_spinlock_t) -> c_int; pub fn pthread_spin_lock(lock: *mut pthread_spinlock_t) -> c_int; pub fn pthread_spin_trylock(lock: *mut pthread_spinlock_t) -> c_int; pub fn pthread_spin_unlock(lock: *mut pthread_spinlock_t) -> c_int; + pub fn pthread_getaffinity_np( + td: crate::pthread_t, + cpusetsize: size_t, + cpusetp: *mut cpuset_t, + ) -> c_int; + pub fn pthread_setaffinity_np( + td: crate::pthread_t, + cpusetsize: size_t, + cpusetp: *const cpuset_t, + ) -> c_int; + pub fn sched_getaffinity(pid: crate::pid_t, cpusetsize: size_t, mask: *mut cpu_set_t) -> c_int; pub fn sched_setaffinity( pid: crate::pid_t, @@ -1411,6 +1436,7 @@ extern "C" { pub fn sched_getcpu() -> c_int; pub fn setproctitle(fmt: *const c_char, ...); + pub fn ftok(path: *const c_char, id: c_int) -> crate::key_t; pub fn shmget(key: crate::key_t, size: size_t, shmflg: c_int) -> c_int; pub fn shmat(shmid: c_int, shmaddr: *const c_void, shmflg: c_int) -> *mut c_void; pub fn shmdt(shmaddr: *const c_void) -> c_int; @@ -1443,6 +1469,27 @@ extern "C" { flags: c_int, ) -> c_int; + pub fn extattr_delete_file( + path: *const c_char, + attrnamespace: c_int, + attrname: *const c_char, + ) -> c_int; + pub fn extattr_get_file( + path: *const c_char, + attrnamespace: c_int, + attrname: *const c_char, + data: *mut c_void, + nbytes: size_t, + ) -> ssize_t; + pub fn extattr_set_file( + path: *const c_char, + attrnamespace: c_int, + attrname: *const c_char, + data: *const c_void, + nbytes: size_t, + ) -> c_int; + + pub fn dup3(src: c_int, dst: c_int, flags: c_int) -> c_int; pub fn closefrom(lowfd: c_int) -> c_int; } From 3b21a15ac2693cdf38fc672714cb2648895439db Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Tue, 26 May 2026 22:02:57 +0800 Subject: [PATCH 7/9] libc-test: expand DragonFly coverage --- libc-test/build.rs | 175 +++++++++++++++++++++++++++++++-- libc-test/semver/dragonfly.txt | 57 ++++++++++- 2 files changed, 220 insertions(+), 12 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 18d020363e13..496c3134f271 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -35,6 +35,7 @@ fn do_cc() { || target.contains("android") || target.contains("emscripten") || target.contains("fuchsia") + || target.contains("dragonfly") || target.contains("bsd") || target.contains("cygwin") { @@ -1535,6 +1536,14 @@ fn test_dragonflybsd(target: &str) { let mut cfg = ctest_cfg(); cfg.flag("-Wno-deprecated-declarations"); + let dragonfly_version = if let Ok(version) = env::var("RUST_LIBC_UNSTABLE_DRAGONFLY_VERSION") { + let vers = parse_dragonfly_version(&version).unwrap(); + println!("cargo:warning=setting DragonFly version to {vers}"); + vers + } else { + which_dragonfly().unwrap_or(600_200) + }; + headers!( cfg, "aio.h", @@ -1576,6 +1585,7 @@ fn test_dragonflybsd(target: &str) { "sched.h", "semaphore.h", "signal.h", + "spawn.h", "stddef.h", "stdint.h", "stdio.h", @@ -1586,6 +1596,7 @@ fn test_dragonflybsd(target: &str) { "sys/ioctl.h", "sys/cpuctl.h", "sys/eui64.h", + "sys/extattr.h", "sys/ipc.h", "sys/kinfo.h", "sys/ktrace.h", @@ -1595,6 +1606,7 @@ fn test_dragonflybsd(target: &str) { "sys/procctl.h", "sys/ptrace.h", "sys/reboot.h", + "sys/random.h", "sys/resource.h", "sys/rtprio.h", "sys/sched.h", @@ -1620,8 +1632,8 @@ fn test_dragonflybsd(target: &str) { "util.h", "utime.h", "utmpx.h", + "vm/vm.h", "vfs/ufs/quota.h", - "vm/vm_map.h", "wchar.h", "iconv.h", ); @@ -1642,6 +1654,12 @@ fn test_dragonflybsd(target: &str) { match ty { // FIXME(dragonflybsd): OSX calls this something else "sighandler_t" => Some("sig_t".to_string()), + "lwpstat" => Some("enum lwpstat".to_string()), + "procstat" => Some("enum procstat".to_string()), + "vm_map_t" => Some("struct vm_map *".to_string()), + "vm_map_entry_t" => Some("struct vm_map_entry *".to_string()), + "vm_eflags_t" => Some("unsigned int".to_string()), + "vm_subsys_t" => Some("int".to_string()), _ => None, } }); @@ -1676,7 +1694,7 @@ fn test_dragonflybsd(target: &str) { "termios2" => true, // Extern types - "DIR" | "FILE" | "fpos_t" => true, + "DIR" | "FILE" | "fpos_t" | "sem" | "timezone" => true, _ => false, } @@ -1695,11 +1713,62 @@ fn test_dragonflybsd(target: &str) { _ => false, } }); + cfg.alias_is_c_enum(move |e| match e { + "lwpstat" | "procstat" => true, + _ => false, + }); cfg.skip_const(move |constant| { match constant.ident() { "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness + // Kernel-only symbols in DragonFly headers. + "DTYPE_VNODE" | "DTYPE_SOCKET" | "DTYPE_PIPE" | "DTYPE_FIFO" | "DTYPE_KQUEUE" + | "DTYPE_CRYPTO" | "DTYPE_MQUEUE" | "DTYPE_DMABUF" => true, + + // Not exposed by current DragonFly userland headers. + "REG_DUMP" + | "REG_ASSERT" + | "REG_ATOI" + | "REG_ITOA" + | "REG_TRACE" + | "REG_LARGE" + | "IP_ADD_SOURCE_MEMBERSHIP" + | "IP_DROP_SOURCE_MEMBERSHIP" + | "IP_BLOCK_SOURCE" + | "IP_UNBLOCK_SOURCE" + | "MAP_RENAME" + | "MAP_NORESERVE" + | "CTL_UNSPEC" + | "KERN_PROF" + | "CTL_P1003_1B_UNUSED1" + | "CTL_P1003_1B_SEM_VALUE_MAX" + | "DOWNTIME" + | "SF_CACHE" => true, + + // libc exposes the 6.0-compatible value for this version-dependent mask. + "KERN_PROC_FLAGMASK" => true, + + // Renamed in current DragonFly headers. + "CPUCTL_RSMSR" | "UTX_DB_LASTLOG" => true, + + // Introduced after DragonFly 5.8. + "AF_ARP" + | "PF_ARP" + | "IP_SENDSRCADDR" + | "F_GETPATH" + | "ENOTRECOVERABLE" + | "EOWNERDEAD" + | "SO_PASSCRED" + | "PROC_PDEATHSIG_CTL" + | "PROC_PDEATHSIG_STATUS" + | "KERN_STATIC_TLS_EXTRA" + | "KERN_MAXID" + if dragonfly_version < 600_000 => + { + true + } + // weird signed extension or something like that? "MS_NOUSER" => true, "MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13 @@ -1720,18 +1789,40 @@ fn test_dragonflybsd(target: &str) { "prlimit" | "prlimit64" // non-int in 2nd arg => true, + // These are exposed unconditionally by libc, but older DragonFly + // headers cannot validate them. + "clock_nanosleep" | "fexecve" | "pthread_getname_np" | "pthread_setname_np" + if dragonfly_version < 600_000 => true, + "pthread_getaffinity_np" | "pthread_setaffinity_np" if dragonfly_version < 600_000 => { + true + }, + "fdatasync" | "getentropy" | "posix_fallocate" if dragonfly_version < 600_200 => true, + "malloc_usable_size" if dragonfly_version < 600_400 => true, _ => false, } }); - cfg.skip_struct_field_type(move |struct_, field| { - match (struct_.ident(), field.ident()) { - // This is a weird union, don't check the type. - ("ifaddrs", "ifa_ifu") => true, - // sighandler_t type is super weird - ("sigaction", "sa_sigaction") => true, - // aio_buf is "volatile void*" and Rust doesn't understand volatile - ("aiocb", "aio_buf") => true, + cfg.skip_alias(move |ty| { + match ty.ident() { + // sighandler_t is crazy across platforms + "sighandler_t" => true, + // Kernel-only or opaque types in userland. + "kvm_t" | "pmap" | "umtx_t" | "Elf32_Lword" => true, + _ => false, + } + }); + + cfg.skip_struct(move |struct_| { + match struct_.ident() { + // FIXME(dragonflybsd): These are tested as part of the linux_fcntl tests since + // there are header conflicts when including them with all the other + // structs. + "termios2" => true, + + // Not available as userland-complete structs on DragonFly. + "ip_mreq_source" | "vm_map_entry" | "vmspace" => true, + "ip_mreqn" if dragonfly_version < 600_000 => true, + _ => false, } }); @@ -1743,13 +1834,77 @@ fn test_dragonflybsd(target: &str) { ("siginfo_t", "_pad") => true, // sigev_notify_thread_id is actually part of a sigev_un union ("sigevent", "sigev_notify_thread_id") => true, + // Current DragonFly headers use these names instead. + ("kinfo_cputime", "cp_idel") => true, + // conflicting with `p_type` macro from . + ("Elf32_Phdr", "p_type") | ("Elf64_Phdr", "p_type") => true, + ("kinfo_lwp", "kl_stat") | ("kinfo_proc", "kp_stat") => true, + ("utmpx", "ut_type") => true, + ("mcontext_t", "mc_fpregs") => true, + _ => false, + } + }); + + cfg.skip_struct_field_type(move |struct_, field| { + match (struct_.ident(), field.ident()) { + // This is a weird union, don't check the type. + ("ifaddrs", "ifa_ifu") => true, + // sighandler_t type is super weird + ("sigaction", "sa_sigaction") => true, + // aio_buf is "volatile void*" and Rust doesn't understand volatile + ("aiocb", "aio_buf") => true, _ => false, } }); + cfg.skip_roundtrip(move |ty| { + matches!( + ty, + "kvm_t" + | "posix_spawnattr_t" + | "posix_spawn_file_actions_t" + | "umtx_t" + | "pmap" + | "ip_mreq_source" + ) + }); + ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap(); } +fn parse_dragonfly_version(version: &str) -> Option { + let version = version.trim(); + + if let Ok(version) = version.parse::() { + // DragonFly's __DragonFly_version uses major * 100_000 + minor * 100. + // Accept compact test override spellings like 58, 60, 62, and 602. + return Some(match version { + 0..=9 => version * 100_000, + 10..=99 => (version / 10) * 100_000 + (version % 10) * 100, + 100..=999 => (version / 100) * 100_000 + (version % 100) * 100, + _ => version, + }); + } + + let mut pieces = version.split(['.', '-']); + let major = pieces.next()?.parse::().ok()?; + let minor = pieces.next()?.parse::().ok()?; + Some(major * 100_000 + minor * 100) +} + +fn which_dragonfly() -> Option { + if env::var("CARGO_CFG_TARGET_OS").ok()?.as_str() != "dragonfly" { + return None; + } + + if try_command_output("uname", &["-s"])?.trim() != "DragonFly" { + return None; + } + + let stdout = try_command_output("uname", &["-r"])?; + parse_dragonfly_version(stdout.trim()) +} + fn test_wasi(target: &str) { assert!(target.contains("wasi")); let p2 = target.contains("wasip2"); diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index 0b158da70a17..b9fe580cea0e 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -19,6 +19,7 @@ ABMON_8 ABMON_9 ACCOUNTING AF_APPLETALK +AF_ARP AF_ATM AF_BLUETOOTH AF_CCITT @@ -52,6 +53,13 @@ AIO_ALLDONE AIO_CANCELED AIO_LISTIO_MAX AIO_NOTCANCELED +AI_ADDRCONFIG +AI_ALL +AI_CANONNAME +AI_NUMERICHOST +AI_NUMERICSERV +AI_PASSIVE +AI_V4MAPPED ALTMON_1 ALTMON_10 ALTMON_11 @@ -80,8 +88,10 @@ AT_SYMLINK_FOLLOW AT_SYMLINK_NOFOLLOW B14400 B28800 +B460800 B7200 B76800 +B921600 BIOCFLUSH BIOCGBLEN BIOCGDLT @@ -146,6 +156,7 @@ CPUCTL_CPUID CPUCTL_CPUID_COUNT CPUCTL_MSRCBIT CPUCTL_MSRSBIT +CPUCTL_RDMSR CPUCTL_RSMSR CPUCTL_UPDATE CPUCTL_WRMSR @@ -275,6 +286,9 @@ EV_ONESHOT EV_RECEIPT EV_SYSFLAGS EXTA +EXTATTR_NAMESPACE_EMPTY +EXTATTR_NAMESPACE_SYSTEM +EXTATTR_NAMESPACE_USER EXTB EXTPROC Elf32_Addr @@ -356,6 +370,7 @@ IFF_MONITOR IFF_MULTICAST IFF_NOARP IFF_NPOLLING +IFF_OACTIVE IFF_OACTIVE_COMPAT IFF_POINTOPOINT IFF_POLLING_COMPAT @@ -560,6 +575,7 @@ KERN_PROF KERN_PS_STRINGS KERN_SAVED_IDS KERN_SECURELVL +KERN_STATIC_TLS_EXTRA KERN_UPDATEINTERVAL KERN_USRSTACK KERN_VERSION @@ -685,6 +701,12 @@ NET_RT_FLAGS NET_RT_IFLIST NET_RT_MAXID NEW_TIME +NI_DGRAM +NI_NAMEREQD +NI_NOFQDN +NI_NUMERICHOST +NI_NUMERICSCOPE +NI_NUMERICSERV NOEXPR NOKERNINFO NOSTR @@ -719,13 +741,21 @@ OXTABS O_ASYNC O_DIRECT O_EXLOCK +O_FAPPEND +O_FASYNCWRITE +O_FBLOCKING +O_FMASK +O_FNONBLOCKING +O_FOFFSET O_FSYNC +O_FSYNCWRITE O_NDELAY O_NOCTTY O_SHLOCK O_SYNC PENDIN PF_APPLETALK +PF_ARP PF_ATM PF_BLUETOOTH PF_CCITT @@ -767,6 +797,12 @@ POLLRDNORM POLLSTANDARD POLLWRBAND POLLWRNORM +POSIX_FADV_DONTNEED +POSIX_FADV_NOREUSE +POSIX_FADV_NORMAL +POSIX_FADV_RANDOM +POSIX_FADV_SEQUENTIAL +POSIX_FADV_WILLNEED POSIX_MADV_DONTNEED POSIX_MADV_NORMAL POSIX_MADV_RANDOM @@ -968,6 +1004,7 @@ SO_ACCEPTFILTER SO_CPUHINT SO_NOSIGPIPE SO_PASSCRED +SO_REUSEPORT SO_SNDSPACE SO_TIMESTAMP SO_USELOOPBACK @@ -1112,6 +1149,7 @@ USER_TZNAME_MAX UTIME_NOW UTIME_OMIT UTX_DB_LASTLOG +UTX_DB_LASTLOGX UTX_DB_UTMPX UTX_DB_WTMPX VCHECKPT @@ -1321,6 +1359,7 @@ dl_iterate_phdr dl_phdr_info dlvsym drand48 +dup3 duplocale eaccess endgrent @@ -1336,9 +1375,13 @@ exect execvP exit_status explicit_bzero +extattr_delete_file +extattr_get_file +extattr_set_file faccessat fchdir fchflags +fdatasync fdopendir fexecve fmemopen @@ -1349,6 +1392,7 @@ freelocale freezero fsid_t fstatfs +ftok futimes getdomainname getdtablesize @@ -1404,9 +1448,11 @@ if_nameindex ifaddrs in6_pktinfo initgroups +ipc_perm issetugid jrand48 kevent +key_t killpg kinfo_cputime kinfo_file @@ -1424,7 +1470,7 @@ kvm_vm_map_entry_first kvm_vm_map_entry_next kvm_write labs -lastlog +lastlogx lchflags lcong48 lio_listio @@ -1528,8 +1574,10 @@ pthread_condattr_getpshared pthread_condattr_setclock pthread_condattr_setpshared pthread_get_name_np +pthread_getaffinity_np pthread_getcpuclockid pthread_getname_np +pthread_getschedparam pthread_kill pthread_main_np pthread_mutex_timedlock @@ -1538,7 +1586,9 @@ pthread_mutexattr_setpshared pthread_rwlockattr_getpshared pthread_rwlockattr_setpshared pthread_set_name_np +pthread_setaffinity_np pthread_setname_np +pthread_setschedparam pthread_spin_destroy pthread_spin_init pthread_spin_lock @@ -1550,10 +1600,12 @@ ptrace_io_desc pututxline pwritev qsort +qsort_r querylocale rand readdir_r readlinkat +reallocarray reallocf recvmsg regcomp @@ -1607,6 +1659,7 @@ shmat shmctl shmdt shmget +shmid_ds sigaltstack sigevent siginfo_t @@ -1640,7 +1693,7 @@ ucontext_t umtx_sleep umtx_wakeup unmount -updatelastlogx +updlastlogx updwtmpx useconds_t uselocale From 8f547a6cdb597aa5f167068da6a9a1d6a0addb51 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Thu, 25 Jun 2026 01:54:59 +0800 Subject: [PATCH 8/9] bsd: move FreeBSD-only definitions out of freebsdlike --- libc-test/build.rs | 6 +----- libc-test/semver/dragonfly.txt | 1 - src/unix/bsd/freebsdlike/freebsd/mod.rs | 12 ++++++++++++ src/unix/bsd/freebsdlike/mod.rs | 11 ----------- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 496c3134f271..119269743f32 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1733,10 +1733,6 @@ fn test_dragonflybsd(target: &str) { | "REG_ITOA" | "REG_TRACE" | "REG_LARGE" - | "IP_ADD_SOURCE_MEMBERSHIP" - | "IP_DROP_SOURCE_MEMBERSHIP" - | "IP_BLOCK_SOURCE" - | "IP_UNBLOCK_SOURCE" | "MAP_RENAME" | "MAP_NORESERVE" | "CTL_UNSPEC" @@ -1807,7 +1803,7 @@ fn test_dragonflybsd(target: &str) { // sighandler_t is crazy across platforms "sighandler_t" => true, // Kernel-only or opaque types in userland. - "kvm_t" | "pmap" | "umtx_t" | "Elf32_Lword" => true, + "kvm_t" | "pmap" | "umtx_t" => true, _ => false, } }); diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index b9fe580cea0e..48b13e62f33c 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -293,7 +293,6 @@ EXTB EXTPROC Elf32_Addr Elf32_Half -Elf32_Lword Elf32_Off Elf32_Phdr Elf32_Sword diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 88b8870bab6c..f24d48d9dcff 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -6,6 +6,8 @@ use crate::{ pub type fflags_t = u32; +pub type Elf32_Lword = u64; + pub type vm_prot_t = u_char; pub type kvaddr_t = u64; pub type segsz_t = isize; @@ -207,6 +209,12 @@ s! { pub ip6: *mut crate::in6_addr, } + pub struct ip_mreq_source { + pub imr_multiaddr: crate::in_addr, + pub imr_sourceaddr: crate::in_addr, + pub imr_interface: crate::in_addr, + } + pub struct statvfs { pub f_bavail: crate::fsblkcnt_t, pub f_bfree: crate::fsblkcnt_t, @@ -3194,6 +3202,10 @@ pub const IP_RECVORIGDSTADDR: c_int = IP_ORIGDSTADDR; pub const IP_DONTFRAG: c_int = 67; pub const IP_RECVTOS: c_int = 68; +pub const IP_ADD_SOURCE_MEMBERSHIP: c_int = 70; +pub const IP_DROP_SOURCE_MEMBERSHIP: c_int = 71; +pub const IP_BLOCK_SOURCE: c_int = 72; +pub const IP_UNBLOCK_SOURCE: c_int = 73; pub const IPV6_BINDANY: c_int = 64; pub const IPV6_ORIGDSTADDR: c_int = 72; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 192db118d1aa..cc11040b086f 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -22,7 +22,6 @@ pub type key_t = c_long; pub type Elf32_Addr = u32; pub type Elf32_Half = u16; -pub type Elf32_Lword = u64; pub type Elf32_Off = u32; pub type Elf32_Sword = i32; pub type Elf32_Word = u32; @@ -101,12 +100,6 @@ s! { pub imr_ifindex: c_int, } - pub struct ip_mreq_source { - pub imr_multiaddr: in_addr, - pub imr_sourceaddr: in_addr, - pub imr_interface: in_addr, - } - pub struct glob_t { pub gl_pathc: size_t, pub gl_matchc: size_t, @@ -941,10 +934,6 @@ pub const IPV6_PKTINFO: c_int = 46; pub const IPV6_HOPLIMIT: c_int = 47; pub const IPV6_RECVTCLASS: c_int = 57; pub const IPV6_TCLASS: c_int = 61; -pub const IP_ADD_SOURCE_MEMBERSHIP: c_int = 70; -pub const IP_DROP_SOURCE_MEMBERSHIP: c_int = 71; -pub const IP_BLOCK_SOURCE: c_int = 72; -pub const IP_UNBLOCK_SOURCE: c_int = 73; pub const TCP_NOPUSH: c_int = 4; pub const TCP_NOOPT: c_int = 8; From bd4e8ca542c4cd5922b9bc1c34d6ee58562ecb12 Mon Sep 17 00:00:00 2001 From: Xuntao Chi Date: Thu, 25 Jun 2026 01:55:16 +0800 Subject: [PATCH 9/9] dragonfly: remove private VM type bindings --- libc-test/build.rs | 21 ++------- libc-test/semver/dragonfly.txt | 1 - src/unix/bsd/freebsdlike/dragonfly/mod.rs | 53 +---------------------- 3 files changed, 5 insertions(+), 70 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 119269743f32..ea9298c020b9 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1658,8 +1658,6 @@ fn test_dragonflybsd(target: &str) { "procstat" => Some("enum procstat".to_string()), "vm_map_t" => Some("struct vm_map *".to_string()), "vm_map_entry_t" => Some("struct vm_map_entry *".to_string()), - "vm_eflags_t" => Some("unsigned int".to_string()), - "vm_subsys_t" => Some("int".to_string()), _ => None, } }); @@ -1802,8 +1800,9 @@ fn test_dragonflybsd(target: &str) { match ty.ident() { // sighandler_t is crazy across platforms "sighandler_t" => true, - // Kernel-only or opaque types in userland. - "kvm_t" | "pmap" | "umtx_t" => true, + // Same as FreeBSD: `kvm_t` is an opaque handle used through + // pointers, and libc does not bind the private `struct __kvm`. + "kvm_t" => true, _ => false, } }); @@ -1815,8 +1814,6 @@ fn test_dragonflybsd(target: &str) { // structs. "termios2" => true, - // Not available as userland-complete structs on DragonFly. - "ip_mreq_source" | "vm_map_entry" | "vmspace" => true, "ip_mreqn" if dragonfly_version < 600_000 => true, _ => false, @@ -1853,18 +1850,6 @@ fn test_dragonflybsd(target: &str) { } }); - cfg.skip_roundtrip(move |ty| { - matches!( - ty, - "kvm_t" - | "posix_spawnattr_t" - | "posix_spawn_file_actions_t" - | "umtx_t" - | "pmap" - | "ip_mreq_source" - ) - }); - ctest::generate_test(&mut cfg, "../src/lib.rs", "ctest_output.rs").unwrap(); } diff --git a/libc-test/semver/dragonfly.txt b/libc-test/semver/dragonfly.txt index 48b13e62f33c..4636e3761465 100644 --- a/libc-test/semver/dragonfly.txt +++ b/libc-test/semver/dragonfly.txt @@ -1704,7 +1704,6 @@ uuid uuid_t vm_map_entry_t vm_size_t -vmspace wait4 waitid xucred diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 62a633a18032..2971b7188720 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -30,7 +30,6 @@ pub type cpuset_t = cpumask_t; pub type cpu_set_t = cpumask_t; pub type register_t = c_long; -pub type umtx_t = c_int; pub type pthread_barrierattr_t = *mut __c_anonymous_pthread_barrierattr; pub type pthread_barrier_t = *mut __c_anonymous_pthread_barrier; pub type pthread_spinlock_t = crate::uintptr_t; @@ -40,13 +39,9 @@ pub type segsz_t = isize; pub type vm_prot_t = u8; pub type vm_maptype_t = u8; pub type vm_inherit_t = i8; -pub type vm_subsys_t = c_int; -pub type vm_eflags_t = c_uint; -pub type vm_map_t = *mut __c_anonymous_vm_map; -pub type vm_map_entry_t = *mut vm_map_entry; - -pub type pmap = __c_anonymous_pmap; +pub type vm_map_t = *mut c_void; +pub type vm_map_entry_t = *mut c_void; extern_ty! { pub type sem; @@ -347,50 +342,6 @@ s! { kp_spare: [c_int; 2], } - pub struct __c_anonymous_vm_map { - _priv: [crate::uintptr_t; 36], - } - - pub struct vm_map_entry { - _priv: [crate::uintptr_t; 15], - pub eflags: crate::vm_eflags_t, - pub maptype: crate::vm_maptype_t, - pub protection: crate::vm_prot_t, - pub max_protection: crate::vm_prot_t, - pub inheritance: crate::vm_inherit_t, - pub wired_count: c_int, - pub id: crate::vm_subsys_t, - } - - pub struct __c_anonymous_pmap { - _priv1: [crate::uintptr_t; 32], - _priv2: [crate::uintptr_t; 32], - _priv3: [crate::uintptr_t; 32], - _priv4: [crate::uintptr_t; 32], - _priv5: [crate::uintptr_t; 8], - } - - pub struct vmspace { - vm_map: __c_anonymous_vm_map, - vm_pmap: __c_anonymous_pmap, - pub vm_flags: c_int, - pub vm_shm: *mut c_char, - pub vm_rssize: crate::segsz_t, - pub vm_swrss: crate::segsz_t, - pub vm_tsize: crate::segsz_t, - pub vm_dsize: crate::segsz_t, - pub vm_ssize: crate::segsz_t, - pub vm_taddr: *mut c_char, - pub vm_daddr: *mut c_char, - pub vm_maxsaddr: *mut c_char, - pub vm_minsaddr: *mut c_char, - _unused1: Padding, - _unused2: Padding, - pub vm_pagesupply: c_int, - pub vm_holdcnt: c_uint, - pub vm_refcnt: c_uint, - } - pub struct cpuctl_msr_args_t { pub msr: c_int, pub data: u64,