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

This reverts commit 009fb59b69.
This commit is contained in:
mintsuki 2022-07-24 22:32:25 +02:00
parent d2b1579668
commit 4859ee9790
2 changed files with 10 additions and 20 deletions

View File

@ -166,7 +166,6 @@ noreturn void 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 @@ noreturn void 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 @@ noreturn void 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

View File

@ -299,7 +299,6 @@ noreturn void 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 @@ noreturn void 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 @@ noreturn void 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