Author: fireball
Date: Thu Mar 17 10:59:54 2011
New Revision: 51079
URL:
http://svn.reactos.org/svn/reactos?rev=51079&view=rev
Log:
[NTDLL/LDR]
- Fix a typo in LdrQueryProcessModuleInformationEx().
- Stub LdrpEnsureLoaderLockIsHeld() for now.
- Improve LdrpRunInitializeRoutines() and enable it (just compiling, it's not in the
running path of the code yet).
- Fix an uninit var warning in ldrpe.c
- Implement LdrpClearLoadInProgress().
- Rename "ExeModule" to a more consistent LdrpImageEntry.
Modified:
trunk/reactos/dll/ntdll/ldr/ldrapi.c
trunk/reactos/dll/ntdll/ldr/ldrinit.c
trunk/reactos/dll/ntdll/ldr/ldrpe.c
trunk/reactos/dll/ntdll/ldr/ldrutils.c
trunk/reactos/dll/ntdll/ldr/startup.c
trunk/reactos/dll/ntdll/ldr/utils.c
Modified: trunk/reactos/dll/ntdll/ldr/ldrapi.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrapi.c?rev…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrapi.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -461,7 +461,7 @@
while (InitEntry != InitListHead)
{
- InitModule = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY,
InInitializationOrderModuleList);
+ InitModule = CONTAINING_RECORD(InitEntry, LDR_DATA_TABLE_ENTRY,
InInitializationOrderModuleList);
/* Increase the index */
ModulePtr->InitOrderIndex++;
Modified: trunk/reactos/dll/ntdll/ldr/ldrinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrinit.c?re…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrinit.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -23,6 +23,9 @@
BOOLEAN LdrpInLdrInit;
PLDR_DATA_TABLE_ENTRY LdrpImageEntry;
+PUNICODE_STRING LdrpTopLevelDllBeingLoaded;
+extern PTEB LdrpTopLevelDllBeingLoadedTeb; // defined in rtlsupp.c!
+PLDR_DATA_TABLE_ENTRY LdrpCurrentDllInitializer;
//RTL_BITMAP TlsBitMap;
//RTL_BITMAP TlsExpansionBitMap;
@@ -333,11 +336,17 @@
FALSE);
}
+VOID
+NTAPI
+LdrpEnsureLoaderLockIsHeld()
+{
+ // Ignored atm
+}
+
NTSTATUS
NTAPI
LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
{
-#if 0
PLDR_DATA_TABLE_ENTRY LocalArray[16];
PLIST_ENTRY ListHead;
PLIST_ENTRY NextEntry;
@@ -350,6 +359,7 @@
RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED ActCtx;
ULONG BreakOnDllLoad;
PTEB OldTldTeb;
+ BOOLEAN DllStatus;
DPRINT1("LdrpRunInitializeRoutines() called for %wZ\n",
&LdrpImageEntry->BaseDllName);
@@ -493,7 +503,7 @@
if (ShowSnaps)
{
DPRINT1("LDR: %wZ loaded.", &LdrEntry->BaseDllName);
- DPRINT1(" - About to call init routine at %lx\n", EntryPoint);
+ DPRINT1(" - About to call init routine at %p\n", EntryPoint);
}
/* Break in debugger */
@@ -526,10 +536,10 @@
/* Call the Entrypoint */
DPRINT1("%wZ - Calling entry point at %x for thread attaching\n",
&LdrEntry->BaseDllName, EntryPoint);
- LdrpCallDllEntry(EntryPoint,
- LdrEntry->DllBase,
- DLL_PROCESS_ATTACH,
- Context);
+ DllStatus = LdrpCallDllEntry(EntryPoint,
+ LdrEntry->DllBase,
+ DLL_PROCESS_ATTACH,
+ Context);
/* Deactivate the ActCtx */
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
@@ -539,6 +549,16 @@
/* Mark the entry as processed */
LdrEntry->Flags |= LDRP_PROCESS_ATTACH_CALLED;
+
+ /* Fail if DLL init failed */
+ if (!DllStatus)
+ {
+ DPRINT1("LDR: DLL_PROCESS_ATTACH for dll \"%wZ\"
(InitRoutine: %p) failed\n",
+ &LdrEntry->BaseDllName, EntryPoint);
+
+ Status = STATUS_DLL_INIT_FAILED;
+ goto Quickie;
+ }
}
}
@@ -551,6 +571,7 @@
LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY,
InInitializationOrderModuleList);
/* FIXME: Verify NX Compat */
+ // LdrpCheckNXCompatibility()
/* Next entry */
NextEntry = NextEntry->Flink;
@@ -569,12 +590,13 @@
LdrpImageEntry->EntryPointActivationContext);
/* Do TLS callbacks */
- LdrpTlsCallback(Peb->ImageBaseAddress, DLL_PROCESS_DETACH);
+ LdrpTlsCallback(Peb->ImageBaseAddress, DLL_PROCESS_ATTACH);
/* Deactivate the ActCtx */
RtlDeactivateActivationContextUnsafeFast(&ActCtx);
}
+Quickie:
/* Restore old TEB */
LdrpTopLevelDllBeingLoadedTeb = OldTldTeb;
@@ -586,12 +608,8 @@
}
/* Return to caller */
- DPRINT("LdrpAttachProcess() done\n");
+ DPRINT("LdrpRunInitializeRoutines() done\n");
return Status;
-#else
- UNIMPLEMENTED;
- return STATUS_NOT_IMPLEMENTED;
-#endif
}
NTSTATUS
Modified: trunk/reactos/dll/ntdll/ldr/ldrpe.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrpe.c?rev=…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrpe.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -59,7 +59,7 @@
PIMAGE_IMPORT_BY_NAME AddressOfData;
PULONG NameTable;
PUSHORT OrdinalTable;
- LPSTR ImportName;
+ LPSTR ImportName = NULL;
USHORT Hint;
NTSTATUS Status;
ULONG_PTR HardErrorParameters[3];
Modified: trunk/reactos/dll/ntdll/ldr/ldrutils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/ldrutils.c?r…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/ldrutils.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -326,4 +326,35 @@
return STATUS_NOT_IMPLEMENTED;
}
+ULONG
+NTAPI
+LdrpClearLoadInProgress()
+{
+ PLIST_ENTRY ListHead;
+ PLIST_ENTRY Entry;
+ PLDR_DATA_TABLE_ENTRY Module;
+ ULONG ModulesCount = 0;
+
+ /* Traverse the init list */
+ ListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
+ Entry = ListHead->Flink;
+
+ while (Entry != ListHead)
+ {
+ Module = CONTAINING_RECORD(Entry, LDR_DATA_TABLE_ENTRY,
InInitializationOrderModuleList);
+
+ /* Clear load in progress flag */
+ Module->Flags &= ~LDRP_LOAD_IN_PROGRESS;
+
+ /* Increase counter for modules with entry point count but not processed yet */
+ if (Module->EntryPoint &&
+ !(Module->Flags & LDRP_ENTRY_PROCESSED)) ModulesCount++;
+
+ /* Advance to the next entry */
+ Entry = Entry->Flink;
+ }
+
+ return ModulesCount;
+}
+
/* EOF */
Modified: trunk/reactos/dll/ntdll/ldr/startup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/startup.c?re…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/startup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/startup.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -23,7 +23,7 @@
/* GLOBALS *******************************************************************/
-PLDR_DATA_TABLE_ENTRY ExeModule;
+extern PLDR_DATA_TABLE_ENTRY LdrpImageEntry;
static RTL_CRITICAL_SECTION PebLock;
static RTL_BITMAP TlsBitMap;
static RTL_BITMAP TlsExpansionBitMap;
@@ -526,17 +526,17 @@
&NtModule->InInitializationOrderModuleList);
/* add entry for executable (becomes first list entry) */
- ExeModule = (PLDR_DATA_TABLE_ENTRY)
+ LdrpImageEntry = (PLDR_DATA_TABLE_ENTRY)
RtlAllocateHeap(Peb->ProcessHeap,
HEAP_ZERO_MEMORY,
sizeof(LDR_DATA_TABLE_ENTRY));
- if (ExeModule == NULL)
+ if (LdrpImageEntry == NULL)
{
DPRINT1("Failed to create loader module infomation\n");
ZwTerminateProcess(NtCurrentProcess(), STATUS_INSUFFICIENT_RESOURCES);
}
- ExeModule->DllBase = Peb->ImageBaseAddress;
+ LdrpImageEntry->DllBase = Peb->ImageBaseAddress;
if ((Peb->ProcessParameters == NULL) ||
(Peb->ProcessParameters->ImagePathName.Length == 0))
@@ -545,32 +545,32 @@
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
}
- RtlCreateUnicodeString(&ExeModule->FullDllName,
+ RtlCreateUnicodeString(&LdrpImageEntry->FullDllName,
Peb->ProcessParameters->ImagePathName.Buffer);
- RtlCreateUnicodeString(&ExeModule->BaseDllName,
- wcsrchr(ExeModule->FullDllName.Buffer, L'\\') +
1);
-
- DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n",
&ExeModule->BaseDllName, &ExeModule->FullDllName);
-
- ExeModule->Flags = LDRP_ENTRY_PROCESSED;
- ExeModule->LoadCount = -1; /* don't unload */
- ExeModule->TlsIndex = -1;
- ExeModule->SectionPointer = NULL;
- ExeModule->CheckSum = 0;
-
- NTHeaders = RtlImageNtHeader(ExeModule->DllBase);
- ExeModule->SizeOfImage = LdrpGetResidentSize(NTHeaders);
- ExeModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
+ RtlCreateUnicodeString(&LdrpImageEntry->BaseDllName,
+ wcsrchr(LdrpImageEntry->FullDllName.Buffer, L'\\')
+ 1);
+
+ DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n",
&LdrpImageEntry->BaseDllName, &LdrpImageEntry->FullDllName);
+
+ LdrpImageEntry->Flags = LDRP_ENTRY_PROCESSED;
+ LdrpImageEntry->LoadCount = -1; /* don't unload */
+ LdrpImageEntry->TlsIndex = -1;
+ LdrpImageEntry->SectionPointer = NULL;
+ LdrpImageEntry->CheckSum = 0;
+
+ NTHeaders = RtlImageNtHeader(LdrpImageEntry->DllBase);
+ LdrpImageEntry->SizeOfImage = LdrpGetResidentSize(NTHeaders);
+ LdrpImageEntry->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
LdrpTopLevelDllBeingLoadedTeb = NtCurrentTeb();
InsertHeadList(&Peb->Ldr->InLoadOrderModuleList,
- &ExeModule->InLoadOrderLinks);
+ &LdrpImageEntry->InLoadOrderLinks);
LdrpInitLoader();
EntryPoint = LdrPEStartup((PVOID)ImageBase, NULL, NULL, NULL);
- ExeModule->EntryPoint = EntryPoint;
+ LdrpImageEntry->EntryPoint = EntryPoint;
/* all required dlls are loaded now */
Peb->Ldr->Initialized = TRUE;
Modified: trunk/reactos/dll/ntdll/ldr/utils.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/ldr/utils.c?rev=…
==============================================================================
--- trunk/reactos/dll/ntdll/ldr/utils.c [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/ldr/utils.c [iso-8859-1] Thu Mar 17 10:59:54 2011
@@ -35,7 +35,7 @@
static HANDLE LdrpKnownDllsDirHandle = NULL;
static UNICODE_STRING LdrpKnownDllPath = {0, 0, NULL};
static PLDR_DATA_TABLE_ENTRY LdrpLastModule = NULL;
-extern PLDR_DATA_TABLE_ENTRY ExeModule;
+extern PLDR_DATA_TABLE_ENTRY LdrpImageEntry;
/* PROTOTYPES ****************************************************************/
@@ -222,7 +222,7 @@
ULONG Length;
NTSTATUS Status;
- DPRINT("LdrpInitLoader() called for %wZ\n",
&ExeModule->BaseDllName);
+ DPRINT("LdrpInitLoader() called for %wZ\n",
&LdrpImageEntry->BaseDllName);
/* Get handle to the 'KnownDlls' directory */
RtlInitUnicodeString(&Name,
@@ -865,7 +865,7 @@
// NULL is the current process
if (Name == NULL)
{
- *Module = ExeModule;
+ *Module = LdrpImageEntry;
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
return(STATUS_SUCCESS);
}
@@ -2416,7 +2416,7 @@
/* NULL is the current executable */
if (DllName == NULL)
{
- *DllHandle = ExeModule->DllBase;
+ *DllHandle = LdrpImageEntry->DllBase;
DPRINT("BaseAddress 0x%lx\n", *DllHandle);
return STATUS_SUCCESS;
}
@@ -2560,7 +2560,7 @@
static ULONG CallingCount = 0;
DPRINT("LdrpDetachProcess() called for %wZ\n",
- &ExeModule->BaseDllName);
+ &LdrpImageEntry->BaseDllName);
if (UnloadAll)
LdrpDllShutdownInProgress = TRUE;
@@ -2672,7 +2672,7 @@
NTSTATUS Status = STATUS_SUCCESS;
DPRINT("LdrpAttachProcess() called for %wZ\n",
- &ExeModule->BaseDllName);
+ &LdrpImageEntry->BaseDllName);
ModuleListHead = &NtCurrentPeb()->Ldr->InInitializationOrderModuleList;
Entry = ModuleListHead->Flink;
@@ -2752,7 +2752,7 @@
NTSTATUS Status;
DPRINT("LdrpAttachThread() called for %wZ\n",
- &ExeModule->BaseDllName);
+ &LdrpImageEntry->BaseDllName);
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
@@ -2810,7 +2810,7 @@
PLDR_DATA_TABLE_ENTRY Module;
DPRINT("LdrShutdownThread() called for %wZ\n",
- &ExeModule->BaseDllName);
+ &LdrpImageEntry->BaseDllName);
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);