elf: Load non-load sections in memory for multiboot

This commit is contained in:
mintsuki 2022-05-29 06:03:59 +02:00
parent 9a89e72dc8
commit ab79b95632
1 changed files with 26 additions and 0 deletions

View File

@ -317,6 +317,19 @@ struct elf_section_hdr_info* elf64_section_hdr_info(uint8_t *elf) {
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
for (size_t i = 0; i < info->num; i++) {
struct elf64_shdr *shdr = info->section_hdrs + i * hdr.shdr_size;
if (shdr->sh_addr != 0 || shdr->sh_size == 0) {
continue;
}
void *section = conv_mem_alloc(shdr->sh_size);
memcpy(section, elf + shdr->sh_offset, shdr->sh_size);
shdr->sh_addr = (uintptr_t)section;
}
return info;
}
@ -336,6 +349,19 @@ struct elf_section_hdr_info* elf32_section_hdr_info(uint8_t *elf) {
memcpy(info->section_hdrs, elf + (hdr.shoff), info->section_hdr_size);
for (size_t i = 0; i < info->num; i++) {
struct elf32_shdr *shdr = info->section_hdrs + i * hdr.shdr_size;
if (shdr->sh_addr != 0 || shdr->sh_size == 0) {
continue;
}
void *section = conv_mem_alloc(shdr->sh_size);
memcpy(section, elf + shdr->sh_offset, shdr->sh_size);
shdr->sh_addr = (uintptr_t)section;
}
return info;
}