diff options
Diffstat (limited to 'kernel/api/syscall.c')
-rw-r--r-- | kernel/api/syscall.c | 14 |
1 files changed, 10 insertions, 4 deletions
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) |