title: Linux C debugging library to detect memory corruptions
body: <p>When working sometimes ago on an embedded system with a simple MMU, I used to program dynamically this MMU to detect memory corruptions.</p>
  
  <p>For instance, at some moment at runtime, the foo variable was overwritten with some unexpected data (probably by a dangling pointer or whatever). So I added the additional debugging code :</p>
  
  <ul>
  <li>at init, the memory used by foo was indicated as a forbidden region to the MMU;</li>
  <li>each time foo was accessed on purpose, access to the region was allowed just before then forbidden just after;</li>
  <li>a MMU irq handler was added to dump the master and the address responsible of the violation.</li>
  </ul>
  
  <p>This was actually some kind of watchpoint, but directly self-handled by the code itself.</p>
  
  <p>Now, I would like to reuse the same trick, but on a x86 platform. The problem is that I am very far from understanding how is working the MMU on this platform, and how it is used by Linux, but I wonder if any library/tool/system call already exist to deal with this problem.</p>
  
  <p>Note that I am aware that various tools exist like Valgrind or GDB to manage memory problems, but as far as I know, none of these tools car be dynamically reconfigured by the debugged code.</p>
  
  <p>I am mainly interested for user space under Linux, but any info on kernel mode or under Windows is also welcome!</p>