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

This commit is contained in:
mintsuki 2023-10-24 18:09:46 +02:00
parent e604a8ccb5
commit 9869174475
5 changed files with 14 additions and 10 deletions

View File

@ -649,7 +649,10 @@ noreturn void _menu(bool first_run) {
rewound_s2_data = ext_mem_alloc(s2_data_size); rewound_s2_data = ext_mem_alloc(s2_data_size);
rewound_bss = ext_mem_alloc(bss_size); rewound_bss = ext_mem_alloc(bss_size);
#endif #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)); memcpy(rewound_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
rewound_memmap_entries = memmap_entries; rewound_memmap_entries = memmap_entries;
memcpy(rewound_data, data_begin, data_size); memcpy(rewound_data, data_begin, data_size);

View File

@ -22,6 +22,8 @@ struct memmap_entry {
#define MEMMAP_FRAMEBUFFER 0x1002 #define MEMMAP_FRAMEBUFFER 0x1002
#define MEMMAP_EFI_RECLAIMABLE 0x2000 #define MEMMAP_EFI_RECLAIMABLE 0x2000
#define MEMMAP_MAX 512
struct meminfo { struct meminfo {
size_t uppermem; size_t uppermem;
size_t lowermem; size_t lowermem;

View File

@ -33,7 +33,6 @@
#include <limine.h> #include <limine.h>
#define MAX_REQUESTS 128 #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, 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, uint64_t physical_base, uint64_t virtual_base,
@ -1008,8 +1007,8 @@ FEAT_START
if (memmap_request != NULL) { if (memmap_request != NULL) {
memmap_response = ext_mem_alloc(sizeof(struct limine_memmap_response)); memmap_response = ext_mem_alloc(sizeof(struct limine_memmap_response));
_memmap = ext_mem_alloc(sizeof(struct limine_memmap_entry) * MAX_MEMMAP); _memmap = ext_mem_alloc(sizeof(struct limine_memmap_entry) * MEMMAP_MAX);
memmap_list = ext_mem_alloc(MAX_MEMMAP * sizeof(uint64_t)); memmap_list = ext_mem_alloc(MEMMAP_MAX * sizeof(uint64_t));
} }
size_t mmap_entries; size_t mmap_entries;
@ -1019,7 +1018,7 @@ FEAT_START
break; // next feature break; // next feature
} }
if (mmap_entries > MAX_MEMMAP) { if (mmap_entries > MEMMAP_MAX) {
panic(false, "limine: Too many memmap entries"); panic(false, "limine: Too many memmap entries");
} }

View File

@ -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(section_entry_size * section_num), 16) + // ELF info
ALIGN_UP(sizeof(struct multiboot1_module) * modules_count, 16) + // modules count ALIGN_UP(sizeof(struct multiboot1_module) * modules_count, 16) + // modules count
ALIGN_UP(modules_cmdlines_size, 16) + // modules command lines 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) { static void *mb1_info_alloc(void **mb1_info_raw, size_t size) {

View File

@ -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(sizeof(struct multiboot_tag_load_base_addr), MULTIBOOT_TAG_ALIGN) + // load base address
ALIGN_UP(smbios_tag_size, MULTIBOOT_TAG_ALIGN) + // SMBIOS 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_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) #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__) #if defined (__i386__)
ALIGN_UP(sizeof(struct multiboot_tag_efi32), MULTIBOOT_TAG_ALIGN) + // EFI system table 32 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 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 // Create memory map tag
////////////////////////////////////////////// //////////////////////////////////////////////
{ {
if (mb_mmap_count > 256) { if (mb_mmap_count > MEMMAP_MAX) {
panic(false, "multiboot2: too many memory map entries"); panic(false, "multiboot2: too many memory map entries");
} }
@ -785,7 +785,7 @@ skip_modeset:;
////////////////////////////////////////////// //////////////////////////////////////////////
#if defined (UEFI) #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"); panic(false, "multiboot2: too many EFI memory map entries");
} }