Struct mmap_rs::MemoryArea

source ·
pub struct MemoryArea { /* private fields */ }
Expand description

Describes a memory area of a process.

Implementations§

source§

impl MemoryArea

source

pub fn range(&self) -> &Range<usize>

The address range of the memory area.

source

pub fn start(&self) -> usize

The start address of the area.

Examples found in repository?
examples/areas.rs (line 10)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}
source

pub fn end(&self) -> usize

The end address of the area.

Examples found in repository?
examples/areas.rs (line 11)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}
source

pub fn protection(&self) -> Protection

The protection with which the memory area has been mapped.

Examples found in repository?
examples/areas.rs (line 12)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}
source

pub fn share_mode(&self) -> ShareMode

The share mode of the memory area.

Examples found in repository?
examples/areas.rs (line 27)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}
source

pub fn path(&self) -> Option<&PathBuf>

The path to the file that backs this memory area, if backed by a file.

Examples found in repository?
examples/areas.rs (line 34)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}
source

pub fn file_offset(&self) -> Option<u64>

The file offset, if backed by a file.

Examples found in repository?
examples/areas.rs (line 33)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
fn main() -> Result<(), Error> {
    let maps = MemoryAreas::open(None)?;

    for area in maps {
        let area = area?;

        println!("{:x}-{:x} {}{}{}{}{}",
            area.start(),
            area.end(),
            if area.protection().contains(Protection::READ) {
                "r"
            } else {
                "-"
            },
            if area.protection().contains(Protection::WRITE) {
                "w"
            } else {
                "-"
            },
            if area.protection().contains(Protection::EXECUTE) {
                "x"
            } else {
                "-"
            },
            if area.share_mode() == ShareMode::Shared {
                "s"
            } else {
                "p"
            },
            format!(" {:x} {}",
                area.file_offset().unwrap_or(0),
                area.path().map(|path| path.display().to_string()).unwrap_or(String::new()),
            ),
        );
    }

    Ok(())
}

Trait Implementations§

source§

impl Clone for MemoryArea

source§

fn clone(&self) -> MemoryArea

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MemoryArea

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.