aboutsummaryrefslogtreecommitdiff
path: root/pk/vm.c
diff options
context:
space:
mode:
authorYunsup Lee <yunsup@cs.berkeley.edu>2015-10-20 00:36:50 -0700
committerYunsup Lee <yunsup@cs.berkeley.edu>2015-10-20 00:36:50 -0700
commitfa1b72958119abad2c6e1659ab6db914bf30059f (patch)
tree798363fbfb3ff264a9b3eacf393c528293acb2f5 /pk/vm.c
parent69b5de4ffa20d6e2028b1656b2de68fbb929c231 (diff)
downloadpk-fa1b72958119abad2c6e1659ab6db914bf30059f.zip
pk-fa1b72958119abad2c6e1659ab6db914bf30059f.tar.gz
pk-fa1b72958119abad2c6e1659ab6db914bf30059f.tar.bz2
fix pte_create to deal with protection bits correctly
Diffstat (limited to 'pk/vm.c')
-rw-r--r--pk/vm.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/pk/vm.c b/pk/vm.c
index 2303ae1..b1ee62c 100644
--- a/pk/vm.c
+++ b/pk/vm.c
@@ -79,12 +79,30 @@ static pte_t ptd_create(uintptr_t ppn)
static inline pte_t pte_create(uintptr_t ppn, int prot, int user)
{
pte_t pte = (ppn << PTE_PPN_SHIFT) | PTE_V;
- if (prot & PROT_WRITE)
- pte |= PTE_TYPE_URW_SRW;
- if (prot & PROT_EXEC)
- pte |= PTE_TYPE_URX_SRX;
- if (!user)
- pte |= PTE_TYPE_SR;
+ prot &= PROT_READ|PROT_WRITE|PROT_EXEC;
+ if (user) {
+ switch (prot) {
+ case PROT_NONE: pte |= PTE_TYPE_SR; break;
+ case PROT_READ: pte |= PTE_TYPE_UR_SR; break;
+ case PROT_WRITE: pte |= PTE_TYPE_URW_SRW; break;
+ case PROT_EXEC: pte |= PTE_TYPE_URX_SRX; break;
+ case PROT_READ|PROT_WRITE: pte |= PTE_TYPE_URW_SRW; break;
+ case PROT_READ|PROT_EXEC: pte |= PTE_TYPE_URX_SRX; break;
+ case PROT_WRITE|PROT_EXEC: pte |= PTE_TYPE_URWX_SRWX; break;
+ case PROT_READ|PROT_WRITE|PROT_EXEC: pte |= PTE_TYPE_URWX_SRWX; break;
+ }
+ } else {
+ switch (prot) {
+ case PROT_NONE: kassert(0); break;
+ case PROT_READ: pte |= PTE_TYPE_SR; break;
+ case PROT_WRITE: pte |= PTE_TYPE_SRW; break;
+ case PROT_EXEC: pte |= PTE_TYPE_SRX; break;
+ case PROT_READ|PROT_WRITE: pte |= PTE_TYPE_SRW; break;
+ case PROT_READ|PROT_EXEC: pte |= PTE_TYPE_SRX; break;
+ case PROT_WRITE|PROT_EXEC: pte |= PTE_TYPE_SRWX; break;
+ case PROT_READ|PROT_WRITE|PROT_EXEC: pte |= PTE_TYPE_SRWX; break;
+ }
+ }
return pte;
}