Author: fireball
Date: Mon Mar 21 22:58:47 2011
New Revision: 51113
URL:
http://svn.reactos.org/svn/reactos?rev=51113&view=rev
Log:
[NTDLL/LDR]
- Implement misc utility functions needed for monstrous LdrpInitializeProcess(). Currently
unused.
Modified:
trunk/reactos/dll/ntdll/include/ntdllp.h
trunk/reactos/dll/ntdll/ldr/ldrutils.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] Mon Mar 21 22:58:47 2011
@@ -8,7 +8,7 @@
/* INCLUDES ******************************************************************/
-extern BOOLEAN ShowSnaps;
+#define LDR_HASH_TABLE_ENTRIES 32
typedef struct _LDRP_TLS_DATA
{
@@ -24,6 +24,8 @@
/* Global data */
extern RTL_CRITICAL_SECTION LdrpLoaderLock;
extern BOOLEAN LdrpInLdrInit;
+extern LIST_ENTRY LdrpHashTable[LDR_HASH_TABLE_ENTRIES];
+extern BOOLEAN ShowSnaps;
/* ldrinit.c */
NTSTATUS NTAPI LdrpRunInitializeRoutines(IN PCONTEXT Context OPTIONAL);
@@ -34,6 +36,7 @@
VOID NTAPI LdrpTlsCallback(PVOID BaseAddress, ULONG Reason);
BOOLEAN NTAPI LdrpCallDllEntry(PDLLMAIN_FUNC EntryPoint, PVOID BaseAddress, ULONG Reason,
PVOID Context);
NTSTATUS NTAPI LdrpInitializeProcess(PCONTEXT Context, PVOID SystemArgument1);
+VOID NTAPI LdrpInitFailure(NTSTATUS Status);
/* ldrpe.c */
@@ -48,6 +51,11 @@
IN BOOLEAN Static,
IN LPSTR DllName);
+NTSTATUS NTAPI
+LdrpWalkImportDescriptor(IN LPWSTR DllPath OPTIONAL,
+ IN PLDR_DATA_TABLE_ENTRY LdrEntry);
+
+
/* ldrutils.c */
NTSTATUS NTAPI
LdrpGetProcedureAddress(IN PVOID BaseAddress,
@@ -55,6 +63,13 @@
IN ULONG Ordinal,
OUT PVOID *ProcedureAddress,
IN BOOLEAN ExecuteInit);
+
+PLDR_DATA_TABLE_ENTRY NTAPI
+LdrpAllocateDataTableEntry(IN PVOID BaseAddress);
+
+VOID NTAPI
+LdrpInsertMemoryTableEntry(IN PLDR_DATA_TABLE_ENTRY LdrEntry);
+
NTSTATUS NTAPI
LdrpLoadDll(IN BOOLEAN Redirected,
IN PWSTR DllPath OPTIONAL,
@@ -65,6 +80,26 @@
ULONG NTAPI
LdrpClearLoadInProgress();
+
+BOOLEAN NTAPI
+LdrpCheckForLoadedDll(IN PWSTR DllPath,
+ IN PUNICODE_STRING DllName,
+ IN BOOLEAN Flag,
+ IN BOOLEAN RedirectedDll,
+ OUT PLDR_DATA_TABLE_ENTRY *LdrEntry);
+
+NTSTATUS NTAPI
+LdrpMapDll(IN PWSTR SearchPath OPTIONAL,
+ IN PWSTR DllPath2,
+ IN PWSTR DllName OPTIONAL,
+ IN PULONG DllCharacteristics,
+ IN BOOLEAN Static,
+ IN BOOLEAN Redirect,
+ OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry);
+
+PVOID NTAPI
+LdrpFetchAddressOfEntryPoint(PVOID ImageBase);
+
/* FIXME: Cleanup this mess */
typedef NTSTATUS (NTAPI *PEPFUNC)(PPEB);
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] Mon Mar 21 22:58:47 2011
@@ -17,6 +17,8 @@
PLDR_DATA_TABLE_ENTRY LdrpLoadedDllHandleCache;
+#define LDR_GET_HASH_ENTRY(x) (RtlUpcaseUnicodeChar((x)) & (LDR_HASH_TABLE_ENTRIES -
1))
+
/* FUNCTIONS *****************************************************************/
BOOLEAN
@@ -80,6 +82,85 @@
/* Do nothing */
}
_SEH2_END;
+}
+
+PVOID
+NTAPI
+LdrpFetchAddressOfEntryPoint(PVOID ImageBase)
+{
+ PIMAGE_NT_HEADERS NtHeaders;
+ ULONG_PTR EntryPoint;
+
+ /* Get entry point offset from NT headers */
+ NtHeaders = RtlImageNtHeader(ImageBase);
+ EntryPoint = NtHeaders->OptionalHeader.AddressOfEntryPoint;
+
+ /* If it's 0 - return so */
+ if (!EntryPoint) return NULL;
+
+ /* Add image base */
+ EntryPoint += (ULONG_PTR)ImageBase;
+
+ /* Return calculated pointer */
+ return (PVOID)EntryPoint;
+}
+
+NTSTATUS
+NTAPI
+LdrpMapDll(IN PWSTR SearchPath OPTIONAL,
+ IN PWSTR DllPath2,
+ IN PWSTR DllName OPTIONAL,
+ IN PULONG DllCharacteristics,
+ IN BOOLEAN Static,
+ IN BOOLEAN Redirect,
+ OUT PLDR_DATA_TABLE_ENTRY *DataTableEntry)
+{
+ UNIMPLEMENTED;
+ return STATUS_SUCCESS;
+}
+
+PLDR_DATA_TABLE_ENTRY
+NTAPI
+LdrpAllocateDataTableEntry(IN PVOID BaseAddress)
+{
+ PLDR_DATA_TABLE_ENTRY LdrEntry = NULL;
+ PIMAGE_NT_HEADERS NtHeader = RtlImageNtHeader(BaseAddress);
+
+ /* Make sure the header is valid */
+ if (NtHeader)
+ {
+ /* Allocate an entry */
+ LdrEntry = RtlAllocateHeap(RtlGetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ sizeof(LDR_DATA_TABLE_ENTRY));
+
+ /* Make sure we got one */
+ if (LdrEntry)
+ {
+ /* Set it up */
+ LdrEntry->DllBase = BaseAddress;
+ LdrEntry->SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
+ LdrEntry->TimeDateStamp = NtHeader->FileHeader.TimeDateStamp;
+ }
+ }
+
+ /* Return the entry */
+ return LdrEntry;
+}
+
+VOID
+NTAPI
+LdrpInsertMemoryTableEntry(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
+{
+ PPEB_LDR_DATA PebData = NtCurrentPeb()->Ldr;
+ ULONG i;
+
+ /* Get the Hash entry */
+ i = LDR_GET_HASH_ENTRY(LdrEntry->BaseDllName.Buffer[0]);
+
+ InsertTailList(&LdrpHashTable[i], &LdrEntry->HashLinks);
+ InsertTailList(&PebData->InLoadOrderModuleList,
&LdrEntry->InLoadOrderLinks);
+ InsertTailList(&PebData->InMemoryOrderModuleList,
&LdrEntry->InMemoryOrderModuleList);
}
BOOLEAN