Skip to content

Commit

Permalink
mod: Fix page count calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
marv7000 committed Dec 11, 2024
1 parent 75a38bc commit b87b9d4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion kernel/system/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ i32 module_load_elf(const char* path)
// If the aligned address was unaligned, that means the original addr is inbetween two pages.
// Allocate one more.
if (aligned_virt < seg->p_vaddr)
seg->p_memsz += page_size - seg->p_memsz;
seg->p_memsz += page_size - (seg->p_memsz % page_size);

PhysAddr pages = pm_alloc((seg->p_memsz / page_size) + 1);

Expand All @@ -416,6 +416,7 @@ i32 module_load_elf(const char* path)

// Read data from file.
handle->read(handle, NULL, (void*)seg->p_vaddr, seg->p_filesz, seg->p_offset);

// Zero out unloaded data.
memset((void*)seg->p_vaddr + seg->p_filesz, 0, seg->p_memsz - seg->p_filesz);

Expand Down Expand Up @@ -455,6 +456,8 @@ i32 module_load_elf(const char* path)
}
}

module_log("Relocated module \"%s\"\n", path);

// Load section string table.
char* shstrtab_data = kmalloc(section_headers[hdr->e_shstrndx].sh_size);
handle->read(handle, NULL, shstrtab_data, section_headers[hdr->e_shstrndx].sh_size,
Expand Down

0 comments on commit b87b9d4

Please sign in to comment.