Dynamic Libraries
From ReactOS
| This page is a short article on something that should have a lot more information written on it. If you know anything else about it, you are STRONGLY encouraged to add the information in. If you are unsure of proper formatting or style, add it to the talk page or this page itself as you think best and others will help. |
Contents |
Definition
Dynamic link libraries, or DLL, are the implementation of the shared library concept in the Windows and OS/2 operating systems. These libraries usually have the file extension DLL, OCX (for libraries containing ActiveX controls), or DRV (for legacy(win9x) Device drivers/system drivers). The file formats for DLLs are the same as for Windows EXE files — that is, Portable Executable (PE) for 32-bit and 64-bit Windows. As with EXEs, DLLs can contain code, data, and resource sections, in any combination.
Sections
TLS
The .tls section provides direct support for static thread local storage (TLS). TLS is a special storage class in which a data object is not an stack variable, yet is local to each individual thread that runs the code. Thus, each thread can maintain a different value for a variable declared by using TLS.
//__declspec (thread) int tlsVar = 1;
Note that TLS data can be supported by using the API calls TlsAlloc, TlsFree, TlsSetValue, and TlsGetValue. The PE implementation is an alternative approach to using the API and has the advantage of being simpler from the high-level-language programmer’s viewpoint. To support this programming construct, the PE .tls section specifies the following information: initialization data, callback routines for per-thread initialization and termination, and the TLS index.
On Windows operating systems before Windows Vista, statically declared TLS data objects can be used only in statically loaded image files. This fact makes it unreliable to use static TLS data in a DLL unless you know that the DLL, or anything statically linked with it, will never be loaded dynamically with the LoadLibrary API function, which could cause a protection fault. Someone should write a test case for ReactOS.
For more details see: Rules and Limitations for TLS(msdn)

