diff --git a/reactos/ntoskrnl/ex/callback.c b/reactos/ntoskrnl/ex/callback.c index f18f33944eb..371064b1cd8 100644 --- a/reactos/ntoskrnl/ex/callback.c +++ b/reactos/ntoskrnl/ex/callback.c @@ -71,6 +71,8 @@ KEVENT ExpCallbackEvent; * TRUE if the Callback Object Type was successfully created. */ VOID +INIT_FUNCTION +STDCALL ExpInitializeCallbacks(VOID) { OBJECT_ATTRIBUTES ObjectAttributes; diff --git a/reactos/ntoskrnl/ex/event.c b/reactos/ntoskrnl/ex/event.c index 7625168b4b0..368e79d8b51 100644 --- a/reactos/ntoskrnl/ex/event.c +++ b/reactos/ntoskrnl/ex/event.c @@ -34,6 +34,7 @@ static const INFORMATION_CLASS_INFO ExEventInfoClass[] = { VOID INIT_FUNCTION +STDCALL ExpInitializeEventImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/evtpair.c b/reactos/ntoskrnl/ex/evtpair.c index 545ffef13ea..0ce88dcab30 100644 --- a/reactos/ntoskrnl/ex/evtpair.c +++ b/reactos/ntoskrnl/ex/evtpair.c @@ -31,6 +31,7 @@ static GENERIC_MAPPING ExEventPairMapping = { VOID INIT_FUNCTION +STDCALL ExpInitializeEventPairImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 8f471f00434..fdf708df666 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -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 */ diff --git a/reactos/ntoskrnl/ex/lookas.c b/reactos/ntoskrnl/ex/lookas.c index 770faebbb02..4076a7e8086 100644 --- a/reactos/ntoskrnl/ex/lookas.c +++ b/reactos/ntoskrnl/ex/lookas.c @@ -26,6 +26,7 @@ KSPIN_LOCK ExpPagedLookasideListLock; VOID INIT_FUNCTION +STDCALL ExpInitLookasideLists() { /* Initialize Lock and Listhead */ diff --git a/reactos/ntoskrnl/ex/mutant.c b/reactos/ntoskrnl/ex/mutant.c index 8790ce21269..52ca69eca19 100644 --- a/reactos/ntoskrnl/ex/mutant.c +++ b/reactos/ntoskrnl/ex/mutant.c @@ -51,6 +51,7 @@ ExpDeleteMutant(PVOID ObjectBody) VOID INIT_FUNCTION +STDCALL ExpInitializeMutantImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/profile.c b/reactos/ntoskrnl/ex/profile.c index 6dd52492a43..0644d9601d6 100644 --- a/reactos/ntoskrnl/ex/profile.c +++ b/reactos/ntoskrnl/ex/profile.c @@ -74,6 +74,7 @@ ExpDeleteProfile(PVOID ObjectBody) VOID INIT_FUNCTION +STDCALL ExpInitializeProfileImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/sem.c b/reactos/ntoskrnl/ex/sem.c index b4d85c01f56..55d886e5d48 100644 --- a/reactos/ntoskrnl/ex/sem.c +++ b/reactos/ntoskrnl/ex/sem.c @@ -32,6 +32,7 @@ static const INFORMATION_CLASS_INFO ExSemaphoreInfoClass[] = { VOID INIT_FUNCTION +STDCALL ExpInitializeSemaphoreImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index 89f5ad98c1a..6e34248e2a4 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -27,7 +27,9 @@ ULONG ExpTimeZoneId; /* FUNCTIONS ****************************************************************/ -VOID INIT_FUNCTION +VOID +INIT_FUNCTION +STDCALL ExpInitTimeZoneInfo(VOID) { LARGE_INTEGER CurrentTime; diff --git a/reactos/ntoskrnl/ex/timer.c b/reactos/ntoskrnl/ex/timer.c index 9bbaadf145d..1237fb53625 100644 --- a/reactos/ntoskrnl/ex/timer.c +++ b/reactos/ntoskrnl/ex/timer.c @@ -221,6 +221,7 @@ ExpTimerApcKernelRoutine(PKAPC Apc, VOID INIT_FUNCTION +STDCALL ExpInitializeTimerImplementation(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/uuid.c b/reactos/ntoskrnl/ex/uuid.c index 7bb415650e1..bfb75580c7c 100644 --- a/reactos/ntoskrnl/ex/uuid.c +++ b/reactos/ntoskrnl/ex/uuid.c @@ -41,7 +41,9 @@ static ULONG UuidCount; /* FUNCTIONS ****************************************************************/ -VOID INIT_FUNCTION +VOID +INIT_FUNCTION +STDCALL ExpInitUuids(VOID) { ExInitializeFastMutex(&UuidMutex); diff --git a/reactos/ntoskrnl/ex/win32k.c b/reactos/ntoskrnl/ex/win32k.c index 6d969f5ef80..7f86bb2be00 100644 --- a/reactos/ntoskrnl/ex/win32k.c +++ b/reactos/ntoskrnl/ex/win32k.c @@ -119,6 +119,7 @@ ExpDesktopDelete(PVOID DeletedObject) VOID INIT_FUNCTION +STDCALL ExpWin32kInit(VOID) { OBJECT_TYPE_INITIALIZER ObjectTypeInitializer; diff --git a/reactos/ntoskrnl/ex/work.c b/reactos/ntoskrnl/ex/work.c index 90608d161f5..ff6a24c24ec 100644 --- a/reactos/ntoskrnl/ex/work.c +++ b/reactos/ntoskrnl/ex/work.c @@ -132,6 +132,7 @@ ExpInitializeWorkQueue(WORK_QUEUE_TYPE WorkQueueType, VOID INIT_FUNCTION +STDCALL ExpInitializeWorkerThreads(VOID) { ULONG WorkQueueType; diff --git a/reactos/ntoskrnl/include/internal/ex.h b/reactos/ntoskrnl/include/internal/ex.h index 7f3322631a1..7b0cf905895 100644 --- a/reactos/ntoskrnl/include/internal/ex.h +++ b/reactos/ntoskrnl/include/internal/ex.h @@ -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 ***************************************************/ diff --git a/reactos/ntoskrnl/include/internal/ke.h b/reactos/ntoskrnl/include/internal/ke.h index 40830894598..77d5b51dc8f 100644 --- a/reactos/ntoskrnl/include/internal/ke.h +++ b/reactos/ntoskrnl/include/internal/ke.h @@ -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 diff --git a/reactos/ntoskrnl/include/internal/ldr.h b/reactos/ntoskrnl/include/internal/ldr.h index 7cfaec78fab..73bfde37f85 100644 --- a/reactos/ntoskrnl/include/internal/ldr.h +++ b/reactos/ntoskrnl/include/internal/ldr.h @@ -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, diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h index 2894640ce44..12f4f13f398 100644 --- a/reactos/ntoskrnl/include/internal/ps.h +++ b/reactos/ntoskrnl/include/internal/ps.h @@ -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); diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 5036825ca29..ef5e42503f5 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -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; } diff --git a/reactos/ntoskrnl/ke/catch.c b/reactos/ntoskrnl/ke/catch.c index 56a552d79c1..97a83f5a02a 100644 --- a/reactos/ntoskrnl/ke/catch.c +++ b/reactos/ntoskrnl/ke/catch.c @@ -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; } diff --git a/reactos/ntoskrnl/ke/i386/exp.c b/reactos/ntoskrnl/ke/i386/exp.c index fadbf129add..f21c45edf9e 100644 --- a/reactos/ntoskrnl/ke/i386/exp.c +++ b/reactos/ntoskrnl/ke/i386/exp.c @@ -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); } diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index f999e5f8277..70e19f7c8c2 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -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 */ diff --git a/reactos/ntoskrnl/ke/usercall.c b/reactos/ntoskrnl/ke/usercall.c index 96592954e0b..b7f7ac0056a 100644 --- a/reactos/ntoskrnl/ke/usercall.c +++ b/reactos/ntoskrnl/ke/usercall.c @@ -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; diff --git a/reactos/ntoskrnl/ldr/init.c b/reactos/ntoskrnl/ldr/init.c deleted file mode 100644 index 2ceac6a632a..00000000000 --- a/reactos/ntoskrnl/ldr/init.c +++ /dev/null @@ -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 - -#define NDEBUG -#include - -/* 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 */ diff --git a/reactos/ntoskrnl/ldr/sysdll.c b/reactos/ntoskrnl/ldr/sysdll.c deleted file mode 100644 index 44e69896660..00000000000 --- a/reactos/ntoskrnl/ldr/sysdll.c +++ /dev/null @@ -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 -#define NDEBUG -#include - -/* 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 */ diff --git a/reactos/ntoskrnl/ldr/userldr.c b/reactos/ntoskrnl/ldr/userldr.c deleted file mode 100644 index 136ef09166f..00000000000 --- a/reactos/ntoskrnl/ldr/userldr.c +++ /dev/null @@ -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 -#define NDEBUG -#include - - -/* 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); -} diff --git a/reactos/ntoskrnl/ntoskrnl.xml b/reactos/ntoskrnl/ntoskrnl.xml index 8da017e248b..8445ea943df 100644 --- a/reactos/ntoskrnl/ntoskrnl.xml +++ b/reactos/ntoskrnl/ntoskrnl.xml @@ -212,12 +212,9 @@ kdmain.c - init.c loader.c resource.c rtl.c - sysdll.c - userldr.c close.c diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index a73ea57eb48..06de86f6f65 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -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 */ diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index 4b5ea867dd2..b68a454a2c6 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -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 diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 763ea5fbef8..3838dfd1bd3 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -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);