Skip to content

Commit

Permalink
Merge #1534
Browse files Browse the repository at this point in the history
1534: Actually connect the mman tests to the build r=asomers a=asomers

This was an oversight from #1306.

Reported-by:	`@ocadaruma`

Co-authored-by: Alan Somers <[email protected]>
  • Loading branch information
bors[bot] and asomers authored Sep 19, 2021
2 parents 8cb9dc5 + f2be3c3 commit e94bf0e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions test/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down
30 changes: 16 additions & 14 deletions test/sys/test_mman.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit e94bf0e

Please sign in to comment.