Author: ion
Date: Sun Jul 10 02:14:29 2011
New Revision: 52596
URL:
http://svn.reactos.org/svn/reactos?rev=52596&view=rev
Log:
[NTDLL]: More attempts at fixing up the loader, this time in the PE side of things.
Modified:
trunk/reactos/dll/ntdll/include/ntdllp.h
trunk/reactos/dll/ntdll/ldr/ldrpe.c
Modified: trunk/reactos/dll/ntdll/include/ntdllp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/include/ntdllp.h…
==============================================================================
--- trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/include/ntdllp.h [iso-8859-1] Sun Jul 10 02:14:29 2011
@@ -145,6 +145,14 @@
ULONG
LdrpGetResidentSize(PIMAGE_NT_HEADERS NTHeaders);
+NTSTATUS
+NTAPI
+LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,
+ IN LPSTR ImportName,
+ IN PVOID DllBase,
+ OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry,
+ OUT PBOOLEAN Existing);
+
extern HANDLE WindowsApiPort;
/* EOF */
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] Sun Jul 10 02:14:29 2011
@@ -13,20 +13,10 @@
#include <debug.h>
/* GLOBALS *******************************************************************/
+
ULONG LdrpFatalHardErrorCount;
PVOID LdrpManifestProberRoutine;
-
-/* PROTOTYPES ****************************************************************/
-
-#define IMAGE_REL_BASED_HIGH3ADJ 11
-
-NTSTATUS
-NTAPI
-LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,
- IN LPSTR ImportName,
- IN PVOID DllBase,
- OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry,
- OUT PBOOLEAN Existing);
+ULONG LdrpNormalSnap;
/* FUNCTIONS *****************************************************************/
@@ -511,22 +501,21 @@
NTAPI
LdrpHandleOneOldFormatImportDescriptor(IN LPWSTR DllPath OPTIONAL,
IN PLDR_DATA_TABLE_ENTRY LdrEntry,
- IN PIMAGE_IMPORT_DESCRIPTOR ImportEntry)
+ IN PIMAGE_IMPORT_DESCRIPTOR *ImportEntry)
{
- //ULONG IatSize, i;
LPSTR ImportName;
NTSTATUS Status;
- BOOLEAN AlreadyLoaded = FALSE, StaticEntriesValid = FALSE, SkipSnap = FALSE;
+ BOOLEAN AlreadyLoaded = FALSE;
PLDR_DATA_TABLE_ENTRY DllLdrEntry;
PIMAGE_THUNK_DATA FirstThunk;
PPEB Peb = NtCurrentPeb();
/* Get the import name's VA */
- ImportName = (LPSTR)((ULONG_PTR)LdrEntry->DllBase + ImportEntry->Name);
+ ImportName = (LPSTR)((ULONG_PTR)LdrEntry->DllBase + (*ImportEntry)->Name);
/* Get the first thunk */
FirstThunk = (PIMAGE_THUNK_DATA)((ULONG_PTR)LdrEntry->DllBase +
- ImportEntry->FirstThunk);
+ (*ImportEntry)->FirstThunk);
/* Make sure it's valid */
if (!FirstThunk->u1.Function) goto SkipEntry;
@@ -545,7 +534,21 @@
LdrEntry->DllBase,
&DllLdrEntry,
&AlreadyLoaded);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ /* Fail */
+ if (ShowSnaps)
+ {
+ DbgPrint("LDR: LdrpWalkImportTable - LdrpLoadImportModule failed "
+ "on import %s with status %x\n",
+ ImportName,
+ Status);
+ }
+
+ /* Return */
+ *ImportEntry = *ImportEntry;
+ return Status;
+ }
/* Show debug message */
if (ShowSnaps)
@@ -555,41 +558,8 @@
ImportName);
}
- /* Check if the image was bound when compiled */
- if (ImportEntry->OriginalFirstThunk)
- {
- /* It was, so check if the static IAT entries are still valid */
- if ((ImportEntry->TimeDateStamp) &&
- (ImportEntry->TimeDateStamp == DllLdrEntry->TimeDateStamp) &&
- (!(DllLdrEntry->Flags & LDRP_IMAGE_NOT_AT_BASE)))
- {
- /* Show debug message */
- if (ShowSnaps)
- {
- DPRINT1("LDR: Snap bypass %s from %wZ\n",
- ImportName,
- &LdrEntry->BaseDllName);
- }
-
- /*
- * They are still valid, so we can skip snapping them.
- * Additionally, if we have no forwarders, we are totally
- * done.
- */
- if (ImportEntry->ForwarderChain == -1)
- {
- /* Totally skip LdrpSnapIAT */
- SkipSnap = TRUE;
- }
- else
- {
- /* Set this so LdrpSnapIAT will only do forwarders */
- StaticEntriesValid = TRUE;
- }
- }
- }
-
/* Check if it wasn't already loaded */
+ ++LdrpNormalSnap;
if (!AlreadyLoaded)
{
/* Add the DLL to our list */
@@ -597,18 +567,26 @@
&DllLdrEntry->InInitializationOrderModuleList);
}
- /* Check if we should snap at all */
- if (!SkipSnap)
- {
- /* Now snap the IAT Entry */
- Status = LdrpSnapIAT(DllLdrEntry,
- LdrEntry,
- ImportEntry,
- StaticEntriesValid);
- if (!NT_SUCCESS(Status)) return Status;
+ /* Now snap the IAT Entry */
+ Status = LdrpSnapIAT(DllLdrEntry, LdrEntry, *ImportEntry, FALSE);
+ if (!NT_SUCCESS(Status))
+ {
+ /* Fail */
+ if (ShowSnaps)
+ {
+ DbgPrint("LDR: LdrpWalkImportTable - LdrpSnapIAT #2 failed with "
+ "status %x\n",
+ Status);
+ }
+
+ /* Return */
+ *ImportEntry = *ImportEntry;
+ return Status;
}
SkipEntry:
+ /* Move on */
+ *ImportEntry = (*ImportEntry)++;
return STATUS_SUCCESS;
}
@@ -621,34 +599,31 @@
NTSTATUS Status;
/* Check for Name and Thunk */
- while (ImportEntry->Name && ImportEntry->FirstThunk)
+ while ((ImportEntry->Name) && (ImportEntry->FirstThunk))
{
/* Parse this descriptor */
Status = LdrpHandleOneOldFormatImportDescriptor(DllPath,
LdrEntry,
- ImportEntry);
+ &ImportEntry);
if (!NT_SUCCESS(Status)) return Status;
-
- /* Move to the next entry */
- ImportEntry++;
}
/* Done */
return STATUS_SUCCESS;
}
-USHORT NTAPI
-LdrpNameToOrdinal(LPSTR ImportName,
- ULONG NumberOfNames,
- PVOID ExportBase,
- PULONG NameTable,
- PUSHORT OrdinalTable)
+USHORT
+NTAPI
+LdrpNameToOrdinal(IN LPSTR ImportName,
+ IN ULONG NumberOfNames,
+ IN PVOID ExportBase,
+ IN PULONG NameTable,
+ IN PUSHORT OrdinalTable)
{
- ULONG Start, End, Next;
- LONG CmpResult;
+ LONG Start, End, Next, CmpResult;
/* Use classical binary search to find the ordinal */
- Start = 0;
+ Start = Next = 0;
End = NumberOfNames - 1;
while (End >= Start)
{
@@ -663,9 +638,13 @@
/* We didn't find, update our range then */
if (CmpResult < 0)
+ {
End = Next - 1;
+ }
else if (CmpResult > 0)
+ {
Start = Next + 1;
+ }
}
/* If end is before start, then the search failed */
@@ -686,13 +665,12 @@
PIMAGE_BOUND_IMPORT_DESCRIPTOR BoundEntry = NULL;
PIMAGE_IMPORT_DESCRIPTOR ImportEntry;
ULONG BoundSize, IatSize;
-
DPRINT("LdrpWalkImportDescriptor('%S' %x)\n", DllPath, LdrEntry);
/* Set up the Act Ctx */
ActCtx.Size = sizeof(ActCtx);
- ActCtx.Format = 1;
- RtlZeroMemory(&ActCtx.Frame, sizeof(RTL_ACTIVATION_CONTEXT_STACK_FRAME));
+ ActCtx.Format = RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_FORMAT_WHISTLER;
+ RtlZeroMemory(&ActCtx.Frame, sizeof(ActCtx));
/* Check if we have a manifest prober routine */
if (LdrpManifestProberRoutine)
@@ -705,7 +683,16 @@
/* Get the Active ActCtx */
Status =
RtlGetActiveActivationContext(&LdrEntry->EntryPointActivationContext);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ /* Exit */
+ DbgPrintEx(51, // DPFLTR_SXS_ID
+ DPFLTR_WARNING_LEVEL,
+ "LDR: RtlGetActiveActivationContext() failed; ntstatus = "
+ "0x%08lx\n",
+ Status);
+ return Status;
+ }
/* Activate the ActCtx */
RtlActivateActivationContextUnsafeFast(&ActCtx,
@@ -728,7 +715,7 @@
&IatSize);
/* Check if we got at least one */
- if (BoundEntry || ImportEntry)
+ if ((BoundEntry) || (ImportEntry))
{
/* Do we have a Bound IAT */
if (BoundEntry)
@@ -782,6 +769,7 @@
return Status;
}
+/* FIXME: This function is missing SxS support and has wrong prototype */
NTSTATUS
NTAPI
LdrpLoadImportModule(IN PWSTR DllPath OPTIONAL,