region-rs
Cross-platform virtual memory API
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
).
Platforms
This library is continuously tested against these targets:
- Linux
aarch64-linux-android
armv7-unknown-linux-gnueabihf
i686-unknown-linux-gnu
mips-unknown-linux-gnu
x86_64-unknown-linux-gnu
x86_64-unknown-linux-musl
- Windows
i686-pc-windows-gnu
i686-pc-windows-msvc
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc
- macOS
x86_64-apple-darwin
- NetBSD
x86_64-unknown-netbsd
- FreeBSD
x86_64-unknown-freebsd
- OpenBSD
x86_64-unknown-openbsd
... and continuously checked against these targets:
- Illumos
x86_64-unknown-illumos
Beyond the aformentioned target triplets, the library is also expected to work against a multitude of omitted architectures.
Installation
Add this to your Cargo.toml
:
[]
= "3.0.2"
Example
- Cross-platform equivalents:
let data = ;
// Page size
let pz = size;
// VirtualQuery | '/proc/self/maps'
let q = query?;
let qr = query_range?;
// VirtualAlloc | mmap
let alloc = alloc?;
// VirtualProtect | mprotect
protect?;
// ... you can also temporarily change one or more pages' protection
let handle = protect_with_handle?;
// VirtualLock | mlock
let guard = lock?;