From c1aa09eadeae7703061a9f20f3588e7ebc5947fa Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 25 Jul 2023 19:02:59 -0300 Subject: [PATCH] kernel: misc fixes --- kernel-src/include/util.h | 6 ++++++ kernel-src/lib/util.c | 3 +++ kernel-src/sys/syscalls/fcntl.c | 8 ++++---- kernel-src/sys/syscalls/mmap.c | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 kernel-src/lib/util.c diff --git a/kernel-src/include/util.h b/kernel-src/include/util.h index b28d9bd1..13915c65 100644 --- a/kernel-src/include/util.h +++ b/kernel-src/include/util.h @@ -1,6 +1,10 @@ #ifndef _UTIL_H #define _UTIL_H +#include + +#define UTIL_ZEROBUFFERSIZE (1024 * 64) + #define ROUND_DOWN(v, n) ((v) - ((v) % (n))) #define ROUND_UP(v, n) ROUND_DOWN((v) + (n) - 1, n) @@ -16,4 +20,6 @@ static inline long min(long x, long y) { return x > y ? y : x; } +extern uint8_t util_zerobuffer[]; + #endif diff --git a/kernel-src/lib/util.c b/kernel-src/lib/util.c new file mode 100644 index 00000000..e5627fd6 --- /dev/null +++ b/kernel-src/lib/util.c @@ -0,0 +1,3 @@ +#include + +uint8_t util_zerobuffer[UTIL_ZEROBUFFERSIZE]; diff --git a/kernel-src/sys/syscalls/fcntl.c b/kernel-src/sys/syscalls/fcntl.c index c2c2e36e..0835b567 100644 --- a/kernel-src/sys/syscalls/fcntl.c +++ b/kernel-src/sys/syscalls/fcntl.c @@ -46,11 +46,11 @@ syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) { break; default: ret.errno = EINVAL; - break; + goto cleanup; } - - fd_release(file); - ret.errno = 0; + + cleanup: + fd_release(file); return ret; } diff --git a/kernel-src/sys/syscalls/mmap.c b/kernel-src/sys/syscalls/mmap.c index 41686442..c5045c55 100644 --- a/kernel-src/sys/syscalls/mmap.c +++ b/kernel-src/sys/syscalls/mmap.c @@ -27,7 +27,7 @@ syscallret_t syscall_mmap(context_t *context, void *hint, size_t len, int prot, __assert((~KNOWN_PROT & prot) == 0); // check alignment - if (len == 0 || (uintptr_t)hint % PAGE_SIZE || len % PAGE_SIZE) { + if (len == 0 || (uintptr_t)hint % PAGE_SIZE) { ret.errno = EINVAL; return ret; }