https://bugs.winehq.org/show_bug.cgi?id=53960
Bug ID: 53960 Summary: ucrt has different struct layout than msvcrt Product: Wine Version: unspecified Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: msvcrt Assignee: wine-bugs@winehq.org Reporter: euloanty@live.com Distribution: ---
https://bugs.winehq.org/show_bug.cgi?id=51698
I found that bug before it was actually because UCRT definition of struct _iobuf in wine is just wrong.
This is a serious abi issue that has to be fixed and that is also probably why UCRT programs do not work very well on wine.
/* referenced from win10sdk ucrt C:\Program Files (x86)\Windows Kits\10\Source\10.0.19041.0\ucrt //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // // Internal Stream Types (__crt_stdio_stream and friends) // //-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // Ensure that __crt_stdio_stream_data* and FILE* pointers are freely convertible: struct ucrt_stdio_stream_data { union { FILE public_file; char* ptr; }; char* base; int cnt; long flags; long file; int charbuf; int bufsiz; char* tmpfname; };
The definition of UCRT is
struct #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] #endif ucrt_iobuf { char* _ptr; char* _base; int _cnt; long _flag; long _file; int _charbuf; int _bufsiz; char* _tmpfname; };
while msvcrt is
struct #if __has_cpp_attribute(__gnu__::__may_alias__) [[__gnu__::__may_alias__]] #endif ucrt_iobuf { char* _ptr; int _cnt; char* _base; int _flag; int _file; int _charbuf; int _bufsiz; char* _tmpfname; };
The location of _base and _cnt swaps.
https://bugs.winehq.org/show_bug.cgi?id=53960
cqwrteur euloanty@live.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |euloanty@live.com
--- Comment #1 from cqwrteur euloanty@live.com --- https://github.com/wine-mirror/wine/blob/master/include/msvcrt/corecrt_wstdi...
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #2 from cqwrteur euloanty@live.com --- https://github.com/trcrsired/fast_io/blob/master/include/fast_io_legacy_impl...
Here the fast_io library uses it
https://bugs.winehq.org/show_bug.cgi?id=53960
cqwrteur euloanty@live.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |critical Priority|P2 |P1
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #3 from cqwrteur euloanty@live.com --- https://github.com/wine-mirror/wine/blob/master/include/msvcrt/stdio.h
Also
/* file._flag flags */ #define _IOREAD 0x0001 #define _IOWRT 0x0002 #define _IOMYBUF 0x0008 #define _IOEOF 0x0010 #define _IOERR 0x0020 #define _IOSTRG 0x0040 #define _IORW 0x0080
These flags are all different for UCRT. This part must be changed. They are all super wrong.
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #4 from Alexandre Julliard julliard@winehq.org --- Comment removed, please don't copy/paste anything from Microsoft's proprietary code, we can't use it as reference.
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #5 from cqwrteur euloanty@live.com --- https://github.com/wine-mirror/wine/blob/a8c1d5c108fc57e4d78e9db126f395c8908...
Also. I do not know whether this is correct or not. Because the behavior in the UCRT is just locking EnterCriticalSection(&((file_crit*)file)->crit);
It does not match the ms behavior
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #6 from cqwrteur euloanty@live.com --- https://github.com/wine-mirror/wine/blob/a8c1d5c108fc57e4d78e9db126f395c8908...
Also. I do not know whether this is correct or not. Because the behavior in the UCRT is just locking EnterCriticalSection(&((file_crit*)file)->crit);
It does not match the ms behavior
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #7 from cqwrteur euloanty@live.com --- Created attachment 73547 --> https://bugs.winehq.org/attachment.cgi?id=73547 A patch to fix the layout issue first
I am still trying to understand whether the _lock_file and _unlock_file part need to change too since I do not know how ms deals with this before UCRT. Also, according to the API documentation of MSDN, _lock and _unlock have been deprecated. The implementation in _UCRT always locks the CriticalSection in _iobuf even if it lives in _IOB_ENTRIES.
I would like to listen to how wine is going to deal with this.
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #8 from cqwrteur euloanty@live.com --- Created attachment 73548 --> https://bugs.winehq.org/attachment.cgi?id=73548 Fix layout issue of UCRT by adding a pseudo struct
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #9 from cqwrteur euloanty@live.com --- *** Bug 51698 has been marked as a duplicate of this bug. ***
https://bugs.winehq.org/show_bug.cgi?id=53960
cqwrteur euloanty@live.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #73547|0 |1 is obsolete| | Attachment #73548|0 |1 is obsolete| |
--- Comment #10 from cqwrteur euloanty@live.com --- Created attachment 73549 --> https://bugs.winehq.org/attachment.cgi?id=73549 Fix potential build issues
https://bugs.winehq.org/show_bug.cgi?id=53960
cqwrteur euloanty@live.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #73549|0 |1 is obsolete| |
--- Comment #11 from cqwrteur euloanty@live.com --- Created attachment 73552 --> https://bugs.winehq.org/attachment.cgi?id=73552 Fix initializecriticalsection for twice for stdin, stdout and stderr
To change to InitializeCriticalSectionEx
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #12 from cqwrteur euloanty@live.com --- https://gitlab.winehq.org/wine/wine/-/merge_requests/5752 I have submitted a PR to fix it by myself
https://bugs.winehq.org/show_bug.cgi?id=53960
Ken Sharp imwellcushtymelike@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |source
https://bugs.winehq.org/show_bug.cgi?id=53960
--- Comment #13 from cqwrteur euloanty@live.com --- Example of code break //a.dll dynamically linked with ucrt __declspec(dllexport) extern "C" void export_fp(FILE* fp) noexcept { fprintf(fp, "%s", "hello world"); //crash }
//main.exe uses function from a.dll //main.exe compiled with msvc __declspec(dllimport) extern "C" void export_fp(FILE* fp) noexcept;
int main() { FILE* fp = fopen("a.txt", "wb"); export_fp(fp); fclose(fp); }
https://bugs.winehq.org/show_bug.cgi?id=53960
Piotr Caban piotr.caban@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |piotr.caban@gmail.com
--- Comment #14 from Piotr Caban piotr.caban@gmail.com --- It should be fixed now. Please retest.
https://bugs.winehq.org/show_bug.cgi?id=53960
cqwrteur euloanty@live.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED
--- Comment #15 from cqwrteur euloanty@live.com --- fixed
https://bugs.winehq.org/show_bug.cgi?id=53960
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #16 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 9.11.
https://bugs.winehq.org/show_bug.cgi?id=53960
Fabian Maurer dark.shadow4@web.de changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |dark.shadow4@web.de
--- Comment #17 from Fabian Maurer dark.shadow4@web.de --- This seems to have caused a regression, see bug 56956.