[boot] Zero extra memory in loaded sections

When loading ELF headers (as opposed to sections), the `file_size` of
the data may be smaller than the `mem_size` of the section to be loaded
in memory. Don't blindly copy `mem_size` bytes from the ELF file, but
instead only `file_size`, then zero the rest.

Tags: elf loader
This commit is contained in:
Justin C. Miller
2020-07-04 18:20:49 -07:00
parent 0a28d2db07
commit 8687fe3786

View File

@@ -57,7 +57,13 @@ load(
L"Failed allocating space for kernel code");
void *data_start = offset_ptr<void>(data, pheader->offset);
bs->copy_mem(pages, data_start, pheader->mem_size);
bs->copy_mem(pages, data_start, pheader->file_size);
if (pheader->mem_size > pheader->file_size) {
void *extra = offset_ptr<void>(pages, pheader->file_size);
size_t size = pheader->mem_size - pheader->file_size;
bs->set_mem(extra, size, 0);
}
console::print(L" section %d phys: 0x%lx\r\n", i, pages);
console::print(L" section %d virt: 0x%lx\r\n", i, pheader->vaddr);