diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2025-04-18 11:56:59 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2025-04-18 11:56:59 +0200 |
| commit | 3d975b090ef97bf7f2a03f6652d44af0d77961f9 (patch) | |
| tree | b2580f67182d3bd7917771f8b9b54af312e0f881 /src | |
| parent | 882d933d8494a44cb03c0db8705ca0c96117aeeb (diff) | |
| download | box64-3d975b090ef97bf7f2a03f6652d44af0d77961f9.tar.gz box64-3d975b090ef97bf7f2a03f6652d44af0d77961f9.zip | |
[MMAP] Better guessing of wine process mapping regions
Diffstat (limited to 'src')
| -rw-r--r-- | src/wrapped/wrappedlibc.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 3d8d3e67..2b54cd7e 100644 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -2999,8 +2999,9 @@ EXPORT int my_readlinkat(x64emu_t* emu, int fd, void* path, void* buf, size_t bu return readlinkat(fd, path, buf, bufsize); } extern int have48bits; -void* last_mmap_addr = NULL; -size_t last_mmap_len = 0; +void* last_mmap_addr[2] = {0}; +size_t last_mmap_len[2] = {0}; +int last_mmap_idx = 0; EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int flags, int fd, ssize_t offset) { (void)emu; @@ -3033,8 +3034,10 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int f if(emu && !(flags&MAP_ANONYMOUS) && (fd>0)) { DetectUnityPlayer(fd); // the last_mmap will allow mmap created by wine, even those that have hole, to be fully tracked as one single mmap - if((ret>=last_mmap_addr) && ret+length<(last_mmap_addr+last_mmap_len)) - RecordEnvMappings((uintptr_t)last_mmap_addr, last_mmap_len, fd); + if((ret>=last_mmap_addr[0]) && ret+length<(last_mmap_addr[0]+last_mmap_len[0])) + RecordEnvMappings((uintptr_t)last_mmap_addr[0], last_mmap_len[0], fd); + else if((ret>=last_mmap_addr[1]) && ret+length<(last_mmap_addr[1]+last_mmap_len[1])) + RecordEnvMappings((uintptr_t)last_mmap_addr[1], last_mmap_len[1], fd); else RecordEnvMappings((uintptr_t)ret, length, fd); } @@ -3047,12 +3050,13 @@ EXPORT void* my_mmap64(x64emu_t* emu, void *addr, size_t length, int prot, int f } // hack to capture full size of the mmap done by wine if(emu && (fd==-1) && (flags==(MAP_PRIVATE|MAP_ANON))) { - last_mmap_addr = ret; - last_mmap_len = length; + last_mmap_addr[last_mmap_idx] = ret; + last_mmap_len[last_mmap_idx] = length; } else { - last_mmap_addr = NULL; - last_mmap_len = 0; + last_mmap_addr[last_mmap_idx] = NULL; + last_mmap_len[last_mmap_idx] = 0; } + last_mmap_idx = 1-last_mmap_idx; if(emu) setProtection_mmap((uintptr_t)ret, length, prot); else @@ -3127,8 +3131,8 @@ EXPORT int my_munmap(x64emu_t* emu, void* addr, size_t length) } #endif if(!ret) { - last_mmap_addr = NULL; - last_mmap_len = 0; + last_mmap_addr[1-last_mmap_idx] = NULL; + last_mmap_len[1-last_mmap_idx] = 0; freeProtection((uintptr_t)addr, length); RemoveMapping((uintptr_t)addr, length); } |