title: Linux (Ubuntu), C language: Virtual to Physical Address Translation
body: <p>As the title suggests, I have a problem of obtaining the physical address from a virtual one.</p>
  
  <p>Let me explain: Given a variable declaration in process space, how can I derive it's physical address mapped by the OS?</p>
  
  <p>I've stumbled upon some sys calls <code>/asm/io.h</code> where the <code>virt_to_phys()</code> function is defined; however it seems this header is outdated and I can't find a work around. </p>
  
  <p>However; <code>io.h</code> is available at: <code>/usr/src/linux-headers-2.6.35-28-generic/arch/x86/include/asm/</code>. My current kernel is <code>2.6.35-28</code>, but <code>io.h</code> isn't included in <code>/usr/include/asm/</code>?</p>
  
  <p>So, to reiterate: I need a way to get the physical address from virtual. Preferably derived from within the application at runtime. But even a workaround of using a monitor of <code>/proc/PID/maps</code> will do.</p>
  
  <p>Any ideas or comments would be greatly appreciated.</p>
  
  <hr>
  
  <p><em>EDIT</em>
  After doing a bit of research on this topic I found something that helps in this regard.</p>
  
  <p>It turns out this is more than doable, although requires a bit of a workaround.
  Here is a <a href="http://eqware.net/Articles/CapturingProcessMemoryUsageUnderLinux/index.html" rel="nofollow">link</a> to a simple app that analyses the current mapped pages.
  The file in question turns out is (a binary file) <code>/proc/pid/pagemap</code> (contains the physical mapping of virtual pages). Anyway, the code in that link can be modified to serve as a monitor app or something.</p>
  
  <p>I needed the physical address for cache simulation purposes.</p>
  
  <p>Thanks for all the help and answers!</p>