Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a better way than parsing /proc/self/maps to figure out memory protection?
    primarykey
    data
    text
    <p>On Linux (or Solaris) is there a better way than hand parsing <code>/proc/self/maps</code> repeatedly to figure out whether or not you can read, write or execute whatever is stored at one or more addresses in memory?</p> <p>For instance, in Windows you have <code>VirtualQuery</code>. </p> <p>In Linux, I can <code>mprotect</code> to change those values, but I can't read them back.</p> <p>Furthermore, is there any way to know when those permissions change (e.g. when someone uses <code>mmap</code> on a file behind my back) other than doing something terribly invasive and using <code>ptrace</code> on all threads in the process and intercepting any attempt to make a <code>syscall</code> that could affect the memory map?</p> <p><strong>Update:</strong></p> <p>Unfortunately, I'm using this inside of a JIT that has very little information about the code it is executing to get an approximation of what is constant. Yes, I realize I could have a constant map of mutable data, like the vsyscall page used by Linux. I <em>can</em> safely fall back on an assumption that anything that isn't included in the initial parse is mutable and dangerous, but I'm not entirely happy with that option.</p> <p>Right now what I do is I read <code>/proc/self/maps</code> and build a structure I can binary search through for a given address's protection. Any time I need to know something about a page that isn't in my structure I reread /proc/self/maps assuming it has been added in the meantime or I'd be about to segfault anyways.</p> <p>It just seems that parsing text to get at this information and not knowing when it changes is awfully crufty. (<code>/dev/inotify</code> doesn't work on pretty much anything in <code>/proc</code>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload