19 releases (6 stable)

2.2.0 May 28, 2020
2.1.2 Jun 20, 2019
2.0.0 Jan 3, 2019
1.0.0 Oct 23, 2018
0.0.3 Nov 30, 2016

#12 in Concurrency

Download history 5317/week @ 2020-03-25 4867/week @ 2020-04-01 3928/week @ 2020-04-08 7310/week @ 2020-04-15 7607/week @ 2020-04-22 7052/week @ 2020-04-29 5850/week @ 2020-05-06 6742/week @ 2020-05-13 5485/week @ 2020-05-20 6341/week @ 2020-05-27 6769/week @ 2020-06-03 7011/week @ 2020-06-10 6744/week @ 2020-06-17 6941/week @ 2020-06-24 6582/week @ 2020-07-01 5451/week @ 2020-07-08

25,754 downloads per month
Used in 43 crates (19 directly)

MIT license

40KB
800 lines

region

Azure build Status Cirrus build status crates.io version Documentation Language (Rust)

A Rust library for dealing with memory regions.

It is implemented using platform specific APIs (e.g VirtualQuery, VirtualLock, mprotect, mlock).

Platforms

This library provides CI for the following targets:

  • Linux
    • aarch64-linux-android
    • armv7-unknown-linux-gnueabihf
    • i686-unknown-linux-gnu
    • x86_64-unknown-linux-gnu
  • Windows
    • x86_64-pc-windows-gnu
    • x86_64-pc-windows-msvc
  • macOS
    • x86_64-apple-darwin
  • FreeBSD
    • x86_64-unknown-freebsd

Installation

Add this to your Cargo.toml:

[dependencies]
region = "2.2.0"

and this to your crate root:

extern crate region;

Example

  • Cross-platform equivalents:
let data = [0xDE, 0xAD, 0xBE, 0xEF];

// Page size
let pz = region::page::size();
let pc = region::page::ceil(1234);
let pf = region::page::floor(1234);

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

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

// ... you can also temporarily change a region's 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())?;

Dependencies

~100KB