I want to find the physical address of a variable defined in a user-space process? Is there any way to do it using root privileges?
Linux. Open a terminal and use the ifconfig command. The MAC address will be listed next to HWaddr. If your Linux OS does not have the ifconfig command, you may also use the ip addr command.
In Linux, you can use these functions from asm/io. h : virt_to_phys(virt_addr);
page_address() returns the virtual address of a struct page ; this functions can be called only for pages from lowmem.
As partially answered before, normal programs should not need to worry about physical addresses as they run in a virtual address space with all its conveniences. Furthermore, not every virtual address has a physical address, the may belong to mapped files or swapped pages. However, sometimes it may be interesting to see this mapping, even in userland.
For this purpose, the Linux kernel exposes its mapping to userland through a set of files in the /proc
. The documentation can be found here. Short summary:
/proc/$pid/maps
provides a list of mappings of virtual addresses together with additional information, such as the corresponding file for mapped files./proc/$pid/pagemap
provides more information about each mapped page, including the physical address if it exists.This website provides a C program that dumps the mappings of all running processes using this interface and an explanation of what it does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With