diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elfs/elfloader.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 29a247c6..ebd5f667 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -277,10 +277,10 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) } if(!try_mmap) { uintptr_t paddr = head->multiblocks[n].paddr&~balign; - size_t asize = head->multiblocks[n].asize; + size_t asize = head->multiblocks[n].asize+(head->multiblocks[n].paddr-paddr); void* p = MAP_FAILED; if(paddr==(paddr&~(box64_pagesize-1)) && (asize==ALIGN(asize))) { - printf_dump(log_level, "Allocating 0x%zx (0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", asize, e->p_memsz, (void*)paddr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name); + printf_dump(log_level, "Mmapping 0x%zx (0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", asize, e->p_memsz, (void*)paddr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name); p = mmap64( (void*)paddr, asize, @@ -292,14 +292,18 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin) } else { // difference in pagesize, so need to mmap only what needed to be... //check startint point - uintptr_t new_addr = paddr; - ssize_t new_size = asize; - while(getProtection(new_addr) && (new_size>0)) { - new_size -= ALIGN(new_addr) - new_addr; - new_addr = ALIGN(new_addr); + uintptr_t new_addr = paddr&~(box64_pagesize-1); // new_addr might be smaller than paddr + ssize_t new_size = asize + (paddr-new_addr); // so need new_size to compensate + while(getProtection(new_addr) && (new_size>0)) {// but then, there might be some overlap + uintptr_t diff = ALIGN(new_addr+1) - new_addr; // next page + if(diff<new_size) + new_size -= diff; + else + new_size = 0; + new_addr = ALIGN(new_addr+1); } if(new_size>0) { - printf_dump(log_level, "Allocating 0x%zx (0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", ALIGN(new_size), e->p_memsz, (void*)new_addr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name); + printf_dump(log_level, "Allocating 0x%zx (0x%zx/0x%zx) bytes @%p, will read 0x%zx @%p for Elf \"%s\"\n", ALIGN(new_size), paddr, e->p_memsz, (void*)new_addr, e->p_filesz, (void*)head->multiblocks[n].paddr, head->name); p = mmap64( (void*)new_addr, ALIGN(new_size), |