https://bugs.winehq.org/show_bug.cgi?id=56161
Bug ID: 56161 Summary: MapViewOfFile3 alignment and/or NtMapViewOfSection(Ex) alignment strictness Product: Wine Version: 9.0-rc4 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: ntdll Assignee: wine-bugs@winehq.org Reporter: jan.felix.muenchhalfen@rwth-aachen.de Distribution: ---
Hi,
scenario: .net 7 core self-contained bundle exe (about 180mb) relevant log:
1751.909:011c:0120:Ret KERNEL32.VirtualFree() retval=00000001 ret=1404f06f5 1751.909:011c:0120:Call kernelbase.MapViewOfFile3(0000012c,ffffffffffffffff,024b0000,021eb000,00001000,6fff00004000,00000002,00000000,00000000) ret=1404f0544 1751.909:011c:0120:Call ntdll.NtMapViewOfSectionEx(0000012c,ffffffffffffffff,0019df08,0019df00,0019df40,00004000,100000002,00000000,ffffffff00000000) ret=6fffff455a9f 1751.909:011c:0120:trace:virtual:NtMapViewOfSectionEx handle=0x12c process=0xffffffffffffffff addr=0x24b0000 off=21eb000 size=1000 access=2 1751.909:011c:0120:Ret ntdll.NtMapViewOfSectionEx() retval=c0000220 ret=6fffff455a9f 1751.909:011c:0120:Call ntdll.RtlNtStatusToDosError(c0000220) ret=6fffff455ab6 1751.909:011c:0120:Ret ntdll.RtlNtStatusToDosError() retval=0000046c ret=6fffff455ab6 1751.909:011c:0120:Ret kernelbase.MapViewOfFile3() retval=00000000 ret=1404f0544 1751.909:011c:0120:Call KERNEL32.GetLastError() ret=1402c8e0a 1751.909:011c:0120:Ret KERNEL32.GetLastError() retval=0000046c ret=1402c8e0a 1751.909:011c:0120:Call ntdll.RtlAllocateHeap(001c0000,00000000,00000018) ret=1402c598b 1751.909:011c:0120:trace:heap:RtlAllocateHeap handle 00000000001C0000, flags 0, size 0x18, return 00000000012D7F10, status 0. 1751.909:011c:0120:Ret ntdll.RtlAllocateHeap() retval=012d7f10 ret=1402c598b 1751.909:011c:0120:Call ntdll.RtlPcToFileHeader(14076c100,0019df20) ret=1405a0ee2 1751.909:011c:0120:Ret ntdll.RtlPcToFileHeader() retval=140000000 ret=1405a0ee2 1751.909:011c:0120:Call KERNEL32.RaiseException(e06d7363,00000001,00000004,0019df28) ret=1405a0f28 1751.909:011c:0120:trace:seh:dispatch_exception code=e06d7363 flags=1 addr=00006FFFFF423C47 ip=6fffff423c47 1751.909:011c:0120:trace:seh:dispatch_exception info[0]=0000000019930520 1751.909:011c:0120:trace:seh:dispatch_exception info[1]=000000000019dfb8 1751.909:011c:0120:trace:seh:dispatch_exception info[2]=000000014076c100 1751.909:011c:0120:trace:seh:dispatch_exception info[3]=0000000140000000 1751.909:011c:0120:warn:seh:dispatch_exception EXCEPTION_WINE_CXX_EXCEPTION exception (code=e06d7363) raised
note the return value by NtMapViewOfSectionEx being c0000220 (ERROR_MAPPED_ALIGNMENT)
Bug: MapViewOfFile3 should according to the docs round down the address to 64k alignment. I believe it does not in wine.
Topic for Discussion: this code runs on windows. We suspect that windows is not adhering fully to what's on msdn, and lets things with just Pagesize-Alignment go unharmed. I do not really know how you would proceed with this, just letting you know, you will probably have a better idea than me what to do about it. I just tested patching the alignment requirement to 4k instead of 64k in NtMapViewOfSectionEx and then the self-contained exe just runs fine.
You can see the sourcecode responsible for it here (https://github.com/dotnet/runtime/blob/f21dc6c3dceb6ea76bef73e2a026c770aaed3...)
They align (round down) both address and offset into filehandle to page-size.
According to msdn they are supposed to use 64k alignment. We are posting a bug report for the dotnet team for this, too.
https://bugs.winehq.org/show_bug.cgi?id=56161
Dmitry Timoshkov dmitry@baikal.ru changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Ever confirmed|0 |1
--- Comment #1 from Dmitry Timoshkov dmitry@baikal.ru --- This is essentially duplicate of 56122, however this bug report has more details, and a reference to .Net source.
https://bugs.winehq.org/show_bug.cgi?id=56161
--- Comment #2 from Felix jan.felix.muenchhalfen@rwth-aachen.de --- (In reply to Dmitry Timoshkov from comment #1)
This is essentially duplicate of 56122, however this bug report has more details, and a reference to .Net source.
Oh yes, your patch would work with what .net pe loader does there. I have to add to my "bug" that, though MapViewOfFile3 does not down-round, it would not fix this problem because "offset" is also not 64k aligned in the .net pe loader.
https://bugs.winehq.org/show_bug.cgi?id=56161
--- Comment #3 from Felix jan.felix.muenchhalfen@rwth-aachen.de --- Actually, i didn't see this before, but Dmitry Timoshkov is absolutely right: From msdn: https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-m...
MEM_REPLACE_PLACEHOLDER 0x00004000
....
The 64k alignment requirements on Offset and BaseAddress do not apply when this >flag is specified.
So i add this to my "bug report", wine should ignore the alignment when this flag is specified. About the other one i am really not sure:
[in, optional] BaseAddress
The desired base address of the view. The address is rounded down to the nearest 64k boundary.
Downrounding does not seem necessary do me but, i think the implementation in wine does not do it yet.
https://bugs.winehq.org/show_bug.cgi?id=56161
Felix jan.felix.muenchhalfen@rwth-aachen.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED
--- Comment #4 from Felix jan.felix.muenchhalfen@rwth-aachen.de --- Pull req here, marking this as resolved.
https://gitlab.winehq.org/wine/wine/-/merge_requests/4822
https://bugs.winehq.org/show_bug.cgi?id=56161
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED |--- CC| |alexhenrie24@gmail.com
--- Comment #5 from Alex Henrie alexhenrie24@gmail.com --- Thanks for the patch, but please don't mark the bug as resolved until the patch is accepted upstream.
https://bugs.winehq.org/show_bug.cgi?id=56161
Andrew Nguyen arethusa26@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |DUPLICATE Status|REOPENED |RESOLVED
--- Comment #6 from Andrew Nguyen arethusa26@gmail.com --- I'll take the liberty of marking this bug as a duplicate of one that is already marked fixed and closed.
*** This bug has been marked as a duplicate of bug 56122 ***
https://bugs.winehq.org/show_bug.cgi?id=56161
Alistair Leslie-Hughes leslie_alistair@hotmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #7 from Alistair Leslie-Hughes leslie_alistair@hotmail.com --- Closing duplicate.