Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to trap write to address (x86 - linux)

Tags:

c++

c

linux

x86

I want to be able to detect when a write to memory address occurs -- for example by setting a callback attached to an interrupt. Does anyone know how?

I'd like to be able to do this at runtime (possibly gdb has this feature, but my particular application causes gdb to crash).

like image 400
user48956 Avatar asked Mar 03 '09 22:03

user48956


1 Answers

If you want to intercept writes to a range of addresses, you can use mprotect() to mark the memory in question as non-writeable, and install a signal handler using sigaction() to catch the resulting SIGSEGV, do your logging or whatever and mark the page as writeable again.

like image 115
Khoth Avatar answered Sep 21 '22 08:09

Khoth