From: Fan WenJie fanwj@mail.ustc.edu.cn
Signed-off-by: Fan WenJie fanwj@mail.ustc.edu.cn --- dlls/ntdll/unix/loader.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 4d855a18cff..8f753f7e91b 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -35,6 +35,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h> +#include <sys/syscall.h> #include <sys/wait.h> #include <unistd.h> #include <dlfcn.h> @@ -2378,6 +2379,13 @@ void __wine_main( int argc, char *argv[], char *envp[] ) static char noexec[] = "WINELOADERNOEXEC=1"; char **new_argv = malloc( (argc + 2) * sizeof(*argv) );
+#ifdef _WIN64 + { + Dl_info info = { 0 }; + dladdr(&__wine_main, &info); + setenv("LD_PRELOAD", info.dli_fname, 1); + } +#endif memcpy( new_argv + 1, argv, (argc + 1) * sizeof(*argv) ); putenv( noexec ); loader_exec( new_argv, current_machine ); @@ -2400,3 +2408,49 @@ void __wine_main( int argc, char *argv[], char *envp[] ) #endif start_main_thread(); } + +#ifdef _WIN64 + +#if MAP_32BIT + +void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset) +{ + return (void*)syscall(SYS_mmap, addr, length, prot, flags | MAP_32BIT, fd, offset); +} + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + return mmap64(addr, length, prot, flags, fd, offset); +} + +#else + +void *mmap64(void *addr, size_t length, int prot, int flags, int fd, off64_t offset) +{ + if (wow_peb) + { + NtAllocateVirtualMemory(GetCurrentProcess(), &addr, 0xffffffff, &length, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); + flags |= MAP_FIXED; + } + return (void*)syscall(SYS_mmap, addr, length, prot, flags, fd, offset); +} + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + return mmap64(addr, length, prot, flags, fd, offset); +} + +int munmap(void *addr, size_t length) +{ + int ret = (int)syscall(SYS_munmap, addr, length); + if (wow_peb) + { + length = 0; + NtFreeVirtualMemory(GetCurrentProcess(), &addr, &length, MEM_RELEASE); + } + return ret; +} + +#endif + +#endif
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=133695
Your paranoid android.
=== debian11 (32 bit report) ===
user32: msg.c:6897: Test failed: SetFocus(hwnd) on a button: 4: the msg 0x0007 was expected, but got msg 0x0005 instead msg.c:6897: Test failed: SetFocus(hwnd) on a button: 5: the msg 0x0135 was expected, but got msg 0x030f instead msg.c:6897: Test failed: SetFocus(hwnd) on a button: 6: the msg 0x0111 was expected, but got msg 0x001c instead msg.c:6897: Test failed: SetFocus(hwnd) on a button: 7: the msg 0x8000 was expected, but got msg 0x0086 instead msg.c:6897: Test failed: SetFocus(hwnd) on a button: 8: the msg sequence is not complete: expected 0000 - actual 0006
=== debian11b (64 bit WoW report) ===
ntdll: virtual.c:1260: Test failed: CreateThread with huge stack failed
I am not sure if we want to hook such a low level function unless we have no other choice.
E.g. for Vulkan maps the goal we have is something along the lines of https://github.com/KhronosGroup/Vulkan-Docs/pull/1906 . It would also be nice to handle this more flexibly than mapping everything < 4GB. A lot of allocations are never passed to the Windows application and many libraries that we use allow us to allocate memory first and then pass it to the library, instead of having the library return us some pointer.
MacOS allows us to create a second mapping for arbitrary memory. That's what CrossOver is using for glMapBuffer and friends. In hangover, I blocked every memory above 4GB (by blocking everything below 4GB, then calling mmap until it fails, and then releasing my < 4GB addresses again). Both of these options work but have their own problems.
MAP_32BIT puts the mapping below 2GB, not 4GB. We need the alternative codepath for e.g. arm64 hosts anyway, so I don't think we should bother about MAP_32BIT.
This change workarounds the graphical corruption issues in WineD3D (OpenGL) applications with WoW64 mode enabled
The non-MAP_32BIT code path triggers a `012c:err:unwind:segv_handler_early Got unexpected trap 14 during process initialization` error though (at least with wine-staging)
This merge request was closed by Fan WenJie.