1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

Kernel: Simplify ELF loader by removing the allocator indirections.

This commit is contained in:
Andreas Kling 2019-05-16 14:16:08 +02:00
parent 07df2fa7ec
commit c5434e0cfa
2 changed files with 19 additions and 17 deletions

View file

@ -45,10 +45,25 @@ bool ELFLoader::layout()
kprintf("PH: L%x %u r:%u w:%u\n", program_header.laddr().get(), program_header.size_in_memory(), program_header.is_readable(), program_header.is_writable());
#endif
if (program_header.is_writable()) {
allocate_section(program_header.laddr(), program_header.size_in_memory(), program_header.alignment(), program_header.is_readable(), program_header.is_writable());
alloc_section_hook(
program_header.laddr(),
program_header.size_in_memory(),
program_header.alignment(),
program_header.is_readable(),
program_header.is_writable(),
String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")
);
memcpy(program_header.laddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
} else {
map_section(program_header.laddr(), program_header.size_in_memory(), program_header.alignment(), program_header.offset(), program_header.is_readable(), program_header.is_writable());
map_section_hook(
program_header.laddr(),
program_header.size_in_memory(),
program_header.alignment(),
program_header.offset(),
program_header.is_readable(),
program_header.is_writable(),
String::format("elf-map-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")
);
}
});
return !failed;
@ -162,15 +177,3 @@ char* ELFLoader::symbol_ptr(const char* name)
});
return found_ptr;
}
bool ELFLoader::allocate_section(LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable)
{
ASSERT(alloc_section_hook);
return alloc_section_hook(laddr, size, alignment, is_readable, is_writable, String::format("elf-alloc-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
}
bool ELFLoader::map_section(LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable)
{
ASSERT(alloc_section_hook);
return map_section_hook(laddr, size, alignment, offset_in_image, is_readable, is_writable, String::format("elf-map-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
}