Skip to content

Commit 3418986

Browse files
committed
Properly expose more constants on FreeBSD
The freebsd12 and freebsd13 modules should only be used for symbols that _change_ in those versions, not for newly added symbols. Mostly they should be used for versioned ELF symbols. It does no harm to publish ordinary constants in the base FreeBSD module even if they weren't defined in the lowest supported version of FreeBSD, but it does make it much easier for consumers to use them.
1 parent 255d84d commit 3418986

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

libc-test/build.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,10 +1898,10 @@ fn test_freebsd(target: &str) {
18981898

18991899
cfg.skip_const(move |name| {
19001900
match name {
1901-
// These constants are to be introduced in yet-unreleased FreeBSD 12.2.
1901+
// These constants were introduced in FreeBSD 13:
19021902
"F_ADD_SEALS" | "F_GET_SEALS" | "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
19031903
| "F_SEAL_WRITE"
1904-
if Some(12) <= freebsd_ver =>
1904+
if Some(13) > freebsd_ver =>
19051905
{
19061906
true
19071907
}
@@ -1915,6 +1915,7 @@ fn test_freebsd(target: &str) {
19151915
| "IPV6_ORIGDSTADDR"
19161916
| "IPV6_RECVORIGDSTADDR"
19171917
| "NI_NUMERICSCOPE"
1918+
| "SO_DOMAIN"
19181919
if Some(11) == freebsd_ver =>
19191920
{
19201921
true
@@ -1985,11 +1986,32 @@ fn test_freebsd(target: &str) {
19851986
// commit/06b00ceaa914a3907e4e27bad924f44612bae1d7
19861987
"MINCORE_SUPER" if Some(13) == freebsd_ver => true,
19871988

1989+
// Added in FreeBSD 12.0
1990+
"EINTEGRITY" if Some(11) == freebsd_ver => true,
1991+
19881992
// This was increased to 97 in FreeBSD 12.2 and 13.
19891993
// https://github.com/freebsd/freebsd/
19901994
// commit/72a21ba0f62da5e86a1c0b462aeb3f5ff849a1b7
19911995
"ELAST" if Some(12) == freebsd_ver => true,
19921996

1997+
// Added in FreeBSD 12.0 (r331279)
1998+
"GRND_NONBLOCK" | "GRND_RANDOM" if Some(11) == freebsd_ver => true,
1999+
// Added in FreeBSD 13.0 (r356667)
2000+
"GRND_INSECURE" if Some(13) > freebsd_ver => true,
2001+
2002+
// Added in FreeBSD 12.1 (r343964 and r345228)
2003+
"PROC_ASLR_CTL" | "PROC_ASLR_STATUS" | "PROC_PROCCTL_MD_MIN"
2004+
if Some(11) == freebsd_ver =>
2005+
{
2006+
true
2007+
}
2008+
2009+
// Added in FreeBSD 13.0 (r349609)
2010+
"PROC_PROTMAX_CTL" | "PROC_PROTMAX_STATUS" if Some(13) > freebsd_ver => true,
2011+
2012+
// Added in in FreeBSD 13.0 (r367776 and r367287)
2013+
"SCM_CREDS2" | "LOCAL_CREDS_PERSISTENT" if Some(13) > freebsd_ver => true,
2014+
19932015
_ => false,
19942016
}
19952017
});

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,26 +190,7 @@ cfg_if! {
190190
}
191191
}
192192

193-
pub const F_ADD_SEALS: ::c_int = 19;
194-
pub const F_GET_SEALS: ::c_int = 20;
195-
pub const F_SEAL_SEAL: ::c_int = 0x0001;
196-
pub const F_SEAL_SHRINK: ::c_int = 0x0002;
197-
pub const F_SEAL_GROW: ::c_int = 0x0004;
198-
pub const F_SEAL_WRITE: ::c_int = 0x0008;
199-
200-
pub const GRND_NONBLOCK: ::c_uint = 0x1;
201-
pub const GRND_RANDOM: ::c_uint = 0x2;
202-
203193
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
204-
205-
pub const PROC_ASLR_CTL: ::c_int = 13;
206-
pub const PROC_ASLR_STATUS: ::c_int = 14;
207-
208-
pub const PROC_PROCCTL_MD_MIN: ::c_int = 0x10000000;
209-
210-
pub const SO_DOMAIN: ::c_int = 0x1019;
211-
212-
pub const EINTEGRITY: ::c_int = 97;
213194
pub const ELAST: ::c_int = 97;
214195

215196
extern "C" {

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,32 +201,8 @@ cfg_if! {
201201
}
202202
}
203203

204-
pub const F_ADD_SEALS: ::c_int = 19;
205-
pub const F_GET_SEALS: ::c_int = 20;
206-
pub const F_SEAL_SEAL: ::c_int = 0x0001;
207-
pub const F_SEAL_SHRINK: ::c_int = 0x0002;
208-
pub const F_SEAL_GROW: ::c_int = 0x0004;
209-
pub const F_SEAL_WRITE: ::c_int = 0x0008;
210-
211-
pub const GRND_NONBLOCK: ::c_uint = 0x1;
212-
pub const GRND_RANDOM: ::c_uint = 0x2;
213-
214204
pub const RAND_MAX: ::c_int = 0x7fff_ffff;
215-
216-
pub const SO_DOMAIN: ::c_int = 0x1019;
217-
218-
pub const EINTEGRITY: ::c_int = 97;
219205
pub const ELAST: ::c_int = 97;
220-
pub const GRND_INSECURE: ::c_uint = 0x4;
221-
222-
pub const PROC_ASLR_CTL: ::c_int = 13;
223-
pub const PROC_ASLR_STATUS: ::c_int = 14;
224-
pub const PROC_PROTMAX_CTL: ::c_int = 15;
225-
pub const PROC_PROTMAX_STATUS: ::c_int = 16;
226-
pub const PROC_PROCCTL_MD_MIN: ::c_int = 0x10000000;
227-
228-
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
229-
pub const SCM_CREDS2: ::c_int = 0x08;
230206

231207
f! {
232208
pub fn SOCKCRED2SIZE(ngrps: usize) -> usize {

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ pub const ENOTCAPABLE: ::c_int = 93;
626626
pub const ECAPMODE: ::c_int = 94;
627627
pub const ENOTRECOVERABLE: ::c_int = 95;
628628
pub const EOWNERDEAD: ::c_int = 96;
629+
pub const EINTEGRITY: ::c_int = 97;
629630
pub const RLIMIT_NPTS: ::c_int = 11;
630631
pub const RLIMIT_SWAP: ::c_int = 12;
631632
pub const RLIMIT_KQUEUES: ::c_int = 13;
@@ -903,6 +904,8 @@ pub const MNT_UNION: ::c_int = 0x00000020;
903904
pub const MNT_EXPUBLIC: ::c_int = 0x20000000;
904905
pub const MNT_NONBUSY: ::c_int = 0x04000000;
905906

907+
pub const SCM_CREDS2: ::c_int = 0x08;
908+
906909
pub const SO_BINTIME: ::c_int = 0x2000;
907910
pub const SO_NO_OFFLOAD: ::c_int = 0x4000;
908911
pub const SO_NO_DDP: ::c_int = 0x8000;
@@ -916,9 +919,11 @@ pub const SO_SETFIB: ::c_int = 0x1014;
916919
pub const SO_USER_COOKIE: ::c_int = 0x1015;
917920
pub const SO_PROTOCOL: ::c_int = 0x1016;
918921
pub const SO_PROTOTYPE: ::c_int = SO_PROTOCOL;
922+
pub const SO_DOMAIN: ::c_int = 0x1019;
919923
pub const SO_VENDOR: ::c_int = 0x80000000;
920924

921925
pub const LOCAL_CREDS: ::c_int = 2;
926+
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
922927
pub const LOCAL_CONNWAIT: ::c_int = 4;
923928
pub const LOCAL_VENDOR: ::c_int = SO_VENDOR;
924929

@@ -967,8 +972,13 @@ pub const PROC_TRAPCAP_CTL: ::c_int = 9;
967972
pub const PROC_TRAPCAP_STATUS: ::c_int = 10;
968973
pub const PROC_PDEATHSIG_CTL: ::c_int = 11;
969974
pub const PROC_PDEATHSIG_STATUS: ::c_int = 12;
975+
pub const PROC_ASLR_CTL: ::c_int = 13;
976+
pub const PROC_ASLR_STATUS: ::c_int = 14;
977+
pub const PROC_PROTMAX_CTL: ::c_int = 15;
978+
pub const PROC_PROTMAX_STATUS: ::c_int = 16;
970979
pub const PROC_STACKGAP_CTL: ::c_int = 17;
971980
pub const PROC_STACKGAP_STATUS: ::c_int = 18;
981+
pub const PROC_PROCCTL_MD_MIN: ::c_int = 0x10000000;
972982

973983
pub const AF_SLOW: ::c_int = 33;
974984
pub const AF_SCLUSTER: ::c_int = 34;
@@ -1435,14 +1445,28 @@ pub const UF_READONLY: ::c_ulong = 0x00001000;
14351445
pub const UF_HIDDEN: ::c_ulong = 0x00008000;
14361446
pub const SF_SNAPSHOT: ::c_ulong = 0x00200000;
14371447

1448+
// fcntl commands
1449+
pub const F_ADD_SEALS: ::c_int = 19;
1450+
pub const F_DUP2FD: ::c_int = 10;
1451+
pub const F_DUP2FD_CLOEXEC: ::c_int = 18;
1452+
pub const F_GET_SEALS: ::c_int = 20;
14381453
pub const F_OGETLK: ::c_int = 7;
14391454
pub const F_OSETLK: ::c_int = 8;
14401455
pub const F_OSETLKW: ::c_int = 9;
1441-
pub const F_DUP2FD: ::c_int = 10;
1442-
pub const F_SETLK_REMOTE: ::c_int = 14;
1443-
pub const F_READAHEAD: ::c_int = 15;
14441456
pub const F_RDAHEAD: ::c_int = 16;
1445-
pub const F_DUP2FD_CLOEXEC: ::c_int = 18;
1457+
pub const F_READAHEAD: ::c_int = 15;
1458+
pub const F_SETLK_REMOTE: ::c_int = 14;
1459+
1460+
// for use with F_ADD_SEALS
1461+
pub const F_SEAL_GROW: ::c_int = 4;
1462+
pub const F_SEAL_SEAL: ::c_int = 1;
1463+
pub const F_SEAL_SHRINK: ::c_int = 2;
1464+
pub const F_SEAL_WRITE: ::c_int = 8;
1465+
1466+
// For getrandom()
1467+
pub const GRND_NONBLOCK: ::c_uint = 0x1;
1468+
pub const GRND_RANDOM: ::c_uint = 0x2;
1469+
pub const GRND_INSECURE: ::c_uint = 0x4;
14461470

14471471
// For realhostname* api
14481472
pub const HOSTNAME_FOUND: ::c_int = 0;

0 commit comments

Comments
 (0)