#region #page #lock #maps #protect

region

A library for manipulating memory regions

17 releases (4 stable)

new 2.1.1 Jun 11, 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

#31 in Concurrency

Download history 353/week @ 2019-02-26 458/week @ 2019-03-05 557/week @ 2019-03-12 277/week @ 2019-03-19 342/week @ 2019-03-26 243/week @ 2019-04-02 161/week @ 2019-04-09 333/week @ 2019-04-16 213/week @ 2019-04-23 204/week @ 2019-04-30 152/week @ 2019-05-07 176/week @ 2019-05-14 307/week @ 2019-05-21 281/week @ 2019-05-28 271/week @ 2019-06-04

1,125 downloads per month
Used in 8 crates (6 directly)

MIT license

37KB
781 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.1"

and this to your crate root:

extern crate region;

Example

  • Cross-platform equivalents:
let ret5 = [0xB8, 0x05, 0x00, 0x00, 0x00, 0xC3];

// 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(ret5.as_ptr())?;
let qr = region::query_range(ret5.as_ptr(), ret5.len())?;

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

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

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

Dependencies

~782KB