Skip to content

Commit

Permalink
[BOX32][NON4K] Try to fix elfloader when elf wants to load at an addr…
Browse files Browse the repository at this point in the history
…ess not-compatible with pagesize
  • Loading branch information
ptitSeb committed Sep 23, 2024
1 parent 5fe0a68 commit dd72a45
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/elfs/elfloader32.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ int AllocLoadElfMemory32(box64context_t* context, elfheader_t* head, int mainbin
image = (void*)(((uintptr_t)raw+max_align)&~max_align);
} else {
image = raw = mmap64(from_ptrv(head->vaddr), sz, 0, MAP_ANONYMOUS|MAP_PRIVATE|MAP_NORESERVE, -1, 0);
if(from_ptr(head->vaddr)&(box64_pagesize-1)) {
// load address might be lower
if((uintptr_t)image == from_ptr(head->vaddr)&~(box64_pagesize-1))
image = from_ptrv(head->vaddr);
}
}
if(image!=MAP_FAILED && !head->vaddr && image!=from_ptrv(offs)) {
printf_log(LOG_INFO, "%s: Mmap64 for (@%p 0x%zx) for elf \"%s\" returned %p(%p/0x%zx) instead\n", (((uintptr_t)image)&max_align)?"Error":"Warning", from_ptrv(head->vaddr?head->vaddr:offs), head->memsz, head->name, image, raw, head->align);
Expand Down

0 comments on commit dd72a45

Please sign in to comment.