pmm: Work around potential memmap data race in EFI init_memmap()
This commit is contained in:
parent
9da003d53f
commit
c0c079817d
@ -391,19 +391,22 @@ void init_memmap(void) {
|
|||||||
ext_mem_alloc_type(0x100000, MEMMAP_EFI_RECLAIMABLE);
|
ext_mem_alloc_type(0x100000, MEMMAP_EFI_RECLAIMABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(untouched_memmap, memmap, memmap_entries * sizeof(struct memmap_entry));
|
||||||
|
untouched_memmap_entries = memmap_entries;
|
||||||
|
|
||||||
// Now own all the usable entries
|
// Now own all the usable entries
|
||||||
for (size_t i = 0; i < memmap_entries; i++) {
|
for (size_t i = 0; i < untouched_memmap_entries; i++) {
|
||||||
if (memmap[i].type != MEMMAP_USABLE)
|
if (untouched_memmap[i].type != MEMMAP_USABLE)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
EFI_PHYSICAL_ADDRESS base = memmap[i].base;
|
EFI_PHYSICAL_ADDRESS base = untouched_memmap[i].base;
|
||||||
|
|
||||||
status = gBS->AllocatePages(AllocateAddress, EfiLoaderData,
|
status = gBS->AllocatePages(AllocateAddress, EfiLoaderData,
|
||||||
memmap[i].length / 4096, &base);
|
untouched_memmap[i].length / 4096, &base);
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
for (size_t j = 0; j < memmap[i].length; j += 4096) {
|
for (size_t j = 0; j < untouched_memmap[i].length; j += 4096) {
|
||||||
base = memmap[i].base + j;
|
base = untouched_memmap[i].base + j;
|
||||||
status = gBS->AllocatePages(AllocateAddress, EfiLoaderData, 1, &base);
|
status = gBS->AllocatePages(AllocateAddress, EfiLoaderData, 1, &base);
|
||||||
if (status) {
|
if (status) {
|
||||||
memmap_alloc_range(base, 4096, MEMMAP_EFI_RECLAIMABLE, MEMMAP_USABLE, true, false, false);
|
memmap_alloc_range(base, 4096, MEMMAP_EFI_RECLAIMABLE, MEMMAP_USABLE, true, false, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user