Function region::query_range[][src]

pub fn query_range<T>(address: *const T, size: usize) -> Result<QueryIter>
Expand description

Queries the OS for mapped regions that overlap with the specified range.

The implementation clamps any input that exceeds the boundaries of a process’ address space. Therefore it’s safe to, e.g., pass in std::ptr::null and usize::max_value to iterate the mapped memory pages of an entire process.

If an error is encountered during iteration, the error will be the last item that is yielded. Thereafter the iterator becomes fused.

A 2-byte range straddling a page boundary, will return both pages (or one region, if the pages share the same properties).

This function only returns mapped regions. If required, unmapped regions can be manually identified by inspecting the potential gaps between two neighboring regions.


  • The range is [address, address + size)
  • The address is rounded down to the closest page boundary.
  • The size may not be zero.
  • The size is rounded up to the closest page boundary, relative to the address.


  • If an interaction with the underlying operating system fails, an error will be returned.
  • If size is zero, Error::InvalidParameter will be returned.


let data = [0; 100];
let region = region::query_range(data.as_ptr(), data.len())?

assert_eq!(region.len(), 1);
assert_eq!(region[0].protection(), region::Protection::READ_WRITE);