:: commit a0127f9f40558fb7c3d304b76be95fb5cb659c89

mintsuki <mintsuki@protonmail.com> — 2023-10-24 16:09

parents: e49865a467

pmm: Add MEMMAP_MAX macro and use it instead of hardcoding 256

diff --git a/common/menu.c b/common/menu.c
index ac162001..810ad5e8 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -649,7 +649,10 @@ noreturn void _menu(bool first_run) {
         rewound_s2_data = ext_mem_alloc(s2_data_size);
         rewound_bss = ext_mem_alloc(bss_size);
 #endif
-        rewound_memmap = ext_mem_alloc(256 * sizeof(struct memmap_entry));
+        rewound_memmap = ext_mem_alloc(MEMMAP_MAX * sizeof(struct memmap_entry));
+        if (memmap_entries > MEMMAP_MAX) {
+            panic(false, "menu: Too many memmap entries");
+        }
         memcpy(rewound_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
         rewound_memmap_entries = memmap_entries;
         memcpy(rewound_data, data_begin, data_size);
diff --git a/common/mm/pmm.h b/common/mm/pmm.h
index 52e24404..c8e88c28 100644
--- a/common/mm/pmm.h
+++ b/common/mm/pmm.h
@@ -22,6 +22,8 @@ struct memmap_entry {
 #define MEMMAP_FRAMEBUFFER            0x1002
 #define MEMMAP_EFI_RECLAIMABLE        0x2000
 
+#define MEMMAP_MAX 512
+
 struct meminfo {
     size_t uppermem;
     size_t lowermem;
diff --git a/common/protos/limine.c b/common/protos/limine.c
index 049042fb..8b4d4ca5 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -33,7 +33,6 @@
 #include <limine.h>
 
 #define MAX_REQUESTS 128
-#define MAX_MEMMAP 256
 
 static pagemap_t build_pagemap(int paging_mode, bool nx, struct elf_range *ranges, size_t ranges_count,
                                uint64_t physical_base, uint64_t virtual_base,
@@ -1008,8 +1007,8 @@ FEAT_START
 
     if (memmap_request != NULL) {
         memmap_response = ext_mem_alloc(sizeof(struct limine_memmap_response));
-        _memmap = ext_mem_alloc(sizeof(struct limine_memmap_entry) * MAX_MEMMAP);
-        memmap_list = ext_mem_alloc(MAX_MEMMAP * sizeof(uint64_t));
+        _memmap = ext_mem_alloc(sizeof(struct limine_memmap_entry) * MEMMAP_MAX);
+        memmap_list = ext_mem_alloc(MEMMAP_MAX * sizeof(uint64_t));
     }
 
     size_t mmap_entries;
@@ -1019,7 +1018,7 @@ FEAT_START
         break; // next feature
     }
 
-    if (mmap_entries > MAX_MEMMAP) {
+    if (mmap_entries > MEMMAP_MAX) {
         panic(false, "limine: Too many memmap entries");
     }
 
diff --git a/common/protos/multiboot1.c b/common/protos/multiboot1.c
index b757029d..77174313 100644
--- a/common/protos/multiboot1.c
+++ b/common/protos/multiboot1.c
@@ -37,7 +37,7 @@ static size_t get_multiboot1_info_size(
            ALIGN_UP(sizeof(section_entry_size * section_num), 16) +         // ELF info
            ALIGN_UP(sizeof(struct multiboot1_module) * modules_count, 16) + // modules count
            ALIGN_UP(modules_cmdlines_size, 16) +                            // modules command lines
-           ALIGN_UP(sizeof(struct multiboot1_mmap_entry) * 256, 16);        // memory map
+           ALIGN_UP(sizeof(struct multiboot1_mmap_entry) * MEMMAP_MAX, 16);        // memory map
 }
 
 static void *mb1_info_alloc(void **mb1_info_raw, size_t size) {
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index c3fc8c3d..b1830601 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -46,9 +46,9 @@ static size_t get_multiboot2_info_size(
         ALIGN_UP(sizeof(struct multiboot_tag_load_base_addr), MULTIBOOT_TAG_ALIGN) +                                    // load base address
         ALIGN_UP(smbios_tag_size, MULTIBOOT_TAG_ALIGN) +                                                                // SMBIOS
         ALIGN_UP(sizeof(struct multiboot_tag_basic_meminfo), MULTIBOOT_TAG_ALIGN) +                                     // basic memory info
-        ALIGN_UP(sizeof(struct multiboot_tag_mmap) + sizeof(struct multiboot_mmap_entry) * 256, MULTIBOOT_TAG_ALIGN) +  // MMAP
+        ALIGN_UP(sizeof(struct multiboot_tag_mmap) + sizeof(struct multiboot_mmap_entry) * MEMMAP_MAX, MULTIBOOT_TAG_ALIGN) +  // MMAP
         #if defined (UEFI)
-            ALIGN_UP(sizeof(struct multiboot_tag_efi_mmap) + (efi_desc_size * 256), MULTIBOOT_TAG_ALIGN) +              // EFI MMAP
+            ALIGN_UP(sizeof(struct multiboot_tag_efi_mmap) + (efi_desc_size * MEMMAP_MAX), MULTIBOOT_TAG_ALIGN) +              // EFI MMAP
             #if defined (__i386__)
                 ALIGN_UP(sizeof(struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN) +                                     // EFI system table 32
                 ALIGN_UP(sizeof(struct multiboot_tag_efi32_ih), MULTIBOOT_TAG_ALIGN) +                                  // EFI image handle 32
@@ -738,7 +738,7 @@ skip_modeset:;
     // Create memory map tag
     //////////////////////////////////////////////
     {
-        if (mb_mmap_count > 256) {
+        if (mb_mmap_count > MEMMAP_MAX) {
             panic(false, "multiboot2: too many memory map entries");
         }
 
@@ -785,7 +785,7 @@ skip_modeset:;
     //////////////////////////////////////////////
 #if defined (UEFI)
     {
-        if ((efi_mmap_size / efi_desc_size) > 256) {
+        if ((efi_mmap_size / efi_desc_size) > MEMMAP_MAX) {
             panic(false, "multiboot2: too many EFI memory map entries");
         }
 
tab: 248 wrap: offon