Linux C debug library for memory failure detection

When we sometimes worked in an embedded system with a simple MMU, I dynamically programmed this MMU to detect memory failures.

For example, at some point during runtime, the variable foo was overwritten by some unexpected data (probably with a dangling pointer or something else). So I added extra debugging code:

  • in init, the memory used by foo was specified as a forbidden MMU region;
  • every time foo was specifically available, access to the region was allowed immediately before it was prohibited immediately after;
  • An IRU IRQ handler has been added to reset the master and the address responsible for the violation.

In fact, it was some kind of observation point, but it was directly processed by the code itself.

Now I would like to use the same trick, but on the x86 platform. The problem is that I am very far from understanding how the MMU works on this platform and how it is used by Linux, but I wonder if there is any library / tool / system call to solve this problem.

Please note that I know that there are various tools for managing memory problems, such as Valgrind or GDB, but as far as I know, none of these tools will be dynamically reconfigured by debug code.

I'm mostly interested in user space on Linux, but any information about kernel mode or under Windows is also welcome!

+3
source share
5

mmap (MAP_ANONYMOUS) mprotect . , . .

, . mmap() malloc .

MMU, .

mmap mprotect

+5

:

+2

, , , , . , , - (.. 10 , 10 ).

+1

mprotect() - , . .

x86 Linux - 4096 . , , . - posix_memalign() , 4096 4096 ( sysconf(_SC_PAGESIZE) , ). , gcc __attribute__ ((aligned (4096)) .

IRQ MMU SIGSEGV, sa_sigaction , sigaction(). siginfo_t , sa_addr, .

+1

, . . .

Valgrind, Valgrind .

0

Source: https://habr.com/ru/post/1743550/


All Articles