about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2022-03-18 11:44:19 +0100
committerptitSeb <sebastien.chev@gmail.com>2022-03-18 11:44:19 +0100
commit795c405e812c9c7e6e1aee93a596652600ee59bf (patch)
tree76da1b286d814ffe4cf0fbc4059d23ab04941cce /src
parent515f4e81195a48da2b924a802750a646df16e760 (diff)
downloadbox64-795c405e812c9c7e6e1aee93a596652600ee59bf.tar.gz
box64-795c405e812c9c7e6e1aee93a596652600ee59bf.zip
Fixed, again, the mmap block selection (shoudl help #587)
Diffstat (limited to 'src')
-rw-r--r--src/custommem.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/custommem.c b/src/custommem.c
index aa6fe422..60336ecd 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -1134,13 +1134,16 @@ void* find47bitBlock(size_t size)
 void* find47bitBlockNearHint(void* hint, size_t size)
 {
     mapmem_t* m = mapmem;
+    uintptr_t h = (uintptr_t)hint;
     if(hint<LOWEST) hint = LOWEST;
     while(m && m->end<0x800000000000LL) {
         // granularity 0x10000
         uintptr_t addr = (m->end+1+0xffff)&~0xffff;
-        uintptr_t end = (m->next)?(m->next->begin-1):0xffffffff;
-        // check hint and availble saize
-        if(addr>=(uintptr_t)hint && end-addr+1>=size)
+        uintptr_t end = (m->next)?(m->next->begin-1):0xffffffffffffffffLL;
+        // check hint and available size
+        if(addr<=h && end>=h && end-h+1>=size)
+            return hint;
+        if(addr>=h && end-addr+1>=size)
             return (void*)addr;
         m = m->next;
     }
@@ -1149,13 +1152,16 @@ void* find47bitBlockNearHint(void* hint, size_t size)
 void* findBlockNearHint(void* hint, size_t size)
 {
     mapmem_t* m = mapmem;
+    uintptr_t h = (uintptr_t)hint;
     if(hint<LOWEST) hint = LOWEST;
     while(m && m->end<0x100000000LL) {
         // granularity 0x10000
         uintptr_t addr = (m->end+1+0xffff)&~0xffff;
-        uintptr_t end = (m->next)?(m->next->begin-1):0xffffffff;
-        // check hint and availble saize
-        if(addr>=(uintptr_t)hint && end-addr+1>=size)
+        uintptr_t end = (m->next)?(m->next->begin-1):0xffffffffffffffffLL;
+        // check hint and available size
+        if(addr<=h && end>=h && end-h+1>=size)
+            return hint;
+        if(addr>=h && end-addr+1>=size)
             return (void*)addr;
         m = m->next;
     }