File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,24 @@ FinalizeSections(PMEMORYMODULE module)
184184#endif
185185}
186186
187+ static void
188+ ExecuteTLS (PMEMORYMODULE module )
189+ {
190+ unsigned char * codeBase = module -> codeBase ;
191+
192+ PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY (module , IMAGE_DIRECTORY_ENTRY_TLS );
193+ if (directory -> VirtualAddress > 0 ) {
194+ PIMAGE_TLS_DIRECTORY tls = (PIMAGE_TLS_DIRECTORY ) (codeBase + directory -> VirtualAddress );
195+ PIMAGE_TLS_CALLBACK * callback = (PIMAGE_TLS_CALLBACK * ) tls -> AddressOfCallBacks ;
196+ if (callback ) {
197+ while (* callback ) {
198+ (* callback )((LPVOID ) codeBase , DLL_PROCESS_ATTACH , NULL );
199+ callback ++ ;
200+ }
201+ }
202+ }
203+ }
204+
187205static void
188206PerformBaseRelocation (PMEMORYMODULE module , SIZE_T delta )
189207{
@@ -419,6 +437,9 @@ HMEMORYMODULE MemoryLoadLibraryEx(const void *data,
419437 // sections that are marked as "discardable"
420438 FinalizeSections (result );
421439
440+ // TLS callbacks are executed BEFORE the main loading
441+ ExecuteTLS (result );
442+
422443 // get entry point of loaded library
423444 if (result -> headers -> OptionalHeader .AddressOfEntryPoint != 0 ) {
424445 DllEntry = (DllEntryProc ) (code + result -> headers -> OptionalHeader .AddressOfEntryPoint );
You can’t perform that action at this time.
0 commit comments