From 80093ab214bc339c4cb4f7e1a4fb79032c09bfa8 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 25 Apr 2024 01:04:08 -0400 Subject: kernel: vm_map: Check for allocation failure Signed-off-by: Ian Moffett --- sys/vm/vm_map.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 05f4c20..5d40d29 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -41,6 +41,7 @@ #include #define ALLOC_MAPPING() dynalloc(sizeof(struct vm_mapping)) +#define DESTROY_MAPPING(MAPPING) dynfree(MAPPING) static size_t vm_hash_vaddr(vaddr_t va) { @@ -315,7 +316,7 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) uintptr_t map_end, map_start; struct proc *td = this_td(); - struct vm_mapping *mapping = ALLOC_MAPPING(); + struct vm_mapping *mapping; struct vm_object *vmobj; size_t misalign = ((vaddr_t)addr) & (GRANULE - 1); @@ -325,6 +326,11 @@ mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off) if ((prot & ~PROT_MASK) != 0) return MAP_FAILED; + /* Try to allocate a mapping */ + mapping = ALLOC_MAPPING(); + if (mapping == NULL) + return MAP_FAILED; + mapping->prot = prot | PROT_USER; /* -- cgit v1.2.3