diff options
author | Jonathan <jonathanwoollettlight@gmail.com> | 2022-11-20 22:53:34 +0000 |
---|---|---|
committer | Jonathan <jonathanwoollettlight@gmail.com> | 2022-11-20 22:53:40 +0000 |
commit | 63c56263fbaa723693ff91f082c30f3a44259c4f (patch) | |
tree | caf82e9d5d3cf708477e31509ad4940416eb0c34 /test/sys/test_mman.rs | |
parent | 33b5f928ea8e691c89d4b7242d44bdb2c1a62167 (diff) | |
download | nix-63c56263fbaa723693ff91f082c30f3a44259c4f.zip |
mmap non-zero length
Diffstat (limited to 'test/sys/test_mman.rs')
-rw-r--r-- | test/sys/test_mman.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/test/sys/test_mman.rs b/test/sys/test_mman.rs index a43991c2..e748427b 100644 --- a/test/sys/test_mman.rs +++ b/test/sys/test_mman.rs @@ -1,11 +1,12 @@ use nix::sys::mman::{mmap, MapFlags, ProtFlags}; +use std::num::NonZeroUsize; #[test] fn test_mmap_anonymous() { unsafe { let ptr = mmap( None, - 1, + NonZeroUsize::new(1).unwrap(), ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS, -1, @@ -25,10 +26,12 @@ fn test_mremap_grow() { use nix::sys::mman::{mremap, MRemapFlags}; const ONE_K: size_t = 1024; + let one_k_non_zero = NonZeroUsize::new(ONE_K).unwrap(); + let slice: &mut [u8] = unsafe { let mem = mmap( None, - ONE_K, + one_k_non_zero, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_ANONYMOUS | MapFlags::MAP_PRIVATE, -1, @@ -79,12 +82,14 @@ fn test_mremap_grow() { fn test_mremap_shrink() { use nix::libc::{c_void, size_t}; use nix::sys::mman::{mremap, MRemapFlags}; + use std::num::NonZeroUsize; const ONE_K: size_t = 1024; + let ten_one_k = NonZeroUsize::new(10 * ONE_K).unwrap(); let slice: &mut [u8] = unsafe { let mem = mmap( None, - 10 * ONE_K, + ten_one_k, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, MapFlags::MAP_ANONYMOUS | MapFlags::MAP_PRIVATE, -1, @@ -100,7 +105,7 @@ fn test_mremap_shrink() { let slice: &mut [u8] = unsafe { let mem = mremap( slice.as_mut_ptr() as *mut c_void, - 10 * ONE_K, + ten_one_k.into(), ONE_K, MRemapFlags::empty(), None, |