Author: ion
Date: Fri Feb 23 10:56:01 2007
New Revision: 25886
URL:
http://svn.reactos.org/svn/reactos?rev=25886&view=rev
Log:
- Get rid of LdrGetModuleObject, since MmLoadSystemImage will now return the existing
module object in case it has already been loaded, get rid of LdrGetProcedureAddress, it
doesn't belong in the kernel. Move MmGetSystemRoutineAddress from mm.c to sysldr.c and
rewrite it to use MiFindExportedRoutineByName instead.
- Remove /ldr ntoskrnl directory, since this module is finally gone.
- Make PsInit code search for ntdll lookups using LookupEntryPoint internal function,
instead of LdrGetProcedureAddress. Same code but done with recursion instead, and internal
to this module (remove ANSI_STRINGs since we don't need them anymore).
Removed:
trunk/reactos/ntoskrnl/ldr/
Modified:
trunk/reactos/ntoskrnl/include/internal/ldr.h
trunk/reactos/ntoskrnl/io/iomgr/driver.c
trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c
trunk/reactos/ntoskrnl/mm/mm.c
trunk/reactos/ntoskrnl/mm/pagefile.c
trunk/reactos/ntoskrnl/mm/sysldr.c
trunk/reactos/ntoskrnl/ntoskrnl.rbuild
trunk/reactos/ntoskrnl/ps/psmgr.c
Modified: trunk/reactos/ntoskrnl/include/internal/ldr.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ldr.h (original)
+++ trunk/reactos/ntoskrnl/include/internal/ldr.h Fri Feb 23 10:56:01 2007
@@ -6,8 +6,4 @@
#define DRIVER_ROOT_NAME L"\\Driver\\"
#define FILESYSTEM_ROOT_NAME L"\\FileSystem\\"
-PLDR_DATA_TABLE_ENTRY
-NTAPI
-LdrGetModuleObject(PUNICODE_STRING ModuleName);
-
#endif /* __INCLUDE_INTERNAL_LDR_H */
Modified: trunk/reactos/ntoskrnl/io/iomgr/driver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/driver.c…
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/driver.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/driver.c Fri Feb 23 10:56:01 2007
@@ -435,34 +435,20 @@
return Status;
}
- /*
- * Load the module.
- */
-
- *ModuleObject = LdrGetModuleObject(&ServiceImagePath);
-
- if (*ModuleObject == NULL)
- {
/*
* Case for disabled drivers
*/
- if (ServiceStart >= 4)
- {
- /* FIXME: Check if it is the right status code */
- Status = STATUS_PLUGPLAY_NO_DEVICE;
- }
- else
- {
- DPRINT("Loading module\n");
- Status = MmLoadSystemImage(&ServiceImagePath, NULL, NULL, 0,
(PVOID)ModuleObject, NULL);
- }
- }
- else
- {
- DPRINT("Module already loaded\n");
- Status = STATUS_IMAGE_ALREADY_LOADED;
- }
+ if (ServiceStart >= 4)
+ {
+ /* FIXME: Check if it is the right status code */
+ Status = STATUS_PLUGPLAY_NO_DEVICE;
+ }
+ else
+ {
+ DPRINT("Loading module\n");
+ Status = MmLoadSystemImage(&ServiceImagePath, NULL, NULL, 0,
(PVOID)ModuleObject, NULL);
+ }
ExFreePool(ServiceImagePath.Buffer);
@@ -1062,7 +1048,6 @@
UNICODE_STRING ServiceName;
UNICODE_STRING ObjectName;
PDRIVER_OBJECT DriverObject;
- PLDR_DATA_TABLE_ENTRY ModuleObject;
NTSTATUS Status;
LPWSTR Start;
@@ -1146,16 +1131,6 @@
}
/*
- * ... and check if it's loaded
- */
-
- ModuleObject = LdrGetModuleObject(&ImagePath);
- if (ModuleObject == NULL)
- {
- return STATUS_UNSUCCESSFUL;
- }
-
- /*
* Free the service path
*/
@@ -1169,7 +1144,7 @@
(*DriverObject->DriverUnload)(DriverObject);
ObDereferenceObject(DriverObject);
ObDereferenceObject(DriverObject);
- MmUnloadSystemImage(ModuleObject);
+ MmUnloadSystemImage(DriverObject->DriverSection);
return STATUS_SUCCESS;
}
@@ -1693,18 +1668,6 @@
DPRINT("Type: %lx\n", Type);
/*
- * See, if the driver module isn't already loaded
- */
-
- ModuleObject = LdrGetModuleObject(&ImagePath);
- if (ModuleObject != NULL)
- {
- DPRINT("Image already loaded\n");
- Status = STATUS_IMAGE_ALREADY_LOADED;
- goto ReleaseCapturedString;
- }
-
- /*
* Create device node
*/
Modified: trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/kdbg/kdb_symbols.…
==============================================================================
--- trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c (original)
+++ trunk/reactos/ntoskrnl/kdbg/kdb_symbols.c Fri Feb 23 10:56:01 2007
@@ -608,7 +608,7 @@
IsRaw = FALSE;
}
- ModuleObject = LdrGetModuleObject(ModuleName);
+ ModuleObject = NULL;
if (ModuleObject != NULL)
{
Modified: trunk/reactos/ntoskrnl/mm/mm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/mm.c?rev=25886…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/mm.c (original)
+++ trunk/reactos/ntoskrnl/mm/mm.c Fri Feb 23 10:56:01 2007
@@ -398,70 +398,6 @@
return (FALSE);
}
-/*
- * @implemented
- */
-PVOID
-NTAPI
-MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
-{
- PVOID ProcAddress;
- ANSI_STRING AnsiRoutineName;
- NTSTATUS Status;
- PLIST_ENTRY NextEntry;
- extern LIST_ENTRY PsLoadedModuleList;
- PLDR_DATA_TABLE_ENTRY LdrEntry;
- BOOLEAN Found = FALSE;
- UNICODE_STRING KernelName = RTL_CONSTANT_STRING(L"ntoskrnl.exe");
- UNICODE_STRING HalName = RTL_CONSTANT_STRING(L"hal.dll");
-
- /* Convert routine to ansi name */
- Status = RtlUnicodeStringToAnsiString(&AnsiRoutineName,
- SystemRoutineName,
- TRUE);
- if (!NT_SUCCESS(Status)) return NULL;
-
- /* Loop the loaded module list */
- NextEntry = PsLoadedModuleList.Flink;
- while (NextEntry != &PsLoadedModuleList)
- {
- /* Get the entry */
- LdrEntry = CONTAINING_RECORD(NextEntry,
- LDR_DATA_TABLE_ENTRY,
- InLoadOrderLinks);
-
- /* Check if it's the kernel or HAL */
- if (RtlEqualUnicodeString(&KernelName, &LdrEntry->BaseDllName, TRUE))
- {
- /* Found it */
- Found = TRUE;
- }
- else if (RtlEqualUnicodeString(&HalName, &LdrEntry->BaseDllName,
TRUE))
- {
- /* Found it */
- Found = TRUE;
- }
-
- /* Check if we found a valid binary */
- if (Found)
- {
- /* Find the procedure name */
- Status = LdrGetProcedureAddress(LdrEntry->DllBase,
- &AnsiRoutineName,
- 0,
- &ProcAddress);
- break;
- }
-
- /* Keep looping */
- NextEntry = NextEntry->Flink;
- }
-
- /* Free the string and return */
- RtlFreeAnsiString(&AnsiRoutineName);
- return (NT_SUCCESS(Status) ? ProcAddress : NULL);
-}
-
NTSTATUS
NTAPI
NtGetWriteWatch(IN HANDLE ProcessHandle,
Modified: trunk/reactos/ntoskrnl/mm/pagefile.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/pagefile.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/pagefile.c (original)
+++ trunk/reactos/ntoskrnl/mm/pagefile.c Fri Feb 23 10:56:01 2007
@@ -35,6 +35,10 @@
#pragma alloc_text(INIT, MmInitPagingFile)
#endif
+PVOID
+NTAPI
+MiFindExportedRoutineByName(IN PVOID DllBase,
+ IN PANSI_STRING ExportName);
/* TYPES *********************************************************************/
@@ -694,7 +698,7 @@
UNICODE_STRING DiskDumpName = RTL_CONSTANT_STRING(L"DiskDump");
ANSI_STRING ProcName;
PIO_STACK_LOCATION StackPtr;
- PLDR_DATA_TABLE_ENTRY ModuleObject;
+ PLDR_DATA_TABLE_ENTRY ModuleObject = NULL;
Status = ZwFsControlFile(PageFileHandle,
0,
@@ -767,16 +771,14 @@
}
/* Load the diskdump driver. */
- ModuleObject = LdrGetModuleObject(&DiskDumpName);
+ Status = MmLoadSystemImage(&DiskDumpName, NULL, NULL, 0, (PVOID)&ModuleObject,
NULL);
if (ModuleObject == NULL)
{
return(STATUS_OBJECT_NAME_NOT_FOUND);
}
RtlInitAnsiString(&ProcName, "DiskDumpFunctions");
- Status = LdrGetProcedureAddress(ModuleObject->DllBase,
- &ProcName,
- 0,
- (PVOID*)&MmCoreDumpFunctions);
+ MmCoreDumpFunctions = MiFindExportedRoutineByName(ModuleObject->DllBase,
+ &ProcName);
if (!NT_SUCCESS(Status))
{
ObDereferenceObject(PageFile);
Modified: trunk/reactos/ntoskrnl/mm/sysldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/sysldr.c?rev=2…
==============================================================================
--- trunk/reactos/ntoskrnl/mm/sysldr.c (original)
+++ trunk/reactos/ntoskrnl/mm/sysldr.c Fri Feb 23 10:56:01 2007
@@ -54,6 +54,77 @@
/* Otherwise, free the import list */
ExFreePool(LdrEntry->LoadedImports);
+}
+
+PVOID
+NTAPI
+MiFindExportedRoutineByName(IN PVOID DllBase,
+ IN PANSI_STRING ExportName)
+{
+ PULONG NameTable;
+ PUSHORT OrdinalTable;
+ PIMAGE_EXPORT_DIRECTORY ExportDirectory;
+ LONG Low = 0, Mid = 0, High, Ret;
+ USHORT Ordinal;
+ PVOID Function;
+ ULONG ExportSize;
+ PULONG ExportTable;
+ PAGED_CODE();
+
+ /* Get the export directory */
+ ExportDirectory = RtlImageDirectoryEntryToData(DllBase,
+ TRUE,
+ IMAGE_DIRECTORY_ENTRY_EXPORT,
+ &ExportSize);
+ if (!ExportDirectory) return NULL;
+
+ /* Setup name tables */
+ NameTable = (PULONG)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfNames);
+ OrdinalTable = (PUSHORT)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfNameOrdinals);
+
+ /* Do a binary search */
+ High = ExportDirectory->NumberOfNames - 1;
+ while (High >= Low)
+ {
+ /* Get new middle value */
+ Mid = (Low + High) >> 1;
+
+ /* Compare name */
+ Ret = strcmp(ExportName->Buffer, (PCHAR)DllBase + NameTable[Mid]);
+ if (Ret < 0)
+ {
+ /* Update high */
+ High = Mid - 1;
+ }
+ else if (Ret > 0)
+ {
+ /* Update low */
+ Low = Mid + 1;
+ }
+ else
+ {
+ /* We got it */
+ break;
+ }
+ }
+
+ /* Check if we couldn't find it */
+ if (High < Low) return NULL;
+
+ /* Otherwise, this is the ordinal */
+ Ordinal = OrdinalTable[Mid];
+
+ /* Resolve the address and write it */
+ ExportTable = (PULONG)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfFunctions);
+ Function = (PVOID)((ULONG_PTR)DllBase + ExportTable[Ordinal]);
+
+ /* We found it! */
+ ASSERT((Function > (PVOID)ExportDirectory) &&
+ (Function < (PVOID)((ULONG_PTR)ExportDirectory + ExportSize)));
+ return Function;
}
PVOID
@@ -1712,3 +1783,77 @@
return Status;
}
+/*
+ * @implemented
+ */
+PVOID
+NTAPI
+MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
+{
+ PVOID ProcAddress = NULL;
+ ANSI_STRING AnsiRoutineName;
+ NTSTATUS Status;
+ PLIST_ENTRY NextEntry;
+ extern LIST_ENTRY PsLoadedModuleList;
+ PLDR_DATA_TABLE_ENTRY LdrEntry;
+ BOOLEAN Found = FALSE;
+ UNICODE_STRING KernelName = RTL_CONSTANT_STRING(L"ntoskrnl.exe");
+ UNICODE_STRING HalName = RTL_CONSTANT_STRING(L"hal.dll");
+ ULONG Modules = 0;
+
+ /* Convert routine to ansi name */
+ Status = RtlUnicodeStringToAnsiString(&AnsiRoutineName,
+ SystemRoutineName,
+ TRUE);
+ if (!NT_SUCCESS(Status)) return NULL;
+
+ /* Lock the list */
+ KeEnterCriticalRegion();
+
+ /* Loop the loaded module list */
+ NextEntry = PsLoadedModuleList.Flink;
+ while (NextEntry != &PsLoadedModuleList)
+ {
+ /* Get the entry */
+ LdrEntry = CONTAINING_RECORD(NextEntry,
+ LDR_DATA_TABLE_ENTRY,
+ InLoadOrderLinks);
+
+ /* Check if it's the kernel or HAL */
+ if (RtlEqualUnicodeString(&KernelName, &LdrEntry->BaseDllName, TRUE))
+ {
+ /* Found it */
+ Found = TRUE;
+ Modules++;
+ }
+ else if (RtlEqualUnicodeString(&HalName, &LdrEntry->BaseDllName,
TRUE))
+ {
+ /* Found it */
+ Found = TRUE;
+ Modules++;
+ }
+
+ /* Check if we found a valid binary */
+ if (Found)
+ {
+ /* Find the procedure name */
+ ProcAddress = MiFindExportedRoutineByName(LdrEntry->DllBase,
+ &AnsiRoutineName);
+
+ /* Break out if we found it or if we already tried both modules */
+ if (ProcAddress) break;
+ if (Modules == 2) break;
+ }
+
+ /* Keep looping */
+ NextEntry = NextEntry->Flink;
+ }
+
+ /* Release the lock */
+ KeLeaveCriticalRegion();
+
+ /* Free the string and return */
+ RtlFreeAnsiString(&AnsiRoutineName);
+ return ProcAddress;
+}
+
Modified: trunk/reactos/ntoskrnl/ntoskrnl.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.rbuild?r…
==============================================================================
--- trunk/reactos/ntoskrnl/ntoskrnl.rbuild (original)
+++ trunk/reactos/ntoskrnl/ntoskrnl.rbuild Fri Feb 23 10:56:01 2007
@@ -227,10 +227,6 @@
<file>kdio.c</file>
<file>kdmain.c</file>
</directory>
- <directory name="ldr">
- <file>loader.c</file>
- <file>rtl.c</file>
- </directory>
<directory name="lpc">
<file>close.c</file>
<file>complete.c</file>
Modified: trunk/reactos/ntoskrnl/ps/psmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/psmgr.c?rev=25…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/psmgr.c (original)
+++ trunk/reactos/ntoskrnl/ps/psmgr.c Fri Feb 23 10:56:01 2007
@@ -38,15 +38,6 @@
PVOID PspSystemDllSection;
PVOID PspSystemDllEntryPoint;
-ANSI_STRING ThunkName = RTL_CONSTANT_STRING("LdrInitializeThunk");
-ANSI_STRING ApcName = RTL_CONSTANT_STRING("KiUserApcDispatcher");
-ANSI_STRING ExceptName = RTL_CONSTANT_STRING("KiUserExceptionDispatcher");
-ANSI_STRING CallbackName = RTL_CONSTANT_STRING("KiUserCallbackDispatcher");
-ANSI_STRING RaiseName = RTL_CONSTANT_STRING("KiRaiseUserExceptionDispatcher");
-ANSI_STRING FastName = RTL_CONSTANT_STRING("KiFastSystemCall");
-ANSI_STRING FastReturnName = RTL_CONSTANT_STRING("KiFastSystemCallRet");
-ANSI_STRING InterruptName = RTL_CONSTANT_STRING("KiIntSystemCall");
-
UNICODE_STRING PsNtDllPathName =
RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
@@ -67,13 +58,106 @@
/* PRIVATE FUNCTIONS *********************************************************/
+ULONG
+NTAPI
+NameToOrdinal(IN PCHAR Name,
+ IN PVOID DllBase,
+ IN ULONG NumberOfNames,
+ IN PULONG NameTable,
+ IN PUSHORT OrdinalTable)
+{
+ ULONG Mid;
+ LONG Ret;
+
+ /* Fail if no names */
+ if (!NumberOfNames) return -1;
+
+ /* Do binary search */
+ Mid = NumberOfNames >> 1;
+ Ret = strcmp(Name, (PCHAR)((ULONG_PTR)DllBase + NameTable[Mid]));
+
+ /* Check if we found it */
+ if (!Ret) return OrdinalTable[Mid];
+
+ /* We didn't. Check if we only had one name to check */
+ if (NumberOfNames == 1) return -1;
+
+ /* Check if we should look up or down */
+ if (Ret < 0)
+ {
+ /* Loop down */
+ NumberOfNames = Mid;
+ }
+ else
+ {
+ /* Look up, update tables */
+ NameTable = &NameTable[Mid + 1];
+ OrdinalTable = &OrdinalTable[Mid + 1];
+ NumberOfNames -= (Mid - 1);
+ }
+
+ /* Call us recursively */
+ return NameToOrdinal(Name, DllBase, NumberOfNames, NameTable, OrdinalTable);
+}
+
NTSTATUS
NTAPI
-PspLookupSystemDllEntryPoint(IN PANSI_STRING Name,
+LookupEntryPoint(IN PVOID DllBase,
+ IN PCHAR Name,
+ OUT PVOID *EntryPoint)
+{
+ PULONG NameTable;
+ PUSHORT OrdinalTable;
+ PIMAGE_EXPORT_DIRECTORY ExportDirectory;
+ ULONG ExportSize;
+ CHAR Buffer[64];
+ USHORT Ordinal;
+ PULONG ExportTable;
+
+ /* Get the export directory */
+ ExportDirectory = RtlImageDirectoryEntryToData(DllBase,
+ TRUE,
+ IMAGE_DIRECTORY_ENTRY_EXPORT,
+ &ExportSize);
+
+ /* Validate the name and copy it */
+ if (strlen(Name) > sizeof(Buffer) - 2) return STATUS_INVALID_PARAMETER;
+ strcpy(Buffer, Name);
+
+ /* Setup name tables */
+ NameTable = (PULONG)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfNames);
+ OrdinalTable = (PUSHORT)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfNameOrdinals);
+
+ /* Get the ordinal */
+ Ordinal = NameToOrdinal(Buffer,
+ DllBase,
+ ExportDirectory->NumberOfNames,
+ NameTable,
+ OrdinalTable);
+
+ /* Make sure the ordinal is valid */
+ if (Ordinal >= ExportDirectory->NumberOfFunctions)
+ {
+ /* It's not, fail */
+ return STATUS_PROCEDURE_NOT_FOUND;
+ }
+
+ /* Resolve the address and write it */
+ ExportTable = (PULONG)((ULONG_PTR)DllBase +
+ ExportDirectory->AddressOfFunctions);
+ *EntryPoint = (PVOID)((ULONG_PTR)DllBase + ExportTable[Ordinal]);
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NTAPI
+PspLookupSystemDllEntryPoint(IN PCHAR Name,
IN PVOID *EntryPoint)
{
/* Call the LDR Routine */
- return LdrGetProcedureAddress(PspSystemDllBase, Name, 0, EntryPoint);
+ return LookupEntryPoint(PspSystemDllBase, Name, EntryPoint);
}
NTSTATUS
@@ -83,22 +167,22 @@
NTSTATUS Status;
/* Get user-mode APC trampoline */
- Status = PspLookupSystemDllEntryPoint(&ApcName,
+ Status = PspLookupSystemDllEntryPoint("KiUserApcDispatcher",
&KeUserApcDispatcher);
if (!NT_SUCCESS(Status)) return Status;
/* Get user-mode exception dispatcher */
- Status = PspLookupSystemDllEntryPoint(&ExceptName,
+ Status = PspLookupSystemDllEntryPoint("KiUserExceptionDispatcher",
&KeUserExceptionDispatcher);
if (!NT_SUCCESS(Status)) return Status;
/* Get user-mode callback dispatcher */
- Status = PspLookupSystemDllEntryPoint(&CallbackName,
+ Status = PspLookupSystemDllEntryPoint("KiUserCallbackDispatcher",
&KeUserCallbackDispatcher);
if (!NT_SUCCESS(Status)) return Status;
/* Get user-mode exception raise trampoline */
- Status = PspLookupSystemDllEntryPoint(&RaiseName,
+ Status = PspLookupSystemDllEntryPoint("KiRaiseUserExceptionDispatcher",
&KeRaiseUserExceptionDispatcher);
if (!NT_SUCCESS(Status)) return Status;
@@ -106,20 +190,20 @@
if (KeFeatureBits & KF_FAST_SYSCALL)
{
/* Get user-mode sysenter stub */
- Status = PspLookupSystemDllEntryPoint(&FastName,
+ Status = PspLookupSystemDllEntryPoint("KiFastSystemCall",
(PVOID)&SharedUserData->
SystemCall);
if (!NT_SUCCESS(Status)) return Status;
/* Get user-mode sysenter return stub */
- Status = PspLookupSystemDllEntryPoint(&FastReturnName,
+ Status = PspLookupSystemDllEntryPoint("KiFastSystemCallRet",
(PVOID)&SharedUserData->
SystemCallReturn);
}
else
{
/* Get the user-mode interrupt stub */
- Status = PspLookupSystemDllEntryPoint(&InterruptName,
+ Status = PspLookupSystemDllEntryPoint("KiIntSystemCall",
(PVOID)&SharedUserData->
SystemCall);
}
@@ -250,7 +334,8 @@
NTSTATUS Status;
/* Get user-mode startup thunk */
- Status = PspLookupSystemDllEntryPoint(&ThunkName, &PspSystemDllEntryPoint);
+ Status = PspLookupSystemDllEntryPoint("LdrInitializeThunk",
+ &PspSystemDllEntryPoint);
if (!NT_SUCCESS(Status))
{
/* Failed, bugcheck */