diff options
author | Yunsup Lee <yunsup@cs.berkeley.edu> | 2015-10-20 00:36:50 -0700 |
---|---|---|
committer | Yunsup Lee <yunsup@cs.berkeley.edu> | 2015-10-20 00:36:50 -0700 |
commit | fa1b72958119abad2c6e1659ab6db914bf30059f (patch) | |
tree | 798363fbfb3ff264a9b3eacf393c528293acb2f5 /pk/vm.c | |
parent | 69b5de4ffa20d6e2028b1656b2de68fbb929c231 (diff) | |
download | pk-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.c | 30 |
1 files changed, 24 insertions, 6 deletions
@@ -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; } |