# `region-rs` ## Cross-platform virtual memory API [![GitHub CI Status][github-shield]][github] [![crates.io version][crate-shield]][crate] [![Documentation][docs-shield]][docs] [![License][license-shield]][license]

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:

... and continuously checked against these targets:

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:

toml [dependencies] region = "3.0.0"

Example

// Page size let pz = region::page::size();

// VirtualQuery | '/proc/self/maps' let q = region::query(data.asptr())?; let qr = region::queryrange(data.as_ptr(), data.len())?;

// VirtualAlloc | mmap let alloc = region::alloc(100, Protection::READ_WRITE)?;

// VirtualProtect | mprotect region::protect(data.asptr(), data.len(), Protection::READWRITE_EXECUTE)?;

// ... you can also temporarily change one or more pages' protection let handle = region::protectwithhandle(data.asptr(), data.len(), Protection::READWRITE_EXECUTE)?;

// VirtualLock | mlock let guard = region::lock(data.as_ptr(), data.len())?; ```