After allocating a logical memory space for a particular process, protection to that space is enforced by using a base register and limit register. To defend against accessing memory outside of the allocated memory space for a process, CPU hardware compares each requested memory address to these registers. If one of the two following conditions holds, an operating system trap occurs:
- The target address is less than the base register.
- The target address is greater than or equal to the limit register.
This logic can be visually observed in Figure 7.2 below.
The above explains how they occur, e.g.
any attempt of a program executing in user mode to access operating-system memory or other user’s memory results in a trap to the operating system.
But what are some examples of when the requested address would actually be outside of the program's assigned memory space? What would cause this?
[Image and quote source: Operating System Essentials, 2nd Ed. - Abraham Silberschatz]