diff options
author | Anton Kling <anton@kling.gg> | 2024-06-23 23:55:03 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-06-23 23:55:03 +0200 |
commit | f37e21114750c066a1b9f9d8e789185746fd1c45 (patch) | |
tree | c49f57d40f78df286c24c6b96aa6d94d301db989 /kernel/arch | |
parent | eb606d798b18be08e4a403132350b6dc350b522b (diff) |
Kernel: Fix small out of memory issues
Diffstat (limited to 'kernel/arch')
-rw-r--r-- | kernel/arch/i386/mmu.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/kernel/arch/i386/mmu.c b/kernel/arch/i386/mmu.c index 3043816..6948a73 100644 --- a/kernel/arch/i386/mmu.c +++ b/kernel/arch/i386/mmu.c @@ -29,24 +29,28 @@ void change_frame(u32 frame, int on); int get_free_frame(u32 *frame); int allocate_frame(Page *page, int rw, int is_kernel); -static void create_kernel_table(int table_index) { +static int create_kernel_table(int table_index) { u32 physical; active_directory->tables[table_index] = (PageTable *)0xDEADBEEF; PageTable *new_table = (PageTable *)ksbrk_physical(sizeof(PageTable), (void **)&physical); + if (!new_table) { + return 0; + } memset(new_table, 0, sizeof(PageTable)); kernel_directory->tables[table_index] = new_table; kernel_directory->physical_tables[table_index] = physical | 0x3; if (!current_task) { active_directory->tables[table_index] = new_table; active_directory->physical_tables[table_index] = physical | 0x3; - return; + return 1; } for (process_t *p = ready_queue; p; p = p->next) { PageDirectory *pd = p->cr3; pd->tables[table_index] = new_table; pd->physical_tables[table_index] = physical | 0x3; } + return 1; } void *ksbrk(size_t s) { @@ -63,12 +67,14 @@ void *ksbrk(size_t s) { // Determine whether we are approaching a unallocated table int table_index = 1 + (rc / (1024 * 0x1000)); if (!kernel_directory->tables[table_index]) { - create_kernel_table(table_index); + if (!create_kernel_table(table_index)) { + return NULL; + } return ksbrk(s); } if (!mmu_allocate_shared_kernel_region((void *)rc, (data_end - (uintptr_t)rc))) { - return (void *)-1; + return NULL; } get_fast_insecure_random(rc, s); assert(((uintptr_t)rc % PAGE_SIZE) == 0); @@ -77,6 +83,9 @@ void *ksbrk(size_t s) { void *ksbrk_physical(size_t s, void **physical) { void *r = ksbrk(s); + if (!r) { + return NULL; + } if (physical) { *physical = (void *)virtual_to_physical(r, 0); } @@ -256,6 +265,9 @@ PageDirectory *clone_directory(PageDirectory *original) { u32 physical_address; PageDirectory *new_directory = kmalloc_align(sizeof(PageDirectory), (void **)&physical_address); + if (!new_directory) { + return NULL; + } memset(new_directory, 0, sizeof(PageDirectory)); if (!new_directory) { return NULL; |