2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NT User-Mode Library
4 * FILE: dll/ntdll/ldr/ldrinit.c
5 * PURPOSE: User-Mode Process/Thread Startup
6 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
7 * Aleksey Bragin (aleksey@reactos.org)
10 /* INCLUDES *****************************************************************/
21 /* GLOBALS *******************************************************************/
23 HANDLE ImageExecOptionsKey
;
24 HANDLE Wow64ExecOptionsKey
;
25 UNICODE_STRING ImageExecOptionsString
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options");
26 UNICODE_STRING Wow64OptionsString
= RTL_CONSTANT_STRING(L
"");
27 UNICODE_STRING NtDllString
= RTL_CONSTANT_STRING(L
"ntdll.dll");
29 BOOLEAN LdrpInLdrInit
;
30 LONG LdrpProcessInitialized
;
31 BOOLEAN LdrpLoaderLockInit
;
32 BOOLEAN LdrpLdrDatabaseIsSetup
;
33 BOOLEAN LdrpShutdownInProgress
;
34 HANDLE LdrpShutdownThreadId
;
36 BOOLEAN LdrpDllValidation
;
38 PLDR_DATA_TABLE_ENTRY LdrpImageEntry
;
39 PUNICODE_STRING LdrpTopLevelDllBeingLoaded
;
40 WCHAR StringBuffer
[156];
41 extern PTEB LdrpTopLevelDllBeingLoadedTeb
; // defined in rtlsupp.c!
42 PLDR_DATA_TABLE_ENTRY LdrpCurrentDllInitializer
;
43 PLDR_DATA_TABLE_ENTRY LdrpNtDllDataTableEntry
;
46 RTL_BITMAP TlsExpansionBitMap
;
48 BOOLEAN LdrpImageHasTls
;
49 LIST_ENTRY LdrpTlsList
;
50 ULONG LdrpNumberOfTlsEntries
;
51 ULONG LdrpNumberOfProcessors
;
53 extern LARGE_INTEGER RtlpTimeout
;
54 BOOLEAN RtlpTimeoutDisable
;
55 LIST_ENTRY LdrpHashTable
[LDR_HASH_TABLE_ENTRIES
];
56 LIST_ENTRY LdrpDllNotificationList
;
57 HANDLE LdrpKnownDllObjectDirectory
;
58 UNICODE_STRING LdrpKnownDllPath
;
59 WCHAR LdrpKnownDllPathBuffer
[128];
60 UNICODE_STRING LdrpDefaultPath
;
64 RTL_CRITICAL_SECTION_DEBUG LdrpLoaderLockDebug
;
65 RTL_CRITICAL_SECTION LdrpLoaderLock
=
74 RTL_CRITICAL_SECTION FastPebLock
;
78 ULONG LdrpFatalHardErrorCount
;
79 ULONG LdrpActiveUnloadCount
;
81 //extern LIST_ENTRY RtlCriticalSectionList;
83 VOID
RtlpInitializeVectoredExceptionHandling(VOID
);
84 VOID NTAPI
RtlpInitDeferedCriticalSection(VOID
);
85 VOID NTAPI
RtlInitializeHeapManager(VOID
);
86 extern BOOLEAN RtlpPageHeapEnabled
;
88 ULONG RtlpDisableHeapLookaside
; // TODO: Move to heap.c
89 ULONG RtlpShutdownProcessFlags
; // TODO: Use it
91 NTSTATUS
LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders
, PVOID ImageBase
);
92 void actctx_init(void);
95 #define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
97 #define DEFAULT_SECURITY_COOKIE 0xBB40E64E
100 /* FUNCTIONS *****************************************************************/
107 LdrOpenImageFileOptionsKey(IN PUNICODE_STRING SubKey
,
109 OUT PHANDLE NewKeyHandle
)
111 PHANDLE RootKeyLocation
;
113 UNICODE_STRING SubKeyString
;
114 OBJECT_ATTRIBUTES ObjectAttributes
;
118 /* Check which root key to open */
120 RootKeyLocation
= &Wow64ExecOptionsKey
;
122 RootKeyLocation
= &ImageExecOptionsKey
;
124 /* Get the current key */
125 RootKey
= *RootKeyLocation
;
127 /* Setup the object attributes */
128 InitializeObjectAttributes(&ObjectAttributes
,
130 &Wow64OptionsString
: &ImageExecOptionsString
,
131 OBJ_CASE_INSENSITIVE
,
135 /* Open the root key */
136 Status
= ZwOpenKey(&RootKey
, KEY_ENUMERATE_SUB_KEYS
, &ObjectAttributes
);
137 if (NT_SUCCESS(Status
))
139 /* Write the key handle */
140 if (_InterlockedCompareExchange((LONG
*)RootKeyLocation
, (LONG
)RootKey
, 0) != 0)
142 /* Someone already opened it, use it instead */
144 RootKey
= *RootKeyLocation
;
147 /* Extract the name */
148 SubKeyString
= *SubKey
;
149 p1
= (PWCHAR
)((ULONG_PTR
)SubKeyString
.Buffer
+ SubKeyString
.Length
);
150 while (SubKeyString
.Length
)
152 if (p1
[-1] == L
'\\') break;
154 SubKeyString
.Length
-= sizeof(*p1
);
156 SubKeyString
.Buffer
= p1
;
157 SubKeyString
.Length
= SubKey
->Length
- SubKeyString
.Length
;
159 /* Setup the object attributes */
160 InitializeObjectAttributes(&ObjectAttributes
,
162 OBJ_CASE_INSENSITIVE
,
166 /* Open the setting key */
167 Status
= ZwOpenKey((PHANDLE
)NewKeyHandle
, GENERIC_READ
, &ObjectAttributes
);
170 /* Return to caller */
179 LdrQueryImageFileKeyOption(IN HANDLE KeyHandle
,
184 OUT PULONG ReturnedLength OPTIONAL
)
187 UNICODE_STRING ValueNameString
, IntegerString
;
188 ULONG KeyInfoSize
, ResultSize
;
189 PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation
= (PKEY_VALUE_PARTIAL_INFORMATION
)&KeyInfo
;
190 BOOLEAN FreeHeap
= FALSE
;
193 /* Build a string for the value name */
194 Status
= RtlInitUnicodeStringEx(&ValueNameString
, ValueName
);
195 if (!NT_SUCCESS(Status
)) return Status
;
197 /* Query the value */
198 Status
= ZwQueryValueKey(KeyHandle
,
200 KeyValuePartialInformation
,
204 if (Status
== STATUS_BUFFER_OVERFLOW
)
206 /* Our local buffer wasn't enough, allocate one */
207 KeyInfoSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
) +
208 KeyValueInformation
->DataLength
;
209 KeyValueInformation
= RtlAllocateHeap(RtlGetProcessHeap(),
212 if (KeyValueInformation
!= NULL
)
215 Status
= ZwQueryValueKey(KeyHandle
,
217 KeyValuePartialInformation
,
225 /* Give up this time */
226 Status
= STATUS_NO_MEMORY
;
230 /* Check for success */
231 if (NT_SUCCESS(Status
))
233 /* Handle binary data */
234 if (KeyValueInformation
->Type
== REG_BINARY
)
237 if ((Buffer
) && (KeyValueInformation
->DataLength
<= BufferSize
))
239 /* Copy into buffer */
240 RtlMoveMemory(Buffer
,
241 &KeyValueInformation
->Data
,
242 KeyValueInformation
->DataLength
);
246 Status
= STATUS_BUFFER_OVERFLOW
;
249 /* Copy the result length */
250 if (ReturnedLength
) *ReturnedLength
= KeyValueInformation
->DataLength
;
252 else if (KeyValueInformation
->Type
== REG_DWORD
)
254 /* Check for valid type */
255 if (KeyValueInformation
->Type
!= Type
)
258 Status
= STATUS_OBJECT_TYPE_MISMATCH
;
264 (BufferSize
== sizeof(ULONG
)) &&
265 (KeyValueInformation
->DataLength
<= BufferSize
))
267 /* Copy into buffer */
268 RtlMoveMemory(Buffer
,
269 &KeyValueInformation
->Data
,
270 KeyValueInformation
->DataLength
);
274 Status
= STATUS_BUFFER_OVERFLOW
;
277 /* Copy the result length */
278 if (ReturnedLength
) *ReturnedLength
= KeyValueInformation
->DataLength
;
281 else if (KeyValueInformation
->Type
!= REG_SZ
)
283 /* We got something weird */
284 Status
= STATUS_OBJECT_TYPE_MISMATCH
;
288 /* String, check what you requested */
289 if (Type
== REG_DWORD
)
292 if (BufferSize
!= sizeof(ULONG
))
296 Status
= STATUS_INFO_LENGTH_MISMATCH
;
300 /* OK, we know what you want... */
301 IntegerString
.Buffer
= (PWSTR
)KeyValueInformation
->Data
;
302 IntegerString
.Length
= (USHORT
)KeyValueInformation
->DataLength
-
304 IntegerString
.MaximumLength
= (USHORT
)KeyValueInformation
->DataLength
;
305 Status
= RtlUnicodeStringToInteger(&IntegerString
, 0, (PULONG
)Buffer
);
311 if (KeyValueInformation
->DataLength
> BufferSize
)
314 Status
= STATUS_BUFFER_OVERFLOW
;
319 BufferSize
= KeyValueInformation
->DataLength
;
322 /* Copy the string */
323 RtlMoveMemory(Buffer
, &KeyValueInformation
->Data
, BufferSize
);
326 /* Copy the result length */
327 if (ReturnedLength
) *ReturnedLength
= KeyValueInformation
->DataLength
;
331 /* Check if buffer was in heap */
332 if (FreeHeap
) RtlFreeHeap(RtlGetProcessHeap(), 0, KeyValueInformation
);
343 LdrQueryImageFileExecutionOptionsEx(IN PUNICODE_STRING SubKey
,
348 OUT PULONG ReturnedLength OPTIONAL
,
354 /* Open a handle to the key */
355 Status
= LdrOpenImageFileOptionsKey(SubKey
, Wow64
, &KeyHandle
);
357 /* Check for success */
358 if (NT_SUCCESS(Status
))
361 Status
= LdrQueryImageFileKeyOption(KeyHandle
,
372 /* Return to caller */
381 LdrQueryImageFileExecutionOptions(IN PUNICODE_STRING SubKey
,
386 OUT PULONG ReturnedLength OPTIONAL
)
388 /* Call the newer function */
389 return LdrQueryImageFileExecutionOptionsEx(SubKey
,
400 LdrpEnsureLoaderLockIsHeld()
407 LdrpFetchAddressOfSecurityCookie(PVOID BaseAddress
, ULONG SizeOfImage
)
409 PIMAGE_LOAD_CONFIG_DIRECTORY ConfigDir
;
413 /* Check NT header first */
414 if (!RtlImageNtHeader(BaseAddress
)) return NULL
;
416 /* Get the pointer to the config directory */
417 ConfigDir
= RtlImageDirectoryEntryToData(BaseAddress
,
419 IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
,
422 /* Check for sanity */
424 (DirSize
!= 64 && ConfigDir
->Size
!= DirSize
) ||
425 (ConfigDir
->Size
< 0x48))
428 /* Now get the cookie */
429 Cookie
= (PVOID
)ConfigDir
->SecurityCookie
;
431 /* Check this cookie */
432 if ((PCHAR
)Cookie
<= (PCHAR
)BaseAddress
||
433 (PCHAR
)Cookie
>= (PCHAR
)BaseAddress
+ SizeOfImage
)
438 /* Return validated security cookie */
444 LdrpInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry
)
447 LARGE_INTEGER Counter
;
450 /* Fetch address of the cookie */
451 Cookie
= LdrpFetchAddressOfSecurityCookie(LdrEntry
->DllBase
, LdrEntry
->SizeOfImage
);
455 /* Check if it's a default one */
456 if ((*Cookie
== DEFAULT_SECURITY_COOKIE
) ||
459 /* Make up a cookie from a bunch of values which may uniquely represent
460 current moment of time, environment, etc */
461 NtQueryPerformanceCounter(&Counter
, NULL
);
463 NewCookie
= Counter
.LowPart
^ Counter
.HighPart
;
464 NewCookie
^= (ULONG
)NtCurrentTeb()->ClientId
.UniqueProcess
;
465 NewCookie
^= (ULONG
)NtCurrentTeb()->ClientId
.UniqueThread
;
467 /* Loop like it's done in KeQueryTickCount(). We don't want to call it directly. */
468 while (SharedUserData
->SystemTime
.High1Time
!= SharedUserData
->SystemTime
.High2Time
)
473 /* Calculate the milliseconds value and xor it to the cookie */
474 NewCookie
^= Int64ShrlMod32(UInt32x32To64(SharedUserData
->TickCountMultiplier
, SharedUserData
->TickCount
.LowPart
), 24) +
475 (SharedUserData
->TickCountMultiplier
* (SharedUserData
->TickCount
.High1Time
<< 8));
477 /* Make the cookie 16bit if necessary */
478 if (*Cookie
== 0xBB40) NewCookie
&= 0xFFFF;
480 /* If the result is 0 or the same as we got, just subtract one from the existing value
482 if ((NewCookie
== 0) || (NewCookie
== *Cookie
))
484 NewCookie
= *Cookie
- 1;
487 /* Set the new cookie value */
497 LdrpInitializeThread(IN PCONTEXT Context
)
499 PPEB Peb
= NtCurrentPeb();
500 PLDR_DATA_TABLE_ENTRY LdrEntry
;
501 PLIST_ENTRY NextEntry
, ListHead
;
502 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx
;
506 DPRINT("LdrpInitializeThread() called for %wZ (%p/%p)\n",
507 &LdrpImageEntry
->BaseDllName
,
508 NtCurrentTeb()->RealClientId
.UniqueProcess
,
509 NtCurrentTeb()->RealClientId
.UniqueThread
);
511 /* Allocate an Activation Context Stack */
512 DPRINT("ActivationContextStack %p\n", NtCurrentTeb()->ActivationContextStackPointer
);
513 Status
= RtlAllocateActivationContextStack(&NtCurrentTeb()->ActivationContextStackPointer
);
514 if (!NT_SUCCESS(Status
))
516 DPRINT1("Warning: Unable to allocate ActivationContextStack\n");
519 /* Make sure we are not shutting down */
520 if (LdrpShutdownInProgress
) return;
525 /* Start at the beginning */
526 ListHead
= &Peb
->Ldr
->InMemoryOrderModuleList
;
527 NextEntry
= ListHead
->Flink
;
528 while (NextEntry
!= ListHead
)
530 /* Get the current entry */
531 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InMemoryOrderModuleList
);
533 /* Make sure it's not ourselves */
534 if (Peb
->ImageBaseAddress
!= LdrEntry
->DllBase
)
536 /* Check if we should call */
537 if (!(LdrEntry
->Flags
& LDRP_DONT_CALL_FOR_THREADS
))
539 /* Get the entrypoint */
540 EntryPoint
= LdrEntry
->EntryPoint
;
542 /* Check if we are ready to call it */
544 (LdrEntry
->Flags
& LDRP_PROCESS_ATTACH_CALLED
) &&
545 (LdrEntry
->Flags
& LDRP_IMAGE_DLL
))
547 /* Set up the Act Ctx */
548 ActCtx
.Size
= sizeof(ActCtx
);
550 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
552 /* Activate the ActCtx */
553 RtlActivateActivationContextUnsafeFast(&ActCtx
,
554 LdrEntry
->EntryPointActivationContext
);
556 /* Check if it has TLS */
557 if (LdrEntry
->TlsIndex
)
559 /* Make sure we're not shutting down */
560 if (!LdrpShutdownInProgress
)
563 LdrpCallTlsInitializers(LdrEntry
->DllBase
, DLL_THREAD_ATTACH
);
567 /* Make sure we're not shutting down */
568 if (!LdrpShutdownInProgress
)
570 /* Call the Entrypoint */
571 DPRINT("%wZ - Calling entry point at %p for thread attaching, %p/%p\n",
572 &LdrEntry
->BaseDllName
, LdrEntry
->EntryPoint
,
573 NtCurrentTeb()->RealClientId
.UniqueProcess
,
574 NtCurrentTeb()->RealClientId
.UniqueThread
);
575 LdrpCallInitRoutine(LdrEntry
->EntryPoint
,
581 /* Deactivate the ActCtx */
582 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
588 NextEntry
= NextEntry
->Flink
;
592 if (LdrpImageHasTls
&& !LdrpShutdownInProgress
)
594 /* Set up the Act Ctx */
595 ActCtx
.Size
= sizeof(ActCtx
);
597 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
599 /* Activate the ActCtx */
600 RtlActivateActivationContextUnsafeFast(&ActCtx
,
601 LdrpImageEntry
->EntryPointActivationContext
);
603 /* Do TLS callbacks */
604 LdrpCallTlsInitializers(Peb
->ImageBaseAddress
, DLL_THREAD_ATTACH
);
606 /* Deactivate the ActCtx */
607 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
610 DPRINT("LdrpInitializeThread() done\n");
615 LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL
)
617 PLDR_DATA_TABLE_ENTRY LocalArray
[16];
618 PLIST_ENTRY ListHead
;
619 PLIST_ENTRY NextEntry
;
620 PLDR_DATA_TABLE_ENTRY LdrEntry
, *LdrRootEntry
, OldInitializer
;
624 NTSTATUS Status
= STATUS_SUCCESS
;
625 PPEB Peb
= NtCurrentPeb();
626 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx
;
627 ULONG BreakOnDllLoad
;
631 DPRINT("LdrpRunInitializeRoutines() called for %wZ (%p/%p)\n",
632 &LdrpImageEntry
->BaseDllName
,
633 NtCurrentTeb()->RealClientId
.UniqueProcess
,
634 NtCurrentTeb()->RealClientId
.UniqueThread
);
636 /* Check the Loader Lock */
637 LdrpEnsureLoaderLockIsHeld();
639 /* Get the number of entries to call */
640 if ((Count
= LdrpClearLoadInProgress()))
642 /* Check if we can use our local buffer */
645 /* Allocate space for all the entries */
646 LdrRootEntry
= RtlAllocateHeap(RtlGetProcessHeap(),
648 Count
* sizeof(*LdrRootEntry
));
649 if (!LdrRootEntry
) return STATUS_NO_MEMORY
;
653 /* Use our local array */
654 LdrRootEntry
= LocalArray
;
663 /* Show debug message */
666 DPRINT1("[%p,%p] LDR: Real INIT LIST for Process %wZ\n",
667 NtCurrentTeb()->RealClientId
.UniqueThread
,
668 NtCurrentTeb()->RealClientId
.UniqueProcess
,
669 &Peb
->ProcessParameters
->ImagePathName
);
673 ListHead
= &Peb
->Ldr
->InInitializationOrderModuleList
;
674 NextEntry
= ListHead
->Flink
;
676 while (NextEntry
!= ListHead
)
678 /* Get the Data Entry */
679 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InInitializationOrderModuleList
);
681 /* Check if we have a Root Entry */
685 if (!(LdrEntry
->Flags
& LDRP_ENTRY_PROCESSED
))
687 /* Setup the Cookie for the DLL */
688 LdrpInitSecurityCookie(LdrEntry
);
690 /* Check for valid entrypoint */
691 if (LdrEntry
->EntryPoint
)
695 LdrRootEntry
[i
] = LdrEntry
;
697 /* Display debug message */
700 DPRINT1("[%p,%p] LDR: %wZ init routine %p\n",
701 NtCurrentTeb()->RealClientId
.UniqueThread
,
702 NtCurrentTeb()->RealClientId
.UniqueProcess
,
703 &LdrEntry
->FullDllName
,
704 LdrEntry
->EntryPoint
);
712 LdrEntry
->Flags
|= LDRP_ENTRY_PROCESSED
;
713 NextEntry
= NextEntry
->Flink
;
716 /* If we got a context, then we have to call Kernel32 for TS support */
719 /* Check if we have one */
720 //if (Kernel32ProcessInitPostImportfunction)
723 //Kernel32ProcessInitPostImportfunction();
727 //Kernel32ProcessInitPostImportfunction = NULL;
731 /* No root entry? return */
732 if (!LdrRootEntry
) return STATUS_SUCCESS
;
734 /* Set the TLD TEB */
735 OldTldTeb
= LdrpTopLevelDllBeingLoadedTeb
;
736 LdrpTopLevelDllBeingLoadedTeb
= NtCurrentTeb();
743 LdrEntry
= LdrRootEntry
[i
];
745 /* FIXME: Verify NX Compat */
747 /* Move to next entry */
750 /* Get its entrypoint */
751 EntryPoint
= LdrEntry
->EntryPoint
;
753 /* Are we being debugged? */
755 if (Peb
->BeingDebugged
|| Peb
->ReadImageFileExecOptions
)
757 /* Check if we should break on load */
758 Status
= LdrQueryImageFileExecutionOptions(&LdrEntry
->BaseDllName
,
764 if (!NT_SUCCESS(Status
)) BreakOnDllLoad
= 0;
766 /* Reset status back to STATUS_SUCCESS */
767 Status
= STATUS_SUCCESS
;
773 /* Check if we should show a message */
776 DPRINT1("LDR: %wZ loaded.", &LdrEntry
->BaseDllName
);
777 DPRINT1(" - About to call init routine at %p\n", EntryPoint
);
780 /* Break in debugger */
784 /* Make sure we have an entrypoint */
787 /* Save the old Dll Initializer and write the current one */
788 OldInitializer
= LdrpCurrentDllInitializer
;
789 LdrpCurrentDllInitializer
= LdrEntry
;
791 /* Set up the Act Ctx */
792 ActCtx
.Size
= sizeof(ActCtx
);
794 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
796 /* Activate the ActCtx */
797 RtlActivateActivationContextUnsafeFast(&ActCtx
,
798 LdrEntry
->EntryPointActivationContext
);
800 /* Check if it has TLS */
801 if (LdrEntry
->TlsIndex
&& Context
)
804 LdrpCallTlsInitializers(LdrEntry
->DllBase
, DLL_PROCESS_ATTACH
);
807 /* Call the Entrypoint */
810 DPRINT1("%wZ - Calling entry point at %p for DLL_PROCESS_ATTACH\n",
811 &LdrEntry
->BaseDllName
, EntryPoint
);
813 DllStatus
= LdrpCallInitRoutine(EntryPoint
,
818 /* Deactivate the ActCtx */
819 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
821 /* Save the Current DLL Initializer */
822 LdrpCurrentDllInitializer
= OldInitializer
;
824 /* Mark the entry as processed */
825 LdrEntry
->Flags
|= LDRP_PROCESS_ATTACH_CALLED
;
827 /* Fail if DLL init failed */
830 DPRINT1("LDR: DLL_PROCESS_ATTACH for dll \"%wZ\" (InitRoutine: %p) failed\n",
831 &LdrEntry
->BaseDllName
, EntryPoint
);
833 Status
= STATUS_DLL_INIT_FAILED
;
840 ListHead
= &Peb
->Ldr
->InInitializationOrderModuleList
;
841 NextEntry
= NextEntry
->Flink
;
842 while (NextEntry
!= ListHead
)
844 /* Get the Data Entrry */
845 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InInitializationOrderModuleList
);
847 /* FIXME: Verify NX Compat */
848 // LdrpCheckNXCompatibility()
851 NextEntry
= NextEntry
->Flink
;
855 if (LdrpImageHasTls
&& Context
)
857 /* Set up the Act Ctx */
858 ActCtx
.Size
= sizeof(ActCtx
);
860 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
862 /* Activate the ActCtx */
863 RtlActivateActivationContextUnsafeFast(&ActCtx
,
864 LdrpImageEntry
->EntryPointActivationContext
);
866 /* Do TLS callbacks */
867 LdrpCallTlsInitializers(Peb
->ImageBaseAddress
, DLL_PROCESS_ATTACH
);
869 /* Deactivate the ActCtx */
870 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
874 /* Restore old TEB */
875 LdrpTopLevelDllBeingLoadedTeb
= OldTldTeb
;
877 /* Check if the array is in the heap */
878 if (LdrRootEntry
!= LocalArray
)
881 RtlFreeHeap(RtlGetProcessHeap(), 0, LdrRootEntry
);
884 /* Return to caller */
885 DPRINT("LdrpRunInitializeRoutines() done\n");
894 LdrShutdownProcess(VOID
)
896 PPEB Peb
= NtCurrentPeb();
897 PLDR_DATA_TABLE_ENTRY LdrEntry
;
898 PLIST_ENTRY NextEntry
, ListHead
;
899 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx
;
902 DPRINT("LdrShutdownProcess() called for %wZ\n", &LdrpImageEntry
->BaseDllName
);
903 if (LdrpShutdownInProgress
) return STATUS_SUCCESS
;
905 /* Tell the Shim Engine */
917 /* Set the shutdown variables */
918 LdrpShutdownThreadId
= NtCurrentTeb()->RealClientId
.UniqueThread
;
919 LdrpShutdownInProgress
= TRUE
;
921 /* Enter the Loader Lock */
922 RtlEnterCriticalSection(&LdrpLoaderLock
);
924 /* Cleanup trace logging data (Etw) */
925 if (SharedUserData
->TraceLogging
)
928 DPRINT1("We don't support Etw yet.\n");
931 /* Start at the end */
932 ListHead
= &Peb
->Ldr
->InInitializationOrderModuleList
;
933 NextEntry
= ListHead
->Blink
;
934 while (NextEntry
!= ListHead
)
936 /* Get the current entry */
937 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InInitializationOrderModuleList
);
938 NextEntry
= NextEntry
->Blink
;
940 /* Make sure it's not ourselves */
941 if (Peb
->ImageBaseAddress
!= LdrEntry
->DllBase
)
943 /* Get the entrypoint */
944 EntryPoint
= LdrEntry
->EntryPoint
;
946 /* Check if we are ready to call it */
948 (LdrEntry
->Flags
& LDRP_PROCESS_ATTACH_CALLED
) &&
951 /* Set up the Act Ctx */
952 ActCtx
.Size
= sizeof(ActCtx
);
954 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
956 /* Activate the ActCtx */
957 RtlActivateActivationContextUnsafeFast(&ActCtx
,
958 LdrEntry
->EntryPointActivationContext
);
960 /* Check if it has TLS */
961 if (LdrEntry
->TlsIndex
)
964 LdrpCallTlsInitializers(LdrEntry
->DllBase
, DLL_PROCESS_DETACH
);
967 /* Call the Entrypoint */
968 DPRINT("%wZ - Calling entry point at %p for thread detaching\n",
969 &LdrEntry
->BaseDllName
, LdrEntry
->EntryPoint
);
970 LdrpCallInitRoutine(EntryPoint
,
975 /* Deactivate the ActCtx */
976 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
984 /* Set up the Act Ctx */
985 ActCtx
.Size
= sizeof(ActCtx
);
987 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
989 /* Activate the ActCtx */
990 RtlActivateActivationContextUnsafeFast(&ActCtx
,
991 LdrpImageEntry
->EntryPointActivationContext
);
993 /* Do TLS callbacks */
994 LdrpCallTlsInitializers(Peb
->ImageBaseAddress
, DLL_PROCESS_DETACH
);
996 /* Deactivate the ActCtx */
997 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
1000 /* FIXME: Do Heap detection and Etw final shutdown */
1002 /* Release the lock */
1003 RtlLeaveCriticalSection(&LdrpLoaderLock
);
1004 DPRINT("LdrpShutdownProcess() done\n");
1006 return STATUS_SUCCESS
;
1014 LdrShutdownThread(VOID
)
1016 PPEB Peb
= NtCurrentPeb();
1017 PTEB Teb
= NtCurrentTeb();
1018 PLDR_DATA_TABLE_ENTRY LdrEntry
;
1019 PLIST_ENTRY NextEntry
, ListHead
;
1020 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx
;
1023 DPRINT("LdrShutdownThread() called for %wZ\n",
1024 &LdrpImageEntry
->BaseDllName
);
1026 /* Cleanup trace logging data (Etw) */
1027 if (SharedUserData
->TraceLogging
)
1030 DPRINT1("We don't support Etw yet.\n");
1033 /* Get the Ldr Lock */
1034 RtlEnterCriticalSection(&LdrpLoaderLock
);
1036 /* Start at the end */
1037 ListHead
= &Peb
->Ldr
->InInitializationOrderModuleList
;
1038 NextEntry
= ListHead
->Blink
;
1039 while (NextEntry
!= ListHead
)
1041 /* Get the current entry */
1042 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InInitializationOrderModuleList
);
1043 NextEntry
= NextEntry
->Blink
;
1045 /* Make sure it's not ourselves */
1046 if (Peb
->ImageBaseAddress
!= LdrEntry
->DllBase
)
1048 /* Check if we should call */
1049 if (!(LdrEntry
->Flags
& LDRP_DONT_CALL_FOR_THREADS
) &&
1050 (LdrEntry
->Flags
& LDRP_PROCESS_ATTACH_CALLED
) &&
1051 (LdrEntry
->Flags
& LDRP_IMAGE_DLL
))
1053 /* Get the entrypoint */
1054 EntryPoint
= LdrEntry
->EntryPoint
;
1056 /* Check if we are ready to call it */
1059 /* Set up the Act Ctx */
1060 ActCtx
.Size
= sizeof(ActCtx
);
1062 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
1064 /* Activate the ActCtx */
1065 RtlActivateActivationContextUnsafeFast(&ActCtx
,
1066 LdrEntry
->EntryPointActivationContext
);
1068 /* Check if it has TLS */
1069 if (LdrEntry
->TlsIndex
)
1071 /* Make sure we're not shutting down */
1072 if (!LdrpShutdownInProgress
)
1075 LdrpCallTlsInitializers(LdrEntry
->DllBase
, DLL_THREAD_DETACH
);
1079 /* Make sure we're not shutting down */
1080 if (!LdrpShutdownInProgress
)
1082 /* Call the Entrypoint */
1083 DPRINT("%wZ - Calling entry point at %p for thread detaching\n",
1084 &LdrEntry
->BaseDllName
, LdrEntry
->EntryPoint
);
1085 LdrpCallInitRoutine(EntryPoint
,
1091 /* Deactivate the ActCtx */
1092 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
1099 if (LdrpImageHasTls
)
1101 /* Set up the Act Ctx */
1102 ActCtx
.Size
= sizeof(ActCtx
);
1104 RtlZeroMemory(&ActCtx
.Frame
, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME
));
1106 /* Activate the ActCtx */
1107 RtlActivateActivationContextUnsafeFast(&ActCtx
,
1108 LdrpImageEntry
->EntryPointActivationContext
);
1110 /* Do TLS callbacks */
1111 LdrpCallTlsInitializers(Peb
->ImageBaseAddress
, DLL_THREAD_DETACH
);
1113 /* Deactivate the ActCtx */
1114 RtlDeactivateActivationContextUnsafeFast(&ActCtx
);
1119 RtlLeaveCriticalSection(&LdrpLoaderLock
);
1121 /* Check for expansion slots */
1122 if (Teb
->TlsExpansionSlots
)
1124 /* Free expansion slots */
1125 RtlFreeHeap(RtlGetProcessHeap(), 0, Teb
->TlsExpansionSlots
);
1128 /* Check for FLS Data */
1132 DPRINT1("We don't support FLS Data yet\n");
1135 /* Check for Fiber data */
1136 if (Teb
->HasFiberData
)
1138 /* Free Fiber data*/
1139 RtlFreeHeap(RtlGetProcessHeap(), 0, Teb
->NtTib
.FiberData
);
1140 Teb
->NtTib
.FiberData
= NULL
;
1143 /* Free the activation context stack */
1144 RtlFreeThreadActivationContextStack();
1145 DPRINT("LdrShutdownThread() done\n");
1147 return STATUS_SUCCESS
;
1152 LdrpInitializeTls(VOID
)
1154 PLIST_ENTRY NextEntry
, ListHead
;
1155 PLDR_DATA_TABLE_ENTRY LdrEntry
;
1156 PIMAGE_TLS_DIRECTORY TlsDirectory
;
1157 PLDRP_TLS_DATA TlsData
;
1160 /* Initialize the TLS List */
1161 InitializeListHead(&LdrpTlsList
);
1163 /* Loop all the modules */
1164 ListHead
= &NtCurrentPeb()->Ldr
->InLoadOrderModuleList
;
1165 NextEntry
= ListHead
->Flink
;
1166 while (ListHead
!= NextEntry
)
1169 LdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InLoadOrderLinks
);
1170 NextEntry
= NextEntry
->Flink
;
1172 /* Get the TLS directory */
1173 TlsDirectory
= RtlImageDirectoryEntryToData(LdrEntry
->DllBase
,
1175 IMAGE_DIRECTORY_ENTRY_TLS
,
1178 /* Check if we have a directory */
1179 if (!TlsDirectory
) continue;
1181 /* Check if the image has TLS */
1182 if (!LdrpImageHasTls
) LdrpImageHasTls
= TRUE
;
1184 /* Show debug message */
1187 DPRINT1("LDR: Tls Found in %wZ at %p\n",
1188 &LdrEntry
->BaseDllName
,
1192 /* Allocate an entry */
1193 TlsData
= RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(LDRP_TLS_DATA
));
1194 if (!TlsData
) return STATUS_NO_MEMORY
;
1196 /* Lock the DLL and mark it for TLS Usage */
1197 LdrEntry
->LoadCount
= -1;
1198 LdrEntry
->TlsIndex
= -1;
1200 /* Save the cached TLS data */
1201 TlsData
->TlsDirectory
= *TlsDirectory
;
1202 InsertTailList(&LdrpTlsList
, &TlsData
->TlsLinks
);
1204 /* Update the index */
1205 *(PLONG
)TlsData
->TlsDirectory
.AddressOfIndex
= LdrpNumberOfTlsEntries
;
1206 TlsData
->TlsDirectory
.Characteristics
= LdrpNumberOfTlsEntries
++;
1209 /* Done setting up TLS, allocate entries */
1210 return LdrpAllocateTls();
1215 LdrpAllocateTls(VOID
)
1217 PTEB Teb
= NtCurrentTeb();
1218 PLIST_ENTRY NextEntry
, ListHead
;
1219 PLDRP_TLS_DATA TlsData
;
1223 /* Check if we have any entries */
1224 if (!LdrpNumberOfTlsEntries
)
1225 return STATUS_SUCCESS
;
1227 /* Allocate the vector array */
1228 TlsVector
= RtlAllocateHeap(RtlGetProcessHeap(),
1230 LdrpNumberOfTlsEntries
* sizeof(PVOID
));
1231 if (!TlsVector
) return STATUS_NO_MEMORY
;
1232 Teb
->ThreadLocalStoragePointer
= TlsVector
;
1234 /* Loop the TLS Array */
1235 ListHead
= &LdrpTlsList
;
1236 NextEntry
= ListHead
->Flink
;
1237 while (NextEntry
!= ListHead
)
1240 TlsData
= CONTAINING_RECORD(NextEntry
, LDRP_TLS_DATA
, TlsLinks
);
1241 NextEntry
= NextEntry
->Flink
;
1243 /* Allocate this vector */
1244 TlsDataSize
= TlsData
->TlsDirectory
.EndAddressOfRawData
-
1245 TlsData
->TlsDirectory
.StartAddressOfRawData
;
1246 TlsVector
[TlsData
->TlsDirectory
.Characteristics
] = RtlAllocateHeap(RtlGetProcessHeap(),
1249 if (!TlsVector
[TlsData
->TlsDirectory
.Characteristics
])
1252 return STATUS_NO_MEMORY
;
1255 /* Show debug message */
1258 DPRINT1("LDR: TlsVector %p Index %lu = %p copied from %x to %p\n",
1260 TlsData
->TlsDirectory
.Characteristics
,
1261 &TlsVector
[TlsData
->TlsDirectory
.Characteristics
],
1262 TlsData
->TlsDirectory
.StartAddressOfRawData
,
1263 TlsVector
[TlsData
->TlsDirectory
.Characteristics
]);
1267 RtlCopyMemory(TlsVector
[TlsData
->TlsDirectory
.Characteristics
],
1268 (PVOID
)TlsData
->TlsDirectory
.StartAddressOfRawData
,
1273 return STATUS_SUCCESS
;
1280 PLIST_ENTRY ListHead
, NextEntry
;
1281 PLDRP_TLS_DATA TlsData
;
1283 PTEB Teb
= NtCurrentTeb();
1285 /* Get a pointer to the vector array */
1286 TlsVector
= Teb
->ThreadLocalStoragePointer
;
1287 if (!TlsVector
) return;
1289 /* Loop through it */
1290 ListHead
= &LdrpTlsList
;
1291 NextEntry
= ListHead
->Flink
;
1292 while (NextEntry
!= ListHead
)
1294 TlsData
= CONTAINING_RECORD(NextEntry
, LDRP_TLS_DATA
, TlsLinks
);
1295 NextEntry
= NextEntry
->Flink
;
1297 /* Free each entry */
1298 if (TlsVector
[TlsData
->TlsDirectory
.Characteristics
])
1300 RtlFreeHeap(RtlGetProcessHeap(),
1302 TlsVector
[TlsData
->TlsDirectory
.Characteristics
]);
1306 /* Free the array itself */
1307 RtlFreeHeap(RtlGetProcessHeap(),
1314 LdrpInitializeApplicationVerifierPackage(PUNICODE_STRING ImagePathName
, PPEB Peb
, BOOLEAN SystemWide
, BOOLEAN ReadAdvancedOptions
)
1316 /* If global flags request DPH, perform some additional actions */
1317 if (Peb
->NtGlobalFlag
& FLG_HEAP_PAGE_ALLOCS
)
1319 // TODO: Read advanced DPH flags from the registry if requested
1320 if (ReadAdvancedOptions
)
1325 /* Enable page heap */
1326 RtlpPageHeapEnabled
= TRUE
;
1329 return STATUS_SUCCESS
;
1334 LdrpInitializeExecutionOptions(PUNICODE_STRING ImagePathName
, PPEB Peb
, PHANDLE OptionsKey
)
1338 ULONG ExecuteOptions
, MinimumStackCommit
= 0, GlobalFlag
;
1340 /* Return error if we were not provided a pointer where to save the options key handle */
1341 if (!OptionsKey
) return STATUS_INVALID_HANDLE
;
1343 /* Zero initialize the optinos key pointer */
1346 /* Open the options key */
1347 Status
= LdrOpenImageFileOptionsKey(ImagePathName
, 0, &KeyHandle
);
1349 /* Save it if it was opened successfully */
1350 if (NT_SUCCESS(Status
))
1351 *OptionsKey
= KeyHandle
;
1355 /* There are image specific options, read them starting with NXCOMPAT */
1356 Status
= LdrQueryImageFileKeyOption(KeyHandle
,
1360 sizeof(ExecuteOptions
),
1363 if (NT_SUCCESS(Status
))
1365 /* TODO: Set execution options for the process */
1367 if (ExecuteOptions == 0)
1371 ZwSetInformationProcess(NtCurrentProcess(),
1372 ProcessExecuteFlags,
1378 /* Check if this image uses large pages */
1379 if (Peb
->ImageUsesLargePages
)
1381 /* TODO: If it does, open large page key */
1385 /* Get various option values */
1386 LdrQueryImageFileKeyOption(KeyHandle
,
1387 L
"DisableHeapLookaside",
1389 &RtlpDisableHeapLookaside
,
1390 sizeof(RtlpDisableHeapLookaside
),
1393 LdrQueryImageFileKeyOption(KeyHandle
,
1396 &RtlpShutdownProcessFlags
,
1397 sizeof(RtlpShutdownProcessFlags
),
1400 LdrQueryImageFileKeyOption(KeyHandle
,
1401 L
"MinimumStackCommitInBytes",
1403 &MinimumStackCommit
,
1404 sizeof(MinimumStackCommit
),
1407 /* Update PEB's minimum stack commit if it's lower */
1408 if (Peb
->MinimumStackCommit
< MinimumStackCommit
)
1409 Peb
->MinimumStackCommit
= MinimumStackCommit
;
1411 /* Set the global flag */
1412 Status
= LdrQueryImageFileKeyOption(KeyHandle
,
1419 if (NT_SUCCESS(Status
))
1420 Peb
->NtGlobalFlag
= GlobalFlag
;
1424 /* Call AVRF if necessary */
1425 if (Peb
->NtGlobalFlag
& (FLG_POOL_ENABLE_TAIL_CHECK
| FLG_HEAP_PAGE_ALLOCS
))
1427 Status
= LdrpInitializeApplicationVerifierPackage(ImagePathName
, Peb
, TRUE
, FALSE
);
1428 if (!NT_SUCCESS(Status
))
1430 DPRINT1("AVRF: LdrpInitializeApplicationVerifierPackage failed with %08X\n", Status
);
1436 /* There are no image-specific options, so perform global initialization */
1437 if (Peb
->NtGlobalFlag
& (FLG_POOL_ENABLE_TAIL_CHECK
| FLG_HEAP_PAGE_ALLOCS
))
1439 /* Initialize app verifier package */
1440 Status
= LdrpInitializeApplicationVerifierPackage(ImagePathName
, Peb
, TRUE
, FALSE
);
1441 if (!NT_SUCCESS(Status
))
1443 DPRINT1("AVRF: LdrpInitializeApplicationVerifierPackage failed with %08X\n", Status
);
1448 return STATUS_SUCCESS
;
1453 LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry
)
1460 LdrpInitializeProcess(IN PCONTEXT Context
,
1461 IN PVOID SystemArgument1
)
1463 RTL_HEAP_PARAMETERS HeapParameters
;
1464 ULONG ComSectionSize
;
1465 //ANSI_STRING FunctionName = RTL_CONSTANT_STRING("BaseQueryModuleData");
1467 OBJECT_ATTRIBUTES ObjectAttributes
;
1468 //UNICODE_STRING LocalFileName, FullImageName;
1469 HANDLE SymLinkHandle
;
1470 //ULONG DebugHeapOnly;
1471 UNICODE_STRING CommandLine
, NtSystemRoot
, ImagePathName
, FullPath
, ImageFileName
, KnownDllString
;
1472 PPEB Peb
= NtCurrentPeb();
1473 BOOLEAN IsDotNetImage
= FALSE
;
1474 BOOLEAN FreeCurDir
= FALSE
;
1476 PRTL_USER_PROCESS_PARAMETERS ProcessParameters
;
1477 //LPWSTR ImagePathBuffer;
1479 UNICODE_STRING CurrentDirectory
;
1482 PIMAGE_NT_HEADERS NtHeader
;
1483 LPWSTR NtDllName
= NULL
;
1484 NTSTATUS Status
, ImportStatus
;
1485 NLSTABLEINFO NlsTable
;
1486 PIMAGE_LOAD_CONFIG_DIRECTORY LoadConfig
;
1487 PTEB Teb
= NtCurrentTeb();
1488 PLIST_ENTRY ListHead
;
1489 PLIST_ENTRY NextEntry
;
1492 ULONG DebugProcessHeapOnly
= 0;
1493 PLDR_DATA_TABLE_ENTRY NtLdrEntry
;
1495 ULONG ExecuteOptions
= 0;
1498 /* Set a NULL SEH Filter */
1499 RtlSetUnhandledExceptionFilter(NULL
);
1501 /* Get the image path */
1502 ImagePath
= Peb
->ProcessParameters
->ImagePathName
.Buffer
;
1504 /* Check if it's not normalized */
1505 if (!(Peb
->ProcessParameters
->Flags
& RTL_USER_PROCESS_PARAMETERS_NORMALIZED
))
1508 ImagePath
= (PWSTR
)((ULONG_PTR
)ImagePath
+ (ULONG_PTR
)Peb
->ProcessParameters
);
1511 /* Create a unicode string for the Image Path */
1512 ImagePathName
.Length
= Peb
->ProcessParameters
->ImagePathName
.Length
;
1513 ImagePathName
.MaximumLength
= ImagePathName
.Length
+ sizeof(WCHAR
);
1514 ImagePathName
.Buffer
= ImagePath
;
1516 /* Get the NT Headers */
1517 NtHeader
= RtlImageNtHeader(Peb
->ImageBaseAddress
);
1519 /* Get the execution options */
1520 Status
= LdrpInitializeExecutionOptions(&ImagePathName
, Peb
, &OptionsKey
);
1522 /* Check if this is a .NET executable */
1523 if (RtlImageDirectoryEntryToData(Peb
->ImageBaseAddress
,
1525 IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
,
1528 /* Remeber this for later */
1529 IsDotNetImage
= TRUE
;
1532 /* Save the NTDLL Base address */
1533 NtDllBase
= SystemArgument1
;
1535 /* If this is a Native Image */
1536 if (NtHeader
->OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_NATIVE
)
1538 /* Then do DLL Validation */
1539 LdrpDllValidation
= TRUE
;
1542 /* Save the old Shim Data */
1543 OldShimData
= Peb
->pShimData
;
1546 Peb
->pShimData
= NULL
;
1548 /* Save the number of processors and CS Timeout */
1549 LdrpNumberOfProcessors
= Peb
->NumberOfProcessors
;
1550 RtlpTimeout
= Peb
->CriticalSectionTimeout
;
1552 /* Normalize the parameters */
1553 ProcessParameters
= RtlNormalizeProcessParams(Peb
->ProcessParameters
);
1554 if (ProcessParameters
)
1556 /* Save the Image and Command Line Names */
1557 ImageFileName
= ProcessParameters
->ImagePathName
;
1558 CommandLine
= ProcessParameters
->CommandLine
;
1562 /* It failed, initialize empty strings */
1563 RtlInitUnicodeString(&ImageFileName
, NULL
);
1564 RtlInitUnicodeString(&CommandLine
, NULL
);
1567 /* Initialize NLS data */
1568 RtlInitNlsTables(Peb
->AnsiCodePageData
,
1569 Peb
->OemCodePageData
,
1570 Peb
->UnicodeCaseTableData
,
1573 /* Reset NLS Translations */
1574 RtlResetRtlTranslations(&NlsTable
);
1576 /* Get the Image Config Directory */
1577 LoadConfig
= RtlImageDirectoryEntryToData(Peb
->ImageBaseAddress
,
1579 IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
,
1582 /* Setup the Heap Parameters */
1583 RtlZeroMemory(&HeapParameters
, sizeof(RTL_HEAP_PARAMETERS
));
1584 HeapFlags
= HEAP_GROWABLE
;
1585 HeapParameters
.Length
= sizeof(RTL_HEAP_PARAMETERS
);
1587 /* Check if we have Configuration Data */
1588 if ((LoadConfig
) && (ConfigSize
== sizeof(IMAGE_LOAD_CONFIG_DIRECTORY
)))
1590 /* FIXME: Custom heap settings and misc. */
1591 DPRINT1("We don't support LOAD_CONFIG data yet\n");
1594 /* Check for custom affinity mask */
1595 if (Peb
->ImageProcessAffinityMask
)
1598 Status
= NtSetInformationProcess(NtCurrentProcess(),
1599 ProcessAffinityMask
,
1600 &Peb
->ImageProcessAffinityMask
,
1601 sizeof(Peb
->ImageProcessAffinityMask
));
1604 /* Check if verbose debugging (ShowSnaps) was requested */
1605 ShowSnaps
= Peb
->NtGlobalFlag
& FLG_SHOW_LDR_SNAPS
;
1607 /* Start verbose debugging messages right now if they were requested */
1610 DPRINT1("LDR: PID: 0x%p started - '%wZ'\n",
1611 Teb
->ClientId
.UniqueProcess
,
1615 /* If the timeout is too long */
1616 if (RtlpTimeout
.QuadPart
< Int32x32To64(3600, -10000000))
1618 /* Then disable CS Timeout */
1619 RtlpTimeoutDisable
= TRUE
;
1622 /* Initialize Critical Section Data */
1623 RtlpInitDeferedCriticalSection();
1625 /* Initialize VEH Call lists */
1626 RtlpInitializeVectoredExceptionHandling();
1628 /* Set TLS/FLS Bitmap data */
1629 Peb
->FlsBitmap
= &FlsBitMap
;
1630 Peb
->TlsBitmap
= &TlsBitMap
;
1631 Peb
->TlsExpansionBitmap
= &TlsExpansionBitMap
;
1633 /* Initialize FLS Bitmap */
1634 RtlInitializeBitMap(&FlsBitMap
,
1636 FLS_MAXIMUM_AVAILABLE
);
1637 RtlSetBit(&FlsBitMap
, 0);
1639 /* Initialize TLS Bitmap */
1640 RtlInitializeBitMap(&TlsBitMap
,
1642 TLS_MINIMUM_AVAILABLE
);
1643 RtlSetBit(&TlsBitMap
, 0);
1644 RtlInitializeBitMap(&TlsExpansionBitMap
,
1645 Peb
->TlsExpansionBitmapBits
,
1646 TLS_EXPANSION_SLOTS
);
1647 RtlSetBit(&TlsExpansionBitMap
, 0);
1649 /* Initialize the Hash Table */
1650 for (i
= 0; i
< LDR_HASH_TABLE_ENTRIES
; i
++)
1652 InitializeListHead(&LdrpHashTable
[i
]);
1655 /* Initialize the Loader Lock */
1656 // FIXME: What's the point of initing it manually, if two lines lower
1657 // a call to RtlInitializeCriticalSection() is being made anyway?
1658 //InsertTailList(&RtlCriticalSectionList, &LdrpLoaderLock.DebugInfo->ProcessLocksList);
1659 //LdrpLoaderLock.DebugInfo->CriticalSection = &LdrpLoaderLock;
1660 RtlInitializeCriticalSection(&LdrpLoaderLock
);
1661 LdrpLoaderLockInit
= TRUE
;
1663 /* Check if User Stack Trace Database support was requested */
1664 if (Peb
->NtGlobalFlag
& FLG_USER_STACK_TRACE_DB
)
1666 DPRINT1("We don't support user stack trace databases yet\n");
1669 /* Setup Fast PEB Lock */
1670 RtlInitializeCriticalSection(&FastPebLock
);
1671 Peb
->FastPebLock
= &FastPebLock
;
1672 //Peb->FastPebLockRoutine = (PPEBLOCKROUTINE)RtlEnterCriticalSection;
1673 //Peb->FastPebUnlockRoutine = (PPEBLOCKROUTINE)RtlLeaveCriticalSection;
1675 /* Setup Callout Lock and Notification list */
1676 //RtlInitializeCriticalSection(&RtlpCalloutEntryLock);
1677 InitializeListHead(&LdrpDllNotificationList
);
1679 /* For old executables, use 16-byte aligned heap */
1680 if ((NtHeader
->OptionalHeader
.MajorSubsystemVersion
<= 3) &&
1681 (NtHeader
->OptionalHeader
.MinorSubsystemVersion
< 51))
1683 HeapFlags
|= HEAP_CREATE_ALIGN_16
;
1686 /* Setup the Heap */
1687 RtlInitializeHeapManager();
1688 Peb
->ProcessHeap
= RtlCreateHeap(HeapFlags
,
1690 NtHeader
->OptionalHeader
.SizeOfHeapReserve
,
1691 NtHeader
->OptionalHeader
.SizeOfHeapCommit
,
1695 if (!Peb
->ProcessHeap
)
1697 DPRINT1("Failed to create process heap\n");
1698 return STATUS_NO_MEMORY
;
1701 /* Allocate an Activation Context Stack */
1702 Status
= RtlAllocateActivationContextStack(&Teb
->ActivationContextStackPointer
);
1703 if (!NT_SUCCESS(Status
)) return Status
;
1705 // FIXME: Loader private heap is missing
1706 //DPRINT1("Loader private heap is missing\n");
1708 /* Check for Debug Heap */
1711 /* Query the setting */
1712 Status
= LdrQueryImageFileKeyOption(OptionsKey
,
1713 L
"DebugProcessHeapOnly",
1715 &DebugProcessHeapOnly
,
1719 if (NT_SUCCESS(Status
))
1721 /* Reset DPH if requested */
1722 if (RtlpPageHeapEnabled
&& DebugProcessHeapOnly
)
1724 RtlpDphGlobalFlags
&= ~DPH_FLAG_DLL_NOTIFY
;
1725 RtlpPageHeapEnabled
= FALSE
;
1730 /* Build the NTDLL Path */
1731 FullPath
.Buffer
= StringBuffer
;
1732 FullPath
.Length
= 0;
1733 FullPath
.MaximumLength
= sizeof(StringBuffer
);
1734 RtlInitUnicodeString(&NtSystemRoot
, SharedUserData
->NtSystemRoot
);
1735 RtlAppendUnicodeStringToString(&FullPath
, &NtSystemRoot
);
1736 RtlAppendUnicodeToString(&FullPath
, L
"\\System32\\");
1738 /* Open the Known DLLs directory */
1739 RtlInitUnicodeString(&KnownDllString
, L
"\\KnownDlls");
1740 InitializeObjectAttributes(&ObjectAttributes
,
1742 OBJ_CASE_INSENSITIVE
,
1745 Status
= ZwOpenDirectoryObject(&LdrpKnownDllObjectDirectory
,
1746 DIRECTORY_QUERY
| DIRECTORY_TRAVERSE
,
1749 /* Check if it exists */
1750 if (NT_SUCCESS(Status
))
1752 /* Open the Known DLLs Path */
1753 RtlInitUnicodeString(&KnownDllString
, L
"KnownDllPath");
1754 InitializeObjectAttributes(&ObjectAttributes
,
1756 OBJ_CASE_INSENSITIVE
,
1757 LdrpKnownDllObjectDirectory
,
1759 Status
= NtOpenSymbolicLinkObject(&SymLinkHandle
,
1760 SYMBOLIC_LINK_QUERY
,
1762 if (NT_SUCCESS(Status
))
1764 /* Query the path */
1765 LdrpKnownDllPath
.Length
= 0;
1766 LdrpKnownDllPath
.MaximumLength
= sizeof(LdrpKnownDllPathBuffer
);
1767 LdrpKnownDllPath
.Buffer
= LdrpKnownDllPathBuffer
;
1768 Status
= ZwQuerySymbolicLinkObject(SymLinkHandle
, &LdrpKnownDllPath
, NULL
);
1769 NtClose(SymLinkHandle
);
1770 if (!NT_SUCCESS(Status
))
1772 DPRINT1("LDR: %s - failed call to ZwQuerySymbolicLinkObject with status %x\n", "", Status
);
1778 /* Check if we failed */
1779 if (!NT_SUCCESS(Status
))
1781 /* Aassume System32 */
1782 LdrpKnownDllObjectDirectory
= NULL
;
1783 RtlInitUnicodeString(&LdrpKnownDllPath
, StringBuffer
);
1784 LdrpKnownDllPath
.Length
-= sizeof(WCHAR
);
1787 /* If we have process parameters, get the default path and current path */
1788 if (ProcessParameters
)
1790 /* Check if we have a Dll Path */
1791 if (ProcessParameters
->DllPath
.Length
)
1794 LdrpDefaultPath
= *(PUNICODE_STRING
)&ProcessParameters
->DllPath
;
1798 /* We need a valid path */
1799 DPRINT1("No valid DllPath was given!\n");
1800 LdrpInitFailure(STATUS_INVALID_PARAMETER
);
1803 /* Set the current directory */
1804 CurrentDirectory
= ProcessParameters
->CurrentDirectory
.DosPath
;
1806 /* Check if it's empty or invalid */
1807 if ((!CurrentDirectory
.Buffer
) ||
1808 (CurrentDirectory
.Buffer
[0] == UNICODE_NULL
) ||
1809 (!CurrentDirectory
.Length
))
1811 /* Allocate space for the buffer */
1812 CurrentDirectory
.Buffer
= RtlAllocateHeap(Peb
->ProcessHeap
,
1815 sizeof(UNICODE_NULL
));
1816 if (!CurrentDirectory
.Buffer
)
1818 DPRINT1("LDR: LdrpInitializeProcess - unable to allocate current working directory buffer\n");
1822 /* Copy the drive of the system root */
1823 RtlMoveMemory(CurrentDirectory
.Buffer
,
1824 SharedUserData
->NtSystemRoot
,
1826 CurrentDirectory
.Buffer
[3] = UNICODE_NULL
;
1827 CurrentDirectory
.Length
= 3 * sizeof(WCHAR
);
1828 CurrentDirectory
.MaximumLength
= CurrentDirectory
.Length
+ sizeof(WCHAR
);
1831 DPRINT("Using dynamically allocd curdir\n");
1835 /* Use the local buffer */
1836 DPRINT("Using local system root\n");
1840 /* Setup Loader Data */
1842 InitializeListHead(&PebLdr
.InLoadOrderModuleList
);
1843 InitializeListHead(&PebLdr
.InMemoryOrderModuleList
);
1844 InitializeListHead(&PebLdr
.InInitializationOrderModuleList
);
1845 PebLdr
.Length
= sizeof(PEB_LDR_DATA
);
1846 PebLdr
.Initialized
= TRUE
;
1848 /* Allocate a data entry for the Image */
1849 LdrpImageEntry
= NtLdrEntry
= LdrpAllocateDataTableEntry(Peb
->ImageBaseAddress
);
1852 NtLdrEntry
->EntryPoint
= LdrpFetchAddressOfEntryPoint(NtLdrEntry
->DllBase
);
1853 NtLdrEntry
->LoadCount
= -1;
1854 NtLdrEntry
->EntryPointActivationContext
= 0;
1855 NtLdrEntry
->FullDllName
= ImageFileName
;
1858 NtLdrEntry
->Flags
= LDRP_COR_IMAGE
;
1860 NtLdrEntry
->Flags
= 0;
1862 /* Check if the name is empty */
1863 if (!ImageFileName
.Buffer
[0])
1865 /* Use the same Base name */
1866 NtLdrEntry
->BaseDllName
= NtLdrEntry
->FullDllName
;
1870 /* Find the last slash */
1871 Current
= ImageFileName
.Buffer
;
1874 if (*Current
++ == '\\')
1877 NtDllName
= Current
;
1881 /* Did we find anything? */
1884 /* Use the same Base name */
1885 NtLdrEntry
->BaseDllName
= NtLdrEntry
->FullDllName
;
1889 /* Setup the name */
1890 NtLdrEntry
->BaseDllName
.Length
= (USHORT
)((ULONG_PTR
)ImageFileName
.Buffer
+ ImageFileName
.Length
- (ULONG_PTR
)NtDllName
);
1891 NtLdrEntry
->BaseDllName
.MaximumLength
= NtLdrEntry
->BaseDllName
.Length
+ sizeof(WCHAR
);
1892 NtLdrEntry
->BaseDllName
.Buffer
= (PWSTR
)((ULONG_PTR
)ImageFileName
.Buffer
+
1893 (ImageFileName
.Length
- NtLdrEntry
->BaseDllName
.Length
));
1897 /* Processing done, insert it */
1898 LdrpInsertMemoryTableEntry(NtLdrEntry
);
1899 NtLdrEntry
->Flags
|= LDRP_ENTRY_PROCESSED
;
1901 /* Now add an entry for NTDLL */
1902 NtLdrEntry
= LdrpAllocateDataTableEntry(SystemArgument1
);
1903 NtLdrEntry
->Flags
= LDRP_IMAGE_DLL
;
1904 NtLdrEntry
->EntryPoint
= LdrpFetchAddressOfEntryPoint(NtLdrEntry
->DllBase
);
1905 NtLdrEntry
->LoadCount
= -1;
1906 NtLdrEntry
->EntryPointActivationContext
= 0;
1908 NtLdrEntry
->FullDllName
.Length
= FullPath
.Length
;
1909 NtLdrEntry
->FullDllName
.MaximumLength
= FullPath
.MaximumLength
;
1910 NtLdrEntry
->FullDllName
.Buffer
= StringBuffer
;
1911 RtlAppendUnicodeStringToString(&NtLdrEntry
->FullDllName
, &NtDllString
);
1913 NtLdrEntry
->BaseDllName
.Length
= NtDllString
.Length
;
1914 NtLdrEntry
->BaseDllName
.MaximumLength
= NtDllString
.MaximumLength
;
1915 NtLdrEntry
->BaseDllName
.Buffer
= NtDllString
.Buffer
;
1917 /* Processing done, insert it */
1918 LdrpNtDllDataTableEntry
= NtLdrEntry
;
1919 LdrpInsertMemoryTableEntry(NtLdrEntry
);
1921 /* Let the world know */
1924 DPRINT1("LDR: NEW PROCESS\n");
1925 DPRINT1(" Image Path: %wZ (%wZ)\n", &LdrpImageEntry
->FullDllName
, &LdrpImageEntry
->BaseDllName
);
1926 DPRINT1(" Current Directory: %wZ\n", &CurrentDirectory
);
1927 DPRINT1(" Search Path: %wZ\n", &LdrpDefaultPath
);
1930 /* Link the Init Order List */
1931 InsertHeadList(&Peb
->Ldr
->InInitializationOrderModuleList
,
1932 &LdrpNtDllDataTableEntry
->InInitializationOrderModuleList
);
1934 /* Initialize Wine's active context implementation for the current process */
1937 /* Set the current directory */
1938 Status
= RtlSetCurrentDirectory_U(&CurrentDirectory
);
1939 if (!NT_SUCCESS(Status
))
1941 /* We failed, check if we should free it */
1942 if (FreeCurDir
) RtlFreeUnicodeString(&CurrentDirectory
);
1944 /* Set it to the NT Root */
1945 CurrentDirectory
= NtSystemRoot
;
1946 RtlSetCurrentDirectory_U(&CurrentDirectory
);
1950 /* We're done with it, free it */
1951 if (FreeCurDir
) RtlFreeUnicodeString(&CurrentDirectory
);
1954 /* Check if we should look for a .local file */
1955 if (ProcessParameters
->Flags
& RTL_USER_PROCESS_PARAMETERS_LOCAL_DLL_PATH
)
1958 DPRINT1("We don't support .local overrides yet\n");
1961 /* Check if the Application Verifier was enabled */
1962 if (Peb
->NtGlobalFlag
& FLG_POOL_ENABLE_TAIL_CHECK
)
1965 DPRINT1("We don't support Application Verifier yet\n");
1971 DPRINT1("We don't support .NET applications yet\n");
1974 /* FIXME: Load support for Terminal Services */
1975 if (NtHeader
->OptionalHeader
.Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_GUI
)
1977 /* Load kernel32 and call BasePostImportInit... */
1978 DPRINT("Unimplemented codepath!\n");
1981 /* Walk the IAT and load all the DLLs */
1982 ImportStatus
= LdrpWalkImportDescriptor(LdrpDefaultPath
.Buffer
, LdrpImageEntry
);
1984 /* Check if relocation is needed */
1985 if (Peb
->ImageBaseAddress
!= (PVOID
)NtHeader
->OptionalHeader
.ImageBase
)
1987 DPRINT1("LDR: Performing EXE relocation\n");
1989 /* Change the protection to prepare for relocation */
1990 ViewBase
= Peb
->ImageBaseAddress
;
1991 Status
= LdrpSetProtection(ViewBase
, FALSE
);
1992 if (!NT_SUCCESS(Status
)) return Status
;
1994 /* Do the relocation */
1995 Status
= LdrRelocateImageWithBias(ViewBase
,
1999 STATUS_CONFLICTING_ADDRESSES
,
2000 STATUS_INVALID_IMAGE_FORMAT
);
2001 if (!NT_SUCCESS(Status
))
2003 DPRINT1("LdrRelocateImageWithBias() failed\n");
2007 /* Check if a start context was provided */
2010 DPRINT1("WARNING: Relocated EXE Context");
2011 UNIMPLEMENTED
; // We should support this
2012 return STATUS_INVALID_IMAGE_FORMAT
;
2015 /* Restore the protection */
2016 Status
= LdrpSetProtection(ViewBase
, TRUE
);
2017 if (!NT_SUCCESS(Status
)) return Status
;
2021 ListHead
= &Peb
->Ldr
->InLoadOrderModuleList
;
2022 NextEntry
= ListHead
->Flink
;
2023 while (ListHead
!= NextEntry
)
2025 NtLdrEntry
= CONTAINING_RECORD(NextEntry
, LDR_DATA_TABLE_ENTRY
, InLoadOrderLinks
);
2026 NtLdrEntry
->LoadCount
= -1;
2027 NextEntry
= NextEntry
->Flink
;
2030 /* Phase 0 is done */
2031 LdrpLdrDatabaseIsSetup
= TRUE
;
2033 /* Check whether all static imports were properly loaded and return here */
2034 if (!NT_SUCCESS(ImportStatus
)) return ImportStatus
;
2036 /* Initialize TLS */
2037 Status
= LdrpInitializeTls();
2038 if (!NT_SUCCESS(Status
))
2040 DPRINT1("LDR: LdrpProcessInitialization failed to initialize TLS slots; status %x\n",
2045 /* FIXME Mark the DLL Ranges for Stack Traces later */
2047 /* Notify the debugger now */
2048 if (Peb
->BeingDebugged
)
2053 /* Update show snaps again */
2054 ShowSnaps
= Peb
->NtGlobalFlag
& FLG_SHOW_LDR_SNAPS
;
2057 /* Validate the Image for MP Usage */
2058 if (LdrpNumberOfProcessors
> 1) LdrpValidateImageForMp(LdrpImageEntry
);
2060 /* Check NX Options */
2061 if (SharedUserData
->NXSupportPolicy
== 1)
2063 ExecuteOptions
= 0xD;
2065 else if (!SharedUserData
->NXSupportPolicy
)
2067 ExecuteOptions
= 0xA;
2071 ZwSetInformationProcess(NtCurrentProcess(),
2072 ProcessExecuteFlags
,
2076 /* Check if we had Shim Data */
2079 /* Load the Shim Engine */
2080 Peb
->AppCompatInfo
= NULL
;
2081 //LdrpLoadShimEngine(OldShimData, ImagePathName, OldShimData);
2082 DPRINT1("We do not support shims yet\n");
2086 /* Check for Application Compatibility Goo */
2087 //LdrQueryApplicationCompatibilityGoo(hKey);
2088 DPRINT("Querying app compat hacks is missing!\n");
2092 * FIXME: Check for special images, SecuROM, SafeDisc and other NX-
2093 * incompatible images.
2096 /* Now call the Init Routines */
2097 Status
= LdrpRunInitializeRoutines(Context
);
2098 if (!NT_SUCCESS(Status
))
2100 DPRINT1("LDR: LdrpProcessInitialization failed running initialization routines; status %x\n",
2105 /* FIXME: Unload the Shim Engine if it was loaded */
2107 /* Check if we have a user-defined Post Process Routine */
2108 if (NT_SUCCESS(Status
) && Peb
->PostProcessInitRoutine
)
2111 Peb
->PostProcessInitRoutine();
2114 /* Close the key if we have one opened */
2115 if (OptionsKey
) NtClose(OptionsKey
);
2123 LdrpInitFailure(NTSTATUS Status
)
2126 PPEB Peb
= NtCurrentPeb();
2128 /* Print a debug message */
2129 DPRINT1("LDR: Process initialization failure for %wZ; NTSTATUS = %08lx\n",
2130 &Peb
->ProcessParameters
->ImagePathName
, Status
);
2132 /* Raise a hard error */
2133 if (!LdrpFatalHardErrorCount
)
2135 ZwRaiseHardError(STATUS_APP_INIT_FAILURE
, 1, 0, (PULONG_PTR
)&Status
, OptionOk
, &Response
);
2141 LdrpInit(PCONTEXT Context
,
2142 PVOID SystemArgument1
,
2143 PVOID SystemArgument2
)
2145 LARGE_INTEGER Timeout
;
2146 PTEB Teb
= NtCurrentTeb();
2147 NTSTATUS Status
, LoaderStatus
= STATUS_SUCCESS
;
2148 MEMORY_BASIC_INFORMATION MemoryBasicInfo
;
2149 PPEB Peb
= NtCurrentPeb();
2151 DPRINT("LdrpInit() %p/%p\n",
2152 NtCurrentTeb()->RealClientId
.UniqueProcess
,
2153 NtCurrentTeb()->RealClientId
.UniqueThread
);
2155 /* Check if we have a deallocation stack */
2156 if (!Teb
->DeallocationStack
)
2158 /* We don't, set one */
2159 Status
= NtQueryVirtualMemory(NtCurrentProcess(),
2160 Teb
->NtTib
.StackLimit
,
2161 MemoryBasicInformation
,
2163 sizeof(MEMORY_BASIC_INFORMATION
),
2165 if (!NT_SUCCESS(Status
))
2168 LdrpInitFailure(Status
);
2169 RtlRaiseStatus(Status
);
2174 Teb
->DeallocationStack
= MemoryBasicInfo
.AllocationBase
;
2177 /* Now check if the process is already being initialized */
2178 while (_InterlockedCompareExchange(&LdrpProcessInitialized
,
2182 /* Set the timeout to 30 seconds */
2183 Timeout
.QuadPart
= Int32x32To64(30, -10000);
2185 /* Make sure the status hasn't changed */
2186 while (!LdrpProcessInitialized
)
2189 ZwDelayExecution(FALSE
, &Timeout
);
2193 /* Check if we have already setup LDR data */
2196 /* Setup the Loader Lock */
2197 Peb
->LoaderLock
= &LdrpLoaderLock
;
2199 /* Let other code know we're initializing */
2200 LdrpInLdrInit
= TRUE
;
2202 /* Protect with SEH */
2205 /* Initialize the Process */
2206 LoaderStatus
= LdrpInitializeProcess(Context
,
2209 /* Check for success and if MinimumStackCommit was requested */
2210 if (NT_SUCCESS(LoaderStatus
) && Peb
->MinimumStackCommit
)
2212 /* Enforce the limit */
2213 //LdrpTouchThreadStack(Peb->MinimumStackCommit);
2217 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2219 /* Fail with the SEH error */
2220 LoaderStatus
= _SEH2_GetExceptionCode();
2224 /* We're not initializing anymore */
2225 LdrpInLdrInit
= FALSE
;
2227 /* Check if init worked */
2228 if (NT_SUCCESS(LoaderStatus
))
2230 /* Set the process as Initialized */
2231 _InterlockedIncrement(&LdrpProcessInitialized
);
2236 /* Loader data is there... is this a fork() ? */
2237 if(Peb
->InheritedAddressSpace
)
2239 /* Handle the fork() */
2240 //LoaderStatus = LdrpForkProcess();
2241 LoaderStatus
= STATUS_NOT_IMPLEMENTED
;
2246 /* This is a new thread initializing */
2247 LdrpInitializeThread(Context
);
2251 /* All done, test alert the thread */
2255 if (!NT_SUCCESS(LoaderStatus
))
2258 LdrpInitFailure(LoaderStatus
);
2259 RtlRaiseStatus(LoaderStatus
);