https://bugs.winehq.org/show_bug.cgi?id=49802
Bug ID: 49802 Summary: Crash at AfxBeginThread of x64 apps on macOS when built with VS2019 Product: Wine Version: 5.16 Hardware: x86-64 OS: Mac OS X Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown Assignee: wine-bugs@winehq.org Reporter: reinhold.hoffmann@hotmail.com
Created attachment 68117 --> https://bugs.winehq.org/attachment.cgi?id=68117 Samples to demonstrate the issue
Our x64 apps built with Visual Studio 2010 (VS2010) run on macOS for a long time. We recently have started a project to move to Visual Studion 2019 (VS2019). The same x64 app which works fine when built with VS2010 crashes on macOS when it is built with VS2019. The crash occurs when the MFC function AfxBeginThread is called. Static linking is used for linking the MFC and other libs.
After a very painful research we identified that a simular report has been made in Nov. 2019 in the Wineskin area (see https://github.com/Gcenx/WineskinServer/issues/22).
The reporter said "I ended up replacing the AfxBeginThread call with a call to CreateThread which works fine on all versions." We did the same thing with the same result. Replacing AfxBeginThread by CreateThread works fine with VS2019. However, according to https://stackoverflow.com/questions/21718674/difference-between-afxbeginthre... a replacement of AfxBeginThread by CreateThread is not really recommended when MFC is used.
The crash happens on all macOS versions with Wine 5.4, 5.7 and 5.16 (we took 5.16 from Gcenx (https://github.com/Gcenx/macOS_Wine_builds)). On Windows and Linux the VS2019 app runs fine. Further, the Win32 equivalent app runs fine on macOS.
In summary:
A crash happens for AfxbeginThread in an x64 app on macOS with Wine 5.4, 5.7, 5.16.
We did a deeper dive and found that the crash happens inside AfxbeginThread, module Thread.cpp inside the function __acrt_get_begin_thread_init_policy. See address: 0001:001ab7cc __acrt_get_begin_thread_init_policy 00000001401ac7cc f libucrt:win_policies.obj
According to the backtrace.txt (attached) the exception happens when reading from a 32 bit address. This sounds strange to me for a x64 app.
Any help is highly appreciated.
Reinhold
==========================================================================
As a C++ sample I have compiled a trivial app which AfxBeginThread which demonstrate the problem.
In the attached zip file you can find
backtrace.txt Test_of_AfxBeginThread_VS2019.exe Test_of_AfxBeginThread_VS2010.exe
The code and project files for VS2010 and VS2019 can be downloaded from www.notation.com/download/Wine/Bugzilla/Project_Files_AfxBeginThread_samples.zip