3 unstable releases
0.3.0 | Sep 25, 2023 |
---|---|
0.2.1 | Feb 25, 2023 |
0.2.0 | Feb 24, 2023 |
0.1.0 |
|
0.0.1 |
|
#838 in Unix APIs
10KB
89 lines
peekpoke
A lightweight Rust library used for reading and writing from physical memory address using /dev/mem
.
In Linux, /dev/mem
is a character device file containing access to the physical memory in a system. This file can be used to read and write to physical addresses on the bare metal (or virtualized) hardware. This functionality for user-space applications is similar to the devmem
cli utility in busybox.
For more information, refer to the linux kernel manual.
Requirements
- Linux (WSL, Debian, Fedora, Arch)
- Sudo permissions
Usage
Add this to your Cargo.toml
:
[dependencies]
peekpoke = "0.3"
Example
let address: u32 = 0x4000_0000;
let value: u32 = 0xDEAD_BEEF;
peekpoke::write(address, value);
let result: u32 = peekpoke::read(address);
println!("{:#010X}", result); // 0xDEAD_BEEF
Troubleshooting
Access denied to /dev/mem
- Configure your kernel with
CONFIG_STRICT_DEVMEM=n
(RECCOMENDED). The default kernel configuration denies access to RAM using/dev/mem
(default:CONFIG_STRICT_DEVMEM=y
) for non root users. - Run as root user.
Address invalid
The default behavior for /dev/mem
is to return errors if the address you enter is invalid. Refer to your hardware's manual for further troubleshooting steps.
Cross Compiling
For embedded systems development, it may be useful to cross compile your app to run on a different architecture. For more information on this process, check out this example GitHub repo for Rust cross-compiling.
License
Peekpoke is distributed under the terms of the MIT license. See terms and conditions here.
No runtime deps
~0–2MB
~42K SLoC