I am trying to catch write faults on write protected memory pages from my program. I have done following to achieve this :
- protect memory page using mprotect() : allowing only read access
- register signal handler for SIGSEGV called write-fault-handler using sigaction()
- inside signal handler :
- 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 ?