about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-11-13 12:53:09 +0100
committerptitSeb <sebastien.chev@gmail.com>2023-11-13 12:53:09 +0100
commite071406829e5301aab5f53c4a9084aca302bb976 (patch)
tree3d16cb36061f89e856069ea537eae635258efb67 /src
parent590429d10456b346f56114563caac39dfb43c485 (diff)
downloadbox64-e071406829e5301aab5f53c4a9084aca302bb976.tar.gz
box64-e071406829e5301aab5f53c4a9084aca302bb976.zip
[ELFLOADER] Small changes on elf memory managment
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c21
-rw-r--r--src/elfs/elfloader.c8
-rw-r--r--src/include/custommem.h1
3 files changed, 25 insertions, 5 deletions
diff --git a/src/custommem.c b/src/custommem.c
index b4bdde6c..adbdf12e 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -1312,6 +1312,17 @@ void setProtection_mmap(uintptr_t addr, size_t size, uint32_t prot)
     }
 }
 
+void setProtection_elf(uintptr_t addr, size_t size, uint32_t prot)
+{
+    if(prot)
+        setProtection(addr, size, prot);
+    else {
+        mutex_lock(&mutex_prot);
+        addMapMem(mapallmem, addr, addr+size-1);
+        mutex_unlock(&mutex_prot);
+    }
+}
+
 void refreshProtection(uintptr_t addr)
 {
     LOCK_NODYNAREC();
@@ -1421,6 +1432,14 @@ void loadProtectionFromMap()
                 have48bits = 1;
         }
     }
+    static int shown48bits = 0;
+    if(!shown48bits) {
+        shown48bits = 1;
+        if(have48bits)
+            printf_log(LOG_INFO, "Detected 48bits at least of address space\n");
+        else
+            printf_log(LOG_INFO, "Didn't detect 48bits of address space, considering it's 39bits\n");
+    }
     fclose(f);
     box64_mapclean = 1;
 }
@@ -1592,7 +1611,7 @@ void* find47bitBlockElf(size_t size, int mainbin, uintptr_t mask)
 {
     static void* startingpoint = NULL;
     if(!startingpoint) {
-        startingpoint = (void*)(have48bits?0x7fff00000000LL:0x7f00000000LL);
+        startingpoint = (void*)(have48bits?0x7fff00000000LL:0x3f00000000LL);
     }
     void* mainaddr = (void*)0x100000000LL;
     void* ret = find47bitBlockNearHint(mainbin?mainaddr:startingpoint, size, mask);
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c
index c1e5dbdb..80533f96 100644
--- a/src/elfs/elfloader.c
+++ b/src/elfs/elfloader.c
@@ -223,9 +223,9 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
 
     head->image = image;
     #if defined(PAGE8K) || defined(PAGE16K) || defined(PAGE64K)
-    setProtection((uintptr_t)image, head->memsz, PROT_READ|PROT_WRITE|PROT_EXEC);
+    setProtection_elf((uintptr_t)image, head->memsz, PROT_READ|PROT_WRITE|PROT_EXEC);
     #else
-    setProtection((uintptr_t)image, head->memsz, 0);
+    setProtection_elf((uintptr_t)image, head->memsz, 0);
     #endif
 
     head->multiblocks = (multiblock_t*)box_calloc(head->multiblock_n, sizeof(multiblock_t));
@@ -280,7 +280,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
                     try_mmap = 0;
                     printf_log(log_level, "Mapping failed, using regular mmap+read");
                 } else {
-                    setProtection((uintptr_t)p, head->multiblocks[n].asize, prot);
+                    setProtection_elf((uintptr_t)p, head->multiblocks[n].asize, prot);
                     head->multiblocks[n].p = p;
 
                 }
@@ -306,7 +306,7 @@ int AllocLoadElfMemory(box64context_t* context, elfheader_t* head, int mainbin)
                     }
                     return 1;
                 }
-                setProtection((uintptr_t)p, asize, prot);
+                setProtection_elf((uintptr_t)p, asize, prot);
                 head->multiblocks[n].p = p;
                 if(e->p_filesz) {
                     fseeko64(head->file, head->multiblocks[n].offs, SEEK_SET);
diff --git a/src/include/custommem.h b/src/include/custommem.h
index 76157123..60fabcea 100644
--- a/src/include/custommem.h
+++ b/src/include/custommem.h
@@ -78,6 +78,7 @@ uintptr_t getJumpAddress64(uintptr_t addr);
 void updateProtection(uintptr_t addr, size_t size, uint32_t prot);
 void setProtection(uintptr_t addr, size_t size, uint32_t prot);
 void setProtection_mmap(uintptr_t addr, size_t size, uint32_t prot);
+void setProtection_elf(uintptr_t addr, size_t size, uint32_t prot);
 void freeProtection(uintptr_t addr, size_t size);
 void refreshProtection(uintptr_t addr);
 uint32_t getProtection(uintptr_t addr);