Skip to content

Commit 58ef41c

Browse files
committed
Add fspacectl, new in FreeBSD 14
1 parent a8d7606 commit 58ef41c

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn main() {
3131
Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
3232
Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
3333
Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
34+
Some(14) if libc_ci => println!("cargo:rustc-cfg=freebsd14"),
3435
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
3536
}
3637

@@ -150,6 +151,7 @@ fn which_freebsd() -> Option<i32> {
150151
s if s.starts_with("11") => Some(11),
151152
s if s.starts_with("12") => Some(12),
152153
s if s.starts_with("13") => Some(13),
154+
s if s.starts_with("14") => Some(14),
153155
_ => None,
154156
}
155157
}

libc-test/build.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,7 @@ fn test_freebsd(target: &str) {
17561756
Some(11) => cfg.cfg("freebsd11", None),
17571757
Some(12) => cfg.cfg("freebsd12", None),
17581758
Some(13) => cfg.cfg("freebsd13", None),
1759+
Some(14) => cfg.cfg("freebsd14", None),
17591760
_ => &mut cfg,
17601761
};
17611762

@@ -2006,7 +2007,7 @@ fn test_freebsd(target: &str) {
20062007
// This was changed to 96(0x60) in FreeBSD 13:
20072008
// https://github.com/freebsd/freebsd/
20082009
// commit/06b00ceaa914a3907e4e27bad924f44612bae1d7
2009-
"MINCORE_SUPER" if Some(13) == freebsd_ver => true,
2010+
"MINCORE_SUPER" if Some(13) <= freebsd_ver => true,
20102011

20112012
// Added in FreeBSD 12.0
20122013
"EINTEGRITY" if Some(11) == freebsd_ver => true,
@@ -2054,6 +2055,9 @@ fn test_freebsd(target: &str) {
20542055
// Added in in FreeBSD 13.0 (r367776 and r367287)
20552056
"SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true,
20562057

2058+
// Added in FreeBSD 14
2059+
"SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true,
2060+
20572061
"VM_TOTAL" if Some(11) == freebsd_ver => true,
20582062

20592063
_ => false,
@@ -2087,6 +2091,9 @@ fn test_freebsd(target: &str) {
20872091
// `ptrace_sc_ret` is not available in FreeBSD 11
20882092
"ptrace_sc_ret" if Some(11) == freebsd_ver => true,
20892093

2094+
// `spacectl_range` was introduced in FreeBSD 14
2095+
"spacectl_range" if Some(14) > freebsd_ver => true,
2096+
20902097
// obsolete version
20912098
"vmtotal" if Some(11) == freebsd_ver => true,
20922099

@@ -2109,6 +2116,9 @@ fn test_freebsd(target: &str) {
21092116
// `ssize_t` in FreeBSD11:
21102117
"aio_waitcomplete" if Some(10) == freebsd_ver => true,
21112118

2119+
// `fspacectl` was introduced in FreeBSD 14
2120+
"fspacectl" if Some(14) > freebsd_ver => true,
2121+
21122122
// The `uname` function in the `utsname.h` FreeBSD header is a C
21132123
// inline function (has no symbol) that calls the `__xuname` symbol.
21142124
// Therefore the function pointer comparison does not make sense for it.
@@ -3376,6 +3386,7 @@ fn which_freebsd() -> Option<i32> {
33763386
s if s.starts_with("11") => Some(11),
33773387
s if s.starts_with("12") => Some(12),
33783388
s if s.starts_with("13") => Some(13),
3389+
s if s.starts_with("14") => Some(14),
33793390
_ => None,
33803391
}
33813392
}

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ s! {
330330
pub ki_fd: *mut ::c_void,
331331
// This is normally "struct vmspace".
332332
pub ki_vmspace: *mut ::c_void,
333-
#[cfg(freebsd13)]
333+
#[cfg(any(freebsd13, freebsd14))]
334334
pub ki_wchan: *const ::c_void,
335-
#[cfg(not(freebsd13))]
335+
#[cfg(not(any(freebsd13, freebsd14)))]
336336
pub ki_wchan: *mut ::c_void,
337337
pub ki_pid: ::pid_t,
338338
pub ki_ppid: ::pid_t,
@@ -342,7 +342,7 @@ s! {
342342
pub ki_tsid: ::pid_t,
343343
pub ki_jobc: ::c_short,
344344
pub ki_spare_short1: ::c_short,
345-
#[cfg(any(freebsd12, freebsd13))]
345+
#[cfg(any(freebsd12, freebsd13, freebsd14))]
346346
pub ki_tdev_freebsd11: u32,
347347
#[cfg(freebsd11)]
348348
pub ki_tdev: ::dev_t,
@@ -393,7 +393,7 @@ s! {
393393
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
394394
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
395395
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
396-
#[cfg(freebsd13)]
396+
#[cfg(any(freebsd13, freebsd14))]
397397
pub ki_tdev: u64,
398398
#[cfg(freebsd12)]
399399
pub ki_tdev: ::dev_t,
@@ -416,7 +416,7 @@ s! {
416416
// This is normally "struct thread".
417417
pub ki_tdaddr: *mut ::c_void,
418418
// This is normally "struct pwddesc".
419-
#[cfg(freebsd13)]
419+
#[cfg(any(freebsd13, freebsd14))]
420420
pub ki_pd: *mut ::c_void,
421421
pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR],
422422
pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG],
@@ -542,6 +542,11 @@ s_no_extra_traits! {
542542
__unused2: [::c_long; 7]
543543
}
544544

545+
pub struct spacectl_range {
546+
r_offset: ::off_t,
547+
r_len: ::off_t
548+
}
549+
545550
#[cfg(libc_union)]
546551
pub union __c_anonymous_elf32_auxv_union {
547552
pub a_val: ::c_int,
@@ -772,6 +777,29 @@ cfg_if! {
772777
self.sigev_notify_thread_id.hash(state);
773778
}
774779
}
780+
781+
impl ::fmt::Debug for spacectl_range {
782+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
783+
f.debug_struct("spacectl_range")
784+
.field("r_offset", &self.r_offset)
785+
.field("r_len", &self.r_len)
786+
.finish()
787+
}
788+
}
789+
impl ::Hash::Hash for spacectl_range {
790+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
791+
self.r_offset.hash(state);
792+
self.r_len.hash(state);
793+
}
794+
}
795+
impl Eq for spacectl_range {}
796+
impl PartialEq for spacectl_range {
797+
fn eq(&self, other: &Self) -> bool {
798+
self.r_offset == other.r_offset
799+
&& self.r_len == other.r_len
800+
}
801+
}
802+
775803
#[cfg(libc_union)]
776804
impl PartialEq for __c_anonymous_elf32_auxv_union {
777805
fn eq(&self, other: &__c_anonymous_elf32_auxv_union) -> bool {
@@ -1741,6 +1769,9 @@ pub const F_SEAL_SEAL: ::c_int = 1;
17411769
pub const F_SEAL_SHRINK: ::c_int = 2;
17421770
pub const F_SEAL_WRITE: ::c_int = 8;
17431771

1772+
// for use with fspacectl
1773+
pub const SPACECTL_DEALLOC: ::c_int = 1;
1774+
17441775
// For getrandom()
17451776
pub const GRND_NONBLOCK: ::c_uint = 0x1;
17461777
pub const GRND_RANDOM: ::c_uint = 0x2;
@@ -1881,7 +1912,7 @@ pub const KVME_FLAG_SUPER: ::c_int = 0x00000008;
18811912
pub const KVME_FLAG_GROWS_UP: ::c_int = 0x00000010;
18821913
pub const KVME_FLAG_GROWS_DOWN: ::c_int = 0x00000020;
18831914
cfg_if! {
1884-
if #[cfg(any(freebsd12, freebsd13))] {
1915+
if #[cfg(any(freebsd12, freebsd13, freebsd14))] {
18851916
pub const KVME_FLAG_USER_WIRED: ::c_int = 0x00000040;
18861917
}
18871918
}
@@ -2208,6 +2239,8 @@ extern "C" {
22082239
nbytes: ::size_t,
22092240
) -> ::ssize_t;
22102241

2242+
pub fn fspacectl(fd: ::c_int, cmd: ::c_int, rqsr: *const spacectl_range, flags: ::c_int, rmsr: *mut spacectl_range) -> ::c_int;
2243+
22112244
pub fn jail(jail: *mut ::jail) -> ::c_int;
22122245
pub fn jail_attach(jid: ::c_int) -> ::c_int;
22132246
pub fn jail_remove(jid: ::c_int) -> ::c_int;
@@ -2624,7 +2657,9 @@ extern "C" {
26242657
}
26252658

26262659
cfg_if! {
2627-
if #[cfg(freebsd13)] {
2660+
if #[cfg(any(freebsd13, freebsd14))] {
2661+
// For now, there are no differences between FreeBSD 13 and 14 that Rust
2662+
// needs to care about.
26282663
mod freebsd13;
26292664
pub use self::freebsd13::*;
26302665
} else if #[cfg(freebsd12)] {

0 commit comments

Comments
 (0)