From 4c6ba404cbd4d3eabe735486273581e21f728f9a Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 26 Mar 2023 17:07:19 +0100 Subject: [PATCH] netbsd add MAP_ALIGNED macro --- libc-test/semver/netbsd.txt | 1 + src/unix/bsd/netbsdlike/netbsd/mod.rs | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 174396c7202d3..ea2dd956e1af8 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -628,6 +628,7 @@ MADV_NORMAL MADV_RANDOM MADV_SEQUENTIAL MADV_WILLNEED +MAP_ALIGNED MAP_ALIGNMENT_16MB MAP_ALIGNMENT_1TB MAP_ALIGNMENT_256TB diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 87132e2587a92..314d5433a083b 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -1663,13 +1663,13 @@ pub const MAP_WIRED: ::c_int = 0x800; pub const MAP_STACK: ::c_int = 0x2000; // map alignment aliases for MAP_ALIGNED pub const MAP_ALIGNMENT_SHIFT: ::c_int = 24; -pub const MAP_ALIGNMENT_MASK: ::c_int = 0xff << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_64KB: ::c_int = 16 << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_16MB: ::c_int = 24 << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_4GB: ::c_int = 32 << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_1TB: ::c_int = 40 << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_256TB: ::c_int = 48 << MAP_ALIGNMENT_SHIFT; -pub const MAP_ALIGNMENT_64PB: ::c_int = 56 << MAP_ALIGNMENT_SHIFT; +pub const MAP_ALIGNMENT_MASK: ::c_int = MAP_ALIGNED(0xff); +pub const MAP_ALIGNMENT_64KB: ::c_int = MAP_ALIGNED(16); +pub const MAP_ALIGNMENT_16MB: ::c_int = MAP_ALIGNED(24); +pub const MAP_ALIGNMENT_4GB: ::c_int = MAP_ALIGNED(32); +pub const MAP_ALIGNMENT_1TB: ::c_int = MAP_ALIGNED(40); +pub const MAP_ALIGNMENT_256TB: ::c_int = MAP_ALIGNED(48); +pub const MAP_ALIGNMENT_64PB: ::c_int = MAP_ALIGNED(56); // mremap flag pub const MAP_REMAPDUP: ::c_int = 0x004; @@ -2377,6 +2377,19 @@ pub const GRND_NONBLOCK: ::c_uint = 0x1; pub const GRND_RANDOM: ::c_uint = 0x2; pub const GRND_INSECURE: ::c_uint = 0x4; +cfg_if! { + + if #[cfg(libc_const_extern_fn)] { + pub const fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int { + alignment << MAP_ALIGNMENT_SHIFT + } + } else { + pub fn MAP_ALIGNED(alignment: ::c_int) -> ::c_int { + alignment << MAP_ALIGNMENT_SHIFT + } + } +} + const_fn! { {const} fn _ALIGN(p: usize) -> usize { (p + _ALIGNBYTES) & !_ALIGNBYTES