From 53b54f664ed2b4630c23cacc9e216a6a5935b57f Mon Sep 17 00:00:00 2001 From: Michael Foiani Date: Tue, 14 May 2024 17:16:42 -0400 Subject: fixes to work on dept machine --- kernel/api/syscall.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'kernel/api/syscall.c') diff --git a/kernel/api/syscall.c b/kernel/api/syscall.c index 7c76e51..c5fea6d 100644 --- a/kernel/api/syscall.c +++ b/kernel/api/syscall.c @@ -77,10 +77,11 @@ 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 = 0; - while(++size_in_pages * PAGE_SIZE < kargs.nbytes) - ; - void *addr = page_alloc_n(size_in_pages); + // size_t size_in_pages = 0; + // while(++size_in_pages * PAGE_SIZE < kargs.nbytes) + // ; + size_t size_in_pages = ADDR_TO_PN(PAGE_ALIGN_UP(kargs.nbytes)); + char *addr = (char *)page_alloc_n(size_in_pages); if (!addr) { ret = -ENOMEM; @@ -134,6 +135,11 @@ static long sys_write(write_args_t *args) long ret = copy_from_user(&kargs, args, sizeof(kargs)); ERROR_OUT_RET(ret); + if (kargs.nbytes == 0) + { + return 0; + } + // 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 = 0; while(++size_in_pages * PAGE_SIZE < kargs.nbytes) -- cgit v1.2.3-70-g09d2