summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/malloc.c5
-rw-r--r--src/kernel/malloc.h6
-rw-r--r--src/kernel/syscalls.c4
3 files changed, 13 insertions, 2 deletions
diff --git a/src/kernel/malloc.c b/src/kernel/malloc.c
index 8ba00dc..ba1ab42 100644
--- a/src/kernel/malloc.c
+++ b/src/kernel/malloc.c
@@ -116,6 +116,7 @@ mem_debugprint(void)
void
*page_alloc(size_t pages)
{
+ assert(pages == 1); /* not using that assertion... yet */
/* i do realize how painfully slow this is */
size_t streak = 0;
for (size_t i = pbitmap_firstfree; i < pbitmap_len * 8; i++) {
@@ -177,7 +178,11 @@ void
Allocation *hdr;
void *addr;
+ if (KMALLOC_MAX < len) {
+ panic_invalid_state();
+ }
len += sizeof(Allocation);
+ assert(len <= PAGE_SIZE);
hdr = page_alloc(page_amt(len));
hdr->magic = MALLOC_MAGIC;
hdr->len = len;
diff --git a/src/kernel/malloc.h b/src/kernel/malloc.h
index 03934de..3469f5f 100644
--- a/src/kernel/malloc.h
+++ b/src/kernel/malloc.h
@@ -3,12 +3,16 @@
#include <shared/mem.h>
#include <stddef.h>
+/* This seems to be fine for now, and it means that i don't need to concern
+ * myself with allocating contiguous pages for now, which is way easier to do
+ * well. */
+#define KMALLOC_MAX 2048
+
void mem_init(void *memtop);
void mem_reserve(void *addr, size_t len);
void mem_debugprint(void);
// allocates `pages` consecutive pages
-// TODO deprecate
void *page_alloc(size_t pages);
// zeroes the allocated pages
void *page_zalloc(size_t pages);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 5771b6a..7fcbd2a 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -62,6 +62,7 @@ hid_t _sys_open(const char __user *path, long len, int flags) {
if (flags & ~(OPEN_RW | OPEN_CREATE)) SYSCALL_RETURN(-ENOSYS);
+ static_assert(PATH_MAX <= KMALLOC_MAX);
if (PATH_MAX < len)
SYSCALL_RETURN(-ENAMETOOLONG);
/* Doesn't check for free handles. Another thread could use up all
@@ -461,7 +462,8 @@ hid_t _sys_getnull(int flags) {
long _sys_execbuf(void __user *ubuf, size_t len) {
if (len == 0) SYSCALL_RETURN(0);
- if (len > EXECBUF_MAX_LEN)
+ static_assert(EXECBUF_MAX_LEN <= KMALLOC_MAX);
+ if (EXECBUF_MAX_LEN < len)
SYSCALL_RETURN(-1);
if (proc_cur->execbuf.buf)
SYSCALL_RETURN(-1);