aboutsummaryrefslogtreecommitdiff
path: root/sys/vm
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-25 01:04:08 -0400
committerIan Moffett <ian@osmora.org>2024-04-25 01:04:33 -0400
commit80093ab214bc339c4cb4f7e1a4fb79032c09bfa8 (patch)
treef643b5d58daef29873acdcf2eb3b7f4ba3d12372 /sys/vm
parentdbea81051df560226be46a149457e693337357d9 (diff)
kernel: vm_map: Check for allocation failure
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm')
-rw-r--r--sys/vm/vm_map.c8
1 files changed, 7 insertions, 1 deletions
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 <lib/assert.h>
#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;
/*