Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELFLOADER] Fixed align issue (may help #1057) #1058

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
void* image = mmap64((void*)(head->vaddr?head->vaddr:offs), head->memsz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
#endif
if(image!=MAP_FAILED && !head->vaddr && image!=(void*)offs) {
printf_log(LOG_INFO, "Mmap64 for (@%p 0x%zx) for elf \"%s\" returned %p instead\n", (void*)(head->vaddr?head->vaddr:offs), head->memsz, head->name, image);
offs = (uintptr_t)image;
printf_log(LOG_INFO, "Mamp64 for (@%p 0x%zx) for elf \"%s\" returned %p instead", (void*)(head->vaddr?head->vaddr:offs), head->memsz, head->name, image);
}
if(image==MAP_FAILED || image!=(void*)(head->vaddr?head->vaddr:offs)) {
printf_log(LOG_NONE, "Cannot create memory map (@%p 0x%zx) for elf \"%s\"", (void*)(head->vaddr?head->vaddr:offs), head->memsz, head->name);
Expand Down Expand Up @@ -255,7 +255,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
// check if alignment is correct
uintptr_t balign = head->multiblocks[n].align-1;
if(balign<(box64_pagesize-1)) balign = (box64_pagesize-1);
head->multiblocks[n].asize = (e->p_memsz+(e->p_paddr&balign)+box64_pagesize-1)&~(box64_pagesize-1);
head->multiblocks[n].asize = ALIGN(e->p_memsz+(head->multiblocks[n].paddr&balign));
int try_mmap = 1;
if(e->p_paddr&(box64_pagesize-1))
try_mmap = 0;
Expand Down