From c2656eb9bd735878c33f979c273ba59a1f96cc09 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Sun, 24 Jun 2012 17:51:05 +0100 Subject: [PATCH] Improved elf_load_image() a bit. After enabling BOOT_SUPPORT_ELF64 on x86 the x86 kernel could no longer be booted because too many kernel_args allocations were taking place and filling kernel_args_ranges. This was because for each image load it would check if the image is ELF64, fail and fall back to ELF32 (each ELF64 check allocated a preloaded_image). Changed elf_load_image() so that it only tries both when loading the kernel image, and then for modules it will only try the same ELF class as the kernel image. --- src/system/boot/loader/elf.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/system/boot/loader/elf.cpp b/src/system/boot/loader/elf.cpp index f54e96b96d..1e1d7a4309 100644 --- a/src/system/boot/loader/elf.cpp +++ b/src/system/boot/loader/elf.cpp @@ -222,7 +222,7 @@ ELFLoader::Load(int fd, preloaded_image* _image) // inbetween. totalSize = secondRegion->start + secondRegion->size - firstRegion->start; if (totalSize > image->text_region.size + image->data_region.size - + 8 * 1024) { + + 0x200000) { status = B_BAD_DATA; goto error1; } @@ -543,22 +543,27 @@ elf_init() status_t elf_load_image(int fd, preloaded_image** _image) { - status_t status; + status_t status = B_ERROR; TRACE(("elf_load_image(fd = %d, _image = %p)\n", fd, _image)); #if BOOT_SUPPORT_ELF64 - status = ELF64Loader::Create(fd, _image); - if (status == B_OK) { - return ELF64Loader::Load(fd, *_image); - } else if (status == B_BAD_TYPE) { + if (gKernelArgs.kernel_image == NULL + || gKernelArgs.kernel_image->elf_class == ELFCLASS64) { + status = ELF64Loader::Create(fd, _image); + if (status == B_OK) + return ELF64Loader::Load(fd, *_image); + else if (status != B_BAD_TYPE) + return status; + } #endif + + if (gKernelArgs.kernel_image == NULL + || gKernelArgs.kernel_image->elf_class == ELFCLASS32) { status = ELF32Loader::Create(fd, _image); if (status == B_OK) return ELF32Loader::Load(fd, *_image); -#if BOOT_SUPPORT_ELF64 } -#endif return status; }