From 82dcc31606c97c793b2189c4f8cc30ff5f8de44f Mon Sep 17 00:00:00 2001 From: Henry Harrington Date: Wed, 22 Oct 2014 18:25:05 +0100 Subject: [PATCH] bootloader: Translate kernel args before adding them to kernel_args_range. Chunks may be physically contiguous, but virtually disjoint. Adding physical addresses may cause ranges to be merged incorrectly. Signed-off-by: Jessica Hamilton --- headers/private/kernel/boot/platform.h | 2 ++ src/system/boot/loader/elf.cpp | 9 --------- src/system/boot/loader/kernel_args.cpp | 12 ++++++++++++ src/system/boot/platform/efi/start.cpp | 10 ---------- 4 files changed, 14 insertions(+), 19 deletions(-) diff --git a/headers/private/kernel/boot/platform.h b/headers/private/kernel/boot/platform.h index 9f3c8eb637..7d3afda1a3 100644 --- a/headers/private/kernel/boot/platform.h +++ b/headers/private/kernel/boot/platform.h @@ -28,6 +28,8 @@ extern status_t platform_init_heap(struct stage2_args *args, void **_base, void extern status_t platform_allocate_region(void **_virtualAddress, size_t size, uint8 protection, bool exactAddress); extern status_t platform_free_region(void *address, size_t size); +extern status_t platform_bootloader_address_to_kernel_address(void *address, uint64_t *_result); +extern status_t platform_kernel_address_to_bootloader_address(uint64_t address, void **_result); /* boot options */ #define BOOT_OPTION_MENU 1 diff --git a/src/system/boot/loader/elf.cpp b/src/system/boot/loader/elf.cpp index eba9c86b76..37af301bff 100644 --- a/src/system/boot/loader/elf.cpp +++ b/src/system/boot/loader/elf.cpp @@ -101,15 +101,6 @@ typedef ELFLoader ELF32Loader; #ifdef BOOT_SUPPORT_ELF64 - -#ifdef _BOOT_PLATFORM_EFI -extern "C" status_t -platform_bootloader_address_to_kernel_address(void *address, uint64_t *_result); -extern "C" status_t -platform_kernel_address_to_bootloader_address(uint64_t address, void **_result); -#endif - - struct ELF64Class { static const uint8 kIdentClass = ELFCLASS64; diff --git a/src/system/boot/loader/kernel_args.cpp b/src/system/boot/loader/kernel_args.cpp index d625728cf4..a5ddc2bb63 100644 --- a/src/system/boot/loader/kernel_args.cpp +++ b/src/system/boot/loader/kernel_args.cpp @@ -370,7 +370,13 @@ kernel_args_malloc(size_t size) return NULL; } +#ifdef _BOOT_PLATFORM_EFI + uint64 translated_block; + platform_bootloader_address_to_kernel_address(block, &translated_block); + if (add_kernel_args_range((void *)translated_block, size) != B_OK) +#else if (add_kernel_args_range(block, size) != B_OK) +#endif panic("kernel_args max range too low!\n"); return block; } @@ -385,7 +391,13 @@ kernel_args_malloc(size_t size) sFirstFree = (void*)((addr_t)block + size); sLast = block; sFree = kChunkSize - size; +#ifdef _BOOT_PLATFORM_EFI + uint64 translated_block; + platform_bootloader_address_to_kernel_address(block, &translated_block); + if (add_kernel_args_range((void *)translated_block, kChunkSize) != B_OK) +#else if (add_kernel_args_range(block, kChunkSize) != B_OK) +#endif panic("kernel_args max range too low!\n"); return block; diff --git a/src/system/boot/platform/efi/start.cpp b/src/system/boot/platform/efi/start.cpp index d5b3219c1e..3e07eea0b8 100644 --- a/src/system/boot/platform/efi/start.cpp +++ b/src/system/boot/platform/efi/start.cpp @@ -122,16 +122,6 @@ convert_kernel_args() image = next; } - // Set correct kernel args range addresses. - dprintf("kernel args ranges:\n"); - for (uint32 i = 0; i < gKernelArgs.num_kernel_args_ranges; i++) { - gKernelArgs.kernel_args_range[i].start = fix_address( - gKernelArgs.kernel_args_range[i].start); - dprintf(" base %#018" B_PRIx64 ", length %#018" B_PRIx64 "\n", - gKernelArgs.kernel_args_range[i].start, - gKernelArgs.kernel_args_range[i].size); - } - // Fix driver settings files. driver_settings_file* file = gKernelArgs.driver_settings; fix_address(gKernelArgs.driver_settings);