[boot] Only allocate memory map once

The `build_kernel_mem_map` function now calls `get_uefi_mappings`
itself, instead of having the efi map passed in. `get_uefi_mappings`
also now takes a `bool allocate` to direct it to actually allocate
the map or not. If it doesn't, it instead just returns the size of
the map and the metadata - which `build_kernel_mem_map`	uses to decide
how much space to first allocate for the kernel's map.
This commit is contained in:
Justin C. Miller
2020-05-16 18:48:28 -07:00
parent 2adef874ee
commit 42dfa6ccfe
3 changed files with 32 additions and 142 deletions

View File

@@ -68,6 +68,8 @@ struct efi_mem_map
uint32_t version; ///< Version of the `memory_descriptor` struct
desc *entries; ///< The array of UEFI descriptors
efi_mem_map() : length(0), size(0), key(0), version(0), entries(nullptr) {}
/// Get the count of entries in the array
inline size_t num_entries() const { return length / size; }
@@ -79,13 +81,14 @@ struct efi_mem_map
};
/// Get the memory map from UEFI.
efi_mem_map get_uefi_mappings(uefi::boot_services *bs);
/// \arg allocate If false, don't actually fetch the mappings, just
/// return a structure describing them.
efi_mem_map get_uefi_mappings(bool allocate, uefi::boot_services *bs);
/// Add the kernel's memory map as a module to the kernel args.
void build_kernel_mem_map(
efi_mem_map &efi_map,
kernel::args::header *args,
uefi::boot_services *bs);
/// \returns The uefi memory map key for the version used to build
/// this map
size_t build_kernel_mem_map(kernel::args::header *args, uefi::boot_services *bs);
} // namespace boot
} // namespace memory