:: commit 1f1f601c50e862adf69ac8a6952a08491f627d39

mintsuki <mintsuki@protonmail.com> — 2021-03-13 13:10

parents: 05f60916ef

pmm: Make sure conv_mem_alloc() does not return NULL as a valid allocation

diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c
index 6c1f2a0d..29629c5f 100644
--- a/stage23/mm/pmm.s2.c
+++ b/stage23/mm/pmm.s2.c
@@ -300,10 +300,17 @@ void init_memmap(void) {
         if (entry_pool_limit > 0x100000)
             entry_pool_limit = 0x100000;
 
-        size_t entry_pool_size = entry_pool_limit - entry->PhysicalStart;
+        size_t entry_pool_start = entry->PhysicalStart;
+        if (entry_pool_start < 0x1000)
+            entry_pool_start = 0x1000;
+
+        if (entry_pool_start > entry_pool_limit)
+            continue;
+
+        size_t entry_pool_size = entry_pool_limit - entry_pool_start;
 
         if (entry_pool_size > bump_alloc_pool_size) {
-            bump_allocator_base = entry->PhysicalStart;
+            bump_allocator_base = entry_pool_start;
             bump_allocator_limit = entry_pool_limit;
             bump_alloc_pool_size = entry_pool_size;
         }
tab: 248 wrap: offon