aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-05-14 05:21:48 +0000
committersotech117 <michael_foiani@brown.edu>2024-05-14 05:21:48 +0000
commitb90313ddfa4c03f688c6c1cd5ded34aff1bf39c5 (patch)
tree498e7a59cd16eb0429c635066ad054e1811a35c7
parent06d50155ac0bd079bfca0f5728346d8beeb205f2 (diff)
fix
-rw-r--r--kernel/api/access.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/kernel/api/access.c b/kernel/api/access.c
index aa8e83c..82f03ed 100644
--- a/kernel/api/access.c
+++ b/kernel/api/access.c
@@ -114,15 +114,43 @@ 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");
-
- // loop through the vmareas in the process's vmmap
+ // NOT_YET_IMPLEMENTED("VM: addr_perm");
+ // return 0;
vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
- return vma && !!(perm & vma->vma_prot);
+ if (vma == NULL)
+ {
+ return 0;
+ }
+
+ if ((perm & PROT_READ) && !(vma->vma_prot & PROT_READ))
+ {
+ return 0;
+ }
+
+ if ((perm & PROT_WRITE) && !(vma->vma_prot & PROT_WRITE))
+ {
+ return 0;
+ }
+
+ if ((perm & PROT_EXEC) && !(vma->vma_prot & PROT_EXEC))
+ {
+ return 0;
+ }
+
+ return 1;
}
+
/*
* Return 1 if process p has permissions perm for virtual address range [vaddr,
* vaddr + len); otherwise return 0.