18 releases (5 stable)

2.1.2 Jun 20, 2019
2.0.0 Jan 3, 2019
1.0.0 Oct 23, 2018
0.3.0 May 4, 2018
0.0.3 Nov 30, 2016

#30 in Concurrency

Download history 298/week @ 2019-04-12 261/week @ 2019-04-19 198/week @ 2019-04-26 150/week @ 2019-05-03 165/week @ 2019-05-10 248/week @ 2019-05-17 275/week @ 2019-05-24 238/week @ 2019-05-31 459/week @ 2019-06-07 252/week @ 2019-06-14 626/week @ 2019-06-21 382/week @ 2019-06-28 273/week @ 2019-07-05 303/week @ 2019-07-12 429/week @ 2019-07-19

1,093 downloads per month
Used in 22 crates (13 directly)

MIT license

37KB
780 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 has (so far) support for:

  • Windows
  • Linux & Android
  • macOS & iOS
  • FreeBSD

Installation

Add this to your Cargo.toml:

[dependencies]
region = "2.1.2"

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::ReadWriteExecute)?;

// ... you can also temporarily change a region's protection
let handle = region::protect_with_handle(data.as_ptr(), data.len(), Protection::ReadWriteExecute)?;

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

Dependencies

~795KB