ReactOS 0.4.16-dev-974-g5022a45
ldrinit.c
Go to the documentation of this file.
1/*
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)
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <ntdll.h>
13#include <compat_undoc.h>
14#include <compatguid_undoc.h>
15
16#define NDEBUG
17#include <debug.h>
18
19
20/* GLOBALS *******************************************************************/
21
24UNICODE_STRING ImageExecOptionsString = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options");
29
36
38
42extern PTEB LdrpTopLevelDllBeingLoadedTeb; // defined in rtlsupp.c!
45
46static NTSTATUS (WINAPI *Kernel32ProcessInitPostImportFunction)(VOID);
47static BOOL (WINAPI *Kernel32BaseQueryModuleData)(IN LPSTR ModuleName, IN LPSTR Unk1, IN PVOID Unk2, IN PVOID Unk3, IN PVOID Unk4);
48
64
66
69{
71 -1,
72 0,
73 0,
74 0,
75 0
76};
78
80
83
84//extern LIST_ENTRY RtlCriticalSectionList;
85
90
91ULONG RtlpDisableHeapLookaside; // TODO: Move to heap.c
93
97
98#ifdef _WIN64
99#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232ll
100#else
101#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
102#endif
103
104/* FUNCTIONS *****************************************************************/
105
106/*
107 * @implemented
108 */
110NTAPI
112 _In_ PUNICODE_STRING SubKey,
113 _In_ BOOLEAN Wow64,
114 _Out_ PHANDLE NewKeyHandle)
115{
116 PHANDLE RootKeyLocation;
118 UNICODE_STRING SubKeyString;
121 PWCHAR p1;
122
123 /* Check which root key to open */
124 if (Wow64)
125 RootKeyLocation = &Wow64ExecOptionsKey;
126 else
127 RootKeyLocation = &ImageExecOptionsKey;
128
129 /* Get the current key */
130 RootKey = *RootKeyLocation;
131
132 /* Setup the object attributes */
134 Wow64 ?
137 NULL,
138 NULL);
139
140 /* Open the root key */
142 if (NT_SUCCESS(Status))
143 {
144 /* Write the key handle */
145 if (InterlockedCompareExchangePointer(RootKeyLocation, RootKey, NULL) != NULL)
146 {
147 /* Someone already opened it, use it instead */
149 RootKey = *RootKeyLocation;
150 }
151
152 /* Extract the name */
153 SubKeyString = *SubKey;
154 p1 = (PWCHAR)((ULONG_PTR)SubKeyString.Buffer + SubKeyString.Length);
155 while (SubKeyString.Length)
156 {
157 if (p1[-1] == L'\\') break;
158 p1--;
159 SubKeyString.Length -= sizeof(*p1);
160 }
161 SubKeyString.Buffer = p1;
162 SubKeyString.Length = SubKey->Length - SubKeyString.Length;
163
164 /* Setup the object attributes */
166 &SubKeyString,
168 RootKey,
169 NULL);
170
171 /* Open the setting key */
172 Status = ZwOpenKey((PHANDLE)NewKeyHandle, GENERIC_READ, &ObjectAttributes);
173 }
174
175 /* Return to caller */
176 return Status;
177}
178
179/*
180 * @implemented
181 */
183NTAPI
191{
192 ULONG KeyInfo[256];
193 UNICODE_STRING ValueNameString, IntegerString;
194 ULONG KeyInfoSize, ResultSize;
196 BOOLEAN FreeHeap = FALSE;
198
199 /* Build a string for the value name */
200 Status = RtlInitUnicodeStringEx(&ValueNameString, ValueName);
201 if (!NT_SUCCESS(Status)) return Status;
202
203 /* Query the value */
204 Status = ZwQueryValueKey(KeyHandle,
205 &ValueNameString,
207 KeyValueInformation,
208 sizeof(KeyInfo),
209 &ResultSize);
211 {
212 /* Our local buffer wasn't enough, allocate one */
213 KeyInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) +
214 KeyValueInformation->DataLength;
215 KeyValueInformation = RtlAllocateHeap(RtlGetProcessHeap(),
216 0,
217 KeyInfoSize);
218 if (KeyValueInformation != NULL)
219 {
220 /* Try again */
221 Status = ZwQueryValueKey(KeyHandle,
222 &ValueNameString,
224 KeyValueInformation,
225 KeyInfoSize,
226 &ResultSize);
227 FreeHeap = TRUE;
228 }
229 else
230 {
231 /* Give up this time */
233 }
234 }
235
236 /* Check for success */
237 if (NT_SUCCESS(Status))
238 {
239 /* Handle binary data */
240 if (KeyValueInformation->Type == REG_BINARY)
241 {
242 /* Check validity */
243 if ((Buffer) && (KeyValueInformation->DataLength <= BufferSize))
244 {
245 /* Copy into buffer */
247 &KeyValueInformation->Data,
248 KeyValueInformation->DataLength);
249 }
250 else
251 {
253 }
254
255 /* Copy the result length */
256 if (ReturnedLength) *ReturnedLength = KeyValueInformation->DataLength;
257 }
258 else if (KeyValueInformation->Type == REG_DWORD)
259 {
260 /* Check for valid type */
261 if (KeyValueInformation->Type != Type)
262 {
263 /* Error */
265 }
266 else
267 {
268 /* Check validity */
269 if ((Buffer) &&
270 (BufferSize == sizeof(ULONG)) &&
271 (KeyValueInformation->DataLength <= BufferSize))
272 {
273 /* Copy into buffer */
275 &KeyValueInformation->Data,
276 KeyValueInformation->DataLength);
277 }
278 else
279 {
281 }
282
283 /* Copy the result length */
284 if (ReturnedLength) *ReturnedLength = KeyValueInformation->DataLength;
285 }
286 }
287 else if (KeyValueInformation->Type != REG_SZ)
288 {
289 /* We got something weird */
291 }
292 else
293 {
294 /* String, check what you requested */
295 if (Type == REG_DWORD)
296 {
297 /* Validate */
298 if (BufferSize != sizeof(ULONG))
299 {
300 /* Invalid size */
301 BufferSize = 0;
303 }
304 else
305 {
306 /* OK, we know what you want... */
307 IntegerString.Buffer = (PWSTR)KeyValueInformation->Data;
308 IntegerString.Length = (USHORT)KeyValueInformation->DataLength -
309 sizeof(WCHAR);
310 IntegerString.MaximumLength = (USHORT)KeyValueInformation->DataLength;
311 Status = RtlUnicodeStringToInteger(&IntegerString, 0, (PULONG)Buffer);
312 }
313 }
314 else
315 {
316 /* Validate */
317 if (KeyValueInformation->DataLength > BufferSize)
318 {
319 /* Invalid */
321 }
322 else
323 {
324 /* Set the size */
325 BufferSize = KeyValueInformation->DataLength;
326 }
327
328 /* Copy the string */
329 RtlMoveMemory(Buffer, &KeyValueInformation->Data, BufferSize);
330 }
331
332 /* Copy the result length */
333 if (ReturnedLength) *ReturnedLength = KeyValueInformation->DataLength;
334 }
335 }
336
337 /* Check if buffer was in heap */
338 if (FreeHeap) RtlFreeHeap(RtlGetProcessHeap(), 0, KeyValueInformation);
339
340 /* Return status */
341 return Status;
342}
343
344/*
345 * @implemented
346 */
348NTAPI
350 _In_ PUNICODE_STRING SubKey,
356 _In_ BOOLEAN Wow64)
357{
360
361 /* Open a handle to the key */
363
364 /* Check for success */
365 if (NT_SUCCESS(Status))
366 {
367 /* Query the data */
369 ValueName,
370 Type,
371 Buffer,
374
375 /* Close the key */
377 }
378
379 /* Return to caller */
380 return Status;
381}
382
383/*
384 * @implemented
385 */
387NTAPI
389 _In_ PUNICODE_STRING SubKey,
395{
396 /* Call the newer function */
398 ValueName,
399 Type,
400 Buffer,
403 FALSE);
404}
405
406VOID
407NTAPI
409{
410 // Ignored atm
411}
412
413PVOID
414NTAPI
416{
418 ULONG DirSize;
419 PVOID Cookie = NULL;
420
421 /* Check NT header first */
422 if (!RtlImageNtHeader(BaseAddress)) return NULL;
423
424 /* Get the pointer to the config directory */
426 TRUE,
428 &DirSize);
429
430 /* Check for sanity */
431 if (!ConfigDir ||
432 (DirSize != 64 && ConfigDir->Size != DirSize) ||
433 (ConfigDir->Size < 0x48))
434 return NULL;
435
436 /* Now get the cookie */
437 Cookie = (PVOID)ConfigDir->SecurityCookie;
438
439 /* Check this cookie */
441 (PCHAR)Cookie >= (PCHAR)BaseAddress + SizeOfImage)
442 {
443 Cookie = NULL;
444 }
445
446 /* Return validated security cookie */
447 return Cookie;
448}
449
450PVOID
451NTAPI
453{
456 ULONG_PTR NewCookie;
457
458 /* Fetch address of the cookie */
460
461 if (Cookie)
462 {
463 /* Check if it's a default one */
465 (*Cookie == 0xBB40))
466 {
467 /* Make up a cookie from a bunch of values which may uniquely represent
468 current moment of time, environment, etc */
470
471 NewCookie = Counter.LowPart ^ Counter.HighPart;
472 NewCookie ^= (ULONG_PTR)NtCurrentTeb()->ClientId.UniqueProcess;
473 NewCookie ^= (ULONG_PTR)NtCurrentTeb()->ClientId.UniqueThread;
474
475 /* Loop like it's done in KeQueryTickCount(). We don't want to call it directly. */
476 while (SharedUserData->SystemTime.High1Time != SharedUserData->SystemTime.High2Time)
477 {
479 };
480
481 /* Calculate the milliseconds value and xor it to the cookie */
482 NewCookie ^= Int64ShrlMod32(UInt32x32To64(SharedUserData->TickCountMultiplier, SharedUserData->TickCount.LowPart), 24) +
483 (SharedUserData->TickCountMultiplier * (SharedUserData->TickCount.High1Time << 8));
484
485 /* Make the cookie 16bit if necessary */
486 if (*Cookie == 0xBB40) NewCookie &= 0xFFFF;
487
488 /* If the result is 0 or the same as we got, just subtract one from the existing value
489 and that's it */
490 if ((NewCookie == 0) || (NewCookie == *Cookie))
491 {
492 NewCookie = *Cookie - 1;
493 }
494
495 /* Set the new cookie value */
496 *Cookie = NewCookie;
497 }
498 }
499
500 return Cookie;
501}
502
503VOID
504NTAPI
506{
508 PLDR_DATA_TABLE_ENTRY LdrEntry;
509 PLIST_ENTRY NextEntry, ListHead;
510 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
512 PVOID EntryPoint;
513
514 DPRINT("LdrpInitializeThread() called for %wZ (%p/%p)\n",
516 NtCurrentTeb()->RealClientId.UniqueProcess,
517 NtCurrentTeb()->RealClientId.UniqueThread);
518
519 /* Acquire the loader Lock */
521
522 /* Allocate an Activation Context Stack */
523 DPRINT("ActivationContextStack %p\n", NtCurrentTeb()->ActivationContextStackPointer);
524 Status = RtlAllocateActivationContextStack(&NtCurrentTeb()->ActivationContextStackPointer);
525 if (!NT_SUCCESS(Status))
526 {
527 DPRINT1("Warning: Unable to allocate ActivationContextStack\n");
528 }
529
530 /* Make sure we are not shutting down */
532
533 /* Allocate TLS */
535
536 /* Start at the beginning */
537 ListHead = &Peb->Ldr->InMemoryOrderModuleList;
538 NextEntry = ListHead->Flink;
539 while (NextEntry != ListHead)
540 {
541 /* Get the current entry */
542 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
543
544 /* Make sure it's not ourselves */
545 if (Peb->ImageBaseAddress != LdrEntry->DllBase)
546 {
547 /* Check if we should call */
548 if (!(LdrEntry->Flags & LDRP_DONT_CALL_FOR_THREADS))
549 {
550 /* Get the entrypoint */
551 EntryPoint = LdrEntry->EntryPoint;
552
553 /* Check if we are ready to call it */
554 if ((EntryPoint) &&
555 (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) &&
556 (LdrEntry->Flags & LDRP_IMAGE_DLL))
557 {
558 /* Set up the Act Ctx */
559 ActCtx.Size = sizeof(ActCtx);
560 ActCtx.Format = 1;
562
563 /* Activate the ActCtx */
564 RtlActivateActivationContextUnsafeFast(&ActCtx,
566
568 {
569 /* Check if it has TLS */
570 if (LdrEntry->TlsIndex)
571 {
572 /* Make sure we're not shutting down */
574 {
575 /* Call TLS */
577 }
578 }
579
580 /* Make sure we're not shutting down */
582 {
583 /* Call the Entrypoint */
584 DPRINT("%wZ - Calling entry point at %p for thread attaching, %p/%p\n",
585 &LdrEntry->BaseDllName, LdrEntry->EntryPoint,
586 NtCurrentTeb()->RealClientId.UniqueProcess,
587 NtCurrentTeb()->RealClientId.UniqueThread);
589 LdrEntry->DllBase,
591 NULL);
592 }
593 }
595 {
596 DPRINT1("WARNING: Exception 0x%x during LdrpCallInitRoutine(DLL_THREAD_ATTACH) for %wZ\n",
597 _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
598 }
599 _SEH2_END;
600
601 /* Deactivate the ActCtx */
602 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
603 }
604 }
605 }
606
607 /* Next entry */
608 NextEntry = NextEntry->Flink;
609 }
610
611 /* Check for TLS */
613 {
614 /* Set up the Act Ctx */
615 ActCtx.Size = sizeof(ActCtx);
616 ActCtx.Format = 1;
618
619 /* Activate the ActCtx */
620 RtlActivateActivationContextUnsafeFast(&ActCtx,
622
624 {
625 /* Do TLS callbacks */
627 }
629 {
630 /* Do nothing */
631 }
632 _SEH2_END;
633
634 /* Deactivate the ActCtx */
635 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
636 }
637
638Exit:
639
640 /* Release the loader lock */
642
643 DPRINT("LdrpInitializeThread() done\n");
644}
645
647NTAPI
649{
650 PLDR_DATA_TABLE_ENTRY LocalArray[16];
651 PLIST_ENTRY ListHead;
652 PLIST_ENTRY NextEntry;
653 PLDR_DATA_TABLE_ENTRY LdrEntry, *LdrRootEntry, OldInitializer;
654 PVOID EntryPoint;
655 ULONG Count, i;
656 //ULONG BreakOnInit;
659 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
660 ULONG BreakOnDllLoad;
661 PTEB OldTldTeb;
662 BOOLEAN DllStatus;
663
664 DPRINT("LdrpRunInitializeRoutines() called for %wZ (%p/%p)\n",
666 NtCurrentTeb()->RealClientId.UniqueProcess,
667 NtCurrentTeb()->RealClientId.UniqueThread);
668
669 /* Check the Loader Lock */
671
672 /* Get the number of entries to call */
674 {
675 /* Check if we can use our local buffer */
676 if (Count > 16)
677 {
678 /* Allocate space for all the entries */
679 LdrRootEntry = RtlAllocateHeap(LdrpHeap,
680 0,
681 Count * sizeof(*LdrRootEntry));
682 if (!LdrRootEntry) return STATUS_NO_MEMORY;
683 }
684 else
685 {
686 /* Use our local array */
687 LdrRootEntry = LocalArray;
688 }
689 }
690 else
691 {
692 /* Don't need one */
693 LdrRootEntry = NULL;
694 }
695
696 /* Show debug message */
697 if (ShowSnaps)
698 {
699 DPRINT1("[%p,%p] LDR: Real INIT LIST for Process %wZ\n",
700 NtCurrentTeb()->RealClientId.UniqueThread,
701 NtCurrentTeb()->RealClientId.UniqueProcess,
703 }
704
705 /* Loop in order */
707 NextEntry = ListHead->Flink;
708 i = 0;
709 while (NextEntry != ListHead)
710 {
711 /* Get the Data Entry */
712 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
713
714 /* Check if we have a Root Entry */
715 if (LdrRootEntry)
716 {
717 /* Check flags */
718 if (!(LdrEntry->Flags & LDRP_ENTRY_PROCESSED))
719 {
720 /* Setup the Cookie for the DLL */
721 LdrpInitSecurityCookie(LdrEntry);
722
723 /* Check for valid entrypoint */
724 if (LdrEntry->EntryPoint)
725 {
726 /* Write in array */
727 ASSERT(i < Count);
728 LdrRootEntry[i] = LdrEntry;
729
730 /* Display debug message */
731 if (ShowSnaps)
732 {
733 DPRINT1("[%p,%p] LDR: %wZ init routine %p\n",
734 NtCurrentTeb()->RealClientId.UniqueThread,
735 NtCurrentTeb()->RealClientId.UniqueProcess,
736 &LdrEntry->FullDllName,
737 LdrEntry->EntryPoint);
738 }
739 i++;
740 }
741 }
742 }
743
744 /* Set the flag */
745 LdrEntry->Flags |= LDRP_ENTRY_PROCESSED;
746 NextEntry = NextEntry->Flink;
747 }
748
750
751 /* If we got a context, then we have to call Kernel32 for TS support */
752 if (Context)
753 {
754 /* Check if we have one */
755 if (Kernel32ProcessInitPostImportFunction)
756 {
757 /* Call it */
758 Status = Kernel32ProcessInitPostImportFunction();
759 if (!NT_SUCCESS(Status))
760 {
761 DPRINT1("LDR: LdrpRunInitializeRoutines - Failed running kernel32 post-import function, Status=0x%08lx\n", Status);
762 }
763 }
764 /* Clear it */
765 Kernel32ProcessInitPostImportFunction = NULL;
766 }
767
768 /* No root entry? return */
769 if (!LdrRootEntry)
770 return Status;
771
772 /* Set the TLD TEB */
775
776 /* Loop */
777 i = 0;
778 while (i < Count)
779 {
780 /* Get an entry */
781 LdrEntry = LdrRootEntry[i];
782
783 /* FIXME: Verify NX Compat */
784
785 /* Move to next entry */
786 i++;
787
788 /* Get its entrypoint */
789 EntryPoint = LdrEntry->EntryPoint;
790
791 /* Are we being debugged? */
792 BreakOnDllLoad = 0;
794 {
795 /* Check if we should break on load */
797 L"BreakOnDllLoad",
798 REG_DWORD,
799 &BreakOnDllLoad,
800 sizeof(ULONG),
801 NULL);
802 if (!NT_SUCCESS(Status)) BreakOnDllLoad = 0;
803
804 /* Reset status back to STATUS_SUCCESS */
806 }
807
808 /* Break if aksed */
809 if (BreakOnDllLoad)
810 {
811 /* Check if we should show a message */
812 if (ShowSnaps)
813 {
814 DPRINT1("LDR: %wZ loaded.", &LdrEntry->BaseDllName);
815 DPRINT1(" - About to call init routine at %p\n", EntryPoint);
816 }
817
818 /* Break in debugger */
820 }
821
822 /* Make sure we have an entrypoint */
823 if (EntryPoint)
824 {
825 /* Save the old Dll Initializer and write the current one */
826 OldInitializer = LdrpCurrentDllInitializer;
827 LdrpCurrentDllInitializer = LdrEntry;
828
829 /* Set up the Act Ctx */
830 ActCtx.Size = sizeof(ActCtx);
831 ActCtx.Format = 1;
833
834 /* Activate the ActCtx */
835 RtlActivateActivationContextUnsafeFast(&ActCtx,
837
839 {
840 /* Check if it has TLS */
841 if (LdrEntry->TlsIndex && Context)
842 {
843 /* Call TLS */
845 }
846
847 /* Call the Entrypoint */
848 if (ShowSnaps)
849 {
850 DPRINT1("%wZ - Calling entry point at %p for DLL_PROCESS_ATTACH\n",
851 &LdrEntry->BaseDllName, EntryPoint);
852 }
853 DllStatus = LdrpCallInitRoutine(EntryPoint,
854 LdrEntry->DllBase,
856 Context);
857 }
859 {
860 DllStatus = FALSE;
861 DPRINT1("WARNING: Exception 0x%x during LdrpCallInitRoutine(DLL_PROCESS_ATTACH) for %wZ\n",
862 _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
863 }
864 _SEH2_END;
865
866 /* Deactivate the ActCtx */
867 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
868
869 /* Save the Current DLL Initializer */
870 LdrpCurrentDllInitializer = OldInitializer;
871
872 /* Mark the entry as processed */
874
875 /* Fail if DLL init failed */
876 if (!DllStatus)
877 {
878 DPRINT1("LDR: DLL_PROCESS_ATTACH for dll \"%wZ\" (InitRoutine: %p) failed\n",
879 &LdrEntry->BaseDllName, EntryPoint);
880
882 goto Quickie;
883 }
884 }
885 }
886
887 /* Loop in order */
889 NextEntry = NextEntry->Flink;
890 while (NextEntry != ListHead)
891 {
892 /* Get the Data Entry */
893 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
894
895 /* FIXME: Verify NX Compat */
896 // LdrpCheckNXCompatibility()
897
898 /* Next entry */
899 NextEntry = NextEntry->Flink;
900 }
901
902 /* Check for TLS */
904 {
905 /* Set up the Act Ctx */
906 ActCtx.Size = sizeof(ActCtx);
907 ActCtx.Format = 1;
909
910 /* Activate the ActCtx */
911 RtlActivateActivationContextUnsafeFast(&ActCtx,
913
915 {
916 /* Do TLS callbacks */
918 }
920 {
921 /* Do nothing */
922 }
923 _SEH2_END;
924
925 /* Deactivate the ActCtx */
926 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
927 }
928
929Quickie:
930 /* Restore old TEB */
932
933 /* Check if the array is in the heap */
934 if (LdrRootEntry != LocalArray)
935 {
936 /* Free the array */
937 RtlFreeHeap(LdrpHeap, 0, LdrRootEntry);
938 }
939
940 /* Return to caller */
941 DPRINT("LdrpRunInitializeRoutines() done\n");
942 return Status;
943}
944
945/*
946 * @implemented
947 */
949NTAPI
951{
953 PLDR_DATA_TABLE_ENTRY LdrEntry;
954 PLIST_ENTRY NextEntry, ListHead;
955 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
956 PVOID EntryPoint;
957
958 DPRINT("LdrShutdownProcess() called for %wZ\n", &LdrpImageEntry->BaseDllName);
960
961 /* Tell the Shim Engine */
962 if (g_ShimsEnabled)
963 {
967 }
968
969 /* Tell the world */
970 if (ShowSnaps)
971 {
972 DPRINT1("\n");
973 }
974
975 /* Set the shutdown variables */
976 LdrpShutdownThreadId = NtCurrentTeb()->RealClientId.UniqueThread;
978
979 /* Enter the Loader Lock */
981
982 /* Cleanup trace logging data (Etw) */
983 if (SharedUserData->TraceLogging)
984 {
985 /* FIXME */
986 DPRINT1("We don't support Etw yet.\n");
987 }
988
989 /* Start at the end */
991 NextEntry = ListHead->Blink;
992 while (NextEntry != ListHead)
993 {
994 /* Get the current entry */
995 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
996 NextEntry = NextEntry->Blink;
997
998 /* Make sure it's not ourselves */
999 if (Peb->ImageBaseAddress != LdrEntry->DllBase)
1000 {
1001 /* Get the entrypoint */
1002 EntryPoint = LdrEntry->EntryPoint;
1003
1004 /* Check if we are ready to call it */
1005 if (EntryPoint &&
1006 (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) &&
1007 LdrEntry->Flags)
1008 {
1009 /* Set up the Act Ctx */
1010 ActCtx.Size = sizeof(ActCtx);
1011 ActCtx.Format = 1;
1013
1014 /* Activate the ActCtx */
1015 RtlActivateActivationContextUnsafeFast(&ActCtx,
1016 LdrEntry->EntryPointActivationContext);
1017
1018 _SEH2_TRY
1019 {
1020 /* Check if it has TLS */
1021 if (LdrEntry->TlsIndex)
1022 {
1023 /* Call TLS */
1025 }
1026
1027 /* Call the Entrypoint */
1028 DPRINT("%wZ - Calling entry point at %p for thread detaching\n",
1029 &LdrEntry->BaseDllName, LdrEntry->EntryPoint);
1030 LdrpCallInitRoutine(EntryPoint,
1031 LdrEntry->DllBase,
1033 (PVOID)1);
1034 }
1036 {
1037 DPRINT1("WARNING: Exception 0x%x during LdrpCallInitRoutine(DLL_PROCESS_DETACH) for %wZ\n",
1038 _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
1039 }
1040 _SEH2_END;
1041
1042 /* Deactivate the ActCtx */
1043 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
1044 }
1045 }
1046 }
1047
1048 /* Check for TLS */
1049 if (LdrpImageHasTls)
1050 {
1051 /* Set up the Act Ctx */
1052 ActCtx.Size = sizeof(ActCtx);
1053 ActCtx.Format = 1;
1055
1056 /* Activate the ActCtx */
1057 RtlActivateActivationContextUnsafeFast(&ActCtx,
1059
1060 _SEH2_TRY
1061 {
1062 /* Do TLS callbacks */
1064 }
1066 {
1067 /* Do nothing */
1068 }
1069 _SEH2_END;
1070
1071 /* Deactivate the ActCtx */
1072 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
1073 }
1074
1075 /* FIXME: Do Heap detection and Etw final shutdown */
1076
1077 /* Release the lock */
1079 DPRINT("LdrpShutdownProcess() done\n");
1080
1081 return STATUS_SUCCESS;
1082}
1083
1084/*
1085 * @implemented
1086 */
1088NTAPI
1090{
1091 PPEB Peb = NtCurrentPeb();
1092 PTEB Teb = NtCurrentTeb();
1093 PLDR_DATA_TABLE_ENTRY LdrEntry;
1094 PLIST_ENTRY NextEntry, ListHead;
1095 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
1096 PVOID EntryPoint;
1097
1098 DPRINT("LdrShutdownThread() called for %wZ\n",
1100
1101 /* Cleanup trace logging data (Etw) */
1102 if (SharedUserData->TraceLogging)
1103 {
1104 /* FIXME */
1105 DPRINT1("We don't support Etw yet.\n");
1106 }
1107
1108 /* Get the Ldr Lock */
1110
1111 /* Start at the end */
1113 NextEntry = ListHead->Blink;
1114 while (NextEntry != ListHead)
1115 {
1116 /* Get the current entry */
1117 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderLinks);
1118 NextEntry = NextEntry->Blink;
1119
1120 /* Make sure it's not ourselves */
1121 if (Peb->ImageBaseAddress != LdrEntry->DllBase)
1122 {
1123 /* Check if we should call */
1124 if (!(LdrEntry->Flags & LDRP_DONT_CALL_FOR_THREADS) &&
1125 (LdrEntry->Flags & LDRP_PROCESS_ATTACH_CALLED) &&
1126 (LdrEntry->Flags & LDRP_IMAGE_DLL))
1127 {
1128 /* Get the entrypoint */
1129 EntryPoint = LdrEntry->EntryPoint;
1130
1131 /* Check if we are ready to call it */
1132 if (EntryPoint)
1133 {
1134 /* Set up the Act Ctx */
1135 ActCtx.Size = sizeof(ActCtx);
1136 ActCtx.Format = 1;
1138
1139 /* Activate the ActCtx */
1140 RtlActivateActivationContextUnsafeFast(&ActCtx,
1141 LdrEntry->EntryPointActivationContext);
1142
1143 _SEH2_TRY
1144 {
1145 /* Check if it has TLS */
1146 if (LdrEntry->TlsIndex)
1147 {
1148 /* Make sure we're not shutting down */
1150 {
1151 /* Call TLS */
1153 }
1154 }
1155
1156 /* Make sure we're not shutting down */
1158 {
1159 /* Call the Entrypoint */
1160 DPRINT("%wZ - Calling entry point at %p for thread detaching\n",
1161 &LdrEntry->BaseDllName, LdrEntry->EntryPoint);
1162 LdrpCallInitRoutine(EntryPoint,
1163 LdrEntry->DllBase,
1165 NULL);
1166 }
1167 }
1169 {
1170 DPRINT1("WARNING: Exception 0x%x during LdrpCallInitRoutine(DLL_THREAD_DETACH) for %wZ\n",
1171 _SEH2_GetExceptionCode(), &LdrEntry->BaseDllName);
1172 }
1173 _SEH2_END;
1174
1175 /* Deactivate the ActCtx */
1176 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
1177 }
1178 }
1179 }
1180 }
1181
1182 /* Check for TLS */
1183 if (LdrpImageHasTls)
1184 {
1185 /* Set up the Act Ctx */
1186 ActCtx.Size = sizeof(ActCtx);
1187 ActCtx.Format = 1;
1189
1190 /* Activate the ActCtx */
1191 RtlActivateActivationContextUnsafeFast(&ActCtx,
1193
1194 _SEH2_TRY
1195 {
1196 /* Do TLS callbacks */
1198 }
1200 {
1201 /* Do nothing */
1202 }
1203 _SEH2_END;
1204
1205 /* Deactivate the ActCtx */
1206 RtlDeactivateActivationContextUnsafeFast(&ActCtx);
1207 }
1208
1209 /* Free TLS */
1210 LdrpFreeTls();
1212
1213 /* Check for expansion slots */
1214 if (Teb->TlsExpansionSlots)
1215 {
1216 /* Free expansion slots */
1217 RtlFreeHeap(RtlGetProcessHeap(), 0, Teb->TlsExpansionSlots);
1218 }
1219
1220 /* Check for FLS Data */
1221 if (Teb->FlsData)
1222 {
1223 /* Mimic BaseRundownFls */
1224 ULONG n, FlsHighIndex;
1225 PRTL_FLS_DATA pFlsData;
1226 PFLS_CALLBACK_FUNCTION lpCallback;
1227
1228 pFlsData = Teb->FlsData;
1229
1231 FlsHighIndex = NtCurrentPeb()->FlsHighIndex;
1232 RemoveEntryList(&pFlsData->ListEntry);
1234
1235 for (n = 1; n <= FlsHighIndex; ++n)
1236 {
1237 lpCallback = NtCurrentPeb()->FlsCallback[n];
1238 if (lpCallback && pFlsData->Data[n])
1239 {
1240 lpCallback(pFlsData->Data[n]);
1241 }
1242 }
1243
1244 RtlFreeHeap(RtlGetProcessHeap(), 0, pFlsData);
1245 Teb->FlsData = NULL;
1246 }
1247
1248 /* Check for Fiber data */
1249 if (Teb->HasFiberData)
1250 {
1251 /* Free Fiber data*/
1252 RtlFreeHeap(RtlGetProcessHeap(), 0, Teb->NtTib.FiberData);
1253 Teb->NtTib.FiberData = NULL;
1254 }
1255
1256 /* Free the activation context stack */
1258 DPRINT("LdrShutdownThread() done\n");
1259
1260 return STATUS_SUCCESS;
1261}
1262
1264NTAPI
1266{
1267 PLIST_ENTRY NextEntry, ListHead;
1268 PLDR_DATA_TABLE_ENTRY LdrEntry;
1269 PIMAGE_TLS_DIRECTORY TlsDirectory;
1270 PLDRP_TLS_DATA TlsData;
1271 ULONG Size;
1272
1273 /* Initialize the TLS List */
1275
1276 /* Loop all the modules */
1277 ListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
1278 NextEntry = ListHead->Flink;
1279 while (ListHead != NextEntry)
1280 {
1281 /* Get the entry */
1282 LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
1283 NextEntry = NextEntry->Flink;
1284
1285 /* Get the TLS directory */
1286 TlsDirectory = RtlImageDirectoryEntryToData(LdrEntry->DllBase,
1287 TRUE,
1289 &Size);
1290
1291 /* Check if we have a directory */
1292 if (!TlsDirectory) continue;
1293
1294 /* Check if the image has TLS */
1296
1297 /* Show debug message */
1298 if (ShowSnaps)
1299 {
1300 DPRINT1("LDR: Tls Found in %wZ at %p\n",
1301 &LdrEntry->BaseDllName,
1302 TlsDirectory);
1303 }
1304
1305 /* Allocate an entry */
1306 TlsData = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof(LDRP_TLS_DATA));
1307 if (!TlsData) return STATUS_NO_MEMORY;
1308
1309 /* Lock the DLL and mark it for TLS Usage */
1310 LdrEntry->LoadCount = -1;
1311 LdrEntry->TlsIndex = -1;
1312
1313 /* Save the cached TLS data */
1314 TlsData->TlsDirectory = *TlsDirectory;
1315 InsertTailList(&LdrpTlsList, &TlsData->TlsLinks);
1316
1317 /* Update the index */
1320 }
1321
1322 /* Done setting up TLS, allocate entries */
1323 return LdrpAllocateTls();
1324}
1325
1327NTAPI
1329{
1330 PTEB Teb = NtCurrentTeb();
1331 PLIST_ENTRY NextEntry, ListHead;
1332 PLDRP_TLS_DATA TlsData;
1333 SIZE_T TlsDataSize;
1334 PVOID *TlsVector;
1335
1336 /* Check if we have any entries */
1338 return STATUS_SUCCESS;
1339
1340 /* Allocate the vector array */
1341 TlsVector = RtlAllocateHeap(RtlGetProcessHeap(),
1342 0,
1343 LdrpNumberOfTlsEntries * sizeof(PVOID));
1344 if (!TlsVector) return STATUS_NO_MEMORY;
1345 Teb->ThreadLocalStoragePointer = TlsVector;
1346
1347 /* Loop the TLS Array */
1348 ListHead = &LdrpTlsList;
1349 NextEntry = ListHead->Flink;
1350 while (NextEntry != ListHead)
1351 {
1352 /* Get the entry */
1353 TlsData = CONTAINING_RECORD(NextEntry, LDRP_TLS_DATA, TlsLinks);
1354 NextEntry = NextEntry->Flink;
1355
1356 /* Allocate this vector */
1357 TlsDataSize = TlsData->TlsDirectory.EndAddressOfRawData -
1359 TlsVector[TlsData->TlsDirectory.Characteristics] = RtlAllocateHeap(RtlGetProcessHeap(),
1360 0,
1361 TlsDataSize);
1362 if (!TlsVector[TlsData->TlsDirectory.Characteristics])
1363 {
1364 /* Out of memory */
1365 return STATUS_NO_MEMORY;
1366 }
1367
1368 /* Show debug message */
1369 if (ShowSnaps)
1370 {
1371 DPRINT1("LDR: TlsVector %p Index %lu = %p copied from %x to %p\n",
1372 TlsVector,
1374 &TlsVector[TlsData->TlsDirectory.Characteristics],
1376 TlsVector[TlsData->TlsDirectory.Characteristics]);
1377 }
1378
1379 /* Copy the data */
1380 RtlCopyMemory(TlsVector[TlsData->TlsDirectory.Characteristics],
1382 TlsDataSize);
1383 }
1384
1385 /* Done */
1386 return STATUS_SUCCESS;
1387}
1388
1389VOID
1390NTAPI
1392{
1393 PLIST_ENTRY ListHead, NextEntry;
1394 PLDRP_TLS_DATA TlsData;
1395 PVOID *TlsVector;
1396 PTEB Teb = NtCurrentTeb();
1397
1398 /* Get a pointer to the vector array */
1399 TlsVector = Teb->ThreadLocalStoragePointer;
1400 if (!TlsVector) return;
1401
1402 /* Loop through it */
1403 ListHead = &LdrpTlsList;
1404 NextEntry = ListHead->Flink;
1405 while (NextEntry != ListHead)
1406 {
1407 TlsData = CONTAINING_RECORD(NextEntry, LDRP_TLS_DATA, TlsLinks);
1408 NextEntry = NextEntry->Flink;
1409
1410 /* Free each entry */
1411 if (TlsVector[TlsData->TlsDirectory.Characteristics])
1412 {
1413 RtlFreeHeap(RtlGetProcessHeap(),
1414 0,
1415 TlsVector[TlsData->TlsDirectory.Characteristics]);
1416 }
1417 }
1418
1419 /* Free the array itself */
1420 RtlFreeHeap(RtlGetProcessHeap(),
1421 0,
1422 TlsVector);
1423}
1424
1426NTAPI
1428{
1431 ULONG ExecuteOptions, MinimumStackCommit = 0, GlobalFlag;
1432
1433 /* Return error if we were not provided a pointer where to save the options key handle */
1434 if (!OptionsKey) return STATUS_INVALID_HANDLE;
1435
1436 /* Zero initialize the options key pointer */
1437 *OptionsKey = NULL;
1438
1439 /* Open the options key */
1440 Status = LdrOpenImageFileOptionsKey(ImagePathName, 0, &KeyHandle);
1441
1442 /* Save it if it was opened successfully */
1443 if (NT_SUCCESS(Status))
1444 *OptionsKey = KeyHandle;
1445
1446 if (KeyHandle)
1447 {
1448 /* There are image specific options, read them starting with NXCOMPAT */
1450 L"ExecuteOptions",
1451 4,
1452 &ExecuteOptions,
1453 sizeof(ExecuteOptions),
1454 0);
1455
1456 if (NT_SUCCESS(Status))
1457 {
1458 /* TODO: Set execution options for the process */
1459 /*
1460 if (ExecuteOptions == 0)
1461 ExecuteOptions = 1;
1462 else
1463 ExecuteOptions = 2;
1464 ZwSetInformationProcess(NtCurrentProcess(),
1465 ProcessExecuteFlags,
1466 &ExecuteOptions,
1467 sizeof(ULONG));*/
1468
1469 }
1470
1471 /* Check if this image uses large pages */
1472 if (Peb->ImageUsesLargePages)
1473 {
1474 /* TODO: If it does, open large page key */
1476 }
1477
1478 /* Get various option values */
1480 L"DisableHeapLookaside",
1481 REG_DWORD,
1484 NULL);
1485
1487 L"ShutdownFlags",
1488 REG_DWORD,
1491 NULL);
1492
1494 L"MinimumStackCommitInBytes",
1495 REG_DWORD,
1496 &MinimumStackCommit,
1497 sizeof(MinimumStackCommit),
1498 NULL);
1499
1500 /* Update PEB's minimum stack commit if it's lower */
1501 if (Peb->MinimumStackCommit < MinimumStackCommit)
1502 Peb->MinimumStackCommit = MinimumStackCommit;
1503
1504 /* Set the global flag */
1506 L"GlobalFlag",
1507 REG_DWORD,
1508 &GlobalFlag,
1509 sizeof(GlobalFlag),
1510 NULL);
1511
1512 if (NT_SUCCESS(Status))
1513 Peb->NtGlobalFlag = GlobalFlag;
1514 else
1515 GlobalFlag = 0;
1516
1517 /* Call AVRF if necessary */
1519 {
1521 if (!NT_SUCCESS(Status))
1522 {
1523 DPRINT1("AVRF: LdrpInitializeApplicationVerifierPackage failed with %08X\n", Status);
1524 }
1525 }
1526 }
1527 else
1528 {
1529 /* There are no image-specific options, so perform global initialization */
1531 {
1532 /* Initialize app verifier package */
1534 if (!NT_SUCCESS(Status))
1535 {
1536 DPRINT1("AVRF: LdrpInitializeApplicationVerifierPackage failed with %08X\n", Status);
1537 }
1538 }
1539 }
1540
1541 return STATUS_SUCCESS;
1542}
1543
1544VOID
1545NTAPI
1547{
1548 DPRINT("LdrpValidateImageForMp is unimplemented\n");
1549 // TODO:
1550 // Scan the LockPrefixTable in the load config directory
1551}
1552
1553BOOLEAN
1554NTAPI
1556{
1557 UNICODE_STRING PolicyKey = RTL_CONSTANT_STRING(L"\\Registry\\MACHINE\\Software\\Policies\\Microsoft\\Windows\\AppCompat");
1558 UNICODE_STRING DisableDetection = RTL_CONSTANT_STRING(L"DisableCompatGuidDetection");
1564
1565 Status = NtOpenKey(&KeyHandle, KEY_QUERY_VALUE, &PolicyKeyAttributes);
1566 if (NT_SUCCESS(Status))
1567 {
1569 &DisableDetection,
1571 &KeyInfo,
1572 sizeof(KeyInfo),
1573 &ResultLength);
1575 if ((NT_SUCCESS(Status)) &&
1576 (KeyInfo.Type == REG_DWORD) &&
1577 (KeyInfo.DataLength == sizeof(ULONG)) &&
1578 (KeyInfo.Data[0] == TRUE))
1579 {
1580 return TRUE;
1581 }
1582 }
1583 return FALSE;
1584}
1585
1586
1587VOID
1588NTAPI
1589LdrpInitializeProcessCompat(PVOID pProcessActctx, PVOID* pOldShimData)
1590{
1591 static const struct
1592 {
1593 const GUID* Guid;
1594 const DWORD Version;
1595 } KnownCompatGuids[] = {
1596 { &COMPAT_GUID_WIN10, _WIN32_WINNT_WIN10 },
1597 { &COMPAT_GUID_WIN81, _WIN32_WINNT_WINBLUE },
1598 { &COMPAT_GUID_WIN8, _WIN32_WINNT_WIN8 },
1599 { &COMPAT_GUID_WIN7, _WIN32_WINNT_WIN7 },
1600 { &COMPAT_GUID_VISTA, _WIN32_WINNT_VISTA },
1601 };
1602
1603 ULONG Buffer[(sizeof(COMPATIBILITY_CONTEXT_ELEMENT) * 10 + sizeof(ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION)) / sizeof(ULONG)];
1604 ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION* ContextCompatInfo;
1605 SIZE_T SizeRequired;
1607 DWORD n, cur;
1608 ReactOS_ShimData* pShimData = *pOldShimData;
1609
1610 if (pShimData)
1611 {
1612 if (pShimData->dwMagic != REACTOS_SHIMDATA_MAGIC ||
1613 pShimData->dwSize != sizeof(ReactOS_ShimData))
1614 {
1615 DPRINT1("LdrpInitializeProcessCompat: Corrupt pShimData (0x%x, %u)\n", pShimData->dwMagic, pShimData->dwSize);
1616 return;
1617 }
1618 if (pShimData->dwRosProcessCompatVersion)
1619 {
1621 {
1622 DPRINT1("LdrpInitializeProcessCompat: ProcessCompatVersion set to ignore manifest\n");
1623 }
1624 else
1625 {
1626 DPRINT1("LdrpInitializeProcessCompat: ProcessCompatVersion already set to 0x%x\n", pShimData->dwRosProcessCompatVersion);
1627 }
1628 return;
1629 }
1630 }
1631
1632 SizeRequired = sizeof(Buffer);
1634 pProcessActctx,
1635 NULL,
1636 CompatibilityInformationInActivationContext,
1637 Buffer,
1638 sizeof(Buffer),
1639 &SizeRequired);
1640
1641 if (!NT_SUCCESS(Status))
1642 {
1643 DPRINT1("LdrpInitializeProcessCompat: Unable to query process actctx with status %x\n", Status);
1644 return;
1645 }
1646
1647 ContextCompatInfo = (ACTIVATION_CONTEXT_COMPATIBILITY_INFORMATION*)Buffer;
1648 /* No Compatibility elements present, bail out */
1649 if (ContextCompatInfo->ElementCount == 0)
1650 return;
1651
1652 /* Search for known GUIDs, starting from oldest to newest.
1653 Note that on Windows it is somewhat reversed, starting from the latest known
1654 version, going down. But we are not Windows, trying to allow a lower version,
1655 we are ReactOS trying to fake a higher version. So we interpret what Windows
1656 does as "try the closest version to the actual version", so we start with the
1657 lowest version, which is closest to Windows 2003, which we mostly are. */
1658 for (cur = RTL_NUMBER_OF(KnownCompatGuids) - 1; cur != -1; --cur)
1659 {
1660 for (n = 0; n < ContextCompatInfo->ElementCount; ++n)
1661 {
1662 if (ContextCompatInfo->Elements[n].Type == ACTCTX_COMPATIBILITY_ELEMENT_TYPE_OS &&
1663 RtlCompareMemory(&ContextCompatInfo->Elements[n].Id, KnownCompatGuids[cur].Guid, sizeof(GUID)) == sizeof(GUID))
1664 {
1666 {
1667 DPRINT1("LdrpInitializeProcessCompat: Not applying automatic fix for winver 0x%x due to policy\n", KnownCompatGuids[cur].Version);
1668 return;
1669 }
1670
1671 /* If this process did not need shim data before, allocate and store it */
1672 if (pShimData == NULL)
1673 {
1674 PPEB Peb = NtCurrentPeb();
1675
1676 ASSERT(Peb->pShimData == NULL);
1677 pShimData = RtlAllocateHeap(Peb->ProcessHeap, HEAP_ZERO_MEMORY, sizeof(*pShimData));
1678
1679 if (!pShimData)
1680 {
1681 DPRINT1("LdrpInitializeProcessCompat: Unable to allocated %u bytes\n", sizeof(*pShimData));
1682 return;
1683 }
1684
1685 pShimData->dwSize = sizeof(*pShimData);
1686 pShimData->dwMagic = REACTOS_SHIMDATA_MAGIC;
1687
1688 Peb->pShimData = pShimData;
1689 *pOldShimData = pShimData;
1690 }
1691
1692 /* Store the lowest found version, and bail out. */
1693 pShimData->dwRosProcessCompatVersion = KnownCompatGuids[cur].Version;
1694 DPRINT1("LdrpInitializeProcessCompat: Found guid for winver 0x%x in manifest from %wZ\n",
1695 KnownCompatGuids[cur].Version,
1696 &(NtCurrentPeb()->ProcessParameters->ImagePathName));
1697 return;
1698 }
1699 }
1700 }
1701}
1702
1703VOID
1704NTAPI
1706{
1707 UNICODE_STRING ImagePathName = ProcessParameters->ImagePathName;
1708 WCHAR LocalBuffer[MAX_PATH];
1709 UNICODE_STRING DotLocal;
1712
1713 RequiredSize = ImagePathName.Length + LdrpDotLocal.Length + sizeof(UNICODE_NULL);
1714 if (RequiredSize <= sizeof(LocalBuffer))
1715 {
1716 RtlInitEmptyUnicodeString(&DotLocal, LocalBuffer, sizeof(LocalBuffer));
1717 }
1719 {
1720 DotLocal.Buffer = RtlAllocateHeap(RtlGetProcessHeap(), 0, RequiredSize);
1721 DotLocal.Length = 0;
1722 DotLocal.MaximumLength = RequiredSize;
1723 if (!DotLocal.Buffer)
1724 DPRINT1("LDR: Failed to allocate memory for .local check\n");
1725 }
1726 else
1727 {
1728 DotLocal.Buffer = NULL;
1729 DotLocal.Length = 0;
1730 DotLocal.MaximumLength = 0;
1731 DPRINT1("LDR: String too big for .local check\n");
1732 }
1733
1734 if (DotLocal.Buffer)
1735 {
1736 Status = RtlAppendUnicodeStringToString(&DotLocal, &ImagePathName);
1738 if (NT_SUCCESS(Status))
1739 {
1742 }
1743
1744 if (NT_SUCCESS(Status))
1745 {
1746 if (RtlDoesFileExists_UStr(&DotLocal))
1747 {
1749 }
1750 }
1751 else
1752 {
1753 DPRINT1("LDR: Failed to append: 0x%lx\n", Status);
1754 }
1755
1756 if (DotLocal.Buffer != LocalBuffer)
1757 {
1758 RtlFreeHeap(RtlGetProcessHeap(), 0, DotLocal.Buffer);
1759 }
1760 }
1761}
1762
1763
1765NTAPI
1768{
1769 RTL_HEAP_PARAMETERS HeapParameters;
1770 ULONG ComSectionSize;
1771 ANSI_STRING BaseProcessInitPostImportName = RTL_CONSTANT_STRING("BaseProcessInitPostImport");
1772 ANSI_STRING BaseQueryModuleDataName = RTL_CONSTANT_STRING("BaseQueryModuleData");
1773 PVOID OldShimData;
1775 //UNICODE_STRING LocalFileName, FullImageName;
1776 HANDLE SymLinkHandle;
1777 //ULONG DebugHeapOnly;
1778 UNICODE_STRING CommandLine, NtSystemRoot, ImagePathName, FullPath, ImageFileName, KnownDllString;
1779 PPEB Peb = NtCurrentPeb();
1780 BOOLEAN IsDotNetImage = FALSE;
1781 BOOLEAN FreeCurDir = FALSE;
1782 //HANDLE CompatKey;
1783 PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
1784 //LPWSTR ImagePathBuffer;
1785 ULONG ConfigSize;
1787 HANDLE OptionsKey;
1788 ULONG HeapFlags;
1789 PIMAGE_NT_HEADERS NtHeader;
1790 LPWSTR NtDllName = NULL;
1791 NTSTATUS Status, ImportStatus;
1792 NLSTABLEINFO NlsTable;
1794 PTEB Teb = NtCurrentTeb();
1795 PLIST_ENTRY ListHead;
1796 PLIST_ENTRY NextEntry;
1797 ULONG i;
1798 PWSTR ImagePath;
1799 ULONG DebugProcessHeapOnly = 0;
1800 PLDR_DATA_TABLE_ENTRY NtLdrEntry;
1801 PWCHAR Current;
1802 ULONG ExecuteOptions = 0;
1803 PVOID ViewBase;
1804
1805 /* Set a NULL SEH Filter */
1807
1808 /* Get the image path */
1810
1811 /* Check if it's not normalized */
1813 {
1814 /* Normalize it*/
1815 ImagePath = (PWSTR)((ULONG_PTR)ImagePath + (ULONG_PTR)Peb->ProcessParameters);
1816 }
1817
1818 /* Create a unicode string for the Image Path */
1820 ImagePathName.MaximumLength = ImagePathName.Length + sizeof(WCHAR);
1821 ImagePathName.Buffer = ImagePath;
1822
1823 /* Get the NT Headers */
1825
1826 /* Get the execution options */
1827 Status = LdrpInitializeExecutionOptions(&ImagePathName, Peb, &OptionsKey);
1828
1829 /* Check if this is a .NET executable */
1831 TRUE,
1833 &ComSectionSize))
1834 {
1835 /* Remember this for later */
1836 IsDotNetImage = TRUE;
1837 }
1838
1839 /* Save the NTDLL Base address */
1841
1842 /* If this is a Native Image */
1844 {
1845 /* Then do DLL Validation */
1847 }
1848
1849 /* Save the old Shim Data */
1850 OldShimData = Peb->pShimData;
1851
1852 /* ReactOS specific: do not clear it. (Windows starts doing the same in later versions) */
1853 //Peb->pShimData = NULL;
1854
1855 /* Save the number of processors and CS timeout */
1858
1859 /* Normalize the parameters */
1860 ProcessParameters = RtlNormalizeProcessParams(Peb->ProcessParameters);
1861 if (ProcessParameters)
1862 {
1863 /* Save the Image and Command Line Names */
1864 ImageFileName = ProcessParameters->ImagePathName;
1865 CommandLine = ProcessParameters->CommandLine;
1866 }
1867 else
1868 {
1869 /* It failed, initialize empty strings */
1870 RtlInitUnicodeString(&ImageFileName, NULL);
1871 RtlInitUnicodeString(&CommandLine, NULL);
1872 }
1873
1874 /* Initialize NLS data */
1878 &NlsTable);
1879
1880 /* Reset NLS Translations */
1881 RtlResetRtlTranslations(&NlsTable);
1882
1883 /* Get the Image Config Directory */
1885 TRUE,
1887 &ConfigSize);
1888
1889 /* Setup the Heap Parameters */
1890 RtlZeroMemory(&HeapParameters, sizeof(HeapParameters));
1891 HeapFlags = HEAP_GROWABLE;
1892 HeapParameters.Length = sizeof(HeapParameters);
1893
1894 /* Check if we have Configuration Data */
1895#define VALID_CONFIG_FIELD(Name) (ConfigSize >= RTL_SIZEOF_THROUGH_FIELD(IMAGE_LOAD_CONFIG_DIRECTORY, Name))
1896 /* The 'original' load config ends after SecurityCookie */
1897 if ((LoadConfig) && ConfigSize && (VALID_CONFIG_FIELD(SecurityCookie) || ConfigSize == LoadConfig->Size))
1898 {
1899 if (ConfigSize != sizeof(IMAGE_LOAD_CONFIG_DIRECTORY))
1900 DPRINT1("WARN: Accepting different LOAD_CONFIG size!\n");
1901 else
1902 DPRINT1("Applying LOAD_CONFIG\n");
1903
1904 if (VALID_CONFIG_FIELD(GlobalFlagsSet) && LoadConfig->GlobalFlagsSet)
1905 Peb->NtGlobalFlag |= LoadConfig->GlobalFlagsSet;
1906
1907 if (VALID_CONFIG_FIELD(GlobalFlagsClear) && LoadConfig->GlobalFlagsClear)
1908 Peb->NtGlobalFlag &= ~LoadConfig->GlobalFlagsClear;
1909
1910 /* Convert the default CS timeout from milliseconds to 100ns units */
1911 if (VALID_CONFIG_FIELD(CriticalSectionDefaultTimeout) && LoadConfig->CriticalSectionDefaultTimeout)
1912 RtlpTimeout.QuadPart = Int32x32To64(LoadConfig->CriticalSectionDefaultTimeout, -10000);
1913
1914 if (VALID_CONFIG_FIELD(DeCommitFreeBlockThreshold) && LoadConfig->DeCommitFreeBlockThreshold)
1915 HeapParameters.DeCommitFreeBlockThreshold = LoadConfig->DeCommitFreeBlockThreshold;
1916
1917 if (VALID_CONFIG_FIELD(DeCommitTotalFreeThreshold) && LoadConfig->DeCommitTotalFreeThreshold)
1918 HeapParameters.DeCommitTotalFreeThreshold = LoadConfig->DeCommitTotalFreeThreshold;
1919
1920 if (VALID_CONFIG_FIELD(MaximumAllocationSize) && LoadConfig->MaximumAllocationSize)
1921 HeapParameters.MaximumAllocationSize = LoadConfig->MaximumAllocationSize;
1922
1923 if (VALID_CONFIG_FIELD(VirtualMemoryThreshold) && LoadConfig->VirtualMemoryThreshold)
1924 HeapParameters.VirtualMemoryThreshold = LoadConfig->VirtualMemoryThreshold;
1925
1926 if (VALID_CONFIG_FIELD(ProcessHeapFlags) && LoadConfig->ProcessHeapFlags)
1927 HeapFlags = LoadConfig->ProcessHeapFlags;
1928 }
1929#undef VALID_CONFIG_FIELD
1930
1931 /* Check for custom affinity mask */
1933 {
1934 /* Set it */
1938 sizeof(Peb->ImageProcessAffinityMask));
1939 }
1940
1941 /* Check if verbose debugging (ShowSnaps) was requested */
1943
1944 /* Start verbose debugging messages right now if they were requested */
1945 if (ShowSnaps)
1946 {
1947 DPRINT1("LDR: PID: 0x%p started - '%wZ'\n",
1949 &CommandLine);
1950 }
1951
1952 /* If the CS timeout is longer than 1 hour, disable it */
1953 if (RtlpTimeout.QuadPart < Int32x32To64(3600, -10000000))
1955
1956 /* Initialize Critical Section Data */
1958
1959 /* Initialize VEH Call lists */
1961
1962 /* Set TLS/FLS Bitmap data */
1966
1967 /* Initialize FLS Bitmap */
1971 RtlSetBit(&FlsBitMap, 0);
1973
1974 /* Initialize TLS Bitmap */
1978 RtlSetBit(&TlsBitMap, 0);
1983
1984 /* Initialize the Hash Table */
1985 for (i = 0; i < LDR_HASH_TABLE_ENTRIES; i++)
1986 {
1988 }
1989
1990 /* Initialize the Loader Lock */
1991 // FIXME: What's the point of initing it manually, if two lines lower
1992 // a call to RtlInitializeCriticalSection() is being made anyway?
1993 //InsertTailList(&RtlCriticalSectionList, &LdrpLoaderLock.DebugInfo->ProcessLocksList);
1994 //LdrpLoaderLock.DebugInfo->CriticalSection = &LdrpLoaderLock;
1997
1998 /* Check if User Stack Trace Database support was requested */
2000 {
2001 DPRINT1("We don't support user stack trace databases yet\n");
2002 }
2003
2004 /* Setup Fast PEB Lock */
2007 //Peb->FastPebLockRoutine = (PPEBLOCKROUTINE)RtlEnterCriticalSection;
2008 //Peb->FastPebUnlockRoutine = (PPEBLOCKROUTINE)RtlLeaveCriticalSection;
2009
2010 /* Setup Callout Lock */
2011 //RtlInitializeCriticalSection(&RtlpCalloutEntryLock);
2012
2013 /* For old executables, use 16-byte aligned heap */
2014 if ((NtHeader->OptionalHeader.MajorSubsystemVersion <= 3) &&
2015 (NtHeader->OptionalHeader.MinorSubsystemVersion < 51))
2016 {
2017 HeapFlags |= HEAP_CREATE_ALIGN_16;
2018 }
2019
2020 /* Setup the Heap */
2022 Peb->ProcessHeap = RtlCreateHeap(HeapFlags,
2023 NULL,
2026 NULL,
2027 &HeapParameters);
2028
2029 if (!Peb->ProcessHeap)
2030 {
2031 DPRINT1("Failed to create process heap\n");
2032 return STATUS_NO_MEMORY;
2033 }
2034
2036 if (!NT_SUCCESS(Status))
2037 {
2038 DPRINT1("Failed to initialize locale table\n");
2039 return Status;
2040 }
2041
2042 /* Allocate an Activation Context Stack */
2043 Status = RtlAllocateActivationContextStack(&Teb->ActivationContextStackPointer);
2044 if (!NT_SUCCESS(Status)) return Status;
2045
2046 RtlZeroMemory(&HeapParameters, sizeof(HeapParameters));
2047 HeapFlags = HEAP_GROWABLE | HEAP_CLASS_1;
2048 HeapParameters.Length = sizeof(HeapParameters);
2049 LdrpHeap = RtlCreateHeap(HeapFlags, 0, 0x10000, 0x6000, 0, &HeapParameters);
2050 if (!LdrpHeap)
2051 {
2052 DPRINT1("Failed to create loader private heap\n");
2053 return STATUS_NO_MEMORY;
2054 }
2055
2056 /* Check for Debug Heap */
2057 if (OptionsKey)
2058 {
2059 /* Query the setting */
2061 L"DebugProcessHeapOnly",
2062 REG_DWORD,
2063 &DebugProcessHeapOnly,
2064 sizeof(ULONG),
2065 NULL);
2066
2067 if (NT_SUCCESS(Status))
2068 {
2069 /* Reset DPH if requested */
2070 if (RtlpPageHeapEnabled && DebugProcessHeapOnly)
2071 {
2072 RtlpDphGlobalFlags &= ~DPH_FLAG_DLL_NOTIFY;
2074 }
2075 }
2076 }
2077
2078 /* Build the NTDLL Path */
2079 FullPath.Buffer = StringBuffer;
2080 FullPath.Length = 0;
2081 FullPath.MaximumLength = sizeof(StringBuffer);
2084 RtlAppendUnicodeToString(&FullPath, L"\\System32\\");
2085
2086 /* Open the Known DLLs directory */
2087 RtlInitUnicodeString(&KnownDllString, L"\\KnownDlls");
2089 &KnownDllString,
2091 NULL,
2092 NULL);
2096
2097 /* Check if it exists */
2098 if (NT_SUCCESS(Status))
2099 {
2100 /* Open the Known DLLs Path */
2101 RtlInitUnicodeString(&KnownDllString, L"KnownDllPath");
2103 &KnownDllString,
2106 NULL);
2107 Status = NtOpenSymbolicLinkObject(&SymLinkHandle,
2110 if (NT_SUCCESS(Status))
2111 {
2112 /* Query the path */
2116 Status = ZwQuerySymbolicLinkObject(SymLinkHandle, &LdrpKnownDllPath, NULL);
2117 NtClose(SymLinkHandle);
2118 if (!NT_SUCCESS(Status))
2119 {
2120 DPRINT1("LDR: %s - failed call to ZwQuerySymbolicLinkObject with status %x\n", "", Status);
2121 return Status;
2122 }
2123 }
2124 }
2125
2126 /* Check if we failed */
2127 if (!NT_SUCCESS(Status))
2128 {
2129 /* Assume System32 */
2132 LdrpKnownDllPath.Length -= sizeof(WCHAR);
2133 }
2134
2135 /* If we have process parameters, get the default path and current path */
2136 if (ProcessParameters)
2137 {
2138 /* Check if we have a Dll Path */
2139 if (ProcessParameters->DllPath.Length)
2140 {
2141 /* Get the path */
2142 LdrpDefaultPath = *(PUNICODE_STRING)&ProcessParameters->DllPath;
2143 }
2144 else
2145 {
2146 /* We need a valid path */
2147 DPRINT1("No valid DllPath was given!\n");
2149 }
2150
2151 /* Set the current directory */
2152 CurrentDirectory = ProcessParameters->CurrentDirectory.DosPath;
2153
2154 /* Check if it's empty or invalid */
2155 if ((!CurrentDirectory.Buffer) ||
2156 (CurrentDirectory.Buffer[0] == UNICODE_NULL) ||
2157 (!CurrentDirectory.Length))
2158 {
2159 /* Allocate space for the buffer */
2161 0,
2162 3 * sizeof(WCHAR) +
2163 sizeof(UNICODE_NULL));
2164 if (!CurrentDirectory.Buffer)
2165 {
2166 DPRINT1("LDR: LdrpInitializeProcess - unable to allocate current working directory buffer\n");
2167 // FIXME: And what?
2168 }
2169
2170 /* Copy the drive of the system root */
2172 SharedUserData->NtSystemRoot,
2173 3 * sizeof(WCHAR));
2174 CurrentDirectory.Buffer[3] = UNICODE_NULL;
2175 CurrentDirectory.Length = 3 * sizeof(WCHAR);
2176 CurrentDirectory.MaximumLength = CurrentDirectory.Length + sizeof(WCHAR);
2177
2178 FreeCurDir = TRUE;
2179 DPRINT("Using dynamically allocd curdir\n");
2180 }
2181 else
2182 {
2183 /* Use the local buffer */
2184 DPRINT("Using local system root\n");
2185 }
2186 }
2187
2188 /* Setup Loader Data */
2189 Peb->Ldr = &PebLdr;
2193 PebLdr.Length = sizeof(PEB_LDR_DATA);
2195
2196 /* Allocate a data entry for the Image */
2198
2199 /* Set it up */
2203 LdrpImageEntry->FullDllName = ImageFileName;
2204
2205 if (IsDotNetImage)
2207 else
2208 LdrpImageEntry->Flags = 0;
2209
2210 /* Check if the name is empty */
2211 if (!ImageFileName.Buffer[0])
2212 {
2213 /* Use the same Base name */
2215 }
2216 else
2217 {
2218 /* Find the last slash */
2219 Current = ImageFileName.Buffer;
2220 while (*Current)
2221 {
2222 if (*Current++ == '\\')
2223 {
2224 /* Set this path */
2225 NtDllName = Current;
2226 }
2227 }
2228
2229 /* Did we find anything? */
2230 if (!NtDllName)
2231 {
2232 /* Use the same Base name */
2234 }
2235 else
2236 {
2237 /* Setup the name */
2238 LdrpImageEntry->BaseDllName.Length = (USHORT)((ULONG_PTR)ImageFileName.Buffer + ImageFileName.Length - (ULONG_PTR)NtDllName);
2241 (ImageFileName.Length - LdrpImageEntry->BaseDllName.Length));
2242 }
2243 }
2244
2245 /* Processing done, insert it */
2248
2249 /* Now add an entry for NTDLL */
2251 NtLdrEntry->Flags = LDRP_IMAGE_DLL;
2252 NtLdrEntry->EntryPoint = LdrpFetchAddressOfEntryPoint(NtLdrEntry->DllBase);
2253 NtLdrEntry->LoadCount = -1;
2254 NtLdrEntry->EntryPointActivationContext = 0;
2255
2256 NtLdrEntry->FullDllName.Length = FullPath.Length;
2257 NtLdrEntry->FullDllName.MaximumLength = FullPath.MaximumLength;
2258 NtLdrEntry->FullDllName.Buffer = StringBuffer;
2260
2261 NtLdrEntry->BaseDllName.Length = NtDllString.Length;
2263 NtLdrEntry->BaseDllName.Buffer = NtDllString.Buffer;
2264
2265 /* Processing done, insert it */
2266 LdrpNtDllDataTableEntry = NtLdrEntry;
2267 LdrpInsertMemoryTableEntry(NtLdrEntry);
2268
2269 /* Let the world know */
2270 if (ShowSnaps)
2271 {
2272 DPRINT1("LDR: NEW PROCESS\n");
2273 DPRINT1(" Image Path: %wZ (%wZ)\n", &LdrpImageEntry->FullDllName, &LdrpImageEntry->BaseDllName);
2274 DPRINT1(" Current Directory: %wZ\n", &CurrentDirectory);
2275 DPRINT1(" Search Path: %wZ\n", &LdrpDefaultPath);
2276 }
2277
2278 /* Link the Init Order List */
2281
2282 /* Initialize Wine's active context implementation for the current process */
2283 RtlpInitializeActCtx(&OldShimData);
2284
2285 /* Set the current directory */
2287 if (!NT_SUCCESS(Status))
2288 {
2289 /* We failed, check if we should free it */
2290 if (FreeCurDir) RtlFreeUnicodeString(&CurrentDirectory);
2291
2292 /* Set it to the NT Root */
2295 }
2296 else
2297 {
2298 /* We're done with it, free it */
2299 if (FreeCurDir) RtlFreeUnicodeString(&CurrentDirectory);
2300 }
2301
2302 /* Check if we should look for a .local file */
2303 if (ProcessParameters && !(ProcessParameters->Flags & RTL_USER_PROCESS_PARAMETERS_LOCAL_DLL_PATH))
2304 {
2305 LdrpInitializeDotLocalSupport(ProcessParameters);
2306 }
2307
2308 /* Check if the Application Verifier was enabled */
2310 {
2312 if (!NT_SUCCESS(Status))
2313 {
2314 DPRINT1("LDR: AVrfInitializeVerifier failed (ntstatus 0x%x)\n", Status);
2315 return Status;
2316 }
2317
2318 }
2319
2320 if (IsDotNetImage)
2321 {
2322 /* FIXME */
2323 DPRINT1("We don't support .NET applications yet\n");
2324 }
2325
2328 {
2329 PVOID Kernel32BaseAddress;
2330 PVOID FunctionAddress;
2331
2332 Status = LdrLoadDll(NULL, NULL, &Kernel32String, &Kernel32BaseAddress);
2333
2334 if (!NT_SUCCESS(Status))
2335 {
2336 if (ShowSnaps)
2337 DPRINT1("LDR: Unable to load %wZ, Status=0x%08lx\n", &Kernel32String, Status);
2338 return Status;
2339 }
2340
2341 Status = LdrGetProcedureAddress(Kernel32BaseAddress,
2342 &BaseProcessInitPostImportName,
2343 0,
2344 &FunctionAddress);
2345
2346 if (!NT_SUCCESS(Status))
2347 {
2348 if (ShowSnaps)
2349 DPRINT1("LDR: Unable to find post-import process init function, Status=0x%08lx\n", Status);
2350 return Status;
2351 }
2352 Kernel32ProcessInitPostImportFunction = FunctionAddress;
2353
2354 Status = LdrGetProcedureAddress(Kernel32BaseAddress,
2355 &BaseQueryModuleDataName,
2356 0,
2357 &FunctionAddress);
2358
2359 if (!NT_SUCCESS(Status))
2360 {
2361 if (ShowSnaps)
2362 DPRINT1("LDR: Unable to find BaseQueryModuleData, Status=0x%08lx\n", Status);
2363 return Status;
2364 }
2365 Kernel32BaseQueryModuleData = FunctionAddress;
2366 }
2367
2368 /* Walk the IAT and load all the DLLs */
2370
2371 /* Check if relocation is needed */
2373 {
2374 DPRINT1("LDR: Performing EXE relocation\n");
2375
2376 /* Change the protection to prepare for relocation */
2377 ViewBase = Peb->ImageBaseAddress;
2378 Status = LdrpSetProtection(ViewBase, FALSE);
2379 if (!NT_SUCCESS(Status)) return Status;
2380
2381 /* Do the relocation */
2383 0LL,
2384 NULL,
2388 if (!NT_SUCCESS(Status))
2389 {
2390 DPRINT1("LdrRelocateImageWithBias() failed\n");
2391 return Status;
2392 }
2393
2394 /* Check if a start context was provided */
2395 if (Context)
2396 {
2397 DPRINT1("WARNING: Relocated EXE Context");
2398 UNIMPLEMENTED; // We should support this
2400 }
2401
2402 /* Restore the protection */
2403 Status = LdrpSetProtection(ViewBase, TRUE);
2404 if (!NT_SUCCESS(Status)) return Status;
2405 }
2406
2407 /* Lock the DLLs */
2408 ListHead = &Peb->Ldr->InLoadOrderModuleList;
2409 NextEntry = ListHead->Flink;
2410 while (ListHead != NextEntry)
2411 {
2412 NtLdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
2413 NtLdrEntry->LoadCount = -1;
2414 NextEntry = NextEntry->Flink;
2415 }
2416
2417 /* Phase 0 is done */
2419
2420 /* Check whether all static imports were properly loaded and return here */
2421 if (!NT_SUCCESS(ImportStatus)) return ImportStatus;
2422
2423 /* Following two calls are for Vista+ support, required for winesync */
2424 /* Initialize the keyed event for condition variables */
2427
2428 /* Initialize TLS */
2430 if (!NT_SUCCESS(Status))
2431 {
2432 DPRINT1("LDR: LdrpProcessInitialization failed to initialize TLS slots; status %x\n",
2433 Status);
2434 return Status;
2435 }
2436
2437 /* FIXME Mark the DLL Ranges for Stack Traces later */
2438
2439 /* Notify the debugger now */
2440 if (Peb->BeingDebugged)
2441 {
2442 /* Break */
2443 DbgBreakPoint();
2444
2445 /* Update show snaps again */
2447 }
2448
2449 /* Validate the Image for MP Usage */
2451
2452 /* Check NX options and set them */
2453 if (SharedUserData->NXSupportPolicy == NX_SUPPORT_POLICY_ALWAYSON)
2454 {
2455 ExecuteOptions = MEM_EXECUTE_OPTION_DISABLE |
2458 }
2459 else if (SharedUserData->NXSupportPolicy == NX_SUPPORT_POLICY_ALWAYSOFF)
2460 {
2462 }
2465 &ExecuteOptions,
2466 sizeof(ExecuteOptions));
2467 if (!NT_SUCCESS(Status))
2468 {
2469 DPRINT1("LDR: Could not set process execute flags 0x%x; status %x\n",
2470 ExecuteOptions, Status);
2471 }
2472
2473 // FIXME: Should be done by Application Compatibility features,
2474 // by reading the registry, etc...
2475 // For now, this is the old code from ntdll!RtlGetVersion().
2476 RtlInitEmptyUnicodeString(&Peb->CSDVersion, NULL, 0);
2477 if (((Peb->OSCSDVersion >> 8) & 0xFF) != 0)
2478 {
2479 WCHAR szCSDVersion[128];
2480 LONG i;
2481 USHORT Length = (USHORT)ARRAYSIZE(szCSDVersion) - 1;
2482 i = _snwprintf(szCSDVersion, Length,
2483 L"Service Pack %d",
2484 ((Peb->OSCSDVersion >> 8) & 0xFF));
2485 if (i < 0)
2486 {
2487 /* Null-terminate if it was overflowed */
2488 szCSDVersion[Length] = UNICODE_NULL;
2489 }
2490
2491 Length *= sizeof(WCHAR);
2492 Peb->CSDVersion.Buffer = RtlAllocateHeap(RtlGetProcessHeap(),
2493 0,
2494 Length + sizeof(UNICODE_NULL));
2495 if (Peb->CSDVersion.Buffer)
2496 {
2499
2501 szCSDVersion,
2504 }
2505 }
2506
2507 /* Check if we had Shim Data */
2508 if (OldShimData)
2509 {
2510 /* Load the Shim Engine */
2512 LdrpLoadShimEngine(OldShimData, &ImagePathName, OldShimData);
2513 }
2514 else
2515 {
2516 /* Check for Application Compatibility Goo */
2517 //LdrQueryApplicationCompatibilityGoo(hKey);
2518 DPRINT("Querying app compat hacks is missing!\n");
2519 }
2520
2521 /*
2522 * FIXME: Check for special images, SecuROM, SafeDisc and other NX-
2523 * incompatible images.
2524 */
2525
2526 /* Now call the Init Routines */
2528 if (!NT_SUCCESS(Status))
2529 {
2530 DPRINT1("LDR: LdrpProcessInitialization failed running initialization routines; status %x\n",
2531 Status);
2532 return Status;
2533 }
2534
2535 /* Notify Shim Engine */
2536 if (g_ShimsEnabled)
2537 {
2540 SE_InstallAfterInit(&ImagePathName, OldShimData);
2541 }
2542
2543 /* Check if we have a user-defined Post Process Routine */
2545 {
2546 /* Call it */
2548 }
2549
2550 /* Close the key if we have one opened */
2551 if (OptionsKey) NtClose(OptionsKey);
2552
2553 /* Return status */
2554 return Status;
2555}
2556
2557VOID
2558NTAPI
2560{
2562 PPEB Peb = NtCurrentPeb();
2563
2564 /* Print a debug message */
2565 DPRINT1("LDR: Process initialization failure for %wZ; NTSTATUS = %08lx\n",
2567
2568 /* Raise a hard error */
2570 {
2572 }
2573}
2574
2575VOID
2576NTAPI
2580{
2582 PTEB Teb = NtCurrentTeb();
2583 NTSTATUS Status, LoaderStatus = STATUS_SUCCESS;
2584 MEMORY_BASIC_INFORMATION MemoryBasicInfo;
2585 PPEB Peb = NtCurrentPeb();
2586
2587 DPRINT("LdrpInit() %p/%p\n",
2588 NtCurrentTeb()->RealClientId.UniqueProcess,
2589 NtCurrentTeb()->RealClientId.UniqueThread);
2590
2591#ifdef _WIN64
2592 /* Set the SList header usage */
2594#endif /* _WIN64 */
2595
2596 /* Check if we have a deallocation stack */
2597 if (!Teb->DeallocationStack)
2598 {
2599 /* We don't, set one */
2601 Teb->NtTib.StackLimit,
2603 &MemoryBasicInfo,
2605 NULL);
2606 if (!NT_SUCCESS(Status))
2607 {
2608 /* Fail */
2611 return;
2612 }
2613
2614 /* Set the stack */
2615 Teb->DeallocationStack = MemoryBasicInfo.AllocationBase;
2616 }
2617
2618 /* Now check if the process is already being initialized */
2620 1,
2621 0) == 1)
2622 {
2623 /* Set the timeout to 30 milliseconds */
2624 Timeout.QuadPart = Int32x32To64(30, -10000);
2625
2626 /* Make sure the status hasn't changed */
2627 while (LdrpProcessInitialized == 1)
2628 {
2629 /* Do the wait */
2631 }
2632 }
2633
2634 /* Check if we have already setup LDR data */
2635 if (!Peb->Ldr)
2636 {
2637 /* Setup the Loader Lock */
2639
2640 /* Let other code know we're initializing */
2642
2643 /* Protect with SEH */
2644 _SEH2_TRY
2645 {
2646 /* Initialize the Process */
2647 LoaderStatus = LdrpInitializeProcess(Context,
2649
2650 /* Check for success and if MinimumStackCommit was requested */
2651 if (NT_SUCCESS(LoaderStatus) && Peb->MinimumStackCommit)
2652 {
2653 /* Enforce the limit */
2654 //LdrpTouchThreadStack(Peb->MinimumStackCommit);
2656 }
2657 }
2659 {
2660 /* Fail with the SEH error */
2661 LoaderStatus = _SEH2_GetExceptionCode();
2662 }
2663 _SEH2_END;
2664
2665 /* We're not initializing anymore */
2667
2668 /* Check if init worked */
2669 if (NT_SUCCESS(LoaderStatus))
2670 {
2671 /* Set the process as Initialized */
2673 }
2674 }
2675 else
2676 {
2677 /* Loader data is there... is this a fork() ? */
2679 {
2680 /* Handle the fork() */
2681 //LoaderStatus = LdrpForkProcess();
2682 LoaderStatus = STATUS_NOT_IMPLEMENTED;
2684 }
2685 else
2686 {
2687 /* This is a new thread initializing */
2689 }
2690 }
2691
2692 /* All done, test alert the thread */
2693 NtTestAlert();
2694
2695 /* Return */
2696 if (!NT_SUCCESS(LoaderStatus))
2697 {
2698 /* Fail */
2699 LdrpInitFailure(LoaderStatus);
2700 RtlRaiseStatus(LoaderStatus);
2701 }
2702}
2703
2704/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
unsigned char BOOLEAN
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
Type
Definition: Type.h:7
#define VOID
Definition: acefi.h:82
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1280
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
WCHAR CurrentDirectory[1024]
Definition: chkdsk.c:74
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:616
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:634
struct _PEB_LDR_DATA PEB_LDR_DATA
Definition: bufpool.h:45
#define REACTOS_SHIMDATA_MAGIC
Definition: compat_undoc.h:15
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: d3dkmdt.h:46
#define RtlInitializeBitMap
Definition: dbgbitmap.h:326
#define RtlSetBit
Definition: dbgbitmap.h:344
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define NTSTATUS
Definition: precomp.h:19
#define DLL_THREAD_DETACH
Definition: compat.h:133
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
#define GENERIC_READ
Definition: compat.h:135
#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG
Definition: compat.h:153
#define RtlImageNtHeader
Definition: compat.h:806
#define MAX_PATH
Definition: compat.h:34
#define DLL_THREAD_ATTACH
Definition: compat.h:132
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
PPEB Peb
Definition: dllmain.c:27
#define ULONG_PTR
Definition: config.h:101
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define InsertHeadList(ListHead, Entry)
UNICODE_STRING * PUNICODE_STRING
Definition: env_spec_w32.h:373
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned long DWORD
Definition: ntddk_ex.h:95
FxCollectionEntry * cur
Status
Definition: gdiplustypes.h:25
GLdouble n
Definition: glext.h:7729
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define REACTOS_COMPATVERSION_IGNOREMANIFEST
Definition: hsdb.c:32
#define FLG_USER_STACK_TRACE_DB
Definition: pstypes.h:67
#define FLG_SHOW_LDR_SNAPS
Definition: pstypes.h:57
#define FLG_HEAP_PAGE_ALLOCS
Definition: pstypes.h:84
#define TLS_EXPANSION_SLOTS
Definition: pstypes.h:311
#define FLG_APPLICATION_VERIFIER
Definition: pstypes.h:64
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI void WINAPI RtlReleasePebLock(void)
Definition: libsupp.c:84
NTSYSAPI void WINAPI RtlAcquirePebLock(void)
Definition: libsupp.c:74
NTSYSAPI void WINAPI DbgBreakPoint(void)
NTSYSAPI NTSTATUS WINAPI RtlInitUnicodeStringEx(PUNICODE_STRING, PCWSTR)
NTSYSAPI void WINAPI RtlFreeThreadActivationContextStack(void)
Definition: actctx.c:5515
NTSYSAPI void WINAPI LdrShutdownProcess(void)
Definition: ldrinit.c:950
@ ProcessAffinityMask
Definition: winternl.h:877
@ ProcessExecuteFlags
Definition: winternl.h:889
NTSYSAPI void WINAPI LdrShutdownThread(void)
Definition: ldrinit.c:1089
NTSYSAPI NTSTATUS WINAPI RtlQueryInformationActivationContext(ULONG, HANDLE, PVOID, ULONG, PVOID, SIZE_T, SIZE_T *)
Definition: actctx.c:5572
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
long __cdecl _InterlockedIncrement(_Interlocked_operand_ long volatile *_Addend)
long __cdecl _InterlockedCompareExchange(_Interlocked_operand_ long volatile *_Destination, long _Exchange, long _Comparand)
#define UInt32x32To64(a, b)
Definition: intsafe.h:252
#define NtCurrentTeb
#define REG_SZ
Definition: layer.c:22
ULONG RtlpDisableHeapLookaside
Definition: ldrinit.c:91
PVOID NtDllBase
Definition: ldrinit.c:56
BOOLEAN LdrpInLdrInit
Definition: ldrinit.c:30
PLDR_DATA_TABLE_ENTRY LdrpImageEntry
Definition: ldrinit.c:39
VOID NTAPI LdrpInitializeDotLocalSupport(PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
Definition: ldrinit.c:1705
BOOLEAN LdrpShutdownInProgress
Definition: ldrinit.c:34
WCHAR LdrpKnownDllPathBuffer[128]
Definition: ldrinit.c:62
VOID NTAPI LdrpInit(PCONTEXT Context, PVOID SystemArgument1, PVOID SystemArgument2)
Definition: ldrinit.c:2577
UNICODE_STRING LdrpDefaultPath
Definition: ldrinit.c:63
NTSTATUS NTAPI LdrQueryImageFileExecutionOptionsEx(_In_ PUNICODE_STRING SubKey, _In_ PCWSTR ValueName, _In_ ULONG Type, _Out_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnedLength, _In_ BOOLEAN Wow64)
Definition: ldrinit.c:349
ULONG RtlpShutdownProcessFlags
Definition: ldrinit.c:92
VOID NTAPI LdrpFreeTls(VOID)
Definition: ldrinit.c:1391
static IN LPSTR IN PVOID IN PVOID Unk3
Definition: ldrinit.c:47
VOID NTAPI RtlpInitDeferredCriticalSection(VOID)
Definition: critical.c:272
HANDLE LdrpShutdownThreadId
Definition: ldrinit.c:35
NTSTATUS NTAPI LdrpInitializeExecutionOptions(PUNICODE_STRING ImagePathName, PPEB Peb, PHANDLE OptionsKey)
Definition: ldrinit.c:1427
RTL_CRITICAL_SECTION FastPebLock
Definition: ldrinit.c:77
LONG LdrpProcessInitialized
Definition: ldrinit.c:31
ULONG LdrpNumberOfTlsEntries
Definition: ldrinit.c:54
ULONG LdrpNumberOfProcessors
Definition: ldrinit.c:55
LIST_ENTRY LdrpTlsList
Definition: ldrinit.c:53
RTL_BITMAP FlsBitMap
Definition: ldrinit.c:51
PLDR_DATA_TABLE_ENTRY LdrpCurrentDllInitializer
Definition: ldrinit.c:43
ULONG LdrpActiveUnloadCount
Definition: ldrinit.c:82
NTSTATUS NTAPI LdrQueryImageFileExecutionOptions(_In_ PUNICODE_STRING SubKey, _In_ PCWSTR ValueName, _In_ ULONG Type, _Out_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnedLength)
Definition: ldrinit.c:388
RTL_BITMAP TlsBitMap
Definition: ldrinit.c:49
PVOID NTAPI LdrpInitSecurityCookie(PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: ldrinit.c:452
BOOLEAN LdrpLoaderLockInit
Definition: ldrinit.c:32
const UNICODE_STRING LdrpDotLocal
Definition: ldrinit.c:28
HANDLE ImageExecOptionsKey
Definition: ldrinit.c:22
static IN LPSTR IN PVOID Unk2
Definition: ldrinit.c:47
LARGE_INTEGER RtlpTimeout
Definition: critical.c:25
NTSTATUS LdrPerformRelocations(PIMAGE_NT_HEADERS NTHeaders, PVOID ImageBase)
HANDLE Wow64ExecOptionsKey
Definition: ldrinit.c:23
static IN LPSTR Unk1
Definition: ldrinit.c:47
NTSTATUS NTAPI RtlpInitializeLocaleTable(VOID)
Definition: locale.c:529
#define DEFAULT_SECURITY_COOKIE
Definition: ldrinit.c:101
NTSTATUS NTAPI LdrQueryImageFileKeyOption(_In_ HANDLE KeyHandle, _In_ PCWSTR ValueName, _In_ ULONG Type, _Out_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnedLength)
Definition: ldrinit.c:184
PTEB LdrpTopLevelDllBeingLoadedTeb
Definition: libsupp.c:20
VOID NTAPI RtlInitializeHeapManager(VOID)
Definition: libsupp.c:243
NTSTATUS NTAPI LdrOpenImageFileOptionsKey(_In_ PUNICODE_STRING SubKey, _In_ BOOLEAN Wow64, _Out_ PHANDLE NewKeyHandle)
Definition: ldrinit.c:111
PVOID NTAPI LdrpFetchAddressOfSecurityCookie(PVOID BaseAddress, ULONG SizeOfImage)
Definition: ldrinit.c:415
ULONG LdrpFatalHardErrorCount
Definition: ldrinit.c:81
VOID NTAPI LdrpValidateImageForMp(IN PLDR_DATA_TABLE_ENTRY LdrDataTableEntry)
Definition: ldrinit.c:1546
LIST_ENTRY LdrpHashTable[LDR_HASH_TABLE_ENTRIES]
Definition: ldrinit.c:59
UNICODE_STRING LdrpKnownDllPath
Definition: ldrinit.c:61
NTSTATUS NTAPI LdrpInitializeProcess(IN PCONTEXT Context, IN PVOID SystemArgument1)
Definition: ldrinit.c:1766
RTL_BITMAP TlsExpansionBitMap
Definition: ldrinit.c:50
BOOLEAN LdrpImageHasTls
Definition: ldrinit.c:52
NTSTATUS NTAPI LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
Definition: ldrinit.c:648
BOOLEAN LdrpLdrDatabaseIsSetup
Definition: ldrinit.c:33
RTL_CRITICAL_SECTION_DEBUG LdrpLoaderLockDebug
Definition: ldrinit.c:67
VOID NTAPI RtlpInitializeVectoredExceptionHandling(VOID)
Definition: vectoreh.c:30
BOOLEAN NTAPI LdrpDisableProcessCompatGuidDetection(VOID)
Definition: ldrinit.c:1555
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
BOOLEAN ShowSnaps
Definition: ldrinit.c:79
HANDLE LdrpKnownDllObjectDirectory
Definition: ldrinit.c:60
RTL_CRITICAL_SECTION LdrpLoaderLock
Definition: ldrinit.c:68
VOID NTAPI LdrpInitFailure(NTSTATUS Status)
Definition: ldrinit.c:2559
PUNICODE_STRING LdrpTopLevelDllBeingLoaded
Definition: ldrinit.c:40
PLDR_DATA_TABLE_ENTRY LdrpNtDllDataTableEntry
Definition: ldrinit.c:44
VOID NTAPI LdrpInitializeProcessCompat(PVOID pProcessActctx, PVOID *pOldShimData)
Definition: ldrinit.c:1589
NTSTATUS NTAPI LdrpInitializeTls(VOID)
Definition: ldrinit.c:1265
VOID NTAPI LdrpEnsureLoaderLockIsHeld(VOID)
Definition: ldrinit.c:408
#define VALID_CONFIG_FIELD(Name)
UNICODE_STRING ImageExecOptionsString
Definition: ldrinit.c:24
UNICODE_STRING Kernel32String
Definition: ldrinit.c:27
BOOLEAN RtlpTimeoutDisable
Definition: critical.c:26
UNICODE_STRING Wow64OptionsString
Definition: ldrinit.c:25
VOID NTAPI LdrpInitializeThread(IN PCONTEXT Context)
Definition: ldrinit.c:505
UNICODE_STRING NtDllString
Definition: ldrinit.c:26
NTSTATUS NTAPI RtlpInitializeActCtx(PVOID *pOldShimData)
NTSTATUS NTAPI LdrpAllocateTls(VOID)
Definition: ldrinit.c:1328
static IN LPSTR IN PVOID IN PVOID IN PVOID Unk4
Definition: ldrinit.c:47
BOOLEAN LdrpDllValidation
Definition: ldrinit.c:37
PEB_LDR_DATA PebLdr
Definition: ldrinit.c:65
BOOLEAN RtlpUse16ByteSLists
NTSTATUS NTAPI DECLSPEC_HOTPATCH LdrLoadDll(_In_opt_ PWSTR SearchPath, _In_opt_ PULONG DllCharacteristics, _In_ PUNICODE_STRING DllName, _Out_ PVOID *BaseAddress)
Definition: ldrapi.c:312
NTSTATUS NTAPI LdrGetProcedureAddress(_In_ PVOID BaseAddress, _In_opt_ _When_(Ordinal==0, _Notnull_) PANSI_STRING Name, _In_opt_ _When_(Name==NULL, _In_range_(>, 0)) ULONG Ordinal, _Out_ PVOID *ProcedureAddress)
Definition: ldrapi.c:789
#define LDRP_ENTRY_PROCESSED
Definition: ldrtypes.h:48
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:264
#define LDRP_DONT_CALL_FOR_THREADS
Definition: ldrtypes.h:52
#define LDRP_COR_IMAGE
Definition: ldrtypes.h:56
#define LDRP_IMAGE_DLL
Definition: ldrtypes.h:39
#define LDRP_PROCESS_ATTACH_CALLED
Definition: ldrtypes.h:53
if(dx< 0)
Definition: linetemp.h:194
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwRaiseHardError(_In_ NTSTATUS ErrorStatus, _In_ ULONG NumberOfParameters, _In_ ULONG UnicodeStringParameterMask, _In_ PULONG_PTR Parameters, _In_ ULONG ValidResponseOptions, _Out_ PULONG Response)
@ OptionOk
Definition: extypes.h:187
NTSYSAPI NTSTATUS NTAPI ZwDelayExecution(_In_ BOOLEAN Alertable, _In_ LARGE_INTEGER *Interval)
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define MEM_EXECUTE_OPTION_DISABLE
Definition: mmtypes.h:73
@ MemoryBasicInformation
Definition: mmtypes.h:183
#define MEM_EXECUTE_OPTION_PERMANENT
Definition: mmtypes.h:76
#define MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION
Definition: mmtypes.h:75
#define MEM_EXECUTE_OPTION_ENABLE
Definition: mmtypes.h:74
NTSYSAPI NTSTATUS NTAPI ZwOpenDirectoryObject(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
NTSYSAPI VOID NTAPI RtlInitNlsTables(_In_ PUSHORT AnsiTableBase, _In_ PUSHORT OemTableBase, _In_ PUSHORT CaseTableBase, _Out_ PNLSTABLEINFO NlsTable)
NTSYSAPI VOID NTAPI RtlResetRtlTranslations(_In_ PNLSTABLEINFO NlsTable)
NTSYSAPI NTSTATUS NTAPI RtlSetCurrentDirectory_U(_In_ PUNICODE_STRING name)
NTSYSAPI NTSTATUS NTAPI RtlEnterCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
Definition: image.c:474
NTSYSAPI NTSTATUS NTAPI RtlLeaveCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
NTSYSAPI NTSTATUS NTAPI RtlInitializeCriticalSection(_In_ PRTL_CRITICAL_SECTION CriticalSection)
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
NTSYSAPI PRTL_USER_PROCESS_PARAMETERS NTAPI RtlNormalizeProcessParams(_In_ PRTL_USER_PROCESS_PARAMETERS ProcessParameters)
#define RTL_USER_PROCESS_PARAMETERS_LOCAL_DLL_PATH
Definition: rtltypes.h:53
#define RTL_USER_PROCESS_PARAMETERS_PRIVATE_DLL_PATH
Definition: rtltypes.h:52
#define RTL_QUERY_ACTIVATION_CONTEXT_FLAG_NO_ADDREF
Definition: rtltypes.h:119
#define RTL_USER_PROCESS_PARAMETERS_NORMALIZED
Definition: rtltypes.h:41
#define _Out_opt_
Definition: no_sal2.h:214
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
int Count
Definition: noreturn.cpp:7
#define BOOL
Definition: nt_native.h:43
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
#define SYMBOLIC_LINK_QUERY
Definition: nt_native.h:1265
#define REG_BINARY
Definition: nt_native.h:1496
@ KeyValuePartialInformation
Definition: nt_native.h:1182
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define DIRECTORY_QUERY
Definition: nt_native.h:1254
#define DIRECTORY_TRAVERSE
Definition: nt_native.h:1255
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define HEAP_CLASS_1
Definition: nt_native.h:1711
NTSYSAPI PVOID NTAPI RtlCreateHeap(IN ULONG Flags, IN PVOID HeapBase OPTIONAL, IN ULONG ReserveSize OPTIONAL, IN ULONG CommitSize OPTIONAL, IN PVOID Lock OPTIONAL, IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL)
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSYSAPI NTSTATUS NTAPI NtQueryValueKey(IN HANDLE KeyHandle, IN PUNICODE_STRING ValueName, IN KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass, IN PVOID KeyValueInformation, IN ULONG Length, IN PULONG ResultLength)
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToInteger(PUNICODE_STRING String, ULONG Base, PULONG Value)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define HEAP_GROWABLE
Definition: nt_native.h:1693
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
struct _KEY_VALUE_PARTIAL_INFORMATION * PKEY_VALUE_PARTIAL_INFORMATION
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define HEAP_CREATE_ALIGN_16
Definition: nt_native.h:1701
#define Int32x32To64(a, b)
#define Int64ShrlMod32(a, b)
#define UNICODE_NULL
#define UNICODE_STRING_MAX_BYTES
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
VOID NTAPI LdrpCallTlsInitializers(IN PLDR_DATA_TABLE_ENTRY LdrEntry, IN ULONG Reason)
Definition: ldrutils.c:447
NTSTATUS NTAPI LdrpInitializeApplicationVerifierPackage(IN HANDLE KeyHandle, IN PPEB Peb, IN BOOLEAN SystemWide, IN BOOLEAN ReadAdvancedOptions)
BOOLEAN NTAPI RtlDoesFileExists_UStr(IN PUNICODE_STRING FileName)
Definition: path.c:1503
PVOID g_pfnSE_InstallAfterInit
Definition: ldrutils.c:26
VOID NTAPI LdrpLoadShimEngine(IN PWSTR ImageName, IN PUNICODE_STRING ProcessImage, IN PVOID pShimData)
Definition: ldrutils.c:2757
ULONG RtlpDphGlobalFlags
Definition: heappage.c:108
NTSTATUS NTAPI LdrpWalkImportDescriptor(IN LPWSTR DllPath OPTIONAL, IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: ldrpe.c:670
PVOID g_pfnSE_ProcessDying
Definition: ldrutils.c:27
NTSTATUS NTAPI AVrfInitializeVerifier(VOID)
Definition: verifier.c:672
PVOID LdrpHeap
Definition: ldrinit.c:3
#define LDR_HASH_TABLE_ENTRIES
Definition: ntdllp.h:11
VOID NTAPI RtlpInitializeThreadPooling(VOID)
VOID NTAPI LdrpInsertMemoryTableEntry(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: ldrutils.c:1561
NTSTATUS NTAPI LdrpSetProtection(PVOID ViewBase, BOOLEAN Restore)
Definition: ldrutils.c:921
BOOLEAN NTAPI LdrpCallInitRoutine(IN PDLL_INIT_ROUTINE EntryPoint, IN PVOID BaseAddress, IN ULONG Reason, IN PVOID Context)
Definition: ldrutils.c:100
PVOID NTAPI LdrpFetchAddressOfEntryPoint(PVOID ImageBase)
BOOLEAN RtlpPageHeapEnabled
Definition: heappage.c:107
PLDR_DATA_TABLE_ENTRY NTAPI LdrpAllocateDataTableEntry(IN PVOID BaseAddress)
Definition: ldrutils.c:1528
BOOLEAN g_ShimsEnabled
Definition: ldrutils.c:21
ULONG NTAPI LdrpClearLoadInProgress(VOID)
Definition: ldrutils.c:2649
VOID NTAPI RtlpInitializeKeyedEvent(VOID)
Definition: condvar.c:460
#define IMAGE_SUBSYSTEM_WINDOWS_CUI
Definition: ntimage.h:438
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
Definition: ntimage.h:489
#define IMAGE_SUBSYSTEM_NATIVE
Definition: ntimage.h:436
UNICODE_STRING NtSystemRoot
Definition: init.c:76
NTSTATUS NTAPI NtQueryPerformanceCounter(OUT PLARGE_INTEGER PerformanceCounter, OUT PLARGE_INTEGER PerformanceFrequency OPTIONAL)
Definition: profile.c:278
NTSTATUS NTAPI NtQueryVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, IN MEMORY_INFORMATION_CLASS MemoryInformationClass, OUT PVOID MemoryInformation, IN SIZE_T MemoryInformationLength, OUT PSIZE_T ReturnLength)
Definition: virtual.c:4409
NTSTATUS NTAPI NtSetInformationProcess(IN HANDLE ProcessHandle, IN PROCESSINFOCLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength)
Definition: query.c:1154
NTSTATUS NTAPI NtTestAlert(VOID)
Definition: state.c:465
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define STATUS_INVALID_IMAGE_FORMAT
Definition: ntstatus.h:359
#define STATUS_DLL_INIT_FAILED
Definition: ntstatus.h:558
#define STATUS_APP_INIT_FAILURE
Definition: ntstatus.h:561
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
#define L(x)
Definition: ntvdm.h:50
long LONG
Definition: pedump.c:60
#define IMAGE_DIRECTORY_ENTRY_TLS
Definition: pedump.c:268
unsigned short USHORT
Definition: pedump.c:61
static ULONG Timeout
Definition: ping.c:61
static VOID LoadConfig(HWND hwndDlg, PPOWER_SCHEMES_PAGE_DATA pPageData, PPOWER_SCHEME pScheme)
Definition: powershemes.c:237
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:181
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:82
#define _SEH2_END
Definition: pseh2_64.h:171
#define _SEH2_TRY
Definition: pseh2_64.h:71
#define REG_DWORD
Definition: sdbapi.c:596
#define YieldProcessor
Definition: ke.h:48
#define SharedUserData
VOID NTAPI RtlSetUnhandledExceptionFilter(IN PRTLP_UNHANDLED_EXCEPTION_FILTER TopLevelExceptionFilter)
Definition: exception.c:341
PVOID NTAPI RtlDecodeSystemPointer(IN PVOID Pointer)
Definition: process.c:439
static PMEMKEY RootKey
Definition: registry.c:55
#define _WIN32_WINNT_WIN10
Definition: sdkddkver.h:32
#define _WIN32_WINNT_WINBLUE
Definition: sdkddkver.h:30
#define _WIN32_WINNT_WIN8
Definition: sdkddkver.h:29
#define _WIN32_WINNT_WIN7
Definition: sdkddkver.h:28
#define _WIN32_WINNT_VISTA
Definition: sdkddkver.h:25
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
VOID NTAPI SE_InstallAfterInit(PUNICODE_STRING ProcessImage, PVOID pShimData)
Definition: shimeng.c:1436
VOID NTAPI SE_ProcessDying(VOID)
Definition: shimeng.c:1441
#define DPRINT
Definition: sndvol32.h:73
static void Exit(void)
Definition: sock.c:1330
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define TLS_MINIMUM_AVAILABLE
Definition: ntddk_ex.h:236
Definition: ncftp.h:89
HANDLE UniqueProcess
Definition: compat.h:825
UNICODE_STRING DosPath
Definition: rtltypes.h:1362
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
ULONG StartAddressOfRawData
Definition: ntimage.h:546
IMAGE_TLS_DIRECTORY TlsDirectory
Definition: ntdllp.h:29
LIST_ENTRY TlsLinks
Definition: ntdllp.h:28
Definition: btrfs_drv.h:1876
PACTIVATION_CONTEXT EntryPointActivationContext
Definition: ldrtypes.h:167
USHORT LoadCount
Definition: ntddk_ex.h:208
PVOID EntryPoint
Definition: ntddk_ex.h:203
UNICODE_STRING FullDllName
Definition: btrfs_drv.h:1882
ULONG SizeOfImage
Definition: ldrtypes.h:147
LIST_ENTRY InInitializationOrderLinks
Definition: ldrtypes.h:144
PVOID DllBase
Definition: btrfs_drv.h:1880
USHORT TlsIndex
Definition: ntddk_ex.h:209
ULONG Flags
Definition: ntddk_ex.h:207
UNICODE_STRING BaseDllName
Definition: ldrtypes.h:149
Definition: typedefs.h:120
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
PVOID FiberData
Definition: compat.h:716
PVOID StackLimit
Definition: compat.h:713
LIST_ENTRY InInitializationOrderModuleList
Definition: ldrtypes.h:126
LIST_ENTRY InMemoryOrderModuleList
Definition: btrfs_drv.h:1895
ULONG Length
Definition: ntddk_ex.h:221
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:124
BOOLEAN Initialized
Definition: ntddk_ex.h:222
UNICODE_STRING CSDVersion
Definition: winternl.h:353
PVOID LoaderLock
Definition: ntddk_ex.h:295
BOOLEAN ReadImageFileExecOptions
Definition: ntddk_ex.h:240
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1912
ULONG NumberOfProcessors
Definition: ntddk_ex.h:269
ULONG TlsBitmapBits[2]
Definition: ntddk_ex.h:260
ULONG ImageProcessAffinityMask
Definition: ntddk_ex.h:307
PVOID ImageBaseAddress
Definition: ntddk_ex.h:245
ULONG FlsBitmapBits[4]
Definition: winternl.h:362
PPS_POST_PROCESS_INIT_ROUTINE PostProcessInitRoutine
Definition: btrfs_drv.h:1916
PVOID ProcessHeap
Definition: ntddk_ex.h:249
PRTL_USER_PROCESS_PARAMETERS ProcessParameters
Definition: btrfs_drv.h:1913
LARGE_INTEGER CriticalSectionTimeout
Definition: ntddk_ex.h:274
ULONG TlsExpansionBitmapBits[32]
Definition: winternl.h:347
PVOID AnsiCodePageData
Definition: ntddk_ex.h:264
BYTE BeingDebugged
Definition: btrfs_drv.h:1909
SIZE_T MinimumStackCommit
Definition: winternl.h:358
PVOID FastPebLock
Definition: ntddk_ex.h:250
PVOID TlsBitmap
Definition: ntddk_ex.h:259
PVOID OemCodePageData
Definition: ntddk_ex.h:265
LIST_ENTRY FlsListHead
Definition: winternl.h:360
ULONG NtGlobalFlag
Definition: ntddk_ex.h:270
PRTL_BITMAP FlsBitmap
Definition: winternl.h:361
PVOID AppCompatInfo
Definition: winternl.h:352
BOOLEAN InheritedAddressSpace
Definition: ntddk_ex.h:239
PRTL_BITMAP TlsExpansionBitmap
Definition: winternl.h:346
PVOID UnicodeCaseTableData
Definition: ntddk_ex.h:266
LIST_ENTRY ListEntry
Definition: rtltypes.h:1217
PVOID Data[RTL_FLS_MAXIMUM_AVAILABLE]
Definition: rtltypes.h:1218
ULONG DeCommitFreeBlockThreshold
Definition: nt_native.h:1670
ULONG VirtualMemoryThreshold
Definition: nt_native.h:1673
ULONG DeCommitTotalFreeThreshold
Definition: nt_native.h:1671
UNICODE_STRING CommandLine
Definition: btrfs_drv.h:1902
UNICODE_STRING ImagePathName
Definition: btrfs_drv.h:1901
DWORD dwRosProcessCompatVersion
Definition: compat_undoc.h:11
Definition: compat.h:836
PVOID ActivationContextStackPointer
Definition: compat.h:854
PVOID * TlsExpansionSlots
Definition: compat.h:894
NT_TIB NtTib
Definition: ntddk_ex.h:332
PVOID ThreadLocalStoragePointer
Definition: compat.h:841
CLIENT_ID ClientId
Definition: compat.h:839
PVOID DeallocationStack
Definition: compat.h:878
USHORT MaximumLength
Definition: env_spec_w32.h:370
static LARGE_INTEGER Counter
Definition: clock.c:43
#define LL
Definition: tui.h:166
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG_PTR
Definition: typedefs.h:65
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
int32_t * PLONG
Definition: typedefs.h:58
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
uint16_t * PWCHAR
Definition: typedefs.h:56
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID _Out_ PULONG RequiredSize
Definition: wdfdevice.h:4439
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
VOID(WINAPI * PFLS_CALLBACK_FUNCTION)(PVOID)
Definition: winbase.h:1475
#define WINAPI
Definition: msvc.h:6
#define FLS_MAXIMUM_AVAILABLE
Definition: winnt_old.h:1097
_In_opt_ PVOID _Out_ PLARGE_INTEGER Cookie
Definition: cmfuncs.h:14
#define NX_SUPPORT_POLICY_ALWAYSOFF
Definition: ketypes.h:1260
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
#define NX_SUPPORT_POLICY_ALWAYSON
Definition: ketypes.h:1261
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689
#define PF_COMPARE_EXCHANGE128
Definition: ketypes.h:138
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184