Skip to content

Commit

Permalink
Add fspacectl, new in FreeBSD 14
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Nov 17, 2021
1 parent a8d7606 commit 58ef41c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn main() {
Some(11) if libc_ci => println!("cargo:rustc-cfg=freebsd11"),
Some(12) if libc_ci => println!("cargo:rustc-cfg=freebsd12"),
Some(13) if libc_ci => println!("cargo:rustc-cfg=freebsd13"),
Some(14) if libc_ci => println!("cargo:rustc-cfg=freebsd14"),
Some(_) | None => println!("cargo:rustc-cfg=freebsd11"),
}

Expand Down Expand Up @@ -150,6 +151,7 @@ fn which_freebsd() -> Option<i32> {
s if s.starts_with("11") => Some(11),
s if s.starts_with("12") => Some(12),
s if s.starts_with("13") => Some(13),
s if s.starts_with("14") => Some(14),
_ => None,
}
}
13 changes: 12 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,7 @@ fn test_freebsd(target: &str) {
Some(11) => cfg.cfg("freebsd11", None),
Some(12) => cfg.cfg("freebsd12", None),
Some(13) => cfg.cfg("freebsd13", None),
Some(14) => cfg.cfg("freebsd14", None),
_ => &mut cfg,
};

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

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

// Added in FreeBSD 14
"SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true,

"VM_TOTAL" if Some(11) == freebsd_ver => true,

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

// `spacectl_range` was introduced in FreeBSD 14
"spacectl_range" if Some(14) > freebsd_ver => true,

// obsolete version
"vmtotal" if Some(11) == freebsd_ver => true,

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

// `fspacectl` was introduced in FreeBSD 14
"fspacectl" if Some(14) > freebsd_ver => true,

// The `uname` function in the `utsname.h` FreeBSD header is a C
// inline function (has no symbol) that calls the `__xuname` symbol.
// Therefore the function pointer comparison does not make sense for it.
Expand Down Expand Up @@ -3376,6 +3386,7 @@ fn which_freebsd() -> Option<i32> {
s if s.starts_with("11") => Some(11),
s if s.starts_with("12") => Some(12),
s if s.starts_with("13") => Some(13),
s if s.starts_with("14") => Some(14),
_ => None,
}
}
Expand Down
49 changes: 42 additions & 7 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ s! {
pub ki_fd: *mut ::c_void,
// This is normally "struct vmspace".
pub ki_vmspace: *mut ::c_void,
#[cfg(freebsd13)]
#[cfg(any(freebsd13, freebsd14))]
pub ki_wchan: *const ::c_void,
#[cfg(not(freebsd13))]
#[cfg(not(any(freebsd13, freebsd14)))]
pub ki_wchan: *mut ::c_void,
pub ki_pid: ::pid_t,
pub ki_ppid: ::pid_t,
Expand All @@ -342,7 +342,7 @@ s! {
pub ki_tsid: ::pid_t,
pub ki_jobc: ::c_short,
pub ki_spare_short1: ::c_short,
#[cfg(any(freebsd12, freebsd13))]
#[cfg(any(freebsd12, freebsd13, freebsd14))]
pub ki_tdev_freebsd11: u32,
#[cfg(freebsd11)]
pub ki_tdev: ::dev_t,
Expand Down Expand Up @@ -393,7 +393,7 @@ s! {
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
#[cfg(freebsd13)]
#[cfg(any(freebsd13, freebsd14))]
pub ki_tdev: u64,
#[cfg(freebsd12)]
pub ki_tdev: ::dev_t,
Expand All @@ -416,7 +416,7 @@ s! {
// This is normally "struct thread".
pub ki_tdaddr: *mut ::c_void,
// This is normally "struct pwddesc".
#[cfg(freebsd13)]
#[cfg(any(freebsd13, freebsd14))]
pub ki_pd: *mut ::c_void,
pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR],
pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG],
Expand Down Expand Up @@ -542,6 +542,11 @@ s_no_extra_traits! {
__unused2: [::c_long; 7]
}

pub struct spacectl_range {
r_offset: ::off_t,
r_len: ::off_t
}

#[cfg(libc_union)]
pub union __c_anonymous_elf32_auxv_union {
pub a_val: ::c_int,
Expand Down Expand Up @@ -772,6 +777,29 @@ cfg_if! {
self.sigev_notify_thread_id.hash(state);
}
}

impl ::fmt::Debug for spacectl_range {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("spacectl_range")
.field("r_offset", &self.r_offset)
.field("r_len", &self.r_len)
.finish()
}
}
impl ::Hash::Hash for spacectl_range {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.r_offset.hash(state);
self.r_len.hash(state);
}
}
impl Eq for spacectl_range {}
impl PartialEq for spacectl_range {
fn eq(&self, other: &Self) -> bool {
self.r_offset == other.r_offset
&& self.r_len == other.r_len
}
}

#[cfg(libc_union)]
impl PartialEq for __c_anonymous_elf32_auxv_union {
fn eq(&self, other: &__c_anonymous_elf32_auxv_union) -> bool {
Expand Down Expand Up @@ -1741,6 +1769,9 @@ pub const F_SEAL_SEAL: ::c_int = 1;
pub const F_SEAL_SHRINK: ::c_int = 2;
pub const F_SEAL_WRITE: ::c_int = 8;

// for use with fspacectl
pub const SPACECTL_DEALLOC: ::c_int = 1;

// For getrandom()
pub const GRND_NONBLOCK: ::c_uint = 0x1;
pub const GRND_RANDOM: ::c_uint = 0x2;
Expand Down Expand Up @@ -1881,7 +1912,7 @@ pub const KVME_FLAG_SUPER: ::c_int = 0x00000008;
pub const KVME_FLAG_GROWS_UP: ::c_int = 0x00000010;
pub const KVME_FLAG_GROWS_DOWN: ::c_int = 0x00000020;
cfg_if! {
if #[cfg(any(freebsd12, freebsd13))] {
if #[cfg(any(freebsd12, freebsd13, freebsd14))] {
pub const KVME_FLAG_USER_WIRED: ::c_int = 0x00000040;
}
}
Expand Down Expand Up @@ -2208,6 +2239,8 @@ extern "C" {
nbytes: ::size_t,
) -> ::ssize_t;

pub fn fspacectl(fd: ::c_int, cmd: ::c_int, rqsr: *const spacectl_range, flags: ::c_int, rmsr: *mut spacectl_range) -> ::c_int;

pub fn jail(jail: *mut ::jail) -> ::c_int;
pub fn jail_attach(jid: ::c_int) -> ::c_int;
pub fn jail_remove(jid: ::c_int) -> ::c_int;
Expand Down Expand Up @@ -2624,7 +2657,9 @@ extern "C" {
}

cfg_if! {
if #[cfg(freebsd13)] {
if #[cfg(any(freebsd13, freebsd14))] {
// For now, there are no differences between FreeBSD 13 and 14 that Rust
// needs to care about.
mod freebsd13;
pub use self::freebsd13::*;
} else if #[cfg(freebsd12)] {
Expand Down

0 comments on commit 58ef41c

Please sign in to comment.