3 stable releases
1.1.0 | Feb 26, 2025 |
---|---|
1.0.1 | Feb 22, 2025 |
1.0.0 | Feb 15, 2025 |
#451 in Unix APIs
402 downloads per month
Used in agesafetch
38KB
541 lines
linux-memutils
Basic utilities for reading from physical memory on Linux.
Features
This crate provides modules for:
- Parsing the physical memory map provided by Linux's
/proc/iomem
file. - Tolerantly reading data from the
/dev/mem
character device file without erroring out on inaccessible bytes. - Searching for the system firmware's AGESA version in physical memory.
Usage
Add the dependency to your Cargo.toml
:
[dependencies]
linux-memutils = "1.0.1"
Examples
Obtaining memory regions in /proc/iomem
use linux_memutils::iomem;
fn main() {
let memory_map = iomem::parse_proc_iomem().unwrap();
let third_memory_region = &memory_map[2];
println!("{third_memory_region}");
// => [0x000000000009f000-0x000000000009ffff] (Reserved)
}
Reading bytes from a region in physical memory
use linux_memutils::reader;
use std::fs::File;
fn main() {
// [...]
let file = File::open("/dev/mem").unwrap();
let reader = reader::SkippingBufReader::new(
file,
third_memory_region.start_address,
Some(third_memory_region.end_address),
);
// Our `reader` can now be used similarly to an io:BufReader,
// the key difference being that it skips inaccessible bytes
}
Finding the system firmware's embedded AGESA version
use linux_memutils::agesa;
fn main() {
match agesa::find_agesa_version().unwrap() {
Some(found_version) => {
println!("{}", found_version.agesa_version)
}
None => eprintln!("Did not find AGESA version.")
}
}
⚠️ Note that these examples need to be run with elevated privileges.
Documentation
As usual, the documentation for this library can be found on docs.rs.
License
This project is licensed under the MIT license. See the LICENSE file for more information.
Author
Dependencies
~0.6–1.1MB
~22K SLoC