I'm capturing a SIGSEGV
on a read/write to a known block of memory. The block is mmaped and under my control, so it can be manipulated. I'd like to simulate the read/write succeeding, actually process the data and continue the application. I've got two possible solutions, but they all seem too complicated. I'm hoping there's a better way to achieve this:
Borrow the trick from debuggers and:
- mmap the area and protect
- wait for
SIGSEGV
- get the read/write size from instruction type
- for reads, put the required data in memory and remove protection
- single-step the app
- for writes, read what was written and process
- in the single-step
TRAP
protect the page again and continue the app
Do some crazy processing on the instruction itself and:
- mmap the area and protect
- wait for
SIGSEGV
- get the instruction under
eip
and simulate its effects - return after the instruction
The app is not running under root account, in case that matters.
I'm assuming x86_64 and don't really care about other platforms at the moment.