about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-10-31 16:36:54 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-10-31 16:36:54 +0100
commit936fa20928ecaebf68826e1284bbf65e7b42e29c (patch)
tree685f1896b370e47f9da5a8c1c87ae6a5750bbed0 /src
parent362a3fde10a3bb2738fcf30ae2e2eaf4a53df042 (diff)
downloadbox64-936fa20928ecaebf68826e1284bbf65e7b42e29c.tar.gz
box64-936fa20928ecaebf68826e1284bbf65e7b42e29c.zip
[ELFLOADER] Small improvment in new elfloader memory manager
Diffstat (limited to 'src')
-rw-r--r--src/elfs/elfloader.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index a7d6e5b3..a398694b 100644
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -219,7 +219,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
                 try_mmap = 0;
             if(head->multiblocks[n].asize != head->multiblocks[n].size)
                 try_mmap = 0;
-            if(!e->p_flags)
+            if(!e->p_flags || !e->p_filesz)
                 try_mmap = 0;
             uint8_t prot = e->p_flags?(PROT_READ|PROT_WRITE|((e->p_flags & PF_X)?PROT_EXEC:0)):0;
             if(try_mmap) {
@@ -257,10 +257,12 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
                     return 1;
                 }
                 setProtection_mmap((uintptr_t)p, head->multiblocks[n].asize, prot);
-                fseeko64(head->file, head->multiblocks[n].offs, SEEK_SET);
-                if(fread((void*)head->multiblocks[n].paddr, head->multiblocks[n].size, 1, head->file)!=1) {
-                    printf_log(LOG_NONE, "Cannot read elf block (@%p 0x%zx/0x%zx) for elf \"%s\"\n", (void*)head->multiblocks[n].offs, head->multiblocks[n].asize, balign, head->name);
-                    return 1;
+                if(e->p_filesz) {
+                    fseeko64(head->file, head->multiblocks[n].offs, SEEK_SET);
+                    if(fread((void*)head->multiblocks[n].paddr, head->multiblocks[n].size, 1, head->file)!=1) {
+                        printf_log(LOG_NONE, "Cannot read elf block (@%p 0x%zx/0x%zx) for elf \"%s\"\n", (void*)head->multiblocks[n].offs, head->multiblocks[n].asize, balign, head->name);
+                        return 1;
+                    }
                 }
             }
 #ifdef DYNAREC