From adf18134c7788b91b126d97017c928cd757053e3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 19 Sep 2021 09:10:07 -0600 Subject: [PATCH] Actually connect the mman tests to the build This was an oversight from #1306. Reported-by: @ocadaruma --- CHANGELOG.md | 2 ++ src/sys/mman.rs | 1 - test/sys/mod.rs | 1 + test/sys/test_mman.rs | 28 ++++++++++++++-------------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9181018707..e8b413c4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,8 @@ This project adheres to [Semantic Versioning](https://semver.org/). (#[1525](https://github.com/nix-rust/nix/pull/1525)) - Added `MAP_ALIGNED_SUPER` mmap flag for freebsd. (#[1522](https://github.com/nix-rust/nix/pull/1522)) +- Added `MAP_ANONYMOUS` for all operating systems. + (#[1534](https://github.com/nix-rust/nix/pull/1534)) ### Changed diff --git a/src/sys/mman.rs b/src/sys/mman.rs index b8a17e5e77..81be3a1986 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -47,7 +47,6 @@ libc_bitflags!{ /// Synonym for `MAP_ANONYMOUS`. MAP_ANON; /// The mapping is not backed by any file. - #[cfg(any(target_os = "android", target_os = "linux", target_os = "freebsd"))] MAP_ANONYMOUS; /// Put the mapping into the first 2GB of the process address space. #[cfg(any(all(any(target_os = "android", target_os = "linux"), diff --git a/test/sys/mod.rs b/test/sys/mod.rs index 14b03784a0..4a27491cc4 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -11,6 +11,7 @@ mod test_signal; target_os = "macos", target_os = "netbsd"))] mod test_aio; +mod test_mman; #[cfg(target_os = "linux")] mod test_signalfd; #[cfg(not(target_os = "redox"))] diff --git a/test/sys/test_mman.rs b/test/sys/test_mman.rs index 4d1409487e..9352142be2 100644 --- a/test/sys/test_mman.rs +++ b/test/sys/test_mman.rs @@ -1,27 +1,24 @@ -use nix::Error; -use nix::libc::{c_void, size_t}; use nix::sys::mman::{mmap, MapFlags, ProtFlags}; -#[cfg(target_os = "linux")] -use nix::sys::mman::{mremap, MRemapFlags}; - #[test] fn test_mmap_anonymous() { - let ref mut byte = unsafe { + unsafe { let ptr = mmap(std::ptr::null_mut(), 1, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS, -1, 0) - .unwrap(); - *(ptr as * mut u8) - }; - assert_eq !(*byte, 0x00u8); - *byte = 0xffu8; - assert_eq !(*byte, 0xffu8); + .unwrap() as *mut u8; + assert_eq !(*ptr, 0x00u8); + *ptr = 0xffu8; + assert_eq !(*ptr, 0xffu8); + } } #[test] #[cfg(any(target_os = "linux", target_os = "netbsd"))] fn test_mremap_grow() { + use nix::sys::mman::{mremap, MRemapFlags}; + use nix::libc::{c_void, size_t}; + const ONE_K : size_t = 1024; let slice : &mut[u8] = unsafe { let mem = mmap(std::ptr::null_mut(), ONE_K, @@ -58,6 +55,9 @@ fn test_mremap_grow() { #[test] #[cfg(any(target_os = "linux", target_os = "netbsd"))] fn test_mremap_shrink() { + use nix::sys::mman::{mremap, MRemapFlags}; + use nix::libc::{c_void, size_t}; + const ONE_K : size_t = 1024; let slice : &mut[u8] = unsafe { let mem = mmap(std::ptr::null_mut(), 10 * ONE_K, @@ -77,9 +77,9 @@ fn test_mremap_shrink() { .unwrap(); // Since we didn't supply MREMAP_MAYMOVE, the address should be the // same. - #[cfg(target_os = "linux")] + #[cfg(target_os = "netbsd")] let mem = mremap(slice.as_mut_ptr() as * mut c_void, 10 * ONE_K, ONE_K, - MRemapFlags::MAP_FIXED), None) + MRemapFlags::MAP_FIXED, None) .unwrap(); assert_eq !(mem, slice.as_mut_ptr() as * mut c_void); std::slice::from_raw_parts_mut(mem as * mut u8, ONE_K)