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 /src/sys | |
parent | 33b5f928ea8e691c89d4b7242d44bdb2c1a62167 (diff) | |
download | nix-63c56263fbaa723693ff91f082c30f3a44259c4f.zip |
mmap non-zero length
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/mman.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/sys/mman.rs b/src/sys/mman.rs index dab8f445..2bee0916 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -418,7 +418,7 @@ pub fn munlockall() -> Result<()> { /// [`mmap(2)`]: https://man7.org/linux/man-pages/man2/mmap.2.html pub unsafe fn mmap( addr: Option<NonZeroUsize>, - length: size_t, + length: NonZeroUsize, prot: ProtFlags, flags: MapFlags, fd: RawFd, @@ -428,8 +428,8 @@ pub unsafe fn mmap( std::ptr::null_mut(), |a| usize::from(a) as *mut c_void ); - - let ret = libc::mmap(ptr, length, prot.bits(), flags.bits(), fd, offset); + + let ret = libc::mmap(ptr, length.into(), prot.bits(), flags.bits(), fd, offset); if ret == libc::MAP_FAILED { Err(Errno::last()) @@ -520,8 +520,9 @@ pub unsafe fn madvise( /// # use nix::sys::mman::{mmap, mprotect, MapFlags, ProtFlags}; /// # use std::ptr; /// const ONE_K: size_t = 1024; +/// let one_k_non_zero = std::num::NonZeroUsize::new(ONE_K).unwrap(); /// let mut slice: &mut [u8] = unsafe { -/// let mem = mmap(None, ONE_K, ProtFlags::PROT_NONE, +/// let mem = mmap(None, one_k_non_zero, ProtFlags::PROT_NONE, /// MapFlags::MAP_ANON | MapFlags::MAP_PRIVATE, -1, 0).unwrap(); /// mprotect(mem, ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE).unwrap(); /// std::slice::from_raw_parts_mut(mem as *mut u8, ONE_K) |