Mini-merge from my local changes. Rewrite of Process Creation. Notable
improvements:
- Subsystemization of Process Creation code. Memory code done by new
Mm functions (not all used yet),
Kernel code done by Ke*, etc.
- Written to be compatible with the information in "Windows
Internals".
- Optimized and cleaned up.
- ObInsertObject is now called at the end, fixing a plethora of
wrong things that were covered with FIXMEs.
- PEB is allocated with a Memory Area, and so will TEB soon, which
allows 4KB allocation without 64KB gra
nularity.
- System DLL Mapping/Loading has been changed to be cached at system
bootup, resulting in faster code.
Also changed Peb to report NT 5.0
NOTE: Messy, more to come soon. The full benefits of this patch won't be
realized until the complete changes
are in.
Modified: trunk/reactos/ntoskrnl/Makefile
Modified: trunk/reactos/ntoskrnl/ex/init.c
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
Modified: trunk/reactos/ntoskrnl/include/internal/ldr.h
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
Modified: trunk/reactos/ntoskrnl/include/internal/se.h
Modified: trunk/reactos/ntoskrnl/ke/apc.c
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
Modified: trunk/reactos/ntoskrnl/ke/main.c
Modified: trunk/reactos/ntoskrnl/ke/process.c
Modified: trunk/reactos/ntoskrnl/ke/wait.c
Modified: trunk/reactos/ntoskrnl/ldr/sysdll.c
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
Modified: trunk/reactos/ntoskrnl/mm/mm.c
Modified: trunk/reactos/ntoskrnl/ob/wait.c
Modified: trunk/reactos/ntoskrnl/ps/create.c
Modified: trunk/reactos/ntoskrnl/ps/process.c
Modified: trunk/reactos/ntoskrnl/ps/security.c
Modified: trunk/reactos/ntoskrnl/se/token.c
_____
Modified: trunk/reactos/ntoskrnl/Makefile
--- trunk/reactos/ntoskrnl/Makefile 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/Makefile 2005-04-18 00:42:31 UTC (rev
14660)
@@ -144,6 +144,7 @@
mm/pool.o \
mm/ppool.o \
mm/physical.o \
+ mm/process.o \
mm/region.o \
mm/rmap.o \
mm/section.o \
_____
Modified: trunk/reactos/ntoskrnl/ex/init.c
--- trunk/reactos/ntoskrnl/ex/init.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ex/init.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -494,7 +494,7 @@
/* Initialize I/O Objects, Filesystems, Error Logging and Shutdown
*/
IoInit();
-
+
/* TBD */
PoInit((PLOADER_PARAMETER_BLOCK)&KeLoaderBlock, ForceAcpiDisable);
@@ -562,6 +562,9 @@
/* Create ARC Names, SystemRoot SymLink, Load Drivers and Assign
Letters */
IoInit3();
+
+ /* Load the System DLL and its Entrypoints */
+ LdrpInitializeSystemDll();
/* Initialize the Default Locale */
PiInitDefaultLocale();
_____
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h
--- trunk/reactos/ntoskrnl/include/internal/ke.h 2005-04-17
20:46:36 UTC (rev 14659)
+++ trunk/reactos/ntoskrnl/include/internal/ke.h 2005-04-18
00:42:31 UTC (rev 14660)
@@ -259,7 +259,14 @@
KiAbortWaitThread(PKTHREAD Thread,
NTSTATUS WaitStatus,
KPRIORITY Increment);
-
+
+VOID
+STDCALL
+KeInitializeProcess(struct _KPROCESS *Process,
+ KPRIORITY Priority,
+ KAFFINITY Affinity,
+ LARGE_INTEGER DirectoryTableBase);
+
ULONG
STDCALL
KeForceResumeThread(IN PKTHREAD Thread);
_____
Modified: trunk/reactos/ntoskrnl/include/internal/ldr.h
--- trunk/reactos/ntoskrnl/include/internal/ldr.h 2005-04-17
20:46:36 UTC (rev 14659)
+++ trunk/reactos/ntoskrnl/include/internal/ldr.h 2005-04-18
00:42:31 UTC (rev 14660)
@@ -34,10 +34,18 @@
);
NTSTATUS
-LdrpMapSystemDll (
- HANDLE ProcessHandle,
- PVOID * LdrStartupAddress
- );
+STDCALL
+LdrpMapSystemDll(PEPROCESS Process,
+ PVOID *DllBase);
+
+NTSTATUS
+STDCALL
+LdrpInitializeSystemDll(VOID);
+
+NTSTATUS
+STDCALL
+LdrpGetSystemDllEntryPoints(VOID);
+
PVOID
LdrpGetSystemDllEntryPoint (VOID);
PVOID
_____
Modified: trunk/reactos/ntoskrnl/include/internal/mm.h
--- trunk/reactos/ntoskrnl/include/internal/mm.h 2005-04-17
20:46:36 UTC (rev 14659)
+++ trunk/reactos/ntoskrnl/include/internal/mm.h 2005-04-18
00:42:31 UTC (rev 14660)
@@ -37,6 +37,7 @@
#define MEMORY_AREA_KERNEL_STACK (11)
#define MEMORY_AREA_PAGED_POOL (12)
#define MEMORY_AREA_NO_ACCESS (13)
+#define MEMORY_AREA_PEB_OR_TEB (14)
#define PAGE_TO_SECTION_PAGE_DIRECTORY_OFFSET(x) \
((x) / (4*1024*1024))
@@ -496,6 +497,17 @@
VOID MmShowOutOfSpaceMessagePagingFile(VOID);
+/* process.c
****************************************************************/
+
+NTSTATUS
+STDCALL
+MmCreateProcessAddressSpace(IN struct _EPROCESS* Process,
+ IN PSECTION_OBJECT Section OPTIONAL);
+
+NTSTATUS
+STDCALL
+MmCreatePeb(PEPROCESS Process);
+
/* i386/pfault.c
*************************************************************/
NTSTATUS MmPageFault(ULONG Cs,
@@ -579,6 +591,17 @@
VOID
MmInitializePageOp(VOID);
+/* process.c
*****************************************************************/
+
+PVOID
+STDCALL
+MmCreateKernelStack(BOOLEAN GuiStack);
+
+VOID
+STDCALL
+MmDeleteKernelStack(PVOID Stack,
+ BOOLEAN GuiStack);
+
/* balace.c
******************************************************************/
VOID MmInitializeMemoryConsumer(ULONG Consumer,
@@ -737,7 +760,11 @@
PFN_TYPE MmGetPfnForProcess(struct _EPROCESS* Process, PVOID Address);
-NTSTATUS MmCopyMmInfo(struct _EPROCESS* Src, struct _EPROCESS* Dest);
+NTSTATUS
+STDCALL
+MmCopyMmInfo(struct _EPROCESS* Src,
+ struct _EPROCESS* Dest,
+ PPHYSICAL_ADDRESS DirectoryTableBase);
NTSTATUS MmReleaseMmInfo(struct _EPROCESS* Process);
_____
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
--- trunk/reactos/ntoskrnl/include/internal/ps.h 2005-04-17
20:46:36 UTC (rev 14659)
+++ trunk/reactos/ntoskrnl/include/internal/ps.h 2005-04-18
00:42:31 UTC (rev 14660)
@@ -492,6 +492,11 @@
PVOID *NormalContext,
PVOID *SystemArgument1,
PVOID *SystemArgument2);
+
+NTSTATUS
+STDCALL
+PspInitializeProcessSecurity(PEPROCESS Process,
+ PEPROCESS Parent OPTIONAL);
#define THREAD_STATE_INITIALIZED (0)
#define THREAD_STATE_READY (1)
_____
Modified: trunk/reactos/ntoskrnl/include/internal/se.h
--- trunk/reactos/ntoskrnl/include/internal/se.h 2005-04-17
20:46:36 UTC (rev 14659)
+++ trunk/reactos/ntoskrnl/include/internal/se.h 2005-04-18
00:42:31 UTC (rev 14660)
@@ -117,9 +117,7 @@
VOID SepInitializeTokenImplementation(VOID);
-NTSTATUS SepCreateSystemProcessToken(struct _EPROCESS* Process);
-NTSTATUS SepInitializeNewProcess(struct _EPROCESS* NewProcess,
- struct _EPROCESS* ParentProcess);
+PTOKEN STDCALL SepCreateSystemProcessToken(VOID);
NTSTATUS SeExchangePrimaryToken(struct _EPROCESS* Process,
PACCESS_TOKEN NewToken,
@@ -149,6 +147,16 @@
KPROCESSOR_MODE PreviousMode);
NTSTATUS
+STDCALL
+SepDuplicateToken(PTOKEN Token,
+ POBJECT_ATTRIBUTES ObjectAttributes,
+ BOOLEAN EffectiveOnly,
+ TOKEN_TYPE TokenType,
+ SECURITY_IMPERSONATION_LEVEL Level,
+ KPROCESSOR_MODE PreviousMode,
+ PTOKEN* NewAccessToken);
+
+NTSTATUS
SepCaptureSecurityQualityOfService(IN POBJECT_ATTRIBUTES
ObjectAttributes OPTIONAL,
IN KPROCESSOR_MODE AccessMode,
IN POOL_TYPE PoolType,
_____
Modified: trunk/reactos/ntoskrnl/ke/apc.c
--- trunk/reactos/ntoskrnl/ke/apc.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ke/apc.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -756,6 +756,7 @@
Esp[4] = (ULONG)SystemArgument2;
Esp[5] = (ULONG)Context;
TrapFrame->Eip = (ULONG)LdrpGetSystemDllApcDispatcher();
+ DPRINT("TrapFrame->Eip: %x\n", TrapFrame->Eip);
TrapFrame->Esp = (ULONG)Esp;
}
_____
Modified: trunk/reactos/ntoskrnl/ke/kthread.c
--- trunk/reactos/ntoskrnl/ke/kthread.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ke/kthread.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -205,13 +205,14 @@
} else {
/* Set the Thread Data as Requested */
- DPRINT("Dispatching Thread as blocked\n");
+ DPRINT("Dispatching Thread as blocked: %d\n",
Thread->WaitStatus);
Thread->Alertable = Alertable;
Thread->WaitMode = (UCHAR)WaitMode;
Thread->WaitReason = WaitReason;
/* Dispatch it and return status */
KiDispatchThreadNoLock(THREAD_STATE_BLOCKED);
+ DPRINT("Dispatching Thread as blocked: %d\n",
Thread->WaitStatus);
if (Status != NULL) *Status = Thread->WaitStatus;
}
_____
Modified: trunk/reactos/ntoskrnl/ke/main.c
--- trunk/reactos/ntoskrnl/ke/main.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ke/main.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -19,7 +19,7 @@
#define BUILD_OSCSDVERSION(major, minor) (((major & 0xFF) << 8) |
(minor & 0xFF))
-ULONG NtMajorVersion = 4;
+ULONG NtMajorVersion = 5;
ULONG NtMinorVersion = 0;
ULONG NtOSCSDVersion = BUILD_OSCSDVERSION(6, 0);
#ifdef __GNUC__
_____
Modified: trunk/reactos/ntoskrnl/ke/process.c
--- trunk/reactos/ntoskrnl/ke/process.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ke/process.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -53,6 +53,35 @@
MmUpdatePageDir((PEPROCESS)Process, (PVOID)Thread,
sizeof(ETHREAD));
}
+VOID
+STDCALL
+KeInitializeProcess(PKPROCESS Process,
+ KPRIORITY Priority,
+ KAFFINITY Affinity,
+ LARGE_INTEGER DirectoryTableBase)
+{
+ DPRINT1("KeInitializeProcess. Process: %x, DirectoryTableBase:
%x\n", Process, DirectoryTableBase);
+
+ /* Initialize the Dispatcher Header */
+ KeInitializeDispatcherHeader(&Process->DispatcherHeader,
+ ProcessObject,
+ sizeof(KPROCESS),
+ FALSE);
+
+ /* Initialize Scheduler Data, Disable Alignment Faults and Set the
PDE */
+ Process->Affinity = Affinity;
+ Process->BasePriority = Priority;
+ Process->ThreadQuantum = 6;
+ Process->DirectoryTableBase = DirectoryTableBase;
+ Process->AutoAlignment = TRUE;
+ Process->IopmOffset = 0xFFFF;
+ Process->State = PROCESS_STATE_ACTIVE;
+
+ /* Initialize the Thread List */
+ InitializeListHead(&Process->ThreadListHead);
+ DPRINT1("The Process has now been initalized with the Kernel\n");
+}
+
ULONG
STDCALL
KeSetProcess(PKPROCESS Process,
@@ -148,6 +177,7 @@
}
/* Swap the Processes */
+ DPRINT("Swapping\n");
KiSwapProcess(Process, SavedApcState->Process);
/* Return to old IRQL*/
_____
Modified: trunk/reactos/ntoskrnl/ke/wait.c
--- trunk/reactos/ntoskrnl/ke/wait.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ke/wait.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -445,7 +445,6 @@
*/
if (CurrentObject->Type == IO_TYPE_FILE) {
- DPRINT1("Hack used: %x\n",
&((PFILE_OBJECT)CurrentObject)->Event);
CurrentObject =
(PDISPATCHER_HEADER)(&((PFILE_OBJECT)CurrentObject)->Event);
}
@@ -571,7 +570,7 @@
DPRINT("Waking Queue\n");
KiWakeQueue(CurrentThread->Queue);
}
-
+
/* Block the Thread */
DPRINT("Blocking the Thread: %d, %d, %d, %x\n", Alertable,
WaitMode, WaitReason, KeGetCurrentThread());
KiBlockThread(&Status,
_____
Modified: trunk/reactos/ntoskrnl/ldr/sysdll.c
--- trunk/reactos/ntoskrnl/ldr/sysdll.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ldr/sysdll.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -24,6 +24,9 @@
PVOID SystemDllExceptionDispatcher = NULL;
PVOID SystemDllRaiseExceptionDispatcher = NULL;
+PVOID LdrpSystemDllBase = NULL;
+PVOID LdrpSystemDllSection = NULL;
+
/* FUNCTIONS
*****************************************************************/
PVOID LdrpGetSystemDllExceptionDispatcher(VOID)
@@ -51,282 +54,223 @@
return(SystemDllRaiseExceptionDispatcher);
}
-NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
- PVOID* LdrStartupAddr)
-/*
- * FUNCTION: LdrpMapSystemDll maps the system dll into the specified
process
- * address space and returns its startup address.
- * PARAMETERS:
- * ProcessHandle
- * Points to the process to map the system dll into
- *
- * LdrStartupAddress
- * Receives the startup address of the system dll on
function
- * completion
- *
- * RETURNS: Status
- */
+NTSTATUS
+STDCALL
+LdrpGetSystemDllEntryPoints(VOID)
{
- CHAR BlockBuffer [1024];
- DWORD ImageBase;
- ULONG ImageSize;
- NTSTATUS Status;
- OBJECT_ATTRIBUTES FileObjectAttributes;
- HANDLE FileHandle;
- HANDLE NTDllSectionHandle;
- UNICODE_STRING DllPathname =
ROS_STRING_INITIALIZER(L"\\SystemRoot\\system32\\ntdll.dll");
- PIMAGE_DOS_HEADER DosHeader;
- PIMAGE_NT_HEADERS NTHeaders;
- PEPROCESS Process, CurrentProcess;
- ANSI_STRING ProcedureName;
- ULONG ViewSize;
- IO_STATUS_BLOCK Iosb;
+ 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);
+ }
- /*
- * 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;
- }
- 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;
- }
+ /* 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);
+ }
- /*
- * FIXME: this will fail if the NT headers are
- * more than 1024 bytes from start.
- */
- 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);
- }
- ImageBase = NTHeaders->OptionalHeader.ImageBase;
- ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
-
- /*
- * 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);
-
- /*
- * Map the NTDLL into the process
- */
- ViewSize = 0;
- ImageBase = 0;
- Status = ZwMapViewOfSection(NTDllSectionHandle,
- ProcessHandle,
- (PVOID*)&ImageBase,
- 0,
- ViewSize,
- NULL,
- &ViewSize,
- 0,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NTDLL map view of secion failed (Status %x)", Status);
- ZwClose(NTDllSectionHandle);
- return(Status);
- }
+ /* Return success */
+ return(STATUS_SUCCESS);
+}
- DPRINT("Referencing process\n");
- Status = ObReferenceObjectByHandle(ProcessHandle,
- PROCESS_ALL_ACCESS,
- PsProcessType,
- KernelMode,
- (PVOID*)&Process,
- NULL);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("ObReferenceObjectByProcess() failed (Status %x)\n",
Status);
- return(Status);
- }
+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;
+}
- CurrentProcess = PsGetCurrentProcess();
- if (Process != CurrentProcess)
- {
- DPRINT("Attaching to Process\n");
- KeAttachProcess(&Process->Pcb);
+NTSTATUS
+STDCALL
+LdrpInitializeSystemDll(VOID)
+{
+ UNICODE_STRING DllPathname =
ROS_STRING_INITIALIZER(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;
}
-
- /*
- * retrieve ntdll's startup address
- */
- if (SystemDllEntryPoint == NULL)
- {
- RtlInitAnsiString (&ProcedureName,
- "LdrInitializeThunk");
- Status = LdrGetProcedureAddress ((PVOID)ImageBase,
- &ProcedureName,
- 0,
- &SystemDllEntryPoint);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n",
Status);
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
- ZwClose(NTDllSectionHandle);
- return (Status);
- }
- *LdrStartupAddr = SystemDllEntryPoint;
- }
-
- /*
- * Retrieve the offset of the APC dispatcher from NTDLL
- */
- if (SystemDllApcDispatcher == NULL)
- {
- RtlInitAnsiString (&ProcedureName,
- "KiUserApcDispatcher");
- Status = LdrGetProcedureAddress ((PVOID)ImageBase,
- &ProcedureName,
- 0,
- &SystemDllApcDispatcher);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n",
Status);
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
- ZwClose(NTDllSectionHandle);
- return (Status);
- }
- }
-
- /*
- * Retrieve the offset of the exception dispatcher from NTDLL
- */
- if (SystemDllExceptionDispatcher == NULL)
- {
- RtlInitAnsiString (&ProcedureName,
- "KiUserExceptionDispatcher");
- Status = LdrGetProcedureAddress ((PVOID)ImageBase,
- &ProcedureName,
- 0,
- &SystemDllExceptionDispatcher);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n",
Status);
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
- ZwClose(NTDllSectionHandle);
- return (Status);
- }
- }
-
- /*
- * Retrieve the offset of the callback dispatcher from NTDLL
- */
- if (SystemDllCallbackDispatcher == NULL)
- {
- RtlInitAnsiString (&ProcedureName,
- "KiUserCallbackDispatcher");
- Status = LdrGetProcedureAddress ((PVOID)ImageBase,
- &ProcedureName,
- 0,
- &SystemDllCallbackDispatcher);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n",
Status);
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
- ZwClose(NTDllSectionHandle);
- return (Status);
- }
- }
-
- /*
- * Retrieve the offset of the raise exception dispatcher from NTDLL
- */
- if (SystemDllRaiseExceptionDispatcher == NULL)
- {
- RtlInitAnsiString (&ProcedureName,
- "KiRaiseUserExceptionDispatcher");
- Status = LdrGetProcedureAddress ((PVOID)ImageBase,
- &ProcedureName,
- 0,
-
&SystemDllRaiseExceptionDispatcher);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1 ("LdrGetProcedureAddress failed (Status %x)\n",
Status);
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
- ZwClose(NTDllSectionHandle);
- return (Status);
- }
- }
-
- if (Process != CurrentProcess)
- {
- KeDetachProcess();
- }
- ObDereferenceObject(Process);
-
- ZwClose(NTDllSectionHandle);
-
- return(STATUS_SUCCESS);
+
+ /* 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 */
_____
Modified: trunk/reactos/ntoskrnl/mm/i386/page.c
--- trunk/reactos/ntoskrnl/mm/i386/page.c 2005-04-17 20:46:36 UTC
(rev 14659)
+++ trunk/reactos/ntoskrnl/mm/i386/page.c 2005-04-18 00:42:31 UTC
(rev 14660)
@@ -319,9 +319,12 @@
return(STATUS_SUCCESS);
}
-NTSTATUS MmCopyMmInfo(PEPROCESS Src, PEPROCESS Dest)
+NTSTATUS
+STDCALL
+MmCopyMmInfo(PEPROCESS Src,
+ PEPROCESS Dest,
+ PPHYSICAL_ADDRESS DirectoryTableBase)
{
- PKPROCESS KProcess = &Dest->Pcb;
NTSTATUS Status;
ULONG i, j;
PFN_TYPE Pfn[7];
@@ -389,8 +392,9 @@
MmDeleteHyperspaceMapping(PageDirectory);
}
- KProcess->DirectoryTableBase.QuadPart = PFN_TO_PTE(Pfn[0]);
- DPRINT("Finished MmCopyMmInfo()\n");
+
+ DirectoryTableBase->QuadPart = PFN_TO_PTE(Pfn[0]);
+ DPRINT("Finished MmCopyMmInfo(): %I64x\n",
DirectoryTableBase->QuadPart);
return(STATUS_SUCCESS);
}
_____
Modified: trunk/reactos/ntoskrnl/mm/mm.c
--- trunk/reactos/ntoskrnl/mm/mm.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/mm/mm.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -384,6 +384,7 @@
break;
case MEMORY_AREA_VIRTUAL_MEMORY:
+ case MEMORY_AREA_PEB_OR_TEB:
Status = MmNotPresentFaultVirtualMemory(AddressSpace,
MemoryArea,
(PVOID)Address,
_____
Modified: trunk/reactos/ntoskrnl/ob/wait.c
--- trunk/reactos/ntoskrnl/ob/wait.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ob/wait.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -111,7 +111,7 @@
UserRequest,
PreviousMode,
Alertable,
- TimeOut,
+ TimeOut,
WaitBlockArray);
/* dereference all objects */
_____
Modified: trunk/reactos/ntoskrnl/ps/create.c
--- trunk/reactos/ntoskrnl/ps/create.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ps/create.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -473,7 +473,6 @@
UserMode,
NULL );
KeInsertQueueApc(LdrInitApc, NULL, NULL, IO_NO_INCREMENT);
-
/*
* The thread is non-alertable, so the APC we added did not set
UserApcPending to TRUE.
* We must do this manually. Do NOT attempt to set the Thread to
Alertable before the call,
_____
Modified: trunk/reactos/ntoskrnl/ps/process.c
--- trunk/reactos/ntoskrnl/ps/process.c 2005-04-17 20:46:36 UTC (rev
14659)
+++ trunk/reactos/ntoskrnl/ps/process.c 2005-04-18 00:42:31 UTC (rev
14660)
@@ -41,8 +41,7 @@
PiProcessNotifyRoutine[MAX_PROCESS_NOTIFY_ROUTINE_COUNT];
static PLOAD_IMAGE_NOTIFY_ROUTINE
PiLoadImageNotifyRoutine[MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT];
-
-
+
/* FUNCTIONS
*****************************************************************/
PEPROCESS
@@ -113,8 +112,7 @@
PLIST_ENTRY current_entry;
PEPROCESS current;
- ExAcquireFastMutex(&PspActiveProcessMutex);
-
+ ExAcquireFastMutex(&PspActiveProcessMutex);
current_entry = PsActiveProcessHead.Flink;
while (current_entry != &PsActiveProcessHead)
{
@@ -271,8 +269,16 @@
InsertHeadList(&PsActiveProcessHead,
&PsInitialSystemProcess->ProcessListEntry);
InitializeListHead(&PsInitialSystemProcess->ThreadListHead);
-
- SepCreateSystemProcessToken(PsInitialSystemProcess);
+
+#ifndef SCHED_REWRITE
+ PTOKEN BootToken;
+
+ /* No parent, this is the Initial System Process. Assign Boot Token
*/
+ BootToken = SepCreateSystemProcessToken();
+ BootToken->TokenInUse = TRUE;
+ PsInitialSystemProcess->Token = BootToken;
+ ObReferenceObject(BootToken);
+#endif
}
VOID
@@ -298,99 +304,6 @@
}
}
-static NTSTATUS
-PsCreatePeb(HANDLE ProcessHandle,
- PEPROCESS Process,
- PVOID ImageBase)
-{
- ULONG AllocSize;
- ULONG PebSize;
- PPEB Peb;
- LARGE_INTEGER SectionOffset;
- ULONG ViewSize;
- PVOID TableBase;
- NTSTATUS Status;
-
- PAGED_CODE();
-
- /* Allocate the Process Environment Block (PEB) */
- Process->TebBlock = (PVOID) MM_ROUND_DOWN(PEB_BASE,
MM_VIRTMEM_GRANULARITY);
- AllocSize = MM_VIRTMEM_GRANULARITY;
- Status = NtAllocateVirtualMemory(ProcessHandle,
- &Process->TebBlock,
- 0,
- &AllocSize,
- MEM_RESERVE,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtAllocateVirtualMemory() failed (Status %lx)\n",
Status);
- return(Status);
- }
- ASSERT((ULONG_PTR) Process->TebBlock <= PEB_BASE &&
- PEB_BASE + PAGE_SIZE <= (ULONG_PTR) Process->TebBlock +
AllocSize);
- Peb = (PPEB)PEB_BASE;
- PebSize = PAGE_SIZE;
- Status = NtAllocateVirtualMemory(ProcessHandle,
- (PVOID*)&Peb,
- 0,
- &PebSize,
- MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtAllocateVirtualMemory() failed (Status %lx)\n",
Status);
- return(Status);
- }
- DPRINT("Peb %p PebSize %lu\n", Peb, PebSize);
- ASSERT((PPEB) PEB_BASE == Peb && PAGE_SIZE <= PebSize);
- Process->TebLastAllocated = (PVOID) Peb;
-
- ViewSize = 0;
- SectionOffset.QuadPart = (ULONGLONG)0;
- TableBase = NULL;
- Status = MmMapViewOfSection(NlsSectionObject,
- Process,
- &TableBase,
- 0,
- 0,
- &SectionOffset,
- &ViewSize,
- ViewShare,
- MEM_TOP_DOWN,
- PAGE_READONLY);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("MmMapViewOfSection() failed (Status %lx)\n", Status);
- return(Status);
- }
- DPRINT("TableBase %p ViewSize %lx\n", TableBase, ViewSize);
-
- KeAttachProcess(&Process->Pcb);
-
- /* Initialize the PEB */
- RtlZeroMemory(Peb, sizeof(PEB));
[truncated at 1000 lines; 932 more skipped]