Quantcast
Channel: Claims based access platform (CBA), code-named Geneva forum
Viewing all articles
Browse latest Browse all 2535

Thread local storage slots of C/C++ dll getting loaded for .NET threads.

$
0
0

A WCF service is using a C/C++ DLL.

The dll uses __declspec(thread) specifier for it's globals and static variables. There is a dedicated native (c++) thread that is expected to use the TLS slots.

Now even though the tasks/threads of WCF service dont require TLS slots, the TLS array is getting initialized. Following are the call stacks when threads are being associated to .net tasks:

        50dbaf1 LeakTrack+0x0000baf1
        777e05f6 ntdll!LdrpHandleTlsData+0x00000155
        778356fb ntdll!LdrpLoadImportModule+0x0000034d
        77834fdf ntdll!LdrpHandleOneOldFormatImportDescriptor+0x00000088
        77834f65 ntdll!LdrpHandleOldFormatImportDescriptors+0x0000001c
        77830bbd ntdll!LdrpProcessStaticImports+0x00000256
        778303f1 ntdll!LdrpLoadDll+0x00000314
        778322b2 ntdll!LdrLoadDll+0x00000092


        1f8c0018 2625c8 0000  [00]   1f8c0030    1312e32 - (busy VirtualAlloc)
        7784ddac ntdll!RtlAllocateHeap+0x00000274
        50dbaf1 LeakTrack+0x0000baf1
        777e4b4f ntdll!LdrpAllocateTls+0x0000009b
        778336ff ntdll!LdrpInitializeThread+0x000000b2
        778335bc ntdll!_LdrpInitialize+0x000001ad
        778335e9 ntdll!LdrInitializeThunk+0x00000010

This array consumes apporximately 20MB and is leading to a memory leak.

It would be helpful if inputs can be provided on the following:

1. Why are TLS slots initialized for managed threads and tasks?

2. Is there a way to block or avoid the initialization of TLS slots for managed threads and tasks?

3. Will using TLSAlloc in DLL resolve the issue and TLS slots won't be initialized for managed threads?


Regards, Anand


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>