elf: Return image size

This commit is contained in:
mintsuki 2022-03-26 05:03:02 +01:00
parent 69557e9d2a
commit 8aa1372ce9
7 changed files with 13 additions and 8 deletions

View File

@ -479,7 +479,7 @@ static void elf64_get_ranges(uint8_t *elf, uint64_t slide, bool use_paddr, struc
*_ranges = ranges;
}
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, bool use_paddr, struct elf_range **ranges, uint64_t *ranges_count, bool fully_virtual, uint64_t *physical_base, uint64_t *virtual_base) {
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, bool use_paddr, struct elf_range **ranges, uint64_t *ranges_count, bool fully_virtual, uint64_t *physical_base, uint64_t *virtual_base, uint64_t *_image_size) {
struct elf64_hdr hdr;
memcpy(&hdr, elf + (0), sizeof(struct elf64_hdr));
@ -548,6 +548,9 @@ int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_sl
*physical_base = (uintptr_t)ext_mem_alloc_type_aligned(image_size, alloc_type, max_align);
*virtual_base = min_vaddr;
if (_image_size) {
*_image_size = image_size;
}
}
if (!elf64_is_relocatable(elf, &hdr)) {

View File

@ -27,7 +27,7 @@ struct elf_section_hdr_info {
int elf_bits(uint8_t *elf);
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, bool use_paddr, struct elf_range **ranges, uint64_t *ranges_count, bool fully_virtual, uint64_t *physical_base, uint64_t *virtual_base);
int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_slide, uint32_t alloc_type, bool kaslr, bool use_paddr, struct elf_range **ranges, uint64_t *ranges_count, bool fully_virtual, uint64_t *physical_base, uint64_t *virtual_base, uint64_t *image_size);
int elf64_load_section(uint8_t *elf, void *buffer, const char *name, size_t limit, uint64_t slide);
struct elf_section_hdr_info* elf64_section_hdr_info(uint8_t *elf);

View File

@ -146,17 +146,19 @@ bool limine_load(char *config, char *cmdline) {
struct elf_range *ranges;
uint64_t ranges_count;
uint64_t image_size;
if (elf64_load(kernel, &entry_point, NULL, &slide,
MEMMAP_KERNEL_AND_MODULES, kaslr, false,
&ranges, &ranges_count,
true, &physical_base, &virtual_base)) {
true, &physical_base, &virtual_base, &image_size)) {
return false;
}
// Load requests
requests_count = 0;
uint64_t common_magic[2] = { LIMINE_COMMON_MAGIC };
for (size_t i = 0; i < ALIGN_DOWN(kernel_file_size, 8); i += 8) {
for (size_t i = 0; i < ALIGN_DOWN(image_size, 8); i += 8) {
uint64_t *p = (void *)(uintptr_t)physical_base + i;
if (p[0] != common_magic[0]) {

View File

@ -106,7 +106,7 @@ bool multiboot1_load(char *config, char *cmdline) {
break;
case 64: {
uint64_t e, t;
if (elf64_load(kernel, &e, &t, NULL, MEMMAP_KERNEL_AND_MODULES, false, true, NULL, NULL, false, NULL, NULL))
if (elf64_load(kernel, &e, &t, NULL, MEMMAP_KERNEL_AND_MODULES, false, true, NULL, NULL, false, NULL, NULL, NULL))
panic(true, "multiboot1: ELF64 load failure");
entry_point = e;
kernel_top = t;

View File

@ -219,7 +219,7 @@ bool multiboot2_load(char *config, char* cmdline) {
break;
case 64: {
if (elf64_load(kernel, &e, &t, NULL, MEMMAP_KERNEL_AND_MODULES, false, true, NULL, NULL, false, NULL, NULL))
if (elf64_load(kernel, &e, &t, NULL, MEMMAP_KERNEL_AND_MODULES, false, true, NULL, NULL, false, NULL, NULL, NULL))
panic(true, "multiboot2: ELF64 load failure");
break;

View File

@ -143,7 +143,7 @@ bool stivale_load(char *config, char *cmdline) {
if (!loaded_by_anchor) {
if (elf64_load(kernel, &entry_point, NULL, &slide,
STIVALE_MMAP_KERNEL_AND_MODULES, kaslr, false,
NULL, NULL, false, NULL, NULL))
NULL, NULL, false, NULL, NULL, NULL))
panic(true, "stivale: ELF64 load failure");
ret = elf64_load_section(kernel, &stivale_hdr, ".stivalehdr",

View File

@ -188,7 +188,7 @@ bool stivale2_load(char *config, char *cmdline) {
STIVALE2_MMAP_KERNEL_AND_MODULES, kaslr, false,
want_pmrs ? &ranges : NULL,
want_pmrs ? &ranges_count : NULL,
want_fully_virtual, &physical_base, &virtual_base))
want_fully_virtual, &physical_base, &virtual_base, NULL))
panic(true, "stivale2: ELF64 load failure");
if (want_fully_virtual) {