views:

29

answers:

0

I am trying to catch write faults on write protected memory pages from my program. I have done following to achieve this :

  1. protect memory page using mprotect() : allowing only read access
  2. register signal handler for SIGSEGV called write-fault-handler using sigaction()
  3. inside signal handler :
    1. siginfo->si_addr gives me memory address where write Fault occurs.

However, when I return from signal handler , same statement is executed and I get write fault on the same memroy address again and again.

I tried to solve this problem by removing write protection inside signal handler. But in that case , the write protectionn for entire page has to be removed and then I am not able to catch the next write fault on the same page.

Is there any way to oversome this problem ?