Skip to content

Commit ef7e4be

Browse files
committed
Add fspacectl, new in FreeBSD 14
1 parent bb5b8ef commit ef7e4be

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

libc-test/build.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ fn test_freebsd(target: &str) {
20152015
// This was changed to 96(0x60) in FreeBSD 13:
20162016
// https://github.com/freebsd/freebsd/
20172017
// commit/06b00ceaa914a3907e4e27bad924f44612bae1d7
2018-
"MINCORE_SUPER" if Some(13) == freebsd_ver => true,
2018+
"MINCORE_SUPER" if Some(13) <= freebsd_ver => true,
20192019

20202020
// Added in FreeBSD 12.0
20212021
"EINTEGRITY" if Some(11) == freebsd_ver => true,
@@ -2063,6 +2063,9 @@ fn test_freebsd(target: &str) {
20632063
// Added in in FreeBSD 13.0 (r367776 and r367287)
20642064
"SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true,
20652065

2066+
// Added in FreeBSD 14
2067+
"SPACECTL_DEALLOC" if Some(14) > freebsd_ver => true,
2068+
20662069
"VM_TOTAL" if Some(11) == freebsd_ver => true,
20672070

20682071
// Added in FreeBSD 14.
@@ -2140,6 +2143,9 @@ fn test_freebsd(target: &str) {
21402143
// `ptrace_sc_ret` is not available in FreeBSD 11
21412144
"ptrace_sc_ret" if Some(11) == freebsd_ver => true,
21422145

2146+
// `spacectl_range` was introduced in FreeBSD 14
2147+
"spacectl_range" if Some(14) > freebsd_ver => true,
2148+
21432149
// obsolete version
21442150
"vmtotal" if Some(11) == freebsd_ver => true,
21452151

@@ -2162,6 +2168,9 @@ fn test_freebsd(target: &str) {
21622168
// `ssize_t` in FreeBSD11:
21632169
"aio_waitcomplete" if Some(10) == freebsd_ver => true,
21642170

2171+
// `fspacectl` was introduced in FreeBSD 14
2172+
"fspacectl" if Some(14) > freebsd_ver => true,
2173+
21652174
// The `uname` function in the `utsname.h` FreeBSD header is a C
21662175
// inline function (has no symbol) that calls the `__xuname` symbol.
21672176
// Therefore the function pointer comparison does not make sense for it.

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

+38
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,11 @@ s_no_extra_traits! {
715715
pub devname: [::c_char; SPECNAMELEN as usize + 1],
716716
}
717717

718+
pub struct spacectl_range {
719+
r_offset: ::off_t,
720+
r_len: ::off_t
721+
}
722+
718723
#[cfg(libc_union)]
719724
pub union __c_anonymous_elf32_auxv_union {
720725
pub a_val: ::c_int,
@@ -1098,6 +1103,28 @@ cfg_if! {
10981103
}
10991104
}
11001105

1106+
impl ::fmt::Debug for spacectl_range {
1107+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1108+
f.debug_struct("spacectl_range")
1109+
.field("r_offset", &self.r_offset)
1110+
.field("r_len", &self.r_len)
1111+
.finish()
1112+
}
1113+
}
1114+
impl ::Hash::Hash for spacectl_range {
1115+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1116+
self.r_offset.hash(state);
1117+
self.r_len.hash(state);
1118+
}
1119+
}
1120+
impl Eq for spacectl_range {}
1121+
impl PartialEq for spacectl_range {
1122+
fn eq(&self, other: &Self) -> bool {
1123+
self.r_offset == other.r_offset
1124+
&& self.r_len == other.r_len
1125+
}
1126+
}
1127+
11011128
#[cfg(libc_union)]
11021129
impl PartialEq for __c_anonymous_elf32_auxv_union {
11031130
fn eq(&self, other: &__c_anonymous_elf32_auxv_union) -> bool {
@@ -2662,6 +2689,9 @@ pub const F_SEAL_SEAL: ::c_int = 1;
26622689
pub const F_SEAL_SHRINK: ::c_int = 2;
26632690
pub const F_SEAL_WRITE: ::c_int = 8;
26642691

2692+
// for use with fspacectl
2693+
pub const SPACECTL_DEALLOC: ::c_int = 1;
2694+
26652695
// For getrandom()
26662696
pub const GRND_NONBLOCK: ::c_uint = 0x1;
26672697
pub const GRND_RANDOM: ::c_uint = 0x2;
@@ -3326,6 +3356,14 @@ extern "C" {
33263356
nbytes: ::size_t,
33273357
) -> ::ssize_t;
33283358

3359+
pub fn fspacectl(
3360+
fd: ::c_int,
3361+
cmd: ::c_int,
3362+
rqsr: *const spacectl_range,
3363+
flags: ::c_int,
3364+
rmsr: *mut spacectl_range,
3365+
) -> ::c_int;
3366+
33293367
pub fn jail(jail: *mut ::jail) -> ::c_int;
33303368
pub fn jail_attach(jid: ::c_int) -> ::c_int;
33313369
pub fn jail_remove(jid: ::c_int) -> ::c_int;

0 commit comments

Comments
 (0)