pub unsafe fn pkey_mprotect(
    addr: *mut c_void,
    length: size_t,
    prot: ProtFlags,
    pkey: RawPkey,
) -> Result<()> {
    Errno::result(libc::syscall(
        libc::SYS_pkey_mprotect,
        addr,
        length,
        prot.bits(),
        pkey,
    ))
    .map(drop)
}
// almost same test code of nix's mprotect
/// Set protection with a protection key on a region of memory.
///
/// Calls to pkey_mprotect are inherently unsafe, as changes to memory protection can lead to
/// SIGSEGVs.
///
/// ```
/// # use nix::libc::size_t;
/// # use nix::sys::mman::{mmap, mprotect, MapFlags, ProtFlags};
/// # use std::ptr;
/// # use pkeys::{pkey_alloc, pkey_free, pkey_mprotect, PkeyAccessRights};
/// const ONE_K: size_t = 1024;
/// let pkey = pkey_alloc(0, PkeyAccessRights::PKEY_NONE).unwrap();
/// 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();
///     pkey_mprotect(mem, ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, pkey).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);
/// pkey_free(pkey).unwrap();
/// ```
almost same test code of nix's mprotect
Set protection with a protection key on a region of memory.

Calls to pkey_mprotect are inherently unsafe, as changes to memory protection can lead to
SIGSEGVs.


almost same test code of nix ' s mprotect Set protection with a protection key on a region of memory . Calls to pkey_mprotect are inherently unsafe as changes to memory protection can lead to SIGSEGVs .
pub unsafe fn pkey_mprotect(
    addr: *mut c_void,
    length: size_t,
    prot: ProtFlags,
    pkey: RawPkey,
) -> Result<()> {
    Errno::result(libc::syscall(
        libc::SYS_pkey_mprotect,
        addr,
        length,
        prot.bits(),
        pkey,
    ))
    .map(drop)
}
pub unsafe fn pkey_mprotect ( addr : * mut c_void , length : size_t , prot : ProtFlags , pkey : RawPkey , ) -> Result < ( ) > { Errno :: result ( libc :: syscall ( libc :: SYS_pkey_mprotect , addr , length , prot . bits ( ) , pkey , ) ) . map ( drop ) }
almost same test code of nix's mprotect
Set protection with a protection key on a region of memory.
almost same test code of nix ' s mprotect Set protection with a protection key on a region of memory .
addr
*mut c_void
length
size_t
prot
ProtFlags
pkey
RawPkey
addr
*mut c_void
length
size_t
prot
ProtFlags
pkey
RawPkey
use nix::libc::size_t;
None
use nix::sys::mman::{mmap, mprotect, mapflags, protflags};
None
use std::ptr;
None
use pkeys::{pkey_alloc, pkey_free, pkey_mprotect, pkeyaccessrights};
const ONE_K: size_t = 1024;
let pkey = pkey_alloc(0, PkeyAccessRights::PKEY_NONE).unwrap();
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();
pkey_mprotect(mem, ONE_K, ProtFlags::PROT_READ | ProtFlags::PROT_WRITE, pkey).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);
pkey_free(pkey).unwrap();
```
const ONE_K : size_t = 1024 ; let pkey = pkey_alloc ( 0 PkeyAccessRights :: PKEY_NONE ) . unwrap () ; 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 () ; pkey_mprotect ( mem ONE_K ProtFlags :: PROT_READ | ProtFlags :: PROT_WRITE pkey ) . 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 ) ; pkey_free ( pkey ) . unwrap () ; ` ` `