Function nix::sys::mman::mprotect [−][src]
Expand description
Set protection of memory mapping.
See mprotect(3)
for
details.
Safety
Calls to mprotect
are inherently unsafe, as changes to memory protections can lead to
SIGSEGVs.
const ONE_K: size_t = 1024;
let mut slice: &mut [u8] = unsafe {
let mem = mmap(ptr::null_mut(), ONE_K, 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)
};
assert_eq!(slice[0], 0x00);
slice[0] = 0xFF;
assert_eq!(slice[0], 0xFF);