[PATCH 0/1] MR4822: ntdll: Fix: Ignore alignment if MEM_REPLACE_PLACEHOLDER is set in flags of NtMapViewOfSection(Ex)
I had a bugreport here: https://bugs.winehq.org/show_bug.cgi?id=56161 This pull req fixes the bug that programs that do VirtualAlloc(placeholder)/VirtualFree(keep placeholder)/MapViewOfFile3(replace placeholder), do not run. Like the dotnet pe loader in .net 7 for example. It was not clear to me at first, because i didnt notice it on msdn, but the way that Dmitry Timoshkov "hacked" it in https://bugs.winehq.org/show_bug.cgi?id=56122 is actually exactly how it is supposed to happen according to msdn.
From here: https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-m... 
So thanks to Dmitry Timoshkov. If you are interested you could also look into the thing i mentioned in the bug report, that MapViewOfFile3 doesn't round down to 64k, but, i don't think this is a serious problem yet. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/4822
From: Felix Münchhalfen<jan.felix.muenchhalfen(a)rwth-aachen.de> --- dlls/ntdll/unix/virtual.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index abe1b4dc4ec..fb4fa6f1439 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -5466,7 +5466,8 @@ NTSTATUS WINAPI NtMapViewOfSection( HANDLE handle, HANDLE process, PVOID *addr_p } #endif - if ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask))) + if (!(alloc_type & MEM_REPLACE_PLACEHOLDER) && + ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask)))) return STATUS_MAPPED_ALIGNMENT; if (process != NtCurrentProcess()) @@ -5535,7 +5536,8 @@ NTSTATUS WINAPI NtMapViewOfSectionEx( HANDLE handle, HANDLE process, PVOID *addr } #endif - if ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask))) + if (!(alloc_type & MEM_REPLACE_PLACEHOLDER) && + ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask)))) return STATUS_MAPPED_ALIGNMENT; if (process != NtCurrentProcess()) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/4822
Thank you for the MR. We'll definitely need a test for this, preferably for both the syscall and user wrapper in kernel32. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/4822#note_57073
Alex Henrie (@alexhenrie) commented about dlls/ntdll/unix/virtual.c:
} #endif
- if ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask))) + if (!(alloc_type & MEM_REPLACE_PLACEHOLDER) &&
Please don't leave a space at the end of the line. Trailing whitespace causes warnings in Git. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/4822#note_57074
Alex Henrie (@alexhenrie) commented about dlls/ntdll/unix/virtual.c:
} #endif
- if ((offset.u.LowPart & mask) || (*addr_ptr && ((UINT_PTR)*addr_ptr & mask))) + if (!(alloc_type & MEM_REPLACE_PLACEHOLDER) &&
Same here -- https://gitlab.winehq.org/wine/wine/-/merge_requests/4822#note_57075
participants (3)
-
Alex Henrie (@alexhenrie) -
Felix Münchhalfen -
Nikolay Sivov (@nsivov)