mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-03 04:13:31 +00:00
[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. svn path=/trunk/; revision=51079
This commit is contained in:
@@ -461,7 +461,7 @@ LdrQueryProcessModuleInformationEx(IN ULONG ProcessId,
|
||||
|
||||
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++;
|
||||
|
||||
@@ -23,6 +23,9 @@ UNICODE_STRING Wow64OptionsString = RTL_CONSTANT_STRING(L"");
|
||||
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 @@ LdrQueryImageFileExecutionOptions(IN PUNICODE_STRING SubKey,
|
||||
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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
/* 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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
|
||||
/* 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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
LdrEntry = CONTAINING_RECORD(NextEntry, LDR_DATA_TABLE_ENTRY, InInitializationOrderModuleList);
|
||||
|
||||
/* FIXME: Verify NX Compat */
|
||||
// LdrpCheckNXCompatibility()
|
||||
|
||||
/* Next entry */
|
||||
NextEntry = NextEntry->Flink;
|
||||
@@ -569,12 +590,13 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
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 @@ LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL)
|
||||
}
|
||||
|
||||
/* Return to caller */
|
||||
DPRINT("LdrpAttachProcess() done\n");
|
||||
DPRINT("LdrpRunInitializeRoutines() done\n");
|
||||
return Status;
|
||||
#else
|
||||
UNIMPLEMENTED;
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
|
||||
@@ -59,7 +59,7 @@ LdrpSnapThunk(IN PVOID ExportBase,
|
||||
PIMAGE_IMPORT_BY_NAME AddressOfData;
|
||||
PULONG NameTable;
|
||||
PUSHORT OrdinalTable;
|
||||
LPSTR ImportName;
|
||||
LPSTR ImportName = NULL;
|
||||
USHORT Hint;
|
||||
NTSTATUS Status;
|
||||
ULONG_PTR HardErrorParameters[3];
|
||||
|
||||
@@ -326,4 +326,35 @@ LdrpLoadDll(IN BOOLEAN Redirected,
|
||||
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 */
|
||||
|
||||
@@ -23,7 +23,7 @@ extern PTEB LdrpTopLevelDllBeingLoadedTeb;
|
||||
|
||||
/* 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 @@ LdrpInit2(PCONTEXT Context,
|
||||
&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 @@ LdrpInit2(PCONTEXT Context,
|
||||
ZwTerminateProcess(NtCurrentProcess(), STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
RtlCreateUnicodeString(&ExeModule->FullDllName,
|
||||
RtlCreateUnicodeString(&LdrpImageEntry->FullDllName,
|
||||
Peb->ProcessParameters->ImagePathName.Buffer);
|
||||
RtlCreateUnicodeString(&ExeModule->BaseDllName,
|
||||
wcsrchr(ExeModule->FullDllName.Buffer, L'\\') + 1);
|
||||
RtlCreateUnicodeString(&LdrpImageEntry->BaseDllName,
|
||||
wcsrchr(LdrpImageEntry->FullDllName.Buffer, L'\\') + 1);
|
||||
|
||||
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n", &ExeModule->BaseDllName, &ExeModule->FullDllName);
|
||||
DPRINT("BaseDllName '%wZ' FullDllName '%wZ'\n", &LdrpImageEntry->BaseDllName, &LdrpImageEntry->FullDllName);
|
||||
|
||||
ExeModule->Flags = LDRP_ENTRY_PROCESSED;
|
||||
ExeModule->LoadCount = -1; /* don't unload */
|
||||
ExeModule->TlsIndex = -1;
|
||||
ExeModule->SectionPointer = NULL;
|
||||
ExeModule->CheckSum = 0;
|
||||
LdrpImageEntry->Flags = LDRP_ENTRY_PROCESSED;
|
||||
LdrpImageEntry->LoadCount = -1; /* don't unload */
|
||||
LdrpImageEntry->TlsIndex = -1;
|
||||
LdrpImageEntry->SectionPointer = NULL;
|
||||
LdrpImageEntry->CheckSum = 0;
|
||||
|
||||
NTHeaders = RtlImageNtHeader(ExeModule->DllBase);
|
||||
ExeModule->SizeOfImage = LdrpGetResidentSize(NTHeaders);
|
||||
ExeModule->TimeDateStamp = NTHeaders->FileHeader.TimeDateStamp;
|
||||
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;
|
||||
|
||||
@@ -35,7 +35,7 @@ static BOOLEAN LdrpDllShutdownInProgress = FALSE;
|
||||
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 @@ LdrpInitLoader(VOID)
|
||||
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 @@ LdrFindEntryForName(PUNICODE_STRING Name,
|
||||
// NULL is the current process
|
||||
if (Name == NULL)
|
||||
{
|
||||
*Module = ExeModule;
|
||||
*Module = LdrpImageEntry;
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
@@ -2416,7 +2416,7 @@ LdrGetDllHandle(IN PWSTR DllPath OPTIONAL,
|
||||
/* 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 @@ LdrpDetachProcess(BOOLEAN UnloadAll)
|
||||
static ULONG CallingCount = 0;
|
||||
|
||||
DPRINT("LdrpDetachProcess() called for %wZ\n",
|
||||
&ExeModule->BaseDllName);
|
||||
&LdrpImageEntry->BaseDllName);
|
||||
|
||||
if (UnloadAll)
|
||||
LdrpDllShutdownInProgress = TRUE;
|
||||
@@ -2672,7 +2672,7 @@ LdrpAttachProcess(VOID)
|
||||
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 @@ LdrpAttachThread (VOID)
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT("LdrpAttachThread() called for %wZ\n",
|
||||
&ExeModule->BaseDllName);
|
||||
&LdrpImageEntry->BaseDllName);
|
||||
|
||||
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
|
||||
|
||||
@@ -2810,7 +2810,7 @@ LdrShutdownThread (VOID)
|
||||
PLDR_DATA_TABLE_ENTRY Module;
|
||||
|
||||
DPRINT("LdrShutdownThread() called for %wZ\n",
|
||||
&ExeModule->BaseDllName);
|
||||
&LdrpImageEntry->BaseDllName);
|
||||
|
||||
RtlEnterCriticalSection (NtCurrentPeb()->LoaderLock);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user