:: commit 73ac6d9c43d6ead53b2e01d4788f271cbc922674

mintsuki <mintsuki@protonmail.com> — 2022-07-24 20:32

parents: 09a613b3f0

Revert "multiboot: Take better care of not having the reloc stub overwritten"

This reverts commit 009fb59b695fc3245f294984fa6c3225fddaefa1.
diff --git a/common/protos/multiboot1.c b/common/protos/multiboot1.c
index b5e6d7bd..98642580 100644
--- a/common/protos/multiboot1.c
+++ b/common/protos/multiboot1.c
@@ -166,7 +166,6 @@ bool multiboot1_load(char *config, char *cmdline) {
     // Realloc elsewhere ranges to include mb1 info, modules, and elf sections
     struct elsewhere_range *new_ranges = ext_mem_alloc(sizeof(struct elsewhere_range) *
         (ranges_count
-       + 1 /* relocation stub range */
        + 1 /* mb1 info range */
        + n_modules
        + (section_hdr_info ? section_hdr_info->num : 0)));
@@ -175,15 +174,6 @@ bool multiboot1_load(char *config, char *cmdline) {
     pmm_free(ranges, sizeof(struct elsewhere_range) * ranges_count);
     ranges = new_ranges;
 
-    // Load relocation stub where it won't get overwritten (dummy elsewhere range)
-    size_t reloc_stub_size = (size_t)multiboot_reloc_stub_end - (size_t)multiboot_reloc_stub;
-    void *reloc_stub = ext_mem_alloc(reloc_stub_size);
-    memcpy(reloc_stub, multiboot_reloc_stub, reloc_stub_size);
-    ranges[ranges_count].elsewhere = (uintptr_t)reloc_stub;
-    ranges[ranges_count].target = (uintptr_t)reloc_stub;
-    ranges[ranges_count].length = reloc_stub_size;
-    ranges_count++;
-
     // GRUB allocates boot info at 0x10000, *except* if the kernel happens
     // to overlap this region, then it gets moved to right after the
     // kernel, or whichever PHDR happens to sit at 0x10000.
@@ -390,6 +380,11 @@ bool multiboot1_load(char *config, char *cmdline) {
 #endif
     }
 
+    // Load relocation stub where it won't get overwritten (hopefully)
+    size_t reloc_stub_size = (size_t)multiboot_reloc_stub_end - (size_t)multiboot_reloc_stub;
+    void *reloc_stub = ext_mem_alloc(reloc_stub_size);
+    memcpy(reloc_stub, multiboot_reloc_stub, reloc_stub_size);
+
 #if uefi == 1
     efi_exit_boot_services();
 #endif
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index 2cca23d0..8122475b 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -299,7 +299,6 @@ bool multiboot2_load(char *config, char* cmdline) {
     // Realloc elsewhere ranges to include mb2 info, modules, and elf sections
     struct elsewhere_range *new_ranges = ext_mem_alloc(sizeof(struct elsewhere_range) *
         (ranges_count
-       + 1 /* relocation stub range */
        + 1 /* mb2 info range */
        + n_modules
        + (section_hdr_info ? section_hdr_info->num : 0)));
@@ -308,15 +307,6 @@ bool multiboot2_load(char *config, char* cmdline) {
     pmm_free(ranges, sizeof(struct elsewhere_range) * ranges_count);
     ranges = new_ranges;
 
-    // Load relocation stub where it won't get overwritten (dummy elsewhere range)
-    size_t reloc_stub_size = (size_t)multiboot_reloc_stub_end - (size_t)multiboot_reloc_stub;
-    void *reloc_stub = ext_mem_alloc(reloc_stub_size);
-    memcpy(reloc_stub, multiboot_reloc_stub, reloc_stub_size);
-    ranges[ranges_count].elsewhere = (uintptr_t)reloc_stub;
-    ranges[ranges_count].target = (uintptr_t)reloc_stub;
-    ranges[ranges_count].length = reloc_stub_size;
-    ranges_count++;
-
     // GRUB allocates boot info at 0x10000, *except* if the kernel happens
     // to overlap this region, then it gets moved to right after the
     // kernel, or whichever PHDR happens to sit at 0x10000.
@@ -680,6 +670,11 @@ bool multiboot2_load(char *config, char* cmdline) {
     }
 #endif
 
+    // Load relocation stub where it won't get overwritten (hopefully)
+    size_t reloc_stub_size = (size_t)multiboot_reloc_stub_end - (size_t)multiboot_reloc_stub;
+    void *reloc_stub = ext_mem_alloc(reloc_stub_size);
+    memcpy(reloc_stub, multiboot_reloc_stub, reloc_stub_size);
+
 #if uefi == 1
     efi_exit_boot_services();
 #endif
tab: 248 wrap: offon