Is there a way in Windows/Linux or any other operating system to know at instruction-level, if a memory access generated a Page Fault? The code I’m imagining about would look something like this:
Buffer *buffer = new Buffer();
...Do something with the buffer...
if(thisProcess.generatedPageFault) {
...Do something...
}
...Do something else with the buffer...
if(thisProcess.generatedPageFault) {
...Do something...
}
Accordingly to the Intel documentation for the x86 processor – a page fault is Interrupt 14. The kernel at a low level would have an interrupt handler set up to trap that page fault. When that occurs, the kernel’s interrupt handler handles the situation accordingly.
Now, since this is at the nuts and bolts level, and residing in ring 0 code, I would not think you can actually monitor that…you may get around that by creating a driver to simply watch for a page fault (again, dependent on the OS privileges and internal data structures occupied by the kernel), and pass the information back out to user-land space… I doubt if that would be easily exposable…
Hope this helps,
Best regards,
Tom.