MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / test_mprotect

Function test_mprotect

tests/mm/mmap.rs:75–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73
74#[test]
75fn test_mprotect() {
76 use rustix::mm::{mmap_anonymous, mprotect, munmap, MapFlags, MprotectFlags, ProtFlags};
77 use std::ptr::null_mut;
78 use std::slice;
79
80 unsafe {
81 let addr = mmap_anonymous(null_mut(), 8192, ProtFlags::READ, MapFlags::PRIVATE).unwrap();
82
83 mprotect(addr, 8192, MprotectFlags::empty()).unwrap();
84 mprotect(addr, 8192, MprotectFlags::READ).unwrap();
85
86 let slice = slice::from_raw_parts(addr.cast::<u8>(), 8192);
87 assert_eq!(slice, &[b'\0'; 8192]);
88
89 munmap(addr, 8192).unwrap();
90 }
91}
92
93#[test]
94fn test_mlock() {

Callers

nothing calls this directly

Calls 3

mmap_anonymousFunction · 0.50
mprotectFunction · 0.50
munmapFunction · 0.50

Tested by

no test coverage detected