summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/sys/mman.rs1
-rw-r--r--test/sys/mod.rs2
-rw-r--r--test/sys/test_mman.rs30
4 files changed, 20 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 25de15fe..52104501 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -48,6 +48,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
(#[1522](https://github.com/nix-rust/nix/pull/1522))
- Added `MAP_CONCEAL` mmap flag for openbsd.
(#[1531](https://github.com/nix-rust/nix/pull/1531))
+- 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 803dc50d..bcbe27e2 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 14b03784..e73d9b1d 100644
--- a/test/sys/mod.rs
+++ b/test/sys/mod.rs
@@ -11,6 +11,8 @@ mod test_signal;
target_os = "macos",
target_os = "netbsd"))]
mod test_aio;
+#[cfg(not(target_os = "redox"))]
+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 4d140948..a7ceedcb 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,
@@ -57,7 +54,12 @@ fn test_mremap_grow() {
#[test]
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
+// Segfaults for unknown reasons under QEMU for 32-bit targets
+#[cfg_attr(all(target_pointer_width = "32", qemu), ignore)]
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 +79,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)