Windows DLLs and TLS

Jakob Ovrum jakobovrum at gmail.com
Mon Oct 8 04:42:01 PDT 2012


On Monday, 8 October 2012 at 11:55:24 UTC, Paulo Pinto wrote:
> On Monday, 8 October 2012 at 11:44:28 UTC, Jakob Ovrum wrote:
>> I have a bug in one of my programs that I find particularly 
>> hard to reduce.
>>
>> I am writing a Windows DLL plugin for the IRC chat client 
>> HexChat (aka XChat). Problem is, all TLS variables, regardless 
>> of type, appear to be initialized to complete rubbish values. 
>> Reading them does not cause an access violation or anything, 
>> but the initial values are garbage. I am initializing the 
>> runtime using the helpers found in core.sys.windows.dll [1].
>>
>> I wrote a dummy host application in C mimicking the loading 
>> behaviour of HexChat - the TLS variables are initialized 
>> correctly in this case, even though the DLL file is exactly 
>> the same.
>>
>> What is it that a host application can do to break the TLS of 
>> a D plugin it loads?
>>
>> [1] http://pastebin.com/rg9uUQMe
>
> Did you already went through this howto?
>
> http://dlang.org/dll.html

Of course. I've written many DLLs before, and again, TLS works in 
the exact same DLL when a different host program is used, hence 
why it's so difficult to reduce.

Besides, there's nothing relevant in that article.



More information about the Digitalmars-d mailing list