-
Notifications
You must be signed in to change notification settings - Fork 696
mmap non-zero length #1873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mmap non-zero length #1873
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -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(), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would be worthwhile to bring in the nonzero_ext crate just for these tests?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point no, but if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BTW, I took a look through my other crates and found exactly zero places where nonzero_ext would help. It turns out that |
||||||
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, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ONE_K
is no longer usedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to fix this.