Introduction to /dev/mem
在Linux的应用态程序中,如何access 系统的physical memory呢?此时,就要用上/dev/mem
了。
Introduction
利用/dev/mem
,通过mmap
可以将物理地址映射到用户空间的虚拟地址上,从而可以access physical memory。
Example code
Access physical memory from Linux user space
1 | int mem_dev = open("/dev/mem", O_RDWR | O_SYNC); |
At the end of this code, if no errors occurred, you have a pointer virt_addr
to the physical memory space from address 0x10001234 to 0x10001334. You can use this pointer in read/write mode but be very carefully since an incorrect modify to some critical memory section will crash the system.
参考资料: