about summary refs log tree commit diff stats
path: root/src/custommem.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-10-03 19:36:42 +0200
committerptitSeb <sebastien.chev@gmail.com>2024-10-03 19:36:42 +0200
commit9e853e487deb89e38a0eb105814f6f6846ec9f2b (patch)
tree418374032e47f00e8964fe9e1959af8f858f53f3 /src/custommem.c
parent0e91ad3ed3f2720b988d6aefec0d09b0cadf6dad (diff)
downloadbox64-9e853e487deb89e38a0eb105814f6f6846ec9f2b.tar.gz
box64-9e853e487deb89e38a0eb105814f6f6846ec9f2b.zip
[BOX32] Added more 32bits wrapped function and reworked 32bits memory allocator
Diffstat (limited to 'src/custommem.c')
-rw-r--r--src/custommem.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 03947a66..5e3de17a 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -1579,14 +1579,14 @@ void loadProtectionFromMap()
     box64_mapclean = 1;
 }
 
-int isAddrInPrereserve(uintptr_t addr);
+int isAddrInPrereserve(uintptr_t addr, size_t len);
 void freeProtection(uintptr_t addr, size_t size)
 {
     size = ALIGN(size);
     addr &= ~(box64_pagesize-1);
     dynarec_log(LOG_DEBUG, "freeProtection %p:%p\n", (void*)addr, (void*)(addr+size-1));
     LOCK_PROT();
-    if(!isAddrInPrereserve(addr)) {
+    if(!isAddrInPrereserve(addr, size)) {
         rb_unset(mapallmem, addr, addr+size);
         rb_unset(mmapmem, addr, addr+size);
     }
@@ -1612,14 +1612,28 @@ int getMmapped(uintptr_t addr)
 #define MEDIUM (void*)0x40000000
 #define HIGH   (void*)0x60000000
 
-void* find31bitBlockNearHint(void* hint, size_t size, uintptr_t mask)
+void* find31bitBlockNearHint(void* hint_, size_t size, uintptr_t mask)
 {
     uint32_t prot;
-    if(hint<LOWEST) hint = WINE_LOWEST;
+    uintptr_t hint = (uintptr_t)hint_;
+    if(hint_<LOWEST) hint = (uintptr_t)WINE_LOWEST;
     uintptr_t bend = 0;
     uintptr_t cur = (uintptr_t)hint;
+    uintptr_t upper = 0xc0000000LL;
+    if(cur>upper) upper = 0x100000000LL;
     if(!mask) mask = 0xffff;
-    while(bend<0xc0000000LL) {
+    while(cur<upper) {
+        if(!rb_get_end(mapallmem, cur, &prot, &bend)) {
+            if(bend-cur>=size)
+                return (void*)cur;
+        }
+        // granularity 0x10000
+        cur = (bend+mask)&~mask;
+    }
+    if(hint_)
+        return NULL;
+    cur = (uintptr_t)LOWEST;
+    while(cur<(uintptr_t)hint) {
         if(!rb_get_end(mapallmem, cur, &prot, &bend)) {
             if(bend-cur>=size)
                 return (void*)cur;