aboutsummaryrefslogtreecommitdiff
path: root/kernel/api
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/api')
-rw-r--r--kernel/api/access.c28
-rw-r--r--kernel/api/syscall.c10
2 files changed, 25 insertions, 13 deletions
diff --git a/kernel/api/access.c b/kernel/api/access.c
index 9a7bed0..9941971 100644
--- a/kernel/api/access.c
+++ b/kernel/api/access.c
@@ -118,16 +118,28 @@ 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));
+ // // loop through the vmareas in the process's vmmap
+ // vmarea_t *vma = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
- // if the vma doesn't exist, return 0
- if (!vma)
- {
+ // // if the vma doesn't exist, return 0
+ // if (!vma)
+ // {
+ // return 0;
+ // }
+
+ // return !!(perm & vma->vma_prot);
+
+ // TODO: FIX MEEE
+
+ vmarea_t* area = vmmap_lookup(p->p_vmmap, ADDR_TO_PN(vaddr));
+ if (!area) {
+ return 0;
+ }
+ if (perm & area->vma_prot) {
+ return 1;
+ } else {
return 0;
}
-
- return !!(perm & vma->vma_prot);
}
/*
@@ -145,7 +157,7 @@ long range_perm(proc_t *p, const void *vaddr, size_t len, int perm)
// loop through the page numbers in the range
size_t vfn = ADDR_TO_PN(vaddr);
- size_t end_vfn = ADDR_TO_PN(vaddr + len);
+ size_t end_vfn = ADDR_TO_PN((uintptr_t)vaddr + len);
for (size_t i = vfn; i < end_vfn; i++)
{
// check the permissions for each page
diff --git a/kernel/api/syscall.c b/kernel/api/syscall.c
index e077631..467b7d6 100644
--- a/kernel/api/syscall.c
+++ b/kernel/api/syscall.c
@@ -85,15 +85,15 @@ static long sys_read(read_args_t *args)
}
// Call do_read() with the buffer and then copy the buffer to the userland args after the system call
- ret = do_read(kargs.fd, addr, kargs.nbytes);
+ ssize_t bytes_read = do_read(kargs.fd, addr, kargs.nbytes);
// if ret < 0, free the temporary buffer and return -1
- if (ret < 0)
+ if (bytes_read < 0)
{
page_free_n(addr, size_in_pages);
- ERROR_OUT_RET(ret);
+ ERROR_OUT_RET(bytes_read);
}
// if read nothing, free the temporary buffer and return 0
- if (ret == 0)
+ if (bytes_read == 0)
{
page_free_n(addr, size_in_pages);
return 0;
@@ -110,7 +110,7 @@ static long sys_read(read_args_t *args)
// Make sure to free the temporary buffer allocated
page_free_n(addr, size_in_pages);
- return ret;
+ return bytes_read;
}
/*