File: iomem.rs

package info (click to toggle)
rust-procfs 0.17.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 664 kB
  • sloc: makefile: 2
file content (22 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
// Print physical location of system RAM
// This requires CAP_SYS_ADMIN privilege, or root, otherwise physical memory addresses will be zero
//

fn main() {
    if !rustix::process::geteuid().is_root() {
        println!("WARNING: Access to /proc/iomem requires root, re-run with sudo");
    }

    let iomem = procfs::iomem().expect("Can't read /proc/iomem");

    for (_indent, map) in iomem.iter() {
        if map.name == "System RAM" {
            println!("Found RAM here: 0x{:x}-0x{:x}", map.address.0, map.address.1);
        }
    }

    if !rustix::process::geteuid().is_root() {
        println!("\n\nWARNING: Access to /proc/iomem requires root, re-run with sudo");
    }
}