I have a question about how Linux traps memory access errors. As far as I know, a user space program doesn't need to ask operating system every time it wants to access memory, now when the process tries to access a memory location not in it's address space the CPU must be having a way to stop this and communicate this event to the OS.

So my question is: How does the CPU inform the OS about this event ? Does it start executing a predefined code ? If yes, please let me know about where in memory is that code, what is that code section called, what does it do, etc.


Your guesses seem about 100% correct.

There is hardware called a memory management unit (MMU) (Part of CPU). It is given page tables, that describe what pages do what (what are executable, readable, writable). If a process tries to do what it is not allowed to do, then the MMU interrupts the CPU. The CPU then executes the code in the starting at a particular address. This address is defined in the interrupt vector table. A table of start addresses, for each interrupt type (some CPUs store instructions in this table, not addresses, but they do the same thing).

  • Thanks a lot for pointing me in the right direction. It solved many of my other queries. Thanks again!! – Tezeswar Apr 11 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.