[][src]Crate region

A library for manipulating memory regions

This crate provides several functions for handling memory pages and regions. It is implemented using platform specific APIs. The library exposes both low and high level functionality for manipulating pages.

Not all OS specific quirks are abstracted away. For instance; some OSs enforce memory pages to be readable whilst other may prevent pages from becoming executable (i.e DEP).

Note: a region is a collection of one or more pages laying consecutively in memory, with the same properties.

Installation

This crate is on crates.io and can be used by adding region to your dependencies in your project's Cargo.toml.

[dependencies]
region = "2.1.1"

and this to your crate root:

extern crate region;

Examples

  • 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())?;

Modules

page

Page related functions.

Structs

LockGuard

An RAII implementation of a "scoped lock". When this structure is dropped (falls out of scope), the virtual lock will be unlocked.

ProtectGuard

An RAII implementation of "scoped protection". When this structure is dropped (falls out of scope), the memory region protection will be reset.

Protection

Memory page protection constants.

Region

A descriptor for a memory region

Enums

Error

A collection of possible errors.

Functions

lock

Locks one or more memory regions to RAM.

protect

Changes the memory protection of one or more pages.

protect_with_handle

Changes the memory protection of one or more pages temporarily.

query

Queries the OS with an address, returning the region it resides within.

query_range

Queries the OS with a range, returning the regions it contains.

unlock

Unlocks one or more memory regions from RAM.

Type Definitions

Result

The result type used by this library.