I’m curious if
mprotect can be used successfully in Rust. It’ll basically set memory permissions as far as the address range provided to it is aligned to memory page boundaries. I did some testing to see if it can work in Rust:
let y: i32 = 10; let addr = &y as *const _; let mut aligned = (addr as i32) & !(pagesize-1); //pagesize == 4096 //mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int let r = mprotect(aligned as *mut c_void, pagesize as usize, 1);
This code will fail with errno set to 12 (Cannot allocate memory).
Is there a way to make this work? Or perhaps is there any other way to set memory page permissions in Rust?