aboutsummaryrefslogtreecommitdiff
path: root/kernel/api/access.c
diff options
context:
space:
mode:
authorMichael Foiani <mfoiani@cs.brown.edu>2024-05-14 17:16:42 -0400
committerMichael Foiani <mfoiani@cs.brown.edu>2024-05-14 17:16:42 -0400
commit53b54f664ed2b4630c23cacc9e216a6a5935b57f (patch)
treef0138f1ed2f8894efa560e0e9721e510883f439b /kernel/api/access.c
parentb90313ddfa4c03f688c6c1cd5ded34aff1bf39c5 (diff)
fixes to work on dept machine
Diffstat (limited to 'kernel/api/access.c')
-rw-r--r--kernel/api/access.c46
1 files changed, 13 insertions, 33 deletions
diff --git a/kernel/api/access.c b/kernel/api/access.c
index 82f03ed..944277c 100644
--- a/kernel/api/access.c
+++ b/kernel/api/access.c
@@ -114,40 +114,21 @@ long user_vecdup(argvec_t *uvec, char ***kvecp)
*
* Check against the vmarea's protections on the mapping.
*/
-// long addr_perm(proc_t *p, const void *vaddr, int perm)
-// {
-// // NOT_YET_IMPLEMENTED("vm:: addr_perm");
-
-// // loop through the vmareas in the process's vmmap
-// vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
-// return vma && !!(perm & vma->vma_prot);
-// }
long addr_perm(proc_t *p, const void *vaddr, int perm)
{
- // NOT_YET_IMPLEMENTED("VM: addr_perm");
- // return 0;
- vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
- if (vma == NULL)
- {
- return 0;
- }
-
- if ((perm & PROT_READ) && !(vma->vma_prot & PROT_READ))
- {
- return 0;
- }
+ // NOT_YET_IMPLEMENTED("vm:: addr_perm");
- if ((perm & PROT_WRITE) && !(vma->vma_prot & PROT_WRITE))
- {
- return 0;
- }
+ // loop through the vmareas in the process's vmmap
+ // vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
+ // return vma && !!(perm & vma->vma_prot);
- if ((perm & PROT_EXEC) && !(vma->vma_prot & PROT_EXEC))
+ vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
+ if (vma == NULL)
{
return 0;
}
- return 1;
+ return (vma->vma_prot & perm) == perm;
}
@@ -162,17 +143,16 @@ long addr_perm(proc_t *p, const void *vaddr, int perm)
*/
long range_perm(proc_t *p, const void *vaddr, size_t len, int perm)
{
-
- for (
- size_t vfn = ADDR_TO_PN(vaddr);
- vfn < ADDR_TO_PN(PAGE_ALIGN_UP((uintptr_t)vaddr + len));
- vfn++
- )
+ // NOT_YET_IMPLEMENTED("vm:: range_perm");
+ size_t start = ADDR_TO_PN(vaddr);
+ size_t end = ADDR_TO_PN(PAGE_ALIGN_UP(vaddr + len));
+ while (start < end)
{
- if (!addr_perm(p, PN_TO_ADDR(vfn), perm))
+ if (addr_perm(p, PN_TO_ADDR(start), perm) == 0)
{
return 0;
}
+ start++;
}
return 1;
}