mirror of
https://github.com/reactos/reactos.git
synced 2024-12-30 19:14:31 +00:00
- 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:
parent
3f935aa835
commit
1bb6a5ce2c
29 changed files with 384 additions and 508 deletions
|
@ -71,6 +71,8 @@ KEVENT ExpCallbackEvent;
|
||||||
* TRUE if the Callback Object Type was successfully created.
|
* TRUE if the Callback Object Type was successfully created.
|
||||||
*/
|
*/
|
||||||
VOID
|
VOID
|
||||||
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeCallbacks(VOID)
|
ExpInitializeCallbacks(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
|
|
|
@ -34,6 +34,7 @@ static const INFORMATION_CLASS_INFO ExEventInfoClass[] = {
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeEventImplementation(VOID)
|
ExpInitializeEventImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -31,6 +31,7 @@ static GENERIC_MAPPING ExEventPairMapping = {
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeEventPairImplementation(VOID)
|
ExpInitializeEventPairImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -406,6 +406,79 @@ ExpDisplayNotice(VOID)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
STDCALL
|
STDCALL
|
||||||
|
@ -468,7 +541,7 @@ ExpInitializeExecutive(VOID)
|
||||||
ObInit();
|
ObInit();
|
||||||
|
|
||||||
/* Initialize Lookaside Lists */
|
/* Initialize Lookaside Lists */
|
||||||
ExInit2();
|
ExpInitLookasideLists();
|
||||||
|
|
||||||
/* Set up Region Maps, Sections and the Paging File */
|
/* Set up Region Maps, Sections and the Paging File */
|
||||||
MmInit2();
|
MmInit2();
|
||||||
|
@ -506,7 +579,7 @@ ExpInitializeExecutive(VOID)
|
||||||
HalInitSystem(1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
|
HalInitSystem(1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock);
|
||||||
|
|
||||||
/* Initialize Basic System Objects and Worker Threads */
|
/* Initialize Basic System Objects and Worker Threads */
|
||||||
ExInit3();
|
ExInit2();
|
||||||
|
|
||||||
/* Create the system handle table, assign it to the system process, create
|
/* 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
|
the client id table and assign a PID for the system process. This needs
|
||||||
|
@ -575,7 +648,7 @@ ExpInitializeExecutive(VOID)
|
||||||
IoInit3();
|
IoInit3();
|
||||||
|
|
||||||
/* Load the System DLL and its Entrypoints */
|
/* Load the System DLL and its Entrypoints */
|
||||||
LdrpInitializeSystemDll();
|
PsLocateSystemDll();
|
||||||
|
|
||||||
/* Initialize the Default Locale */
|
/* Initialize the Default Locale */
|
||||||
PiInitDefaultLocale();
|
PiInitDefaultLocale();
|
||||||
|
@ -604,7 +677,7 @@ ExpInitializeExecutive(VOID)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Launch initial process */
|
/* Launch initial process */
|
||||||
Status = LdrLoadInitialProcess(&ProcessHandle,
|
Status = ExpLoadInitialProcess(&ProcessHandle,
|
||||||
&ThreadHandle);
|
&ThreadHandle);
|
||||||
|
|
||||||
/* Check for success, Bugcheck if we failed */
|
/* Check for success, Bugcheck if we failed */
|
||||||
|
@ -671,14 +744,10 @@ ExpInitializeExecutive(VOID)
|
||||||
ZwClose(ProcessHandle);
|
ZwClose(ProcessHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID INIT_FUNCTION
|
VOID
|
||||||
|
STDCALL
|
||||||
|
INIT_FUNCTION
|
||||||
ExInit2(VOID)
|
ExInit2(VOID)
|
||||||
{
|
|
||||||
ExpInitLookasideLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID INIT_FUNCTION
|
|
||||||
ExInit3 (VOID)
|
|
||||||
{
|
{
|
||||||
ExpInitializeEventImplementation();
|
ExpInitializeEventImplementation();
|
||||||
ExpInitializeEventPairImplementation();
|
ExpInitializeEventPairImplementation();
|
||||||
|
|
|
@ -26,6 +26,7 @@ KSPIN_LOCK ExpPagedLookasideListLock;
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitLookasideLists()
|
ExpInitLookasideLists()
|
||||||
{
|
{
|
||||||
/* Initialize Lock and Listhead */
|
/* Initialize Lock and Listhead */
|
||||||
|
|
|
@ -51,6 +51,7 @@ ExpDeleteMutant(PVOID ObjectBody)
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeMutantImplementation(VOID)
|
ExpInitializeMutantImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -74,6 +74,7 @@ ExpDeleteProfile(PVOID ObjectBody)
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeProfileImplementation(VOID)
|
ExpInitializeProfileImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -32,6 +32,7 @@ static const INFORMATION_CLASS_INFO ExSemaphoreInfoClass[] = {
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeSemaphoreImplementation(VOID)
|
ExpInitializeSemaphoreImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -27,7 +27,9 @@ ULONG ExpTimeZoneId;
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
VOID INIT_FUNCTION
|
VOID
|
||||||
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitTimeZoneInfo(VOID)
|
ExpInitTimeZoneInfo(VOID)
|
||||||
{
|
{
|
||||||
LARGE_INTEGER CurrentTime;
|
LARGE_INTEGER CurrentTime;
|
||||||
|
|
|
@ -221,6 +221,7 @@ ExpTimerApcKernelRoutine(PKAPC Apc,
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeTimerImplementation(VOID)
|
ExpInitializeTimerImplementation(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -41,7 +41,9 @@ static ULONG UuidCount;
|
||||||
|
|
||||||
/* FUNCTIONS ****************************************************************/
|
/* FUNCTIONS ****************************************************************/
|
||||||
|
|
||||||
VOID INIT_FUNCTION
|
VOID
|
||||||
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitUuids(VOID)
|
ExpInitUuids(VOID)
|
||||||
{
|
{
|
||||||
ExInitializeFastMutex(&UuidMutex);
|
ExInitializeFastMutex(&UuidMutex);
|
||||||
|
|
|
@ -119,6 +119,7 @@ ExpDesktopDelete(PVOID DeletedObject)
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpWin32kInit(VOID)
|
ExpWin32kInit(VOID)
|
||||||
{
|
{
|
||||||
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
|
||||||
|
|
|
@ -132,6 +132,7 @@ ExpInitializeWorkQueue(WORK_QUEUE_TYPE WorkQueueType,
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
STDCALL
|
||||||
ExpInitializeWorkerThreads(VOID)
|
ExpInitializeWorkerThreads(VOID)
|
||||||
{
|
{
|
||||||
ULONG WorkQueueType;
|
ULONG WorkQueueType;
|
||||||
|
|
|
@ -11,27 +11,31 @@ extern POBJECT_TYPE ExEventPairObjectType;
|
||||||
/* INITIALIZATION FUNCTIONS *************************************************/
|
/* INITIALIZATION FUNCTIONS *************************************************/
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpWin32kInit(VOID);
|
ExpWin32kInit(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExInit2(VOID);
|
ExInit2(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
ExInit3(VOID);
|
STDCALL
|
||||||
|
|
||||||
VOID
|
|
||||||
ExpInitTimeZoneInfo(VOID);
|
ExpInitTimeZoneInfo(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeWorkerThreads(VOID);
|
ExpInitializeWorkerThreads(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitLookasideLists(VOID);
|
ExpInitLookasideLists(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeCallbacks(VOID);
|
ExpInitializeCallbacks(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitUuids(VOID);
|
ExpInitUuids(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -39,24 +43,31 @@ STDCALL
|
||||||
ExpInitializeExecutive(VOID);
|
ExpInitializeExecutive(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeEventImplementation(VOID);
|
ExpInitializeEventImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeEventImplementation(VOID);
|
ExpInitializeEventImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeEventPairImplementation(VOID);
|
ExpInitializeEventPairImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeSemaphoreImplementation(VOID);
|
ExpInitializeSemaphoreImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeMutantImplementation(VOID);
|
ExpInitializeMutantImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeTimerImplementation(VOID);
|
ExpInitializeTimerImplementation(VOID);
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
STDCALL
|
||||||
ExpInitializeProfileImplementation(VOID);
|
ExpInitializeProfileImplementation(VOID);
|
||||||
|
|
||||||
/* HANDLE TABLE FUNCTIONS ***************************************************/
|
/* HANDLE TABLE FUNCTIONS ***************************************************/
|
||||||
|
|
|
@ -19,6 +19,11 @@ struct _KPCR;
|
||||||
struct _KPRCB;
|
struct _KPRCB;
|
||||||
struct _KEXCEPTION_FRAME;
|
struct _KEXCEPTION_FRAME;
|
||||||
|
|
||||||
|
extern PVOID KeUserApcDispatcher;
|
||||||
|
extern PVOID KeUserCallbackDispatcher;
|
||||||
|
extern PVOID KeUserExceptionDispatcher;
|
||||||
|
extern PVOID KeRaiseUserExceptionDispatcher;
|
||||||
|
|
||||||
#define IPI_REQUEST_FUNCTIONCALL 0
|
#define IPI_REQUEST_FUNCTIONCALL 0
|
||||||
#define IPI_REQUEST_APC 1
|
#define IPI_REQUEST_APC 1
|
||||||
#define IPI_REQUEST_DPC 2
|
#define IPI_REQUEST_DPC 2
|
||||||
|
|
|
@ -20,36 +20,6 @@ LdrLoadAutoConfigDrivers (VOID);
|
||||||
VOID
|
VOID
|
||||||
LdrInitModuleManagement (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
|
NTSTATUS
|
||||||
LdrpMapImage(
|
LdrpMapImage(
|
||||||
HANDLE ProcessHandle,
|
HANDLE ProcessHandle,
|
||||||
|
|
|
@ -199,6 +199,21 @@ VOID
|
||||||
STDCALL
|
STDCALL
|
||||||
PspDestroyQuotaBlock(PEPROCESS Process);
|
PspDestroyQuotaBlock(PEPROCESS Process);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
STDCALL
|
||||||
|
PspMapSystemDll(
|
||||||
|
PEPROCESS Process,
|
||||||
|
PVOID *DllBase
|
||||||
|
);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
STDCALL
|
||||||
|
PsLocateSystemDll(VOID);
|
||||||
|
|
||||||
|
NTSTATUS
|
||||||
|
STDCALL
|
||||||
|
PspGetSystemDllEntryPoints(VOID);
|
||||||
|
|
||||||
/* CLIENT ID */
|
/* CLIENT ID */
|
||||||
|
|
||||||
NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);
|
NTSTATUS PsCreateCidHandle(PVOID Object, POBJECT_TYPE ObjectType, PHANDLE Handle);
|
||||||
|
|
|
@ -847,7 +847,7 @@ KiInitializeUserApc(IN PVOID Reserved,
|
||||||
Esp[3] = (ULONG)SystemArgument1;
|
Esp[3] = (ULONG)SystemArgument1;
|
||||||
Esp[4] = (ULONG)SystemArgument2;
|
Esp[4] = (ULONG)SystemArgument2;
|
||||||
Esp[5] = (ULONG)Context;
|
Esp[5] = (ULONG)Context;
|
||||||
TrapFrame->Eip = (ULONG)LdrpGetSystemDllApcDispatcher();
|
TrapFrame->Eip = (ULONG)KeUserApcDispatcher;
|
||||||
DPRINT("TrapFrame->Eip: %x\n", TrapFrame->Eip);
|
DPRINT("TrapFrame->Eip: %x\n", TrapFrame->Eip);
|
||||||
TrapFrame->Esp = (ULONG)Esp;
|
TrapFrame->Esp = (ULONG)Esp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
|
||||||
DPRINT1("User-mode stack was invalid. Terminating target thread\n");
|
DPRINT1("User-mode stack was invalid. Terminating target thread\n");
|
||||||
}
|
}
|
||||||
/* Set EIP to the User-mode Dispathcer */
|
/* Set EIP to the User-mode Dispathcer */
|
||||||
Tf->Eip = (ULONG)LdrpGetSystemDllExceptionDispatcher();
|
Tf->Eip = (ULONG)KeRaiseUserExceptionDispatcher;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -923,7 +923,7 @@ KeRaiseUserException(IN NTSTATUS ExceptionCode)
|
||||||
} _SEH_END;
|
} _SEH_END;
|
||||||
|
|
||||||
OldEip = Thread->TrapFrame->Eip;
|
OldEip = Thread->TrapFrame->Eip;
|
||||||
Thread->TrapFrame->Eip = (ULONG_PTR)LdrpGetSystemDllRaiseExceptionDispatcher();
|
Thread->TrapFrame->Eip = (ULONG_PTR)KeRaiseUserExceptionDispatcher;
|
||||||
return((NTSTATUS)OldEip);
|
return((NTSTATUS)OldEip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,11 @@ ULONG_PTR FirstKrnlPhysAddr;
|
||||||
ULONG_PTR LastKrnlPhysAddr;
|
ULONG_PTR LastKrnlPhysAddr;
|
||||||
ULONG_PTR LastKernelAddress;
|
ULONG_PTR LastKernelAddress;
|
||||||
|
|
||||||
|
PVOID KeUserApcDispatcher = NULL;
|
||||||
|
PVOID KeUserCallbackDispatcher = NULL;
|
||||||
|
PVOID KeUserExceptionDispatcher = NULL;
|
||||||
|
PVOID KeRaiseUserExceptionDispatcher = NULL;
|
||||||
|
|
||||||
ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
|
ULONG KeLargestCacheLine = 0x40; /* FIXME: Arch-specific */
|
||||||
|
|
||||||
/* We allocate 4 pages, but we only use 3. The 4th is to guarantee page alignment */
|
/* We allocate 4 pages, but we only use 3. The 4th is to guarantee page alignment */
|
||||||
|
|
|
@ -207,7 +207,7 @@ KeUserModeCallback(IN ULONG RoutineIndex,
|
||||||
NewFrame = (PKTRAP_FRAME)((char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA));
|
NewFrame = (PKTRAP_FRAME)((char*)NewStack + StackSize - sizeof(KTRAP_FRAME) - sizeof(FX_SAVE_AREA));
|
||||||
/* We need the stack pointer to remain 4-byte aligned */
|
/* We need the stack pointer to remain 4-byte aligned */
|
||||||
NewFrame->Esp -= (((ArgumentLength + 3) & (~ 0x3)) + (4 * sizeof(ULONG)));
|
NewFrame->Esp -= (((ArgumentLength + 3) & (~ 0x3)) + (4 * sizeof(ULONG)));
|
||||||
NewFrame->Eip = (ULONG)LdrpGetSystemDllCallbackDispatcher();
|
NewFrame->Eip = (ULONG)KeUserCallbackDispatcher;
|
||||||
UserEsp = (PULONG)NewFrame->Esp;
|
UserEsp = (PULONG)NewFrame->Esp;
|
||||||
UserEsp[0] = 0; /* Return address. */
|
UserEsp[0] = 0; /* Return address. */
|
||||||
UserEsp[1] = RoutineIndex;
|
UserEsp[1] = RoutineIndex;
|
||||||
|
|
|
@ -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 */
|
|
|
@ -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 */
|
|
|
@ -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);
|
|
||||||
}
|
|
|
@ -212,12 +212,9 @@
|
||||||
<file>kdmain.c</file>
|
<file>kdmain.c</file>
|
||||||
</directory>
|
</directory>
|
||||||
<directory name="ldr">
|
<directory name="ldr">
|
||||||
<file>init.c</file>
|
|
||||||
<file>loader.c</file>
|
<file>loader.c</file>
|
||||||
<file>resource.c</file>
|
<file>resource.c</file>
|
||||||
<file>rtl.c</file>
|
<file>rtl.c</file>
|
||||||
<file>sysdll.c</file>
|
|
||||||
<file>userldr.c</file>
|
|
||||||
</directory>
|
</directory>
|
||||||
<directory name="lpc">
|
<directory name="lpc">
|
||||||
<file>close.c</file>
|
<file>close.c</file>
|
||||||
|
|
|
@ -357,7 +357,7 @@ PspCreateProcess(OUT PHANDLE ProcessHandle,
|
||||||
{
|
{
|
||||||
/* Map the System Dll */
|
/* Map the System Dll */
|
||||||
DPRINT("Mapping System DLL\n");
|
DPRINT("Mapping System DLL\n");
|
||||||
LdrpMapSystemDll(Process, NULL);
|
PspMapSystemDll(Process, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a handle for the Process */
|
/* Create a handle for the Process */
|
||||||
|
|
|
@ -36,6 +36,14 @@ static GENERIC_MAPPING PiThreadMapping = {
|
||||||
extern ULONG NtBuildNumber;
|
extern ULONG NtBuildNumber;
|
||||||
extern ULONG NtMajorVersion;
|
extern ULONG NtMajorVersion;
|
||||||
extern ULONG NtMinorVersion;
|
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
|
VOID
|
||||||
INIT_FUNCTION
|
INIT_FUNCTION
|
||||||
|
@ -274,6 +282,229 @@ PspPostInitSystemProcess(VOID)
|
||||||
KEBUGCHECK(0);
|
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
|
* NAME EXPORTED
|
||||||
* PsGetVersion
|
* PsGetVersion
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
extern LIST_ENTRY PsActiveProcessHead;
|
extern LIST_ENTRY PsActiveProcessHead;
|
||||||
extern PEPROCESS PsIdleProcess;
|
extern PEPROCESS PsIdleProcess;
|
||||||
|
extern PVOID PspSystemDllEntryPoint;
|
||||||
|
|
||||||
POBJECT_TYPE EXPORTED PsThreadType = NULL;
|
POBJECT_TYPE EXPORTED PsThreadType = NULL;
|
||||||
|
|
||||||
|
@ -57,7 +58,7 @@ PspUserThreadStartup(PKSTART_ROUTINE StartRoutine,
|
||||||
OriginalApcEnvironment,
|
OriginalApcEnvironment,
|
||||||
PspThreadSpecialApc,
|
PspThreadSpecialApc,
|
||||||
NULL,
|
NULL,
|
||||||
LdrpGetSystemDllEntryPoint(),
|
PspSystemDllEntryPoint,
|
||||||
UserMode,
|
UserMode,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue