about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2021-07-28 13:19:32 +0200
committerptitSeb <sebastien.chev@gmail.com>2021-07-28 13:19:32 +0200
commit296ee1bacaa99f4aca8c2f80238a47935029d72c (patch)
tree5bb5dec7579e9124ce440646b1be36adee1d35ff /src
parent58b5c6ded9792a1e79a1b3bc2a6e82a1d3108cc7 (diff)
downloadbox64-296ee1bacaa99f4aca8c2f80238a47935029d72c.tar.gz
box64-296ee1bacaa99f4aca8c2f80238a47935029d72c.zip
Try to force 47bits on mmap64 all the time (not just when wine64 is detected)
Diffstat (limited to 'src')
-rwxr-xr-xsrc/wrapped/wrappedlibc.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 54942c7f..3796bfb9 100755
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -2012,6 +2012,7 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot
         prot|=PROT_READ;    // PROT_READ is implicit with PROT_WRITE on i386
     if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "mmap64(%p, %lu, 0x%x, 0x%x, %d, %ld) => ", addr, length, prot, flags, fd, offset);}
     #ifndef NOALIGN
+    void* old_addr = addr;
     if(flags&0x40) {
         // 0x40 is MAP_32BIT, wich only exist on x86_64!
         //flags &= ~0x40;   // let the flags in?
@@ -2019,7 +2020,7 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot
             addr = find32bitBlock(length);
         else
             addr = findBlockNearHint(addr, length);
-    } else if (box64_wine) {
+    } else /*if (box64_wine)*/ {
         if(!addr)
             addr = find47bitBlock(length);
     }
@@ -2027,12 +2028,18 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, unsigned long length, int prot
     void* ret = mmap64(addr, length, prot, flags, fd, offset);
     if((ret!=(void*)-1) && (flags&0x40) && ((uintptr_t)ret>0xffffffff)) {
         printf_log(LOG_INFO, "Warning, mmap on 32bits didn't worked, ask %p, got %p ", addr, ret);
-        // the 32bit mmap didn't worded, lets try again
         munmap(ret, length);
         loadProtectionFromMap();    // reload map, because something went wrong previously
         addr = findBlockNearHint(addr, length); // is this the best way?
         ret = mmap64(addr, length, prot, flags, fd, offset);
         printf_log(LOG_INFO, " tried again with %p, got %p\n", addr, ret);
+    } else if((ret!=(void*)-1) && (old_addr==NULL) && ((uintptr_t)ret>0x7fffffffffffLL)) {
+        printf_log(LOG_INFO, "Warning, mmap on 47bits didn't worked, ask %p, got %p ", addr, ret);
+        munmap(ret, length);
+        loadProtectionFromMap();    // reload map, because something went wrong previously
+        addr = find47bitBlock(length); // is this the best way?
+        ret = mmap64(addr, length, prot, flags, fd, offset);
+        printf_log(LOG_INFO, " tried again with %p, got %p\n", addr, ret);
     }
     if(box64_log<LOG_DEBUG) {dynarec_log(LOG_DEBUG, "%p\n", ret);}
     #ifdef DYNAREC