VOID
2.LdrShutdownThread (
3. VOID
4. )
5./*++
6.Routine Description:
7. This function is called by a thread that is terminating cleanly.
8. It‘s purpose is to call all of the processes DLLs to notify them
9. that the thread is detaching.
10.Arguments:
11. None
12.Return Value:
13. None.
14.--*/
15.{
16. PPEB Peb;
17. PLDR_DATA_TABLE_ENTRY LdrDataTableEntry;
18. PDLL_INIT_ROUTINE InitRoutine;
19. PLIST_ENTRY Next;
20.
21. Peb = NtCurrentPeb();
22.
23. RtlEnterCriticalSection(&LoaderLock);
24.
25. try {
26. //
27. // Go in reverse order initialization order and build
28. // the unload list
29. //
30.
31. Next = Peb->Ldr->InInitializationOrderModuleList.Blink;
32. while ( Next != &Peb->Ldr->InInitializationOrderModuleList) {
33. LdrDataTableEntry
34. = (PLDR_DATA_TABLE_ENTRY)
35. (CONTAINING_RECORD(Next,LDR_DATA_TABLE_ENTRY,InInitializationOrderLinks));
36.
37. Next = Next->Blink;
38.
39. //
40. // Walk through the entire list looking for
41. // entries. For each entry, that has an init
42. // routine, call it.
43. //
44.
45. if (Peb->ImageBaseAddress != LdrDataTableEntry->DllBase) {
46. if ( !(LdrDataTableEntry->Flags & LDRP_DONT_CALL_FOR_THREADS)) {
47. InitRoutine = (PDLL_INIT_ROUTINE)LdrDataTableEntry->EntryPoint;
48. if (InitRoutine && (LdrDataTableEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) ) {
49. if (LdrDataTableEntry->Flags & LDRP_IMAGE_DLL) {
50. if ( LdrDataTableEntry->TlsIndex ) {
51. LdrpCallTlsInitializers(LdrDataTableEntry->DllBase,DLL_THREAD_DETACH);
52. }
53.
54.#if defined (WX86)
55. if (!Wx86ProcessInit ||
56. LdrpRunWx86DllEntryPoint(InitRoutine,
57. NULL,
58. LdrDataTableEntry->DllBase,
59. DLL_THREAD_DETACH,
60. NULL
61. ) == STATUS_IMAGE_MACHINE_TYPE_MISMATCH)
62.#endif
63. {
64. LdrpCallInitRoutine(InitRoutine,
65. LdrDataTableEntry->DllBase,
66. DLL_THREAD_DETACH,
67. NULL);
68. }
69. }
70. }
71. }
72. }
73. }
74.
75. //
76. // If the image has tls than call its initializers
77. //
78.
79. if ( LdrpImageHasTls ) {
80. LdrpCallTlsInitializers(NtCurrentPeb()->ImageBaseAddress,DLL_THREAD_DETACH);
81. }
82. LdrpFreeTls();
83.
84. } finally {
85.
86. RtlLeaveCriticalSection(&LoaderLock);
87. }
88.}