linuxpagingbsdmmumprotect

mprotect : how is memory protection implemented


I already know that mprotect() syscall has 4 protection mode in BSD, but my problem is that how this protection is implemented ( Hardware or Software Implemention ) ?

let's say if we set protection of specific pages to PROT_NONE ,is it really depend on the hardware I'm using or it's kind of some software tricks by setting some flags on that specified page in page table.

it seems that this protection on hardware deponds on MMU we have, but I'm not sure about it.

you can find more information about mprotect and paging on :

BSD man page

Paging - Wiki


Solution

  • Page protection is implemented in hardware with software assistance. Basically, you want to achieve the following:

    1. Enter kernel context automatically when user process wants to do something with specific memory page (the hardware is responsible for this).
    2. Let kernel code do something to the accessing process in order to uphold the mprotect guarantee (this happens in software invoked from hardware trap handler triggered in p.1).

    And yes, without the MMU p.1 would not work, so on ucLinux (a version of Linux designed to support processors without MMU) mprotect is not implemented (as it will be impossible to invoke the code from p.2 transparently).