[PATCH 6/7] msvcrt: Make UCRT _beginthread[ex]() hold the DLL reference.

Piotr Caban piotr.caban at gmail.com
Tue May 4 10:53:35 CDT 2021


On 5/4/21 5:26 PM, Arkadiusz Hiler wrote:
> On Tue, May 04, 2021 at 02:39:17PM +0200, Piotr Caban wrote:
>> Hi Arek,
>>
>> On 5/4/21 1:49 PM, Arkadiusz Hiler wrote:
>>>    /*********************************************************************
>>> @@ -88,7 +90,17 @@ void CDECL _endthreadex(
>>>    {
>>>      TRACE("(%d)\n", retval);
>>> -  /* FIXME */
>>> +#if _MSVCR_VER >= 140
>>> +  {
>>> +      thread_data_t *tls = TlsGetValue(msvcrt_tls_index);
>>> +
>>> +      if (tls && tls->module != NULL)
>>> +          FreeLibraryAndExitThread(tls->module, retval);
>>> +      else
>>> +          WARN("tls=%p tls->module=%p\n", tls, tls ? tls->module : NULL);
>>> +  }
>>> +#endif
>>> +
>>>      ExitThread(retval);
>>>    }
>> I didn't test it but I bet that _endthreadex should still close the handle
>> if thread was created by _beginthread. It will also make the _endthread and
>> _endthreadex functions identical. Did you check it?
> 
> I belive this is covered by msvcrt/tests/misc.c:test_thread_handle_close():
> 
> https://source.winehq.org/git/wine.git/blob/3ba4412be60dafee310b5d3c71aa762aa8846564:/dlls/msvcrt/tests/misc.c#l546
Yes, you're right. It's another difference between msvcrt and ucrtbase. 
The handle is closed in endthreadex if you run the tests with ucrtbase.

Thanks,
Piotr



More information about the wine-devel mailing list