diff --git a/changelog/2000.changed.md b/changelog/2000.changed.md index 39a0bcf738..e6b105417d 100644 --- a/changelog/2000.changed.md +++ b/changelog/2000.changed.md @@ -1 +1 @@ -`mmap`, `mmap_anonymous`, `munmap`, `mremap`, `madvise` and `msync` updated to use `NonNull`. \ No newline at end of file +`mmap`, `mmap_anonymous`, `munmap`, `mremap`, `madvise`, `msync` and `mprotect` updated to use `NonNull`. \ No newline at end of file diff --git a/src/sys/mman.rs b/src/sys/mman.rs index 1d11182ff5..6f9d6aa7f5 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -558,7 +558,7 @@ pub unsafe fn madvise( /// let mut slice: &mut [u8] = unsafe { /// let mem = mmap_anonymous(None, one_k_non_zero, ProtFlags::PROT_NONE, MapFlags::MAP_PRIVATE) /// .unwrap(); -/// mprotect(mem.as_ptr(), ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE).unwrap(); +/// mprotect(mem, ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE).unwrap(); /// std::slice::from_raw_parts_mut(mem.as_ptr().cast(), ONE_K) /// }; /// assert_eq!(slice[0], 0x00); @@ -566,11 +566,11 @@ pub unsafe fn madvise( /// assert_eq!(slice[0], 0xFF); /// ``` pub unsafe fn mprotect( - addr: *mut c_void, + addr: NonNull, length: size_t, prot: ProtFlags, ) -> Result<()> { - Errno::result(libc::mprotect(addr, length, prot.bits())).map(drop) + Errno::result(libc::mprotect(addr.as_ptr(), length, prot.bits())).map(drop) } /// synchronize a mapped region