https://bugs.winehq.org/show_bug.cgi?id=50171
Bug ID: 50171 Summary: 32-bit PE entry point no longer called through BaseThreadInitThunk() assembly wrapper when Wine is built with LLVM MinGW Product: Wine Version: 5.22 Hardware: x86-64 OS: Linux Status: NEW Severity: normal Priority: P2 Component: kernel32 Assignee: wine-bugs@winehq.org Reporter: focht@gmx.net Distribution: ---
Hello folks,
while investigating bug 28332 I found a regression introduced by https://source.winehq.org/git/wine.git/commitdiff/0c631ebb2354334eaf309bc076... ("kernel32: Build with msvcrt.").
With 32-bit kernel32 cross-compiled to PE format, the stack on app entry point is now aligned to 16-byte boundary. This makes the game from bug 28332 "magically" work while the 32-bit non-PE kernel32 causes a crash (expected due to Wine quartz bug).
https://bugs.winehq.org/show_bug.cgi?id=28332#c17
The stack alignment from entry point, including selected functions from the call chain up to alloca() caller.
--- snip --- EIP | PE ESP | non-PE ESP | comment 0x42D5E3 | 0x31FF60 +00 | 0x31FF44 +00 | entry point main thread 0x42A720 | 0x31FEA0 +C0 | 0x31FE84 +C0 | 0x4200C5 | 0x31FE54 +4C | 0x31FE38 +4C | 0x40D8B7 | 0x31FE4C +08 | 0x31FE30 +08 | 0x40D570 | 0x31FE48 +04 | 0x31FE2C +04 | 0x40D6FF | 0x31FB1C +32C | 0x31FB00 +32C | before alloca(0) 0x40D704 | 0x31FB10 +0C | 0x31FB00 +00 | after alloca(0) --- snip ---
It seems in 32-bit PE kernel32.dll, the thread entry point is called through the fastcall "C" version of BaseThreadInitThunk() instead of the fastcall assembly wrapper.
32-bit non-PE kernel32.dll.so works correctly, the thread entry point is called through __fastcall_BaseThreadInitThunk() assembly wrapper.
https://source.winehq.org/git/wine.git/blob/bedfb9cae224a369efa4588332a5518d...
--- snip --- 36 #ifdef __i386__ 37 __ASM_STDCALL_FUNC( __fastcall_BaseThreadInitThunk, 12, 38 "pushl %ebp\n\t" 39 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") 40 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t") 41 "movl %esp,%ebp\n\t" 42 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t") 43 "pushl %ebx\n\t" 44 __ASM_CFI(".cfi_rel_offset %ebx,-4\n\t") 45 "movl 8(%ebp),%ebx\n\t" 46 /* deliberately mis-align the stack by 8, Doom 3 needs this */ 47 "pushl 4(%ebp)\n\t" /* Driller expects readable address at this offset */ 48 "pushl 4(%ebp)\n\t" 49 "pushl %ebx\n\t" 50 "call *%edx\n\t" 51 "movl %eax,(%esp)\n\t" 52 "call " __ASM_STDCALL( "RtlExitUserThread", 4 )) 53 #endif 54 55 /*********************************************************************** 56 * BaseThreadInitThunk (KERNEL32.@) 57 */ 58 void __fastcall BaseThreadInitThunk( DWORD unknown, LPTHREAD_START_ROUTINE entry, void *arg ) 59 { 60 RtlExitUserThread( entry( arg ) ); 61 } --- snip ---
https://source.winehq.org/git/wine.git/blob/bedfb9cae224a369efa4588332a5518d...
--- snip --- 185 @ stdcall -fastcall BaseThreadInitThunk(long ptr ptr) --- snip ---
cross-toolchain used: LLVM MinGW 20201020 with LLVM stable 11.0.0
https://github.com/mstorsjo/llvm-mingw
https://github.com/mstorsjo/llvm-mingw/releases
https://github.com/mstorsjo/llvm-mingw/releases/download/20201020/llvm-mingw...
$ wine --version wine-5.22
Regards
https://bugs.winehq.org/show_bug.cgi?id=50171
Anastasius Focht focht@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.winehq.org/sho | |w_bug.cgi?id=28332 Regression SHA1| |0c631ebb2354334eaf309bc0765 | |d3283654cf902 Keywords| |regression
https://bugs.winehq.org/show_bug.cgi?id=50171
Anastasius Focht focht@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Fixed by SHA1| |d896b1195d876085f7127accd44 | |5c3ecd504da3f Resolution|--- |FIXED
--- Comment #1 from Anastasius Focht focht@gmx.net --- Hello folks,
this is fixed by commit https://source.winehq.org/git/wine.git/commitdiff/d896b1195d876085f7127accd4... ("kernel32: Implement BaseThreadInitThunk in assembly also for PE builds.").
Thanks Alexandre
After the fix:
--- snip --- $ wine --version wine-5.22-39-g4807a8f588c
$ winedbg "c:\windows\syswow64\notepad.exe"
Wine-dbg>b mainCRTStartup Breakpoint 1 at 0x0000000000405280 mainCRTStartup in notepad
Wine-dbg>c
Stopped on breakpoint 1 at 0x0000000000405280 mainCRTStartup in notepad
Wine-dbg>x $esp 7b624240
Wine-dbg>disas 0x7b624240-0x10
# caller is BaseThreadInitThunk assembly wrapper
0x000000007b624230 WriteTapemark+0xa0 in kernel32: pushl %ebp 0x000000007b624231 WriteTapemark+0xa1 in kernel32: movl %esp,%ebp 0x000000007b624233 WriteTapemark+0xa3 in kernel32: pushl %ebx 0x000000007b624234 WriteTapemark+0xa4 in kernel32: movl 0x8(%ebp),%ebx 0x000000007b624237 WriteTapemark+0xa7 in kernel32: pushl 0x4(%ebp) 0x000000007b62423a WriteTapemark+0xaa in kernel32: pushl 0x4(%ebp) 0x000000007b62423d WriteTapemark+0xad in kernel32: pushl %ebx 0x000000007b62423e WriteTapemark+0xae in kernel32: call *%edx 0x000000007b624240 WriteTapemark+0xb0 in kernel32: movl %eax,0x0(%esp) 0x000000007b624243 WriteTapemark+0xb3 in kernel32: call 0x000000007b628c77 _RtlExitUserThread@4 in kernel32 --- snip ---
Before the fix:
--- snip --- $ export PATH=/home/focht/projects/wine/mainline-install-5.22-x86_64/bin:$PATH $ wine --version wine-5.22
Wine-dbg>b mainCRTStartup Breakpoint 1 at 0x0000000000405280 mainCRTStartup in notepad
Wine-dbg>c
Stopped on breakpoint 1 at 0x0000000000405280 mainCRTStartup in notepad
Wine-dbg>x $esp 7b624258
Wine-dbg>disas 0x7b624258-0x8
0x000000007b624250 BaseThreadInitThunk in kernel32: pushl %ebp 0x000000007b624251 BaseThreadInitThunk+0x1 in kernel32: movl %esp,%ebp 0x000000007b624253 BaseThreadInitThunk+0x3 in kernel32: pushl 0x8(%ebp) 0x000000007b624256 BaseThreadInitThunk+0x6 in kernel32: call *%edx 0x000000007b624258 BaseThreadInitThunk+0x8 in kernel32: pushl %eax 0x000000007b624259 BaseThreadInitThunk+0x9 in kernel32: call *0x7b639968 -> (invalid destination) 0x000000007b62425f BaseThreadInitThunk+0xf in kernel32: nop --- snip ---
Regards
https://bugs.winehq.org/show_bug.cgi?id=50171
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #2 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 6.0-rc1.
https://bugs.winehq.org/show_bug.cgi?id=50171
Anastasius Focht focht@gmx.net changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download URL| |https://web.archive.org/web | |/20201121203123/http://www. | |tucows.com/download/games/f | |iles2/Wazzal12.exe