- Remove unused ldr/userldr.c

- Rename LdrLoadInitialProcess to Exp... and move to executive initialization.
- Removed ldr/init.c
- Renamed ldr/sysdll.c functions to Psp (correct naming) and deleted file.
- Renamed SystemDll... ntdll pointers to correct Ke names
- Use direct Ke names instead of going through an API call.
- Make ExpInit... functions STDCALL

svn path=/trunk/; revision=17053
This commit is contained in:
Alex Ionescu 2005-08-05 03:44:24 +00:00
parent 3f935aa835
commit 1bb6a5ce2c
29 changed files with 384 additions and 508 deletions

View file

@ -71,6 +71,8 @@ KEVENT ExpCallbackEvent;
* TRUE if the Callback Object Type was successfully created.
*/
VOID
INIT_FUNCTION
STDCALL
ExpInitializeCallbacks(VOID)
{
OBJECT_ATTRIBUTES ObjectAttributes;

View file

@ -34,6 +34,7 @@ static const INFORMATION_CLASS_INFO ExEventInfoClass[] = {
VOID
INIT_FUNCTION
STDCALL
ExpInitializeEventImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -31,6 +31,7 @@ static GENERIC_MAPPING ExEventPairMapping = {
VOID
INIT_FUNCTION
STDCALL
ExpInitializeEventPairImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -405,6 +405,79 @@ ExpDisplayNotice(VOID)
HalDisplayString(str);
}
INIT_FUNCTION
NTSTATUS
ExpLoadInitialProcess(PHANDLE ProcessHandle,
PHANDLE ThreadHandle)
{
UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
HANDLE SystemProcessHandle;
NTSTATUS Status;
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
RTL_USER_PROCESS_INFORMATION Info;
/* Create a handle to the process */
Status = ObpCreateHandle(PsGetCurrentProcess(),
PsInitialSystemProcess,
PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION,
FALSE,
&SystemProcessHandle);
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create a handle for the system process!\n");
return Status;
}
/* Create the Parameters */
Status = RtlCreateProcessParameters(&Params,
&ImagePath,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL);
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create ppb!\n");
ZwClose(SystemProcessHandle);
return Status;
}
DPRINT("Creating process\n");
Status = RtlCreateUserProcess(&ImagePath,
OBJ_CASE_INSENSITIVE,
Params,
NULL,
NULL,
SystemProcessHandle,
FALSE,
NULL,
NULL,
&Info);
/* Close the handle and free the params */
ZwClose(SystemProcessHandle);
RtlDestroyProcessParameters(Params);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtCreateProcess() failed (Status %lx)\n", Status);
return(Status);
}
/* Start it up */
ZwResumeThread(Info.ThreadHandle, NULL);
/* Return Handles */
*ProcessHandle = Info.ProcessHandle;
*ThreadHandle = Info.ThreadHandle;
DPRINT("Process created successfully\n");
return STATUS_SUCCESS;
}
VOID
INIT_FUNCTION
@ -468,7 +541,7 @@ ExpInitializeExecutive(VOID)
ObInit();
/* Initialize Lookaside Lists */
ExInit2();
ExpInitLookasideLists();
/* Set up Region Maps, Sections and the Paging File */
MmInit2();
@ -506,7 +579,7 @@ ExpInitializeExecutive(VOID)
HalInitSystem(1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
/* Initialize Basic System Objects and Worker Threads */
ExInit3();
ExInit2();
/* Create the system handle table, assign it to the system process, create
the client id table and assign a PID for the system process. This needs
@ -575,7 +648,7 @@ ExpInitializeExecutive(VOID)
IoInit3();
/* Load the System DLL and its Entrypoints */
LdrpInitializeSystemDll();
PsLocateSystemDll();
/* Initialize the Default Locale */
PiInitDefaultLocale();
@ -604,7 +677,7 @@ ExpInitializeExecutive(VOID)
}
/* Launch initial process */
Status = LdrLoadInitialProcess(&ProcessHandle,
Status = ExpLoadInitialProcess(&ProcessHandle,
&ThreadHandle);
/* Check for success, Bugcheck if we failed */
@ -671,25 +744,21 @@ ExpInitializeExecutive(VOID)
ZwClose(ProcessHandle);
}
VOID INIT_FUNCTION
VOID
STDCALL
INIT_FUNCTION
ExInit2(VOID)
{
ExpInitLookasideLists();
}
VOID INIT_FUNCTION
ExInit3 (VOID)
{
ExpInitializeEventImplementation();
ExpInitializeEventPairImplementation();
ExpInitializeMutantImplementation();
ExpInitializeSemaphoreImplementation();
ExpInitializeTimerImplementation();
LpcpInitSystem();
ExpInitializeProfileImplementation();
ExpWin32kInit();
ExpInitUuids();
ExpInitializeHandleTables();
ExpInitializeEventImplementation();
ExpInitializeEventPairImplementation();
ExpInitializeMutantImplementation();
ExpInitializeSemaphoreImplementation();
ExpInitializeTimerImplementation();
LpcpInitSystem();
ExpInitializeProfileImplementation();
ExpWin32kInit();
ExpInitUuids();
ExpInitializeHandleTables();
}
/* EOF */

View file

@ -26,6 +26,7 @@ KSPIN_LOCK ExpPagedLookasideListLock;
VOID
INIT_FUNCTION
STDCALL
ExpInitLookasideLists()
{
/* Initialize Lock and Listhead */

View file

@ -51,6 +51,7 @@ ExpDeleteMutant(PVOID ObjectBody)
VOID
INIT_FUNCTION
STDCALL
ExpInitializeMutantImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -74,6 +74,7 @@ ExpDeleteProfile(PVOID ObjectBody)
VOID
INIT_FUNCTION
STDCALL
ExpInitializeProfileImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -32,6 +32,7 @@ static const INFORMATION_CLASS_INFO ExSemaphoreInfoClass[] = {
VOID
INIT_FUNCTION
STDCALL
ExpInitializeSemaphoreImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -27,7 +27,9 @@ ULONG ExpTimeZoneId;
/* FUNCTIONS ****************************************************************/
VOID INIT_FUNCTION
VOID
INIT_FUNCTION
STDCALL
ExpInitTimeZoneInfo(VOID)
{
LARGE_INTEGER CurrentTime;

View file

@ -221,6 +221,7 @@ ExpTimerApcKernelRoutine(PKAPC Apc,
VOID
INIT_FUNCTION
STDCALL
ExpInitializeTimerImplementation(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -41,7 +41,9 @@ static ULONG UuidCount;
/* FUNCTIONS ****************************************************************/
VOID INIT_FUNCTION
VOID
INIT_FUNCTION
STDCALL
ExpInitUuids(VOID)
{
ExInitializeFastMutex(&UuidMutex);

View file

@ -119,6 +119,7 @@ ExpDesktopDelete(PVOID DeletedObject)
VOID
INIT_FUNCTION
STDCALL
ExpWin32kInit(VOID)
{
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;

View file

@ -132,6 +132,7 @@ ExpInitializeWorkQueue(WORK_QUEUE_TYPE WorkQueueType,
VOID
INIT_FUNCTION
STDCALL
ExpInitializeWorkerThreads(VOID)
{
ULONG WorkQueueType;

View file

@ -11,27 +11,31 @@ extern POBJECT_TYPE ExEventPairObjectType;
/* INITIALIZATION FUNCTIONS *************************************************/
VOID
STDCALL
ExpWin32kInit(VOID);
VOID
STDCALL
ExInit2(VOID);
VOID
ExInit3(VOID);
VOID
STDCALL
ExpInitTimeZoneInfo(VOID);
VOID
STDCALL
ExpInitializeWorkerThreads(VOID);
VOID
STDCALL
ExpInitLookasideLists(VOID);
VOID
STDCALL
ExpInitializeCallbacks(VOID);
VOID
STDCALL
ExpInitUuids(VOID);
VOID
@ -39,24 +43,31 @@ STDCALL
ExpInitializeExecutive(VOID);
VOID
STDCALL
ExpInitializeEventImplementation(VOID);
VOID
STDCALL
ExpInitializeEventImplementation(VOID);
VOID
STDCALL
ExpInitializeEventPairImplementation(VOID);
VOID
STDCALL
ExpInitializeSemaphoreImplementation(VOID);
VOID
STDCALL
ExpInitializeMutantImplementation(VOID);
VOID
STDCALL
ExpInitializeTimerImplementation(VOID);
VOID
STDCALL
ExpInitializeProfileImplementation(VOID);
/* HANDLE TABLE FUNCTIONS ***************************************************/

View file

@ -19,6 +19,11 @@ struct _KPCR;
struct _KPRCB;
struct _KEXCEPTION_FRAME;
extern PVOID KeUserApcDispatcher;
extern PVOID KeUserCallbackDispatcher;
extern PVOID KeUserExceptionDispatcher;
extern PVOID KeRaiseUserExceptionDispatcher;
#define IPI_REQUEST_FUNCTIONCALL 0
#define IPI_REQUEST_APC 1
#define IPI_REQUEST_DPC 2

View file

@ -20,36 +20,6 @@ LdrLoadAutoConfigDrivers (VOID);
VOID
LdrInitModuleManagement (VOID);
NTSTATUS
STDCALL
LdrpMapSystemDll(
PEPROCESS Process,
PVOID *DllBase
);
NTSTATUS
STDCALL
LdrpInitializeSystemDll(VOID);
NTSTATUS
STDCALL
LdrpGetSystemDllEntryPoints(VOID);
PVOID
LdrpGetSystemDllEntryPoint (VOID);
PVOID
LdrpGetSystemDllApcDispatcher(VOID);
PVOID
LdrpGetSystemDllExceptionDispatcher(VOID);
PVOID
LdrpGetSystemDllCallbackDispatcher(VOID);
PVOID
LdrpGetSystemDllRaiseExceptionDispatcher(VOID);
NTSTATUS
LdrpMapImage(
HANDLE ProcessHandle,

View file

@ -199,6 +199,21 @@ VOID
STDCALL
PspDestroyQuotaBlock(PEPROCESS Process);
NTSTATUS
STDCALL
PspMapSystemDll(
PEPROCESS Process,
PVOID *DllBase
);
NTSTATUS
STDCALL
PsLocateSystemDll(VOID);
NTSTATUS
STDCALL
PspGetSystemDllEntryPoints(VOID);
/* CLIENT ID */
NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);

View file

@ -847,7 +847,7 @@ KiInitializeUserApc(IN PVOID Reserved,
Esp[3] = (ULONG)SystemArgument1;
Esp[4] = (ULONG)SystemArgument2;
Esp[5] = (ULONG)Context;
TrapFrame->Eip = (ULONG)LdrpGetSystemDllApcDispatcher();
TrapFrame->Eip = (ULONG)KeUserApcDispatcher;
DPRINT("TrapFrame->Eip: %x\n", TrapFrame->Eip);
TrapFrame->Esp = (ULONG)Esp;
}

View file

@ -161,7 +161,7 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
DPRINT1("User-mode stack was invalid. Terminating target thread\n");
}
/* Set EIP to the User-mode Dispathcer */
Tf->Eip = (ULONG)LdrpGetSystemDllExceptionDispatcher();
Tf->Eip = (ULONG)KeRaiseUserExceptionDispatcher;
return;
}

View file

@ -923,7 +923,7 @@ KeRaiseUserException(IN NTSTATUS ExceptionCode)
} _SEH_END;
OldEip = Thread->TrapFrame->Eip;
Thread->TrapFrame->Eip = (ULONG_PTR)LdrpGetSystemDllRaiseExceptionDispatcher();
Thread->TrapFrame->Eip = (ULONG_PTR)KeRaiseUserExceptionDispatcher;
return((NTSTATUS)OldEip);
}

View file

@ -41,6 +41,11 @@ ULONG_PTR FirstKrnlPhysAddr;
ULONG_PTR LastKrnlPhysAddr;
ULONG_PTR LastKernelAddress;
PVOID KeUserApcDispatcher = NULL;
PVOID KeUserCallbackDispatcher = NULL;
PVOID KeUserExceptionDispatcher = NULL;
PVOID KeRaiseUserExceptionDispatcher = NULL;
ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
/* We allocate 4 pages, but we only use 3. The 4th is to guarantee page alignment */

View file

@ -207,7 +207,7 @@ KeUserModeCallback(IN ULONG RoutineIndex,
NewFrame = (PKTRAP_FRAME)((char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA));
/* We need the stack pointer to remain 4-byte aligned */
NewFrame->Esp -= (((ArgumentLength + 3) & (~ 0x3)) + (4 * sizeof(ULONG)));
NewFrame->Eip = (ULONG)LdrpGetSystemDllCallbackDispatcher();
NewFrame->Eip = (ULONG)KeUserCallbackDispatcher;
UserEsp = (PULONG)NewFrame->Esp;
UserEsp[0] = 0; /* Return address. */
UserEsp[1] = RoutineIndex;

View file

@ -1,103 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ldr/init.c
* PURPOSE: Loaders for PE executables
*
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
*/
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
INIT_FUNCTION
NTSTATUS
LdrLoadInitialProcess(PHANDLE ProcessHandle,
PHANDLE ThreadHandle)
{
UNICODE_STRING ImagePath = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\smss.exe");
HANDLE SystemProcessHandle;
NTSTATUS Status;
PRTL_USER_PROCESS_PARAMETERS Params=NULL;
RTL_USER_PROCESS_INFORMATION Info;
Status = ObpCreateHandle(
PsGetCurrentProcess(),
PsInitialSystemProcess,
PROCESS_CREATE_PROCESS | PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION,
FALSE,
&SystemProcessHandle
);
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create a handle for the system process!\n");
return Status;
}
Status = RtlCreateProcessParameters(
&Params,
&ImagePath,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
);
if(!NT_SUCCESS(Status))
{
DPRINT1("Failed to create ppb!\n");
ZwClose(SystemProcessHandle);
return Status;
}
DPRINT("Creating process\n");
Status = RtlCreateUserProcess(
&ImagePath,
OBJ_CASE_INSENSITIVE, //Valid are OBJ_INHERIT and OBJ_CASE_INSENSITIVE.
Params,
NULL,
NULL,
SystemProcessHandle,
FALSE,
NULL,
NULL,
&Info
);
ZwClose(SystemProcessHandle);
RtlDestroyProcessParameters(Params);
if (!NT_SUCCESS(Status))
{
DPRINT1("NtCreateProcess() failed (Status %lx)\n", Status);
return(Status);
}
ZwResumeThread(Info.ThreadHandle, NULL);
*ProcessHandle = Info.ProcessHandle;
*ThreadHandle= Info.ThreadHandle;
DPRINT("Process created successfully\n");
return(STATUS_SUCCESS);
}
/* EOF */

View file

@ -1,278 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ldr/sysdll.c
* PURPOSE: Loaders for PE executables
*
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
* Skywing
*/
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
PVOID SystemDllEntryPoint = NULL;
PVOID SystemDllApcDispatcher = NULL;
PVOID SystemDllCallbackDispatcher = NULL;
PVOID SystemDllExceptionDispatcher = NULL;
PVOID SystemDllRaiseExceptionDispatcher = NULL;
PVOID LdrpSystemDllBase = NULL;
PVOID LdrpSystemDllSection = NULL;
/* FUNCTIONS *****************************************************************/
PVOID LdrpGetSystemDllExceptionDispatcher(VOID)
{
return(SystemDllExceptionDispatcher);
}
PVOID LdrpGetSystemDllCallbackDispatcher(VOID)
{
return(SystemDllCallbackDispatcher);
}
PVOID LdrpGetSystemDllEntryPoint(VOID)
{
return(SystemDllEntryPoint);
}
PVOID LdrpGetSystemDllApcDispatcher(VOID)
{
return(SystemDllApcDispatcher);
}
PVOID LdrpGetSystemDllRaiseExceptionDispatcher(VOID)
{
return(SystemDllRaiseExceptionDispatcher);
}
NTSTATUS
STDCALL
INIT_FUNCTION
LdrpGetSystemDllEntryPoints(VOID)
{
ANSI_STRING ProcedureName;
NTSTATUS Status;
/* Retrieve ntdll's startup address */
DPRINT("Getting Entrypoint: %p\n", LdrpSystemDllBase);
RtlInitAnsiString(&ProcedureName, "LdrInitializeThunk");
Status = LdrGetProcedureAddress((PVOID)LdrpSystemDllBase,
&ProcedureName,
0,
&SystemDllEntryPoint);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get User APC Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserApcDispatcher");
Status = LdrGetProcedureAddress((PVOID)LdrpSystemDllBase,
&ProcedureName,
0,
&SystemDllApcDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Exception Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserExceptionDispatcher");
Status = LdrGetProcedureAddress((PVOID)LdrpSystemDllBase,
&ProcedureName,
0,
&SystemDllExceptionDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Callback Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserCallbackDispatcher");
Status = LdrGetProcedureAddress((PVOID)LdrpSystemDllBase,
&ProcedureName,
0,
&SystemDllCallbackDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Raise Exception Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiRaiseUserExceptionDispatcher");
Status = LdrGetProcedureAddress((PVOID)LdrpSystemDllBase,
&ProcedureName,
0,
&SystemDllRaiseExceptionDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Return success */
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
LdrpMapSystemDll(PEPROCESS Process,
PVOID *DllBase)
{
NTSTATUS Status;
ULONG ViewSize = 0;
PVOID ImageBase = 0;
/* Map the System DLL */
DPRINT("Mapping System DLL\n");
Status = MmMapViewOfSection(LdrpSystemDllSection,
Process,
(PVOID*)&ImageBase,
0,
0,
NULL,
&ViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status)) {
DPRINT1("Failed to map System DLL Into Process\n");
}
if (DllBase) *DllBase = ImageBase;
return Status;
}
NTSTATUS
STDCALL
INIT_FUNCTION
LdrpInitializeSystemDll(VOID)
{
UNICODE_STRING DllPathname = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
OBJECT_ATTRIBUTES FileObjectAttributes;
IO_STATUS_BLOCK Iosb;
HANDLE FileHandle;
HANDLE NTDllSectionHandle;
NTSTATUS Status;
CHAR BlockBuffer[1024];
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
/* Locate and open NTDLL to determine ImageBase and LdrStartup */
InitializeObjectAttributes(&FileObjectAttributes,
&DllPathname,
0,
NULL,
NULL);
DPRINT("Opening NTDLL\n");
Status = ZwOpenFile(&FileHandle,
FILE_READ_ACCESS,
&FileObjectAttributes,
&Iosb,
FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL open failed (Status %x)\n", Status);
return Status;
}
/* Load NTDLL is valid */
DPRINT("Reading NTDLL\n");
Status = ZwReadFile(FileHandle,
0,
0,
0,
&Iosb,
BlockBuffer,
sizeof(BlockBuffer),
0,
0);
if (!NT_SUCCESS(Status) || Iosb.Information != sizeof(BlockBuffer)) {
DPRINT1("NTDLL header read failed (Status %x)\n", Status);
ZwClose(FileHandle);
return Status;
}
/* Check if it's valid */
DosHeader = (PIMAGE_DOS_HEADER)BlockBuffer;
NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
if ((DosHeader->e_magic != IMAGE_DOS_SIGNATURE) ||
(DosHeader->e_lfanew == 0L) ||
(*(PULONG) NTHeaders != IMAGE_NT_SIGNATURE)) {
DPRINT1("NTDLL format invalid\n");
ZwClose(FileHandle);
return(STATUS_UNSUCCESSFUL);
}
/* Create a section for NTDLL */
DPRINT("Creating section\n");
Status = ZwCreateSection(&NTDllSectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READONLY,
SEC_IMAGE | SEC_COMMIT,
FileHandle);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL create section failed (Status %x)\n", Status);
ZwClose(FileHandle);
return(Status);
}
ZwClose(FileHandle);
/* Reference the Section */
DPRINT("ObReferenceObjectByHandle section: %d\n", NTDllSectionHandle);
Status = ObReferenceObjectByHandle(NTDllSectionHandle,
SECTION_ALL_ACCESS,
MmSectionObjectType,
KernelMode,
(PVOID*)&LdrpSystemDllSection,
NULL);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL section reference failed (Status %x)\n", Status);
return(Status);
}
/* Map it */
LdrpMapSystemDll(PsGetCurrentProcess(), &LdrpSystemDllBase);
DPRINT("LdrpSystemDllBase: %x\n", LdrpSystemDllBase);
/* Now get the Entrypoints */
LdrpGetSystemDllEntryPoints();
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -1,62 +0,0 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/ldr/userldr.c
* PURPOSE: Loaders for PE executables
*
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
*/
/* INCLUDES *****************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
NTSTATUS LdrpMapImage(HANDLE ProcessHandle,
HANDLE SectionHandle,
PVOID* ReturnedImageBase)
/*
* FUNCTION: LdrpMapImage maps a user-mode image into an address space
* PARAMETERS:
* ProcessHandle
* Points to the process to map the image into
*
* SectionHandle
* Points to the section to map
*
* RETURNS: Status
*/
{
ULONG ViewSize;
PVOID ImageBase;
NTSTATUS Status;
ViewSize = 0;
ImageBase = 0;
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
ViewSize,
NULL,
&ViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
CPRINT("Image map view of section failed (Status %x)", Status);
return(Status);
}
*ReturnedImageBase = ImageBase;
return(STATUS_SUCCESS);
}

View file

@ -212,12 +212,9 @@
<file>kdmain.c</file>
</directory>
<directory name="ldr">
<file>init.c</file>
<file>loader.c</file>
<file>resource.c</file>
<file>rtl.c</file>
<file>sysdll.c</file>
<file>userldr.c</file>
</directory>
<directory name="lpc">
<file>close.c</file>

View file

@ -357,7 +357,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
{
/* Map the System Dll */
DPRINT("Mapping System DLL\n");
LdrpMapSystemDll(Process, NULL);
PspMapSystemDll(Process, NULL);
}
/* Create a handle for the Process */

View file

@ -36,6 +36,14 @@ static GENERIC_MAPPING PiThreadMapping = {
extern ULONG NtBuildNumber;
extern ULONG NtMajorVersion;
extern ULONG NtMinorVersion;
extern PVOID KeUserApcDispatcher;
extern PVOID KeUserCallbackDispatcher;
extern PVOID KeUserExceptionDispatcher;
extern PVOID KeRaiseUserExceptionDispatcher;
PVOID PspSystemDllBase = NULL;
PVOID PspSystemDllSection = NULL;
PVOID PspSystemDllEntryPoint = NULL;
VOID
INIT_FUNCTION
@ -274,6 +282,229 @@ PspPostInitSystemProcess(VOID)
KEBUGCHECK(0);
}
}
NTSTATUS
STDCALL
INIT_FUNCTION
PspLookupKernelUserEntryPoints(VOID)
{
ANSI_STRING ProcedureName;
NTSTATUS Status;
/* Retrieve ntdll's startup address */
DPRINT("Getting Entrypoint: %p\n", PspSystemDllBase);
RtlInitAnsiString(&ProcedureName, "LdrInitializeThunk");
Status = LdrGetProcedureAddress((PVOID)PspSystemDllBase,
&ProcedureName,
0,
&PspSystemDllEntryPoint);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get User APC Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserApcDispatcher");
Status = LdrGetProcedureAddress((PVOID)PspSystemDllBase,
&ProcedureName,
0,
&KeUserApcDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Exception Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserExceptionDispatcher");
Status = LdrGetProcedureAddress((PVOID)PspSystemDllBase,
&ProcedureName,
0,
&KeUserExceptionDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Callback Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiUserCallbackDispatcher");
Status = LdrGetProcedureAddress((PVOID)PspSystemDllBase,
&ProcedureName,
0,
&KeUserCallbackDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Get Raise Exception Dispatcher */
DPRINT("Getting Entrypoint\n");
RtlInitAnsiString(&ProcedureName, "KiRaiseUserExceptionDispatcher");
Status = LdrGetProcedureAddress((PVOID)PspSystemDllBase,
&ProcedureName,
0,
&KeRaiseUserExceptionDispatcher);
if (!NT_SUCCESS(Status)) {
DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n", Status);
return (Status);
}
/* Return success */
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
PspMapSystemDll(PEPROCESS Process,
PVOID *DllBase)
{
NTSTATUS Status;
ULONG ViewSize = 0;
PVOID ImageBase = 0;
/* Map the System DLL */
DPRINT("Mapping System DLL\n");
Status = MmMapViewOfSection(PspSystemDllSection,
Process,
(PVOID*)&ImageBase,
0,
0,
NULL,
&ViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status)) {
DPRINT1("Failed to map System DLL Into Process\n");
}
if (DllBase) *DllBase = ImageBase;
return Status;
}
NTSTATUS
STDCALL
INIT_FUNCTION
PsLocateSystemDll(VOID)
{
UNICODE_STRING DllPathname = RTL_CONSTANT_STRING(L"\\SystemRoot\\system32\\ntdll.dll");
OBJECT_ATTRIBUTES FileObjectAttributes;
IO_STATUS_BLOCK Iosb;
HANDLE FileHandle;
HANDLE NTDllSectionHandle;
NTSTATUS Status;
CHAR BlockBuffer[1024];
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
/* Locate and open NTDLL to determine ImageBase and LdrStartup */
InitializeObjectAttributes(&FileObjectAttributes,
&DllPathname,
0,
NULL,
NULL);
DPRINT("Opening NTDLL\n");
Status = ZwOpenFile(&FileHandle,
FILE_READ_ACCESS,
&FileObjectAttributes,
&Iosb,
FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL open failed (Status %x)\n", Status);
return Status;
}
/* Load NTDLL is valid */
DPRINT("Reading NTDLL\n");
Status = ZwReadFile(FileHandle,
0,
0,
0,
&Iosb,
BlockBuffer,
sizeof(BlockBuffer),
0,
0);
if (!NT_SUCCESS(Status) || Iosb.Information != sizeof(BlockBuffer)) {
DPRINT1("NTDLL header read failed (Status %x)\n", Status);
ZwClose(FileHandle);
return Status;
}
/* Check if it's valid */
DosHeader = (PIMAGE_DOS_HEADER)BlockBuffer;
NTHeaders = (PIMAGE_NT_HEADERS)(BlockBuffer + DosHeader->e_lfanew);
if ((DosHeader->e_magic != IMAGE_DOS_SIGNATURE) ||
(DosHeader->e_lfanew == 0L) ||
(*(PULONG) NTHeaders != IMAGE_NT_SIGNATURE)) {
DPRINT1("NTDLL format invalid\n");
ZwClose(FileHandle);
return(STATUS_UNSUCCESSFUL);
}
/* Create a section for NTDLL */
DPRINT("Creating section\n");
Status = ZwCreateSection(&NTDllSectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READONLY,
SEC_IMAGE | SEC_COMMIT,
FileHandle);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL create section failed (Status %x)\n", Status);
ZwClose(FileHandle);
return(Status);
}
ZwClose(FileHandle);
/* Reference the Section */
DPRINT("ObReferenceObjectByHandle section: %d\n", NTDllSectionHandle);
Status = ObReferenceObjectByHandle(NTDllSectionHandle,
SECTION_ALL_ACCESS,
MmSectionObjectType,
KernelMode,
(PVOID*)&PspSystemDllSection,
NULL);
if (!NT_SUCCESS(Status)) {
DPRINT1("NTDLL section reference failed (Status %x)\n", Status);
return(Status);
}
/* Map it */
PspMapSystemDll(PsGetCurrentProcess(), &PspSystemDllBase);
DPRINT("LdrpSystemDllBase: %x\n", PspSystemDllBase);
/* Now get the Entrypoints */
PspLookupKernelUserEntryPoints();
return STATUS_SUCCESS;
}
/**********************************************************************
* NAME EXPORTED
* PsGetVersion

View file

@ -18,6 +18,7 @@
extern LIST_ENTRY PsActiveProcessHead;
extern PEPROCESS PsIdleProcess;
extern PVOID PspSystemDllEntryPoint;
POBJECT_TYPE EXPORTED PsThreadType = NULL;
@ -57,7 +58,7 @@ PspUserThreadStartup(PKSTART_ROUTINE StartRoutine,
OriginalApcEnvironment,
PspThreadSpecialApc,
NULL,
LdrpGetSystemDllEntryPoint(),
PspSystemDllEntryPoint,
UserMode,
NULL);