From 441f19576f577420bd8733891845c22d8f6610fd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Nov 2021 11:06:06 +0100 Subject: [PATCH] Mark consts to be ignored depending on freebsd version --- libc-test/build.rs | 30 +++++++++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 60 +++++++------------------ 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index d00e8bf2aec88..e0ccb90f5b23a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2063,6 +2063,36 @@ fn test_freebsd(target: &str) { "VM_TOTAL" if Some(11) == freebsd_ver => true, + // Added in FreeBSD 14. + "KERN_STACKTOP" if Some(14) > freebsd_ver => true, + // Added in FreeBSD 13. + "KERN_PROC_SIGFASTBLK" + | "USER_LOCALBASE" + | "TDP_SIGFASTBLOCK" + | "TDP_UIOHELD" + | "TDP_SIGFASTPENDING" + | "TDP2_COMPAT32RB" + | "P2_PROTMAX_ENABLE" + | "P2_PROTMAX_DISABLE" + | "CTLFLAG_NEEDGIANT" + | "CTL_SYSCTL_NEXTNOSKIP" + if Some(13) > freebsd_ver => + { + true + } + // Added in FreeBSD 12. + "KERN_MAXPHYS" + | "KVME_FLAG_USER_WIRED" + | "TDP2_SBPAGES" + | "P2_ASLR_ENABLE" + | "P2_ASLR_DISABLE" + | "P2_ASLR_IGNSTART" + | "P_TREE_GRPEXITED" + if Some(12) > freebsd_ver => + { + true + } + _ => false, } }); diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 6a0d248c2360f..0e66304f630c8 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -909,11 +909,7 @@ pub const CTLFLAG_CAPWR: ::c_int = 0x00004000; pub const CTLFLAG_STATS: ::c_int = 0x00002000; pub const CTLFLAG_NOFETCH: ::c_int = 0x00001000; pub const CTLFLAG_CAPRW: ::c_int = CTLFLAG_CAPRD | CTLFLAG_CAPWR; -cfg_if! { - if #[cfg(any(freebsd13, freebsd14))] { - pub const CTLFLAG_NEEDGIANT: ::c_int = 0x00000800; - } -} +pub const CTLFLAG_NEEDGIANT: ::c_int = 0x00000800; pub const CTLSHIFT_SECURE: ::c_int = 20; pub const CTLFLAG_SECURE1: ::c_int = CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE); @@ -929,11 +925,7 @@ pub const CTL_SYSCTL_NAME2OID: ::c_int = 3; pub const CTL_SYSCTL_OIDFMT: ::c_int = 4; pub const CTL_SYSCTL_OIDDESCR: ::c_int = 5; pub const CTL_SYSCTL_OIDLABEL: ::c_int = 6; -cfg_if! { - if #[cfg(any(freebsd13, freebsd14))] { - pub const CTL_SYSCTL_NEXTNOSKIP: ::c_int = 7; - } -} +pub const CTL_SYSCTL_NEXTNOSKIP: ::c_int = 7; pub const KERN_OSTYPE: ::c_int = 1; pub const KERN_OSRELEASE: ::c_int = 2; @@ -1004,11 +996,7 @@ pub const KERN_PROC_OSREL: ::c_int = 40; pub const KERN_PROC_SIGTRAMP: ::c_int = 41; pub const KERN_PROC_CWD: ::c_int = 42; pub const KERN_PROC_NFDS: ::c_int = 43; -cfg_if! { - if #[cfg(any(freebsd13, freebsd14))] { - pub const KERN_PROC_SIGFASTBLK: ::c_int = 44; - } -} +pub const KERN_PROC_SIGFASTBLK: ::c_int = 44; pub const KIPC_MAXSOCKBUF: ::c_int = 1; pub const KIPC_SOCKBUF_WASTE: ::c_int = 2; @@ -1051,11 +1039,7 @@ pub const USER_POSIX2_SW_DEV: ::c_int = 17; pub const USER_POSIX2_UPE: ::c_int = 18; pub const USER_STREAM_MAX: ::c_int = 19; pub const USER_TZNAME_MAX: ::c_int = 20; -cfg_if! { - if #[cfg(any(freebsd13, freebsd14))] { - pub const USER_LOCALBASE: ::c_int = 21; - } -} +pub const USER_LOCALBASE: ::c_int = 21; pub const CTL_P1003_1B_ASYNCHRONOUS_IO: ::c_int = 1; pub const CTL_P1003_1B_MAPPED_FILES: ::c_int = 2; @@ -1862,11 +1846,7 @@ pub const KVME_FLAG_NOCOREDUMP: ::c_int = 0x00000004; 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, freebsd14))] { - pub const KVME_FLAG_USER_WIRED: ::c_int = 0x00000040; - } -} +pub const KVME_FLAG_USER_WIRED: ::c_int = 0x00000040; pub const KKST_MAXLEN: ::c_int = 1024; /// Stack is valid. @@ -2127,25 +2107,17 @@ pub const SLOCK: ::c_char = 7; pub const P_MAGIC: ::c_int = 0xbeefface; -cfg_if! { - if #[cfg(any(freebsd13, freebsd14))] { - pub const TDP_SIGFASTBLOCK: ::c_int = 0x00000100; - pub const TDP_UIOHELD: ::c_int = 0x10000000; - pub const TDP_SIGFASTPENDING: ::c_int = 0x80000000; - pub const TDP2_COMPAT32RB: ::c_int = 0x00000002; - pub const P2_PROTMAX_ENABLE: ::c_int = 0x00000200; - pub const P2_PROTMAX_DISABLE: ::c_int = 0x00000400; - } -} -cfg_if! { - if #[cfg(any(freebsd12, freebsd13, freebsd14))] { - pub const TDP2_SBPAGES: ::c_int = 0x00000001; - pub const P2_ASLR_ENABLE: ::c_int = 0x00000040; - pub const P2_ASLR_DISABLE: ::c_int = 0x00000080; - pub const P2_ASLR_IGNSTART: ::c_int = 0x00000100; - pub const P_TREE_GRPEXITED: ::c_int = 0x00000008; - } -} +pub const TDP_SIGFASTBLOCK: ::c_int = 0x00000100; +pub const TDP_UIOHELD: ::c_int = 0x10000000; +pub const TDP_SIGFASTPENDING: ::c_int = 0x80000000; +pub const TDP2_COMPAT32RB: ::c_int = 0x00000002; +pub const P2_PROTMAX_ENABLE: ::c_int = 0x00000200; +pub const P2_PROTMAX_DISABLE: ::c_int = 0x00000400; +pub const TDP2_SBPAGES: ::c_int = 0x00000001; +pub const P2_ASLR_ENABLE: ::c_int = 0x00000040; +pub const P2_ASLR_DISABLE: ::c_int = 0x00000080; +pub const P2_ASLR_IGNSTART: ::c_int = 0x00000100; +pub const P_TREE_GRPEXITED: ::c_int = 0x00000008; const_fn! { {const} fn _ALIGN(p: usize) -> usize {