about summary refs log tree commit diff stats
path: root/src/custommem.c
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2024-03-27 15:01:16 +0100
committerptitSeb <sebastien.chev@gmail.com>2024-03-27 15:01:16 +0100
commite1f69b9c6171f5d2a67017194232a77025a4a096 (patch)
tree652e533d98d5331f68f643e64caa5cb03e6baa71 /src/custommem.c
parent81f25b219ff69171f2fac2263ce7d49e8b7456b0 (diff)
downloadbox64-e1f69b9c6171f5d2a67017194232a77025a4a096.tar.gz
box64-e1f69b9c6171f5d2a67017194232a77025a4a096.zip
Improve memory handling for wine, again
Diffstat (limited to 'src/custommem.c')
-rw-r--r--src/custommem.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/custommem.c b/src/custommem.c
index 3055a1ef..b745eb74 100644
--- a/src/custommem.c
+++ b/src/custommem.c
@@ -590,14 +590,14 @@ uintptr_t AllocDynarecMap(size_t size)
             #ifndef USE_MMAP
             void *p = NULL;
             if(!(p=box_memalign(box64_pagesize, allocsize))) {
-                dynarec_log(LOG_INFO, "Cannot create dynamic map of %zu bytes\n", allocsize);
+                dynarec_log(LOG_INFO, "Cannot create dynamic map of %zu bytes\n", allocsize), allocsize, strerror(errno);
                 return 0;
             }
             mprotect(p, allocsize, PROT_READ | PROT_WRITE | PROT_EXEC);
             #else
             void* p = internal_mmap(NULL, allocsize, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
             if(p==(void*)-1) {
-                dynarec_log(LOG_INFO, "Cannot create dynamic map of %zu bytes\n", allocsize);
+                dynarec_log(LOG_INFO, "Cannot create dynamic map of %zu bytes (%s)\n", allocsize, strerror(errno));
                 return 0;
             }
             #endif
@@ -1648,12 +1648,32 @@ int isLockAddress(uintptr_t addr)
 
 void* internal_mmap(void *addr, unsigned long length, int prot, int flags, int fd, ssize_t offset)
 {
+    #if 1//def STATICBUILD
     void* ret = (void*)syscall(__NR_mmap, addr, length, prot, flags, fd, offset);
+    #else
+    static int grab = 1;
+    typedef void*(*pFpLiiiL_t)(void*, unsigned long, int, int, int, size_t);
+    static pFpLiiiL_t libc_mmap64 = NULL;
+    if(grab) {
+        libc_mmap64 = dlsym(RTLD_NEXT, "mmap64");
+    }
+    void* ret = libc_mmap64(addr, length, prot, flags, fd, offset);
+    #endif
     return ret;
 }
 int internal_munmap(void* addr, unsigned long length)
 {
+    #if 1//def STATICBUILD
     int ret = syscall(__NR_munmap, addr, length);
+    #else
+    static int grab = 1;
+    typedef int(*iFpL_t)(void*, unsigned long);
+    static iFpL_t libc_munmap = NULL;
+    if(grab) {
+        libc_munmap = dlsym(RTLD_NEXT, "munmap");
+    }
+    int ret = libc_munmap(addr, length);
+    #endif
     return ret;
 }