aboutsummaryrefslogtreecommitdiff
path: root/kernel/api
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-05-14 03:19:46 +0000
committersotech117 <michael_foiani@brown.edu>2024-05-14 03:19:46 +0000
commit06d50155ac0bd079bfca0f5728346d8beeb205f2 (patch)
tree2f20c8ba099304d6ea06fb76e8a0807b8afa5a5f /kernel/api
parent7585cb5ad84babe9db8c6595de464e33fb878f0c (diff)
weenix fixes
Diffstat (limited to 'kernel/api')
-rw-r--r--kernel/api/access.c42
-rw-r--r--kernel/api/syscall.c30
2 files changed, 27 insertions, 45 deletions
diff --git a/kernel/api/access.c b/kernel/api/access.c
index 9941971..aa8e83c 100644
--- a/kernel/api/access.c
+++ b/kernel/api/access.c
@@ -116,30 +116,11 @@ long user_vecdup(argvec_t *uvec, char ***kvecp)
*/
long addr_perm(proc_t *p, const void *vaddr, int perm)
{
- // NOT_YET_IMPLEMENTED("VM: addr_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));
-
- // // 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;
- }
+ // 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);
}
/*
@@ -153,20 +134,17 @@ 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)
{
- // NOT_YET_IMPLEMENTED("VM: range_perm");
- // loop through the page numbers in the range
- size_t vfn = ADDR_TO_PN(vaddr);
- size_t end_vfn = ADDR_TO_PN((uintptr_t)vaddr + len);
- for (size_t i = vfn; i < end_vfn; i++)
+ for (
+ size_t vfn = ADDR_TO_PN(vaddr);
+ vfn < ADDR_TO_PN(PAGE_ALIGN_UP((uintptr_t)vaddr + len));
+ vfn++
+ )
{
- // check the permissions for each page
- if (!addr_perm(p, PN_TO_ADDR(i), perm))
+ if (!addr_perm(p, PN_TO_ADDR(vfn), perm))
{
return 0;
}
}
-
- // return 1 if all pages have the correct permissions
return 1;
}
diff --git a/kernel/api/syscall.c b/kernel/api/syscall.c
index 467b7d6..7c76e51 100644
--- a/kernel/api/syscall.c
+++ b/kernel/api/syscall.c
@@ -77,11 +77,14 @@ static long sys_read(read_args_t *args)
ERROR_OUT_RET(ret);
// Allocate a temporary buffer (a page-aligned block of n pages that are enough space to store the number of bytes to read)
- size_t size_in_pages = (kargs.nbytes + PAGE_SIZE - 1) / PAGE_SIZE;
- void *addr = (void *)page_alloc_n(size_in_pages);
+ size_t size_in_pages = 0;
+ while(++size_in_pages * PAGE_SIZE < kargs.nbytes)
+ ;
+ void *addr = page_alloc_n(size_in_pages);
if (!addr)
{
- ERROR_OUT_RET(-ENOMEM);
+ ret = -ENOMEM;
+ ERROR_OUT_RET(ret);
}
// Call do_read() with the buffer and then copy the buffer to the userland args after the system call
@@ -100,7 +103,7 @@ static long sys_read(read_args_t *args)
}
// copy the buffer to the userland args after the system call
- ret = copy_to_user(kargs.buf, addr, ret);
+ ret = copy_to_user(kargs.buf, addr, kargs.nbytes);
// if ret < 0, free the temporary buffer and return -1
if (ret < 0)
{
@@ -132,7 +135,9 @@ static long sys_write(write_args_t *args)
ERROR_OUT_RET(ret);
// Allocate a temporary buffer (a page-aligned block of n pages that are enough space to store the number of bytes to write)
- size_t size_in_pages = (kargs.nbytes + PAGE_SIZE - 1) / PAGE_SIZE;
+ size_t size_in_pages = 0;
+ while(++size_in_pages * PAGE_SIZE < kargs.nbytes)
+ ;
void *addr = (void *)page_alloc_n(size_in_pages);
if (!addr)
{
@@ -187,10 +192,9 @@ static long sys_getdents(getdents_args_t *args)
ERROR_OUT_RET(-EINVAL);
}
- size_t count_read = 0;
-
- // iterate over the directory entries
- while (count_read * sizeof(dirent_t) <= kargs.count)
+ // iterate over the directory entries to get the number of dirs
+ size_t num_dirs = 0;
+ while (num_dirs * sizeof(dirent_t) < kargs.count)
{
// read count / sizeof(dirent_t) directory entries into the provided dirp and call do_getdent
dirent_t d;
@@ -209,13 +213,13 @@ static long sys_getdents(getdents_args_t *args)
}
// copy the dirent_t to the userland args after the system call
- ret = copy_to_user(kargs.dirp + count_read, &d, sizeof(dirent_t));
+ ret = copy_to_user(kargs.dirp + num_dirs, &d, sizeof(dirent_t));
ERROR_OUT_RET(ret); // error check
- count_read++;
+ num_dirs++;
}
- return count_read * sizeof(dirent_t);
+ return num_dirs * sizeof(dirent_t);
}
#ifdef __MOUNTING__
@@ -868,4 +872,4 @@ static long syscall_dispatch(size_t sysnum, uintptr_t args, regs_t *regs)
curthr->kt_errno = ENOSYS;
return -1;
}
-}
+} \ No newline at end of file