Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the physical address of a variable from user-space in Linux?

Tags:

c

linux

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?

like image 774
Sandip Avatar asked Mar 13 '10 23:03

Sandip


People also ask

How do I find physical address in Linux?

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.

How do I find virtual address in Linux?

In Linux, you can use these functions from asm/io. h : virt_to_phys(virt_addr);

Which call we can use to get the virtual address in Linux kernel?

page_address() returns the virtual address of a struct page ; this functions can be called only for pages from lowmem.


1 Answers

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:

  1. /proc/$pid/maps provides a list of mappings of virtual addresses together with additional information, such as the corresponding file for mapped files.
  2. /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.

like image 126
ingomueller.net Avatar answered Sep 20 '22 14:09

ingomueller.net