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 29, 2021
1 parent bb5b8ef commit b777759
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,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 @@ -2063,6 +2063,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,

// Added in FreeBSD 14.
Expand Down Expand Up @@ -2140,6 +2143,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 @@ -2162,6 +2168,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
38 changes: 38 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ s_no_extra_traits! {
pub devname: [::c_char; SPECNAMELEN as usize + 1],
}

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 @@ -1098,6 +1103,28 @@ cfg_if! {
}
}

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 @@ -2662,6 +2689,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 @@ -3326,6 +3356,14 @@ 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

0 comments on commit b777759

Please sign in to comment.