| Crates.io | region |
| lib.rs | region |
| version | 3.0.2 |
| created_at | 2016-11-06 15:09:42.831638+00 |
| updated_at | 2024-03-25 08:23:23.185308+00 |
| description | Cross-platform virtual memory API |
| homepage | https://github.com/darfink/region-rs |
| repository | https://github.com/darfink/region-rs |
| max_upload_size | |
| id | 7147 |
| size | 88,197 |
This crate provides a cross-platform Rust API for allocating, querying and
manipulating virtual memory. It is a thin abstraction, with the underlying
interaction implemented using platform specific APIs (e.g VirtualQuery,
VirtualAlloc, VirtualLock, mprotect, mmap, mlock).
This library is continuously tested against these targets:
aarch64-linux-androidarmv7-unknown-linux-gnueabihfi686-unknown-linux-gnumips-unknown-linux-gnux86_64-unknown-linux-gnux86_64-unknown-linux-musli686-pc-windows-gnui686-pc-windows-msvcx86_64-pc-windows-gnux86_64-pc-windows-msvcx86_64-apple-darwinx86_64-unknown-netbsdx86_64-unknown-freebsdx86_64-unknown-openbsd... and continuously checked against these targets:
x86_64-unknown-illumosBeyond the aformentioned target triplets, the library is also expected to work against a multitude of omitted architectures.
Add this to your Cargo.toml:
[dependencies]
region = "3.0.2"
let data = [0xDE, 0xAD, 0xBE, 0xEF];
// Page size
let pz = region::page::size();
// VirtualQuery | '/proc/self/maps'
let q = region::query(data.as_ptr())?;
let qr = region::query_range(data.as_ptr(), data.len())?;
// VirtualAlloc | mmap
let alloc = region::alloc(100, Protection::READ_WRITE)?;
// VirtualProtect | mprotect
region::protect(data.as_ptr(), data.len(), Protection::READ_WRITE_EXECUTE)?;
// ... you can also temporarily change one or more pages' protection
let handle = region::protect_with_handle(data.as_ptr(), data.len(), Protection::READ_WRITE_EXECUTE)?;
// VirtualLock | mlock
let guard = region::lock(data.as_ptr(), data.len())?;