Moved user-process loading into ZwCreateProcess

svn path=/trunk/; revision=983
This commit is contained in:
David Welch 2000-02-13 16:05:19 +00:00
parent ca7bca8f84
commit c110a36a78
31 changed files with 1139 additions and 1086 deletions

View file

@ -35,7 +35,7 @@ LOADERS = dos
#
# Select the device drivers and filesystems you want
#
DEVICE_DRIVERS = blue ide keyboard null parallel serial
DEVICE_DRIVERS = blue ide keyboard null parallel serial vidport vga
# DEVICE_DRIVERS = beep event floppy ide_test mouse sound test test1
FS_DRIVERS = vfat
# FS_DRIVERS = minix ext2 template

View file

@ -19,5 +19,9 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
PVOID* LdrStartupAddress);
PIMAGE_NT_HEADERS RtlImageNtHeader(PVOID BaseAddress);
PVOID LdrpGetSystemDllEntryPoint(VOID);
NTSTATUS LdrpMapImage(HANDLE ProcessHandle,
HANDLE SectionHandle,
PVOID* ImageBase);
#endif /* __INCLUDE_INTERNAL_LDR_H */

View file

@ -168,7 +168,7 @@ typedef struct _NT_TEB
LONG ExceptionCode; // 1A8h
ULONG SpareBytes1[0x28]; // 1ACh
PVOID SystemReserved2[0xA]; // 1D4h
GDI_TEB_BATCH GdiTebBatch; // 1FCh
// GDI_TEB_BATCH GdiTebBatch; // 1FCh
ULONG gdiRgn; // 6DCh
ULONG gdiPen; // 6E0h
ULONG gdiBrush; // 6E4h

View file

@ -91,10 +91,12 @@ HENHMETAFILE W32kSetEnhMetaFileBits(UINT BufSize,
HMETAFILE W32kSetMetaFileBitsEx(UINT Size,
CONST PBYTE Data);
#if 0
HENHMETAFILE W32kSetWinMetaFileBits(UINT BufSize,
CONST PBYTE Buffer,
HDC Ref,
CONST METAFILEPICT *mfp);
#endif
#endif

View file

@ -8,6 +8,8 @@ cp services/fs/vfat/vfatfs.sys $1
cp services/dd/ide/ide.sys $1
cp services/dd/keyboard/keyboard.sys $1/reactos/system32/drivers
cp services/dd/blue/blue.sys $1/reactos/system32/drivers
cp services/dd/vga/vgamp.sys $1/reactos/system32/drivers
cp services/dd/vidport/vidport.sys $1/reactos/system32/drivers
cp apps/shell/shell.exe $1/reactos/system32
cp lib/ntdll/ntdll.dll $1/reactos/system32
cp lib/kernel32/kernel32.dll $1/reactos/system32

View file

@ -1,4 +1,4 @@
/* $Id: stubs.c,v 1.1 1999/05/24 20:04:44 ea Exp $
/* $Id: stubs.c,v 1.2 2000/02/13 16:05:12 dwelch Exp $
*
* reactos/lib/gdi32/misc/stubs.c
*
@ -2221,7 +2221,8 @@ SetWinMetaFileBits(
UINT a0,
CONST BYTE *a1,
HDC a2,
CONST METAFILEPICT *a3
// CONST METAFILEPICT *a3
PVOID a3
)
{
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.29 2000/01/21 23:06:25 phreak Exp $
# $Id: makefile,v 1.30 2000/02/13 16:05:12 dwelch Exp $
#
# ReactOS Operating System
#
@ -156,5 +156,5 @@ else
$(CP) $(TARGET).dll ../../$(DIST_DIR)/dlls/$(TARGET).dll
endif
#WARNINGS_ARE_ERRORS = yes
WARNINGS_ARE_ERRORS = yes

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.19 2000/01/27 08:56:47 dwelch Exp $
/* $Id: create.c,v 1.20 2000/02/13 16:05:13 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -89,16 +89,12 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
#define STACK_TOP (0xb0000000)
HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
PPEB Peb,
DWORD dwCreationFlags,
LPDWORD lpThreadId,
HANDLE NTDllSectionHandle,
HANDLE SectionHandle,
PVOID ImageBase)
HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
DWORD dwCreationFlags,
LPDWORD lpThreadId)
{
NTSTATUS Status;
HANDLE ThreadHandle;
@ -108,8 +104,6 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress;
ULONG BytesWritten;
HANDLE DupNTDllSectionHandle, DupSectionHandle;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
@ -155,67 +149,29 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
NtDuplicateObject(NtCurrentProcess(),
&SectionHandle,
ProcessHandle,
&DupSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
NtDuplicateObject(NtCurrentProcess(),
&NTDllSectionHandle,
ProcessHandle,
&DupNTDllSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
Status = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if (lpThreadId != NULL)
{
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
}
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 4),
&DupNTDllSectionHandle,
sizeof(DupNTDllSectionHandle),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 8),
&ImageBase,
sizeof(ImageBase),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 12),
&DupSectionHandle,
sizeof(DupSectionHandle),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 16),
&Peb,
sizeof(PPEB),
&BytesWritten);
Status = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if ( lpThreadId != NULL )
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
return ThreadHandle;
return(ThreadHandle);
}
HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
LPCWSTR lpCommandLine,
PIMAGE_NT_HEADERS Headers,
PIMAGE_DOS_HEADER DosHeader)
HANDLE KlMapFile(LPCWSTR lpApplicationName,
LPCWSTR lpCommandLine)
{
WCHAR TempApplicationName[256];
WCHAR TempFileName[256];
HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock;
LARGE_INTEGER FileOffset;
ULONG i;
WCHAR TempDirectoryName[256];
UNICODE_STRING ApplicationNameString;
@ -293,40 +249,6 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
return(NULL);
}
Status = NtReadFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
DosHeader,
sizeof(IMAGE_DOS_HEADER),
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return(NULL);
}
FileOffset.u.LowPart = DosHeader->e_lfanew;
FileOffset.u.HighPart = 0;
Status = NtReadFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
Headers,
sizeof(IMAGE_NT_HEADERS),
&FileOffset,
NULL);
if (!NT_SUCCESS(Status))
{
SetLastError(RtlNtStatusToDosError(Status));
return(NULL);
}
Status = NtCreateSection(&hSection,
SECTION_ALL_ACCESS,
NULL,
@ -345,20 +267,15 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
return(hSection);
}
static NTSTATUS
CreatePeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
NTSTATUS Status;
PVOID PebBase;
ULONG PebSize;
PEB Peb;
PVOID PpbBase;
ULONG PpbSize;
ULONG BytesWritten;
ULONG Offset;
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize;
@ -381,33 +298,16 @@ CreatePeb (
&BytesWritten);
/* create the PEB */
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = NtAllocateVirtualMemory(ProcessHandle,
&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
return(Status);
}
DPRINT("Peb created\n");
Peb.ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)PpbBase;
/* create the PPB */
Offset = FIELD_OFFSET(PEB, ProcessParameters);
NtWriteVirtualMemory(ProcessHandle,
PebBase,
&Peb,
sizeof(Peb),
PEB_BASE + Offset,
&PpbBase,
sizeof(PpbBase),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return(STATUS_SUCCESS);
}
@ -438,11 +338,14 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
DWORD len = 0;
PRTL_USER_PROCESS_PARAMETERS Ppb;
UNICODE_STRING CommandLine_U;
PPEB Peb;
DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n",
lpApplicationName,lpCommandLine);
/*
* Process the application name and command line
*/
if (lpApplicationName[1] != ':')
{
len = GetCurrentDirectoryW(MAX_PATH,TempCommandLine);
@ -461,39 +364,49 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
wcscat(TempCommandLine, L" ");
wcscat(TempCommandLine, lpCommandLine);
}
/*
* Create the PPB
*/
RtlInitUnicodeString(&CommandLine_U, TempCommandLine);
RtlInitUnicodeString (
&CommandLine_U,
TempCommandLine);
DPRINT("CommandLine_U %w\n", CommandLine_U.Buffer);
RtlCreateProcessParameters (
&Ppb,
&CommandLine_U,
NULL,
NULL,
NULL,
lpEnvironment,
NULL,
NULL,
NULL,
NULL);
hSection = KERNEL32_MapFile (
lpApplicationName,
lpCommandLine,
&Headers,
&DosHeader);
DPRINT("CommandLine_U %w\n", CommandLine_U.Buffer);
RtlCreateProcessParameters(&Ppb,
&CommandLine_U,
NULL,
NULL,
NULL,
lpEnvironment,
NULL,
NULL,
NULL,
NULL);
/*
* Create a section for the executable
*/
hSection = KlMapFile (lpApplicationName, lpCommandLine);
/*
* Create a new process
*/
Status = NtCreateProcess(&hProcess,
PROCESS_ALL_ACCESS,
NULL,
NtCurrentProcess(),
bInheritHandles,
NULL,
hSection,
NULL,
NULL);
/*
* Get some information about the process
*/
ZwQueryInformationProcess(hProcess,
ProcessBasicInformation,
&ProcessBasicInfo,
@ -503,36 +416,11 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
ProcessBasicInfo.UniqueProcessId);
lpProcessInformation->dwProcessId = ProcessBasicInfo.UniqueProcessId;
/*
* Map NT DLL into the process
*/
InitialViewSize = DosHeader.e_lfanew + sizeof(IMAGE_NT_HEADERS)
+ sizeof(IMAGE_SECTION_HEADER) * Headers.FileHeader.NumberOfSections;
BaseAddress = (PVOID)Headers.OptionalHeader.ImageBase;
SectionOffset.QuadPart = 0;
Status = NtMapViewOfSection(hSection,
hProcess,
&BaseAddress,
0,
InitialViewSize,
&SectionOffset,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
RtlDestroyProcessParameters (Ppb);
SetLastError(RtlNtStatusToDosError(Status));
return FALSE;
}
/*
* Create Process Environment Block
*/
DPRINT("Creating peb\n");
CreatePeb(&Peb, hProcess, Ppb);
KlInitPeb(hProcess, Ppb);
RtlDestroyProcessParameters (Ppb);
@ -541,19 +429,19 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
AddressOfEntryPoint +
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase;
hThread = CreateFirstThread(hProcess,
lpThreadAttributes,
Headers.OptionalHeader.SizeOfStackReserve,
lpStartAddress,
Peb,
dwCreationFlags,
&lpProcessInformation->dwThreadId,
NTDllSection,
hSection,
(PVOID)Headers.OptionalHeader.ImageBase);
if ( hThread == NULL )
return FALSE;
hThread = KlCreateFirstThread(hProcess,
lpThreadAttributes,
// Headers.OptionalHeader.SizeOfStackReserve,
0x200000,
lpStartAddress,
dwCreationFlags,
&lpProcessInformation->dwThreadId);
if (hThread == NULL)
{
return FALSE;
}
lpProcessInformation->hProcess = hProcess;
lpProcessInformation->hThread = hThread;

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.17 2000/02/05 16:07:44 ekohl Exp $
/* $Id: startup.c,v 1.18 2000/02/13 16:05:14 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -20,11 +20,9 @@
#include <wchar.h>
#include <ntdll/ldr.h>
#include <ntdll/rtl.h>
#include <csrss/csrss.h>
//#define DBG_NTDLL_LDR_STARTUP
#ifndef DBG_NTDLL_LDR_STARTUP
#define NDEBUG
#endif
#include <ntdll/ntdll.h>
/* GLOBALS *******************************************************************/
@ -36,45 +34,45 @@ extern HANDLE __ProcessHeap;
/* FUNCTIONS *****************************************************************/
/* LdrStartup
* FUNCTION:
* Handles Process Startup Activities.
* ARGUMENTS:
* DWORD ImageBase The base address of the process image
*/
VOID LdrStartup(PPEB Peb,
HANDLE SectionHandle,
DWORD ImageBase,
HANDLE NTDllSectionHandle)
VOID LdrStartup(VOID)
{
PEPFUNC EntryPoint;
PIMAGE_DOS_HEADER PEDosHeader;
NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders;
DPRINT("LdrStartup(Peb %x SectionHandle %x, ImageBase %x, "
"NTDllSectionHandle %x )\n",
Peb, SectionHandle, ImageBase, NTDllSectionHandle);
PVOID ImageBase;
PPEB Peb;
DPRINT("LdrStartup()\n");
LdrDllListHead.BaseAddress = (PVOID)&_image_base__;
LdrDllListHead.Prev = &LdrDllListHead;
LdrDllListHead.Next = &LdrDllListHead;
LdrDllListHead.SectionHandle = NTDllSectionHandle;
LdrDllListHead.SectionHandle = NULL;
PEDosHeader = (PIMAGE_DOS_HEADER)LdrDllListHead.BaseAddress;
LdrDllListHead.Headers = (PIMAGE_NT_HEADERS)(LdrDllListHead.BaseAddress +
PEDosHeader->e_lfanew);
/* If MZ header exists */
PEDosHeader = (PIMAGE_DOS_HEADER) ImageBase;
Peb = (PPEB)(PEB_BASE);
DPRINT("Peb %x\n", Peb);
ImageBase = Peb->ImageBaseAddress;
DPRINT("ImageBase %x\n", ImageBase);
if (ImageBase <= (PVOID)0x1000)
{
DPRINT("ImageBase is null\n");
for(;;);
}
/* If MZ header exists */
PEDosHeader = (PIMAGE_DOS_HEADER) ImageBase;
DPRINT("PEDosHeader %x\n", PEDosHeader);
if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC ||
PEDosHeader->e_lfanew == 0L ||
*(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC ||
PEDosHeader->e_lfanew == 0L ||
*(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
{
DbgPrint("Image has bad header\n");
ZwTerminateProcess(NULL,
STATUS_UNSUCCESSFUL);
ZwTerminateProcess(NULL, STATUS_UNSUCCESSFUL);
}
/* normalize process parameters */
@ -87,7 +85,7 @@ VOID LdrStartup(PPEB Peb,
NTHeaders->OptionalHeader.SizeOfHeapReserve,
NULL,
NULL);
EntryPoint = LdrPEStartup((PVOID)ImageBase, SectionHandle);
EntryPoint = LdrPEStartup((PVOID)ImageBase, NULL);
if (EntryPoint == NULL)
{
@ -104,8 +102,8 @@ VOID LdrStartup(PPEB Peb,
DbgPrint("Failed to connect to csrss.exe: expect trouble\n");
}
// DbgPrint("Transferring control to image at %x\n",EntryPoint);
Status = EntryPoint(Peb);
DbgPrint("Transferring control to image at %x\n",EntryPoint);
Status = EntryPoint(NULL);
ZwTerminateProcess(NtCurrentProcess(),Status);
}

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.23 2000/01/18 12:04:31 ekohl Exp $
/* $Id: utils.c,v 1.24 2000/02/13 16:05:16 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -819,7 +819,7 @@ static NTSTATUS LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders,
*
*/
PEPFUNC LdrPEStartup (PVOID ImageBase,
HANDLE SectionHandle)
HANDLE SectionHandle)
{
NTSTATUS Status;
PEPFUNC EntryPoint;
@ -837,10 +837,13 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
/*
* Initialize image sections.
*/
LdrMapSections(NtCurrentProcess(),
ImageBase,
SectionHandle,
NTHeaders);
if (SectionHandle != NULL)
{
LdrMapSections(NtCurrentProcess(),
ImageBase,
SectionHandle,
NTHeaders);
}
/*
* If the base address is different from the

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.37 2000/02/05 16:06:52 ekohl Exp $
# $Id: makefile,v 1.38 2000/02/13 16:05:13 dwelch Exp $
#
# ReactOS Operating System
#
@ -6,7 +6,6 @@ TARGET=ntdll
BASE_CFLAGS = -I../../include -D__NTDLL__
include ../../rules.mak
IMAGE_BASE = 0x77f60000
ifneq ($(HOST),mingw32-windows)
@ -30,7 +29,7 @@ DBG_OBJECTS = dbg/brkpoint.o dbg/print.o
RTL_OBJECTS = rtl/critical.o rtl/error.o rtl/heap.o rtl/largeint.o \
rtl/math.o rtl/mem.o rtl/nls.o rtl/process.o rtl/sd.o \
rtl/thread.o rtl/unicode.o rtl/env.o rtl/path.o
rtl/thread.o rtl/unicode.o rtl/env.o rtl/path.o rtl/ppb.o
STDIO_OBJECTS = stdio/sprintf.o stdio/swprintf.o
@ -131,4 +130,4 @@ else
endif
#WARNINGS_ARE_ERRORS = yes
include ../../rules.mak

View file

@ -1,4 +1,4 @@
/* $Id: env.c,v 1.5 2000/02/05 16:08:49 ekohl Exp $
/* $Id: env.c,v 1.6 2000/02/13 16:05:16 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -16,7 +16,7 @@
#include <internal/teb.h>
#include <string.h>
#define NDEBUG
//#define NDEBUG
#include <ntdll/ntdll.h>
/* FUNCTIONS *****************************************************************/
@ -107,6 +107,7 @@ RtlDestroyEnvironment (
}
NTSTATUS
STDCALL
RtlExpandEnvironmentStrings_U (

344
reactos/lib/ntdll/rtl/ppb.c Normal file
View file

@ -0,0 +1,344 @@
/* $Id: ppb.c,v 1.1 2000/02/13 16:05:16 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/ntdll/rtl/ppb.c
* PURPOSE: Process functions
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
* UPDATE HISTORY:
* Created 01/11/98
*/
/* INCLUDES ****************************************************************/
#define WIN32_NO_PEHDR
#include <ddk/ntddk.h>
#include <wchar.h>
#include <string.h>
#include <pe.h>
#include <internal/i386/segment.h>
#include <ntdll/ldr.h>
#include <internal/teb.h>
#include <ntdll/base.h>
#include <ntdll/rtl.h>
#define NDEBUG
#include <ntdll/ntdll.h>
/* FUNCTIONS ****************************************************************/
VOID STDCALL RtlAcquirePebLock(VOID)
{
}
VOID STDCALL RtlReleasePebLock(VOID)
{
}
NTSTATUS
STDCALL
RtlCreateProcessParameters (
PRTL_USER_PROCESS_PARAMETERS *Ppb,
PUNICODE_STRING CommandLine,
PUNICODE_STRING LibraryPath,
PUNICODE_STRING CurrentDirectory,
PUNICODE_STRING ImageName,
PVOID Environment,
PUNICODE_STRING Title,
PUNICODE_STRING Desktop,
PUNICODE_STRING Reserved,
PVOID Reserved2
)
{
NTSTATUS Status = STATUS_SUCCESS;
PRTL_USER_PROCESS_PARAMETERS Param = NULL;
ULONG RegionSize = 0;
ULONG DataSize = 0;
PWCHAR Dest;
DPRINT ("RtlCreateProcessParameters\n");
RtlAcquirePebLock ();
/* size of process parameter block */
DataSize = sizeof (RTL_USER_PROCESS_PARAMETERS);
/* size of (reserved) buffer */
DataSize += (256 * sizeof(WCHAR));
/* size of current directory buffer */
DataSize += (MAX_PATH * sizeof(WCHAR));
/* add string lengths */
if (LibraryPath != NULL)
DataSize += (LibraryPath->Length + sizeof(WCHAR));
if (CommandLine != NULL)
DataSize += (CommandLine->Length + sizeof(WCHAR));
if (ImageName != NULL)
DataSize += (ImageName->Length + sizeof(WCHAR));
if (Title != NULL)
DataSize += (Title->Length + sizeof(WCHAR));
if (Desktop != NULL)
DataSize += (Desktop->Length + sizeof(WCHAR));
if (Reserved != NULL)
DataSize += (Reserved->Length + sizeof(WCHAR));
/* Calculate the required block size */
RegionSize = ROUNDUP(DataSize, PAGESIZE);
Status = NtAllocateVirtualMemory (
NtCurrentProcess (),
(PVOID*)&Param,
0,
&RegionSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
RtlReleasePebLock ();
return Status;
}
DPRINT ("Ppb allocated\n");
Param->TotalSize = RegionSize;
Param->DataSize = DataSize;
Param->Flags = TRUE;
Param->Environment = Environment;
// Param->Unknown1 =
// Param->Unknown2 =
// Param->Unknown3 =
// Param->Unknown4 =
/* copy current directory */
Dest = (PWCHAR)(((PBYTE)Param) +
sizeof(RTL_USER_PROCESS_PARAMETERS) +
(256 * sizeof(WCHAR)));
Param->CurrentDirectory.DosPath.Buffer = Dest;
if (CurrentDirectory != NULL)
{
Param->CurrentDirectory.DosPath.Length = CurrentDirectory->Length;
Param->CurrentDirectory.DosPath.MaximumLength =
CurrentDirectory->Length + sizeof(WCHAR);
memcpy(Dest,
CurrentDirectory->Buffer,
CurrentDirectory->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length);
}
*Dest = 0;
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS) +
(256 * sizeof(WCHAR)) + (MAX_PATH * sizeof(WCHAR)));
/* copy library path */
Param->LibraryPath.Buffer = Dest;
if (LibraryPath != NULL)
{
Param->LibraryPath.Length = LibraryPath->Length;
memcpy (Dest,
LibraryPath->Buffer,
LibraryPath->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + LibraryPath->Length);
}
Param->LibraryPath.MaximumLength = Param->LibraryPath.Length +
sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy command line */
Param->CommandLine.Buffer = Dest;
if (CommandLine != NULL)
{
Param->CommandLine.Length = CommandLine->Length;
memcpy (Dest,
CommandLine->Buffer,
CommandLine->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CommandLine->Length);
}
Param->CommandLine.MaximumLength = Param->CommandLine.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy image name */
Param->ImageName.Buffer = Dest;
if (ImageName != NULL)
{
Param->ImageName.Length = ImageName->Length;
memcpy (Dest,
ImageName->Buffer,
ImageName->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + ImageName->Length);
}
Param->ImageName.MaximumLength = Param->ImageName.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy title */
Param->Title.Buffer = Dest;
if (Title != NULL)
{
Param->Title.Length = Title->Length;
memcpy (Dest,
Title->Buffer,
Title->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + Title->Length);
}
Param->Title.MaximumLength = Param->Title.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
/* copy desktop */
Param->Desktop.Buffer = Dest;
if (Desktop != NULL)
{
Param->Desktop.Length = Desktop->Length;
memcpy (Dest,
Desktop->Buffer,
Desktop->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + Desktop->Length);
}
Param->Desktop.MaximumLength = Param->Desktop.Length + sizeof(WCHAR);
*Dest = 0;
Dest++;
RtlDeNormalizeProcessParams (Param);
*Ppb = Param;
RtlReleasePebLock ();
return(Status);
}
VOID STDCALL RtlDestroyProcessParameters (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
ULONG RegionSize = 0;
NtFreeVirtualMemory (NtCurrentProcess (),
(PVOID)Ppb,
&RegionSize,
MEM_RELEASE);
}
/*
* denormalize process parameters (Pointer-->Offset)
*/
VOID
STDCALL
RtlDeNormalizeProcessParams (
PRTL_USER_PROCESS_PARAMETERS Ppb
)
{
if (Ppb == NULL)
return;
if (Ppb->Flags == FALSE)
return;
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer -
(ULONG)Ppb);
}
if (Ppb->LibraryPath.Buffer != NULL)
{
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer -
(ULONG)Ppb);
}
if (Ppb->CommandLine.Buffer != NULL)
{
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer -
(ULONG)Ppb);
}
if (Ppb->ImageName.Buffer != NULL)
{
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer -
(ULONG)Ppb);
}
if (Ppb->Title.Buffer != NULL)
{
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer -
(ULONG)Ppb);
}
if (Ppb->Desktop.Buffer != NULL)
{
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer -
(ULONG)Ppb);
}
Ppb->Flags = FALSE;
}
/*
* normalize process parameters (Offset-->Pointer)
*/
VOID STDCALL RtlNormalizeProcessParams (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
if (Ppb == NULL)
return;
if (Ppb->Flags == TRUE)
return;
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->LibraryPath.Buffer != NULL)
{
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->CommandLine.Buffer != NULL)
{
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer +
(ULONG)Ppb);
}
if (Ppb->ImageName.Buffer != NULL)
{
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer +
(ULONG)Ppb);
}
if (Ppb->Title.Buffer != NULL)
{
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer +
(ULONG)Ppb);
}
if (Ppb->Desktop.Buffer != NULL)
{
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer +
(ULONG)Ppb);
}
Ppb->Flags = TRUE;
}

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.11 2000/02/05 16:08:49 ekohl Exp $
/* $Id: process.c,v 1.12 2000/02/13 16:05:16 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -22,51 +22,40 @@
#include <ntdll/base.h>
#include <ntdll/rtl.h>
#define NDEBUG
//#define NDEBUG
#include <ntdll/ntdll.h>
/* FUNCTIONS ****************************************************************/
#define STACK_TOP (0xb0000000)
static HANDLE STDCALL
RtlpCreateFirstThread(HANDLE ProcessHandle,
PSECURITY_DESCRIPTOR SecurityDescriptor,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
PPEB Peb,
DWORD dwCreationFlags,
LPDWORD lpThreadId,
HANDLE NTDllSectionHandle,
HANDLE SectionHandle,
PVOID ImageBase)
{
HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
DWORD dwCreationFlags,
PCLIENT_ID ClientId)
{
NTSTATUS Status;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress;
ULONG BytesWritten;
HANDLE DupNTDllSectionHandle, DupSectionHandle;
CLIENT_ID Cid;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
// ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = NULL;
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED)
if (dwCreationFlags & CREATE_SUSPENDED)
CreateSuspended = TRUE;
else
CreateSuspended = FALSE;
/* create the process stack (first thead) */
BaseAddress = (PVOID)(STACK_TOP - dwStackSize);
Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress,
@ -76,10 +65,10 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Failed to allocate stack\n");
return(NULL);
}
memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress;
ThreadContext.SegGs = USER_DS;
@ -93,312 +82,198 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
NtDuplicateObject(NtCurrentProcess(),
&SectionHandle,
ProcessHandle,
&DupSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
NtDuplicateObject(NtCurrentProcess(),
&NTDllSectionHandle,
ProcessHandle,
&DupNTDllSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 4),
&DupNTDllSectionHandle,
sizeof(DupNTDllSectionHandle),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 8),
&ImageBase,
sizeof(ImageBase),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 12),
&DupSectionHandle,
sizeof(DupSectionHandle),
&BytesWritten);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 16),
&Peb,
sizeof(PPEB),
&BytesWritten);
Status = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if ( lpThreadId != NULL )
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
THREAD_ALL_ACCESS,
&ObjectAttributes,
ProcessHandle,
&Cid,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if (ClientId != NULL)
{
memcpy(&ClientId->UniqueThread, &Cid.UniqueThread, sizeof(ULONG));
}
return ThreadHandle;
return(ThreadHandle);
}
static NTSTATUS
RtlpMapFile(PUNICODE_STRING ApplicationName,
PIMAGE_NT_HEADERS Headers,
PIMAGE_DOS_HEADER DosHeader,
PHANDLE Section)
static NTSTATUS RtlpMapFile(PUNICODE_STRING ApplicationName,
PHANDLE Section)
{
HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock;
LARGE_INTEGER FileOffset;
OBJECT_ATTRIBUTES ObjectAttributes;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
NTSTATUS Status;
HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock;
OBJECT_ATTRIBUTES ObjectAttributes;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
NTSTATUS Status;
hFile = NULL;
*Section = NULL;
hFile = NULL;
InitializeObjectAttributes(&ObjectAttributes,
ApplicationName,
OBJ_CASE_INSENSITIVE,
NULL,
SecurityDescriptor);
DPRINT("ApplicationName %w\n", ApplicationName->Buffer);
/*
* Try to open the executable
*/
InitializeObjectAttributes(&ObjectAttributes,
ApplicationName,
OBJ_CASE_INSENSITIVE,
NULL,
SecurityDescriptor);
/*
* Try to open the executable
*/
Status = NtOpenFile(&hFile,
Status = NtOpenFile(&hFile,
SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
&ObjectAttributes,
&IoStatusBlock,
FILE_SHARE_DELETE|FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
if (!NT_SUCCESS(Status))
return Status;
Status = NtReadFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
DosHeader,
sizeof(IMAGE_DOS_HEADER),
NULL,
NULL);
if (!NT_SUCCESS(Status))
return Status;
if (!NT_SUCCESS(Status))
{
return(Status);
}
FileOffset.u.LowPart = DosHeader->e_lfanew;
FileOffset.u.HighPart = 0;
Status = NtCreateSection(Section,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_EXECUTE,
SEC_IMAGE,
hFile);
NtClose(hFile);
Status = NtReadFile(hFile,
NULL,
NULL,
NULL,
&IoStatusBlock,
Headers,
sizeof(IMAGE_NT_HEADERS),
&FileOffset,
NULL);
if (!NT_SUCCESS(Status))
return Status;
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = NtCreateSection(Section,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_EXECUTE,
SEC_IMAGE,
hFile);
NtClose(hFile);
if (!NT_SUCCESS(Status))
return Status;
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
static NTSTATUS
RtlpCreatePpbAndPeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
NTSTATUS Status;
ULONG BytesWritten;
PVOID PebBase;
ULONG PebSize;
PEB Peb;
PVOID PpbBase;
ULONG PpbSize;
NTSTATUS Status;
PVOID PpbBase;
ULONG PpbSize;
ULONG BytesWritten;
ULONG Offset;
/* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize;
Status = NtAllocateVirtualMemory (ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
return(Status);
{
return(Status);
}
DPRINT("Ppb size %x\n", PpbSize);
NtWriteVirtualMemory (ProcessHandle,
PpbBase,
Ppb,
Ppb->TotalSize,
&BytesWritten);
DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize);
NtWriteVirtualMemory(ProcessHandle,
PpbBase,
Ppb,
Ppb->TotalSize,
&BytesWritten);
Offset = FIELD_OFFSET(PEB, ProcessParameters);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(PEB_BASE + Offset),
&PpbBase,
sizeof(PpbBase),
&BytesWritten);
/* create the PEB */
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = NtAllocateVirtualMemory (ProcessHandle,
&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
memset (&Peb, 0, sizeof(PEB));
Peb.ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)PpbBase;
NtWriteVirtualMemory (ProcessHandle,
PebBase,
&Peb,
sizeof(PEB),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
NTSTATUS
STDCALL
RtlCreateUserProcess (
PUNICODE_STRING CommandLine,
ULONG Unknown1,
PRTL_USER_PROCESS_PARAMETERS Ppb,
PSECURITY_DESCRIPTOR ProcessSd,
PSECURITY_DESCRIPTOR ThreadSd,
WINBOOL bInheritHandles,
DWORD dwCreationFlags,
PCLIENT_ID ClientId,
PHANDLE ProcessHandle,
PHANDLE ThreadHandle)
NTSTATUS STDCALL RtlCreateUserProcess(PUNICODE_STRING CommandLine,
ULONG Unknown1,
PRTL_USER_PROCESS_PARAMETERS Ppb,
PSECURITY_DESCRIPTOR ProcessSd,
PSECURITY_DESCRIPTOR ThreadSd,
WINBOOL bInheritHandles,
DWORD dwCreationFlags,
PCLIENT_ID ClientId,
PHANDLE ProcessHandle,
PHANDLE ThreadHandle)
{
HANDLE hSection, hProcess, hThread;
HANDLE hSection;
HANDLE hThread;
NTSTATUS Status;
LPTHREAD_START_ROUTINE lpStartAddress = NULL;
WCHAR TempCommandLine[256];
PVOID BaseAddress;
LARGE_INTEGER SectionOffset;
IMAGE_NT_HEADERS Headers;
IMAGE_DOS_HEADER DosHeader;
HANDLE NTDllSection;
ULONG InitialViewSize;
PROCESS_BASIC_INFORMATION ProcessBasicInfo;
CLIENT_ID LocalClientId;
ULONG retlen;
PPEB Peb;
DWORD len = 0;
DPRINT ("RtlCreateUserProcess(CommandLine '%w')\n",
CommandLine->Buffer);
Status = RtlpMapFile(CommandLine,
&Headers,
&DosHeader,
&hSection);
Status = NtCreateProcess(&hProcess,
PROCESS_ALL_ACCESS,
NULL,
NtCurrentProcess(),
bInheritHandles,
NULL,
NULL,
NULL);
NtQueryInformationProcess(hProcess,
ProcessBasicInformation,
&ProcessBasicInfo,
sizeof(ProcessBasicInfo),
&retlen);
DPRINT("ProcessBasicInfo.UniqueProcessId %d\n",
ProcessBasicInfo.UniqueProcessId);
LocalClientId.UniqueProcess = ProcessBasicInfo.UniqueProcessId;
/*
* Map NT DLL into the process
*/
InitialViewSize = DosHeader.e_lfanew + sizeof(IMAGE_NT_HEADERS)
+ sizeof(IMAGE_SECTION_HEADER) * Headers.FileHeader.NumberOfSections;
BaseAddress = (PVOID)Headers.OptionalHeader.ImageBase;
SectionOffset.QuadPart = 0;
Status = NtMapViewOfSection(hSection,
hProcess,
&BaseAddress,
0,
InitialViewSize,
&SectionOffset,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
DPRINT("CreateProcessW(CommandLine '%w')\n", CommandLine->Buffer);
Status = RtlpMapFile(CommandLine,
&hSection);
/*
* Create a new process
*/
Status = NtCreateProcess(ProcessHandle,
PROCESS_ALL_ACCESS,
NULL,
NtCurrentProcess(),
bInheritHandles,
hSection,
NULL,
NULL);
if (!NT_SUCCESS(Status))
return Status;
{
return(Status);
}
/*
* Get some information about the process
*/
ZwQueryInformationProcess(*ProcessHandle,
ProcessBasicInformation,
&ProcessBasicInfo,
sizeof(ProcessBasicInfo),
&retlen);
DPRINT("ProcessBasicInfo.UniqueProcessId %d\n",
ProcessBasicInfo.UniqueProcessId);
if (ClientId != NULL)
{
ClientId->UniqueProcess = (HANDLE)ProcessBasicInfo.UniqueProcessId;
}
/*
*
* Create Process Environment Block
*/
DPRINT("Creating PPB and PEB\n");
RtlpCreatePpbAndPeb (&Peb, hProcess, Ppb);
DPRINT("Creating peb\n");
KlInitPeb(*ProcessHandle, Ppb);
DPRINT("Creating thread for process\n");
lpStartAddress = (LPTHREAD_START_ROUTINE)
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
AddressOfEntryPoint +
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase;
hThread = RtlpCreateFirstThread (
hProcess,
ThreadSd,
Headers.OptionalHeader.SizeOfStackReserve,
lpStartAddress,
Peb,
dwCreationFlags,
&LocalClientId.UniqueThread,
NTDllSection,
hSection,
(PVOID)Headers.OptionalHeader.ImageBase);
if ( hThread == NULL )
return Status;
if (ClientId)
{
ClientId->UniqueProcess = LocalClientId.UniqueProcess;
ClientId->UniqueThread = LocalClientId.UniqueThread;
}
if (ProcessHandle)
*ProcessHandle = hProcess;
if (ThreadHandle)
*ThreadHandle = hThread;
return STATUS_SUCCESS;
hThread = KlCreateFirstThread(*ProcessHandle,
// Headers.OptionalHeader.SizeOfStackReserve,
0x200000,
lpStartAddress,
dwCreationFlags,
ClientId);
if (hThread == NULL)
{
DPRINT("Failed to create thread\n");
return(STATUS_UNSUCCESSFUL);
}
return(STATUS_SUCCESS);
}
@ -507,7 +382,6 @@ RtlCreateProcessParameters (
CurrentDirectory->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length);
}
*Dest = 0;
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS) +
/* (256 * sizeof(WCHAR)) + */ (MAX_PATH * sizeof(WCHAR)));
@ -587,133 +461,6 @@ RtlCreateProcessParameters (
*Ppb = Param;
RtlReleasePebLock ();
return(Status);
}
VOID STDCALL RtlDestroyProcessParameters (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
ULONG RegionSize = 0;
NtFreeVirtualMemory (NtCurrentProcess (),
(PVOID)Ppb,
&RegionSize,
MEM_RELEASE);
}
/*
* denormalize process parameters (Pointer-->Offset)
*/
VOID
STDCALL
RtlDeNormalizeProcessParams (
PRTL_USER_PROCESS_PARAMETERS Ppb
)
{
if (Ppb == NULL)
return;
if (Ppb->Flags == FALSE)
return;
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer -
(ULONG)Ppb);
}
if (Ppb->LibraryPath.Buffer != NULL)
{
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer -
(ULONG)Ppb);
}
if (Ppb->CommandLine.Buffer != NULL)
{
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer -
(ULONG)Ppb);
}
if (Ppb->ImageName.Buffer != NULL)
{
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer -
(ULONG)Ppb);
}
if (Ppb->Title.Buffer != NULL)
{
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer -
(ULONG)Ppb);
}
if (Ppb->Desktop.Buffer != NULL)
{
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer -
(ULONG)Ppb);
}
Ppb->Flags = FALSE;
}
/*
* normalize process parameters (Offset-->Pointer)
*/
VOID STDCALL RtlNormalizeProcessParams (PRTL_USER_PROCESS_PARAMETERS Ppb)
{
if (Ppb == NULL)
return;
if (Ppb->Flags == TRUE)
return;
if (Ppb->CurrentDirectory.DosPath.Buffer != NULL)
{
Ppb->CurrentDirectory.DosPath.Buffer =
(PWSTR)((ULONG)Ppb->CurrentDirectory.DosPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->LibraryPath.Buffer != NULL)
{
Ppb->LibraryPath.Buffer =
(PWSTR)((ULONG)Ppb->LibraryPath.Buffer +
(ULONG)Ppb);
}
if (Ppb->CommandLine.Buffer != NULL)
{
Ppb->CommandLine.Buffer =
(PWSTR)((ULONG)Ppb->CommandLine.Buffer +
(ULONG)Ppb);
}
if (Ppb->ImageName.Buffer != NULL)
{
Ppb->ImageName.Buffer =
(PWSTR)((ULONG)Ppb->ImageName.Buffer +
(ULONG)Ppb);
}
if (Ppb->Title.Buffer != NULL)
{
Ppb->Title.Buffer =
(PWSTR)((ULONG)Ppb->Title.Buffer +
(ULONG)Ppb);
}
if (Ppb->Desktop.Buffer != NULL)
{
Ppb->Desktop.Buffer =
(PWSTR)((ULONG)Ppb->Desktop.Buffer +
(ULONG)Ppb);
}
Ppb->Flags = TRUE;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: print.c,v 1.6 2000/01/17 21:01:37 ekohl Exp $
/* $Id: print.c,v 1.7 2000/02/13 16:05:17 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -26,8 +26,7 @@ __asm__ ("\n\t.global _DbgService\n\t"
"int $0x2D\n\t"
"ret\n\t");
ULONG
DbgPrint(PCH Format, ...)
ULONG DbgPrint(PCH Format, ...)
{
ANSI_STRING DebugString;
CHAR Buffer[512];
@ -41,8 +40,8 @@ DbgPrint(PCH Format, ...)
DebugString.Length = vsprintf (Buffer, Format, ap);
va_end (ap);
DbgService (1, &DebugString, NULL);
HalDisplayString(Buffer);
return (ULONG)DebugString.Length;
}

View file

@ -31,6 +31,26 @@ static KSPIN_LOCK GdtLock;
/* FUNCTIONS *****************************************************************/
VOID KeSetBaseGdtSelector(ULONG Entry,
PVOID Base)
{
KIRQL oldIrql;
KeAcquireSpinLock(&GdtLock, &oldIrql);
KiGdt[Entry*4 + 1] = ((ULONG)Base) & 0xffff;
KiGdt[Entry*4 + 2] = KiGdt[Entry*4 + 2] & ~(0xff);
KiGdt[Entry*4 + 2] = KiGdt[Entry*4 + 2] |
((((ULONG)Base) & 0xff0000) >> 16);
KiGdt[Entry*4 + 3] = KiGdt[Entry*4 + 3] & ~(0xff00);
KiGdt[Entry*4 + 3] = KiGdt[Entry*4 + 3] |
((((ULONG)Base) & 0xff000000) >> 16);
KeReleaseSpinLock(&GdtLock, oldIrql);
}
VOID KeDumpGdtSelector(ULONG Entry)
{
}

View file

@ -309,6 +309,7 @@ asmlinkage void exception_handler(unsigned int edi,
}
else
{
#if 0
DbgPrint("SS:ESP %x:%x\n",ss0,esp0);
stack=(PULONG)(esp0);
@ -324,6 +325,7 @@ asmlinkage void exception_handler(unsigned int edi,
}
}
}
#endif
}
DbgPrint("\n");

View file

@ -42,37 +42,18 @@ VOID HalTaskSwitch(PKTHREAD thread)
* ARGUMENTS:
* thread = Thread to switch to
* NOTE: This function will not return until the current thread is scheduled
* again (possibly never);
* again (possibly never)
*/
{
DPRINT("Scheduling thread %x\n",thread);
DPRINT("Scheduling thread %x\n",thread->Context.nr);
DPRINT("previous task %x reserved1 %x esp0 %x ss0 %x\n",
thread->Context.previous_task,thread->Context.reserved1,
thread->Context.esp0,thread->Context.ss0);
DPRINT("reserved2 %x esp1 %x ss1 %x reserved3 %x esp2 %x ss2 %x\n",
thread->Context.reserved2,thread->Context.esp1,thread->Context.ss1,
thread->Context.reserved3,thread->Context.esp2,thread->Context.ss2);
DPRINT("reserved4 %x cr3 %x eip %x eflags %x eax %x\n",
thread->Context.reserved4,thread->Context.cr3,thread->Context.eip,
thread->Context.eflags,thread->Context.eax);
DPRINT("ecx %x edx %x ebx %x esp %x ebp %x esi %x\n",
thread->Context.ecx,thread->Context.edx,thread->Context.ebx,
thread->Context.esp,thread->Context.ebp,thread->Context.esi);
DPRINT("edi %x es %x reserved5 %x cs %x reserved6 %x\n",
thread->Context.edi,thread->Context.es,thread->Context.reserved5,
thread->Context.cs,thread->Context.reserved6);
DPRINT("ss %x reserved7 %x ds %x reserved8 %x fs %x\n",
thread->Context.ss,thread->Context.reserved7,thread->Context.ds,
thread->Context.reserved8,thread->Context.fs);
DPRINT("reserved9 %x gs %x reserved10 %x ldt %x reserved11 %x\n",
thread->Context.reserved9,thread->Context.gs,
thread->Context.reserved10,thread->Context.ldt,
thread->Context.reserved11);
DPRINT("trap %x iomap_base %x nr %x io_bitmap[0] %x\n",
thread->Context.trap,thread->Context.iomap_base,
thread->Context.nr,thread->Context.io_bitmap[0]);
DPRINT("thread->Context.cr3 %x\n",thread->Context.cr3);
#if 0
PETHREAD Thread;
Thread = CONTAINING_RECORD(thread, ETHREAD, Tcb);
if (Thread->Cid.UniqueThread != (HANDLE)1)
{
DPRINT1("Scheduling thread %x (id %d)\n",Thread,
Thread->Cid.UniqueThread);
}
#endif
__asm__("pushfl\n\t"
"cli\n\t"
"ljmp %0\n\t"

View file

@ -30,308 +30,151 @@
#include <internal/teb.h>
#include <internal/ldr.h>
//#define NDEBUG
#define NDEBUG
#include <internal/debug.h>
#include "syspath.h"
/* FUNCTIONS ****************************************************************/
/* GLOBALS *******************************************************************/
#define STACK_TOP (0xb0000000)
static NTSTATUS LdrCreateUserProcessParameters (
PRTL_USER_PROCESS_PARAMETERS *PpbPtr,
HANDLE ProcessHandle)
{
PVOID PpbBase;
ULONG PpbSize;
RTL_USER_PROCESS_PARAMETERS Ppb;
ULONG BytesWritten;
NTSTATUS Status;
/* Create process parameters block (PPB)*/
PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = sizeof (RTL_USER_PROCESS_PARAMETERS);
/* FUNCTIONS *****************************************************************/
Status = ZwAllocateVirtualMemory (ProcessHandle,
(PVOID*)&PpbBase,
0,
&PpbSize,
MEM_COMMIT,
PAGE_READWRITE);
/*
* FIXME: The location of the initial process should be configurable,
* from command line or registry
*/
NTSTATUS LdrLoadInitialProcess (VOID)
{
NTSTATUS Status;
HANDLE ProcessHandle;
UNICODE_STRING ProcessName;
WCHAR TmpNameBuffer[MAX_PATH];
OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE FileHandle;
HANDLE SectionHandle;
PVOID LdrStartupAddr;
PVOID StackBase;
ULONG StackSize;
PIMAGE_NT_HEADERS NTHeaders;
PPEB Peb;
PEPROCESS Process;
CONTEXT Context;
HANDLE ThreadHandle;
/*
* Get the system directory's name (a DOS device
* alias name which is in \\??\\).
*/
LdrGetSystemDirectory(TmpNameBuffer, sizeof TmpNameBuffer);
wcscat(TmpNameBuffer, L"\\smss.exe");
RtlInitUnicodeString(&ProcessName, TmpNameBuffer);
/*
* Open process image to determine ImageBase
* and StackBase/Size.
*/
InitializeObjectAttributes(&ObjectAttributes,
&ProcessName,
0,
NULL,
NULL);
DPRINT("Opening image file %S\n", ObjectAttributes.ObjectName->Buffer);
Status = ZwOpenFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
NULL,
0,
0);
if (!NT_SUCCESS(Status))
{
DbgPrint("Ppb allocation failed (Status %x)\n", Status);
DPRINT("Image open failed (Status was %x)\n", Status);
return Status;
}
/*
* Create a section for the image
*/
DPRINT("Creating section\n");
Status = ZwCreateSection(&SectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READWRITE,
MEM_COMMIT,
FileHandle);
if (!NT_SUCCESS(Status))
{
DbgPrint("ZwCreateSection failed (Status %x)\n", Status);
ZwClose(FileHandle);
return(Status);
}
ZwClose(FileHandle);
DPRINT("Creating process\n");
Status = ZwCreateProcess(&ProcessHandle,
PROCESS_ALL_ACCESS,
NULL,
SystemProcessHandle,
FALSE,
SectionHandle,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("Could not create process\n");
return Status;
}
/* initialize the ppb */
memset (&Ppb, 0, sizeof(RTL_USER_PROCESS_PARAMETERS));
DPRINT("PpbBase %x\n", PpbBase);
ZwWriteVirtualMemory(ProcessHandle,
PpbBase,
&Ppb,
sizeof(RTL_USER_PROCESS_PARAMETERS),
&BytesWritten);
*PpbPtr = PpbBase;
return STATUS_SUCCESS;
}
static NTSTATUS LdrCreatePeb (PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{
PPEB PebBase;
ULONG PebSize;
PEB Peb;
ULONG BytesWritten;
NTSTATUS Status;
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = ZwAllocateVirtualMemory (ProcessHandle,
(PVOID*)&PebBase,
0,
&PebSize,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint ("Peb allocation failed (Status %x)\n", Status);
return(Status);
}
/* initialize the peb */
memset(&Peb, 0, sizeof Peb);
Peb.ProcessParameters = Ppb;
ZwWriteVirtualMemory (ProcessHandle,
PebBase,
&Peb,
sizeof(Peb),
&BytesWritten);
*PebPtr = (PPEB)PebBase;
return(STATUS_SUCCESS);
}
/**********************************************************************
* NAME
* LdrLoadImage
*
* FUNCTION:
* Builds the initial environment for a process. Should be used
* to load the initial user process.
*
* ARGUMENTS:
* HANDLE ProcessHandle handle of the process to load the module into
* PUNICODE_STRING Filename name of the module to load
*
* RETURNS:
* NTSTATUS
*/
NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
PUNICODE_STRING Filename)
{
CHAR BlockBuffer [1024];
DWORD ImageBase;
DWORD LdrStartupAddr;
DWORD StackBase;
ULONG ImageSize;
ULONG StackSize;
NTSTATUS Status;
OBJECT_ATTRIBUTES FileObjectAttributes;
HANDLE FileHandle;
HANDLE SectionHandle;
HANDLE ThreadHandle;
CONTEXT Context;
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
ULONG BytesWritten;
ULONG InitialViewSize;
HANDLE DupSectionHandle;
PRTL_USER_PROCESS_PARAMETERS Ppb;
PPEB Peb;
/*
* Create initial stack and thread
*/
/*
* Aargh!
*/
LdrStartupAddr = (DWORD)LdrpGetSystemDllEntryPoint();
LdrStartupAddr = (PVOID)LdrpGetSystemDllEntryPoint();
DPRINT("LdrStartupAddr %x\n", LdrStartupAddr);
/*
* Open process image to determine ImageBase
* and StackBase/Size.
*/
InitializeObjectAttributes(&FileObjectAttributes,
Filename,
0,
NULL,
NULL);
DPRINT("Opening image file %S\n",
FileObjectAttributes.ObjectName->Buffer
);
Status = ZwOpenFile(
& FileHandle,
FILE_ALL_ACCESS,
& FileObjectAttributes,
NULL,
0,
0
);
if (!NT_SUCCESS(Status))
{
DPRINT("Image open failed ");
DbgPrintErrorMessage(Status);
return Status;
}
Status = ZwReadFile(
FileHandle,
0,
0,
0,
0,
BlockBuffer,
sizeof BlockBuffer,
0,
0
);
if (!NT_SUCCESS(Status))
{
DPRINT("Image header read failed ");
DbgPrintErrorMessage(Status);
ZwClose(FileHandle);
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_MAGIC)
|| (DosHeader->e_lfanew == 0L)
|| (*(PULONG) NTHeaders != IMAGE_PE_MAGIC)
)
{
DPRINT("Image invalid format rc=%08lx\n", Status);
ZwClose(FileHandle);
return STATUS_UNSUCCESSFUL;
}
ImageBase = NTHeaders->OptionalHeader.ImageBase;
ImageSize = NTHeaders->OptionalHeader.SizeOfImage;
/*
* Create a section for the image
*/
Status = ZwCreateSection(
& SectionHandle,
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_READWRITE,
MEM_COMMIT,
FileHandle
);
if (!NT_SUCCESS(Status))
{
DPRINT("Image create section failed ");
DbgPrintErrorMessage(Status);
ZwClose(FileHandle);
return Status;
}
/*
* Map the image into the process
*/
InitialViewSize =
DosHeader->e_lfanew
+ sizeof (IMAGE_NT_HEADERS)
+ (
sizeof(IMAGE_SECTION_HEADER)
* NTHeaders->FileHeader.NumberOfSections
);
DPRINT("InitialViewSize %x\n",InitialViewSize);
Status = ZwMapViewOfSection(
SectionHandle,
ProcessHandle,
(PVOID *) & ImageBase,
0,
InitialViewSize,
NULL,
& InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE
);
if (!NT_SUCCESS(Status))
{
DPRINT("Image map view of section failed ");
DbgPrintErrorMessage(Status);
/* FIXME: destroy the section here */
ZwClose(FileHandle);
return Status;
}
ZwClose(FileHandle);
/* -- PART III -- */
/* Create the process parameter block (PPB) */
DPRINT("Creating PPB\n");
Status = LdrCreateUserProcessParameters (&Ppb, ProcessHandle);
if (!NT_SUCCESS(Status))
{
DPRINT("PPB creation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status;
}
/* Create the process environment block (PEB) */
DPRINT("Creating Peb\n");
Status = LdrCreatePeb (&Peb,
ProcessHandle,
Ppb);
if (!NT_SUCCESS(Status))
{
DPRINT("PEB creation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
/* FIXME: free the PPB */
return Status;
}
/*
* Create page backed section for stack
*/
DPRINT("Allocating stack\n");
StackBase = (STACK_TOP - NTHeaders->OptionalHeader.SizeOfStackReserve);
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_ALL_ACCESS,
PsProcessType,
KernelMode,
(PVOID*)&Process,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("ObReferenceObjectByProcess() failed (Status %x)\n", Status);
return(Status);
}
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
NTHeaders = RtlImageNtHeader(Peb->ImageBaseAddress);
DPRINT("NTHeaders %x\n", NTHeaders);
StackBase = (PVOID)
(STACK_TOP - NTHeaders->OptionalHeader.SizeOfStackReserve);
DPRINT("StackBase %x\n", StackBase);
StackSize = NTHeaders->OptionalHeader.SizeOfStackReserve;
DPRINT("StackSize %x\n", StackSize);
KeDetachProcess();
DPRINT("Dereferencing process\n");
// ObDereferenceObject(Process);
DbgPrint ("Stack size %x\n", StackSize);
DPRINT("Allocating virtual memory\n");
Status = ZwAllocateVirtualMemory(ProcessHandle,
(PVOID*)&StackBase,
0,
@ -340,42 +183,22 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DPRINT("Stack allocation failed ");
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
DPRINT("Stack allocation failed (Status %x)", Status);
return Status;
}
ZwDuplicateObject(NtCurrentProcess(),
&SectionHandle,
ProcessHandle,
&DupSectionHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 8),
&ImageBase,
sizeof (ImageBase),
&BytesWritten);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 12),
&DupSectionHandle,
sizeof (DupSectionHandle),
&BytesWritten);
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
/* write pointer to peb on the stack (parameter of NtProcessStartup) */
ZwWriteVirtualMemory(ProcessHandle,
(PVOID) (STACK_TOP - 16),
&Peb,
sizeof (ULONG),
&BytesWritten);
DbgPrint ("NTOSKRNL: Peb = %x\n", Peb);
/*
* Initialize context to point to LdrStartup
*/
@ -384,13 +207,14 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
Context.Esp = STACK_TOP - 20;
Context.EFlags = 0x202;
Context.SegCs = USER_CS;
Context.Eip = LdrStartupAddr;
Context.Eip = (ULONG)LdrStartupAddr;
Context.SegDs = USER_DS;
Context.SegEs = USER_DS;
Context.SegFs = USER_DS;
Context.SegGs = USER_DS;
DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
/*
* FIXME: Create process and let 'er rip
*/
@ -413,50 +237,17 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
return Status;
}
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
Peb = (PPEB)PEB_BASE;
DPRINT("Peb %x\n", Peb);
DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
PsGetCurrentProcess(),
Peb->ImageBaseAddress);
KeDetachProcess();
return STATUS_SUCCESS;
}
/*
* FIXME: The location of the initial process should be configurable,
* from command line or registry
*/
NTSTATUS LdrLoadInitialProcess (VOID)
{
NTSTATUS Status;
HANDLE ProcessHandle;
UNICODE_STRING ProcessName;
WCHAR TmpNameBuffer[MAX_PATH];
Status = ZwCreateProcess(&ProcessHandle,
PROCESS_ALL_ACCESS,
NULL,
SystemProcessHandle,
FALSE,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("Could not create process\n");
return Status;
}
/*
* Get the system directory's name (a DOS device
* alias name which is in \\??\\).
*/
LdrGetSystemDirectory(TmpNameBuffer, sizeof TmpNameBuffer);
wcscat(TmpNameBuffer, L"\\smss.exe");
RtlInitUnicodeString(&ProcessName, TmpNameBuffer);
Status = LdrLoadImage(ProcessHandle, &ProcessName);
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to load %wZ\n",&ProcessName);
}
return Status;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: loader.c,v 1.45 2000/02/03 21:34:14 phreak Exp $
/* $Id: loader.c,v 1.46 2000/02/13 16:05:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -190,15 +190,13 @@ static VOID LdrLoadAutoConfigDriver (LPWSTR RelativeDriverName)
Status = LdrLoadDriver(&DriverName);
if (!NT_SUCCESS(Status))
{
DbgPrint("driver load failed, status;%d(%x)\n", Status, Status);
DbgPrintErrorMessage(Status);
DbgPrint("driver load failed, status (%x)\n", Status);
KeBugCheck(0);
}
}
VOID
LdrLoadAutoConfigDrivers (VOID)
VOID LdrLoadAutoConfigDrivers (VOID)
{
/*
* Keyboard driver
@ -248,8 +246,7 @@ LdrCreateModule(PVOID ObjectBody,
* RETURNS: Status
*/
NTSTATUS
LdrLoadDriver(PUNICODE_STRING Filename)
NTSTATUS LdrLoadDriver(PUNICODE_STRING Filename)
{
PMODULE_OBJECT ModuleObject;

View file

@ -32,8 +32,11 @@ PIMAGE_NT_HEADERS RtlImageNtHeader(PVOID BaseAddress)
PIMAGE_DOS_HEADER DosHeader;
PIMAGE_NT_HEADERS NTHeaders;
DPRINT("BaseAddress %x\n", BaseAddress);
DosHeader = (PIMAGE_DOS_HEADER)BaseAddress;
DPRINT("DosHeader %x\n", DosHeader);
NTHeaders = (PIMAGE_NT_HEADERS)(BaseAddress + DosHeader->e_lfanew);
DPRINT("NTHeaders %x\n", NTHeaders);
if ((DosHeader->e_magic != IMAGE_DOS_MAGIC)
|| (DosHeader->e_lfanew == 0L)
|| (*(PULONG) NTHeaders != IMAGE_PE_MAGIC))

View file

@ -23,7 +23,7 @@
#include <internal/symbol.h>
#include <internal/teb.h>
//#define NDEBUG
#define NDEBUG
#include <internal/debug.h>
#include "syspath.h"
@ -132,11 +132,13 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
DPRINT("ImageBase %x\n",ImageBase);
*LdrStartupAddr =
(PVOID)ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
DPRINT("LdrStartupAddr %x\n", LdrStartupAddr);
SystemDllEntryPoint = *LdrStartupAddr;
/*
* Create a section for NTDLL
*/
DPRINT("Creating section\n");
Status = ZwCreateSection(&NTDllSectionHandle,
SECTION_ALL_ACCESS,
NULL,
@ -158,6 +160,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
InitialViewSize = DosHeader->e_lfanew +
sizeof (IMAGE_NT_HEADERS) +
(sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections);
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
@ -181,17 +184,21 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
LARGE_INTEGER Offset;
ULONG Base;
DPRINT("Mapping view of section %d\n", i);
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(BlockBuffer);
DPRINT("Sections %x\n", Sections);
Base = Sections[i].VirtualAddress + ImageBase;
DPRINT("Base %x\n", Base);
Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0;
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle,
(PVOID *) & Base,
(PVOID*)&Base,
0,
Sections[i].Misc.VirtualSize,
&Offset,
(PULONG) & Sections[i].Misc.VirtualSize,
(PULONG)&Sections[i].Misc.VirtualSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
@ -202,6 +209,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
return(Status);
}
}
DPRINT("Finished mapping\n");
ZwClose(NTDllSectionHandle);
return(STATUS_SUCCESS);

View file

@ -0,0 +1,212 @@
/*
* 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)
* UPDATE HISTORY:
* DW 26/01/00 Created
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/i386/segment.h>
#include <internal/linkage.h>
#include <internal/module.h>
#include <internal/ntoskrnl.h>
#include <internal/ob.h>
#include <internal/ps.h>
#include <string.h>
#include <internal/string.h>
#include <internal/symbol.h>
#include <internal/teb.h>
#include <internal/ldr.h>
#define NDEBUG
#include <internal/debug.h>
#include "syspath.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
*/
{
PVOID ImageBase;
NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders;
ULONG InitialViewSize;
ULONG i;
PEPROCESS Process;
PVOID FinalBase;
ULONG NumberOfSections;
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_ALL_ACCESS,
PsProcessType,
KernelMode,
(PVOID*)&Process,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("ObReferenceObjectByProcess() failed (Status %x)\n", Status);
return(Status);
}
/*
* map the dos header into the process
*/
DPRINT("Mapping view of section\n");
InitialViewSize = sizeof(PIMAGE_DOS_HEADER);
ImageBase = NULL;
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
/*
* Map the pe headers into the process
*/
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
InitialViewSize = ((PIMAGE_DOS_HEADER)ImageBase)->e_lfanew +
sizeof(IMAGE_NT_HEADERS);
DPRINT("InitialViewSize %d\n", InitialViewSize);
KeDetachProcess();
DPRINT("Unmapping view of section\n");
Status = ZwUnmapViewOfSection(ProcessHandle,
ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("ZwUnmapViewOfSection failed (Status %x)\n", Status);
return(Status);
}
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
/*
* TBD
*/
DPRINT("Attaching to process\n");
KeAttachProcess(Process);
NTHeaders = RtlImageNtHeader(ImageBase);
InitialViewSize = ((PIMAGE_DOS_HEADER)ImageBase)->e_lfanew +
sizeof(IMAGE_NT_HEADERS) +
(sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections);
DPRINT("InitialViewSize %x\n", InitialViewSize);
FinalBase = (PVOID)NTHeaders->OptionalHeader.ImageBase;
NumberOfSections = NTHeaders->FileHeader.NumberOfSections;
KeDetachProcess();
DPRINT("Unmapping view of section\n");
Status = ZwUnmapViewOfSection(ProcessHandle,
ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("ZwUnmapViewOfSection failed (Status %x)\n", Status);
return(Status);
}
ImageBase = FinalBase;
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID*)&ImageBase,
0,
InitialViewSize,
NULL,
&InitialViewSize,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of section failed (Status %x)", Status);
return(Status);
}
DPRINT("Mapping view of all sections\n");
for (i = 0; i < NumberOfSections; i++)
{
PIMAGE_SECTION_HEADER Sections;
LARGE_INTEGER Offset;
ULONG Base;
ULONG Size;
KeAttachProcess(Process);
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(ImageBase);
DPRINT("Sections %x\n", Sections);
Base = (ULONG)(Sections[i].VirtualAddress + ImageBase);
Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0;
Size = Sections[i].Misc.VirtualSize;
KeDetachProcess();
Status = ZwMapViewOfSection(SectionHandle,
ProcessHandle,
(PVOID *)&Base,
0,
Size,
&Offset,
(PULONG)&Size,
0,
MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("Image map view of secion failed (Status %x)\n", Status);
return(Status);
}
}
DPRINT("Returning\n");
*ReturnedImageBase = ImageBase;
return(STATUS_SUCCESS);
}

View file

@ -1,4 +1,4 @@
# $Id: makefile_rex,v 1.50 2000/01/27 08:56:49 dwelch Exp $
# $Id: makefile_rex,v 1.51 2000/02/13 16:05:16 dwelch Exp $
#
# ReactOS Operating System
#
@ -65,7 +65,8 @@ CM_OBJECTS = cm/registry.o
DBG_OBJECTS = dbg/brkpoint.o dbg/errinfo.o dbg/print.o
LDR_OBJECTS = ldr/loader.o ldr/init.o ldr/syspath.o ldr/sysdll.o ldr/rtl.o
LDR_OBJECTS = ldr/loader.o ldr/init.o ldr/syspath.o ldr/sysdll.o ldr/rtl.o \
ldr/userldr.o
NLS_OBJECTS = nls/nls.o

View file

@ -248,8 +248,8 @@ ULONG MmPageFault(ULONG cs, ULONG eip, ULONG error_code)
* Get the address for the page fault
*/
__asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
// DbgPrint("Page fault address %x eip %x process %x code %x\n",cr2,eip,
// PsGetCurrentProcess(), error_code);
DPRINT("Page fault address %x eip %x process %x code %x\n",cr2,eip,
PsGetCurrentProcess(), error_code);
MmSetPageProtect(PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(PsGetCurrentProcess()),
@ -259,7 +259,7 @@ ULONG MmPageFault(ULONG cs, ULONG eip, ULONG error_code)
if (error_code & 0x1)
{
DPRINT1("Page protection fault at %x with eip %x\n", cr2, eip);
DbgPrint("Page protection fault at %x with eip %x\n", cr2, eip);
return(0);
}

View file

@ -1,4 +1,4 @@
/* $Id: section.c,v 1.22 2000/01/12 19:03:42 ekohl Exp $
/* $Id: section.c,v 1.23 2000/02/13 16:05:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -430,6 +430,7 @@ NTSTATUS STDCALL NtMapViewOfSection(HANDLE SectionHandle,
DPRINT("*BaseAddress %x\n",*BaseAddress);
ObDereferenceObject(Process);
DPRINT("NtMapViewOfSection() returning (Status %x)\n", STATUS_SUCCESS);
return(STATUS_SUCCESS);
}
@ -472,13 +473,24 @@ NTSTATUS STDCALL NtUnmapViewOfSection (HANDLE ProcessHandle,
NTSTATUS Status;
PMEMORY_AREA MemoryArea;
DPRINT("NtUnmapViewOfSection(ProcessHandle %x, BaseAddress %x)\n",
ProcessHandle, BaseAddress);
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION,
PsProcessType,
UserMode,
(PVOID*)&Process,
NULL);
if (!NT_SUCCESS(Status))
{
DPRINT("ObReferenceObjectByHandle failed (Status %x)\n", Status);
return(Status);
}
DPRINT("Opening memory area Process %x BaseAddress %x\n",
Process, BaseAddress);
MemoryArea = MmOpenMemoryAreaByAddress(Process, BaseAddress);
if (MemoryArea == NULL)
{

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.8 2000/01/26 10:07:29 dwelch Exp $
/* $Id: create.c,v 1.9 2000/02/13 16:05:18 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -251,7 +251,10 @@ PACCESS_TOKEN PsReferenceImpersonationToken(PETHREAD Thread,
return(Thread->ImpersonationInfo->Token);
}
static VOID PiTimeoutThread( struct _KDPC *dpc, PVOID Context, PVOID arg1, PVOID arg2 )
static VOID PiTimeoutThread(struct _KDPC *dpc,
PVOID Context,
PVOID arg1,
PVOID arg2 )
{
// wake up the thread, and tell it it timed out
NTSTATUS Status = STATUS_TIMEOUT;
@ -263,10 +266,12 @@ static VOID PiTimeoutThread( struct _KDPC *dpc, PVOID Context, PVOID arg1, PVOID
VOID PiBeforeBeginThread(VOID)
{
PPEB Peb;
DPRINT("PiBeforeBeginThread()\n");
//KeReleaseSpinLock(&PiThreadListLock, PASSIVE_LEVEL);
KeLowerIrql(PASSIVE_LEVEL);
DPRINT("KeGetCurrentIrql() %d\n", KeGetCurrentIrql());
Peb = (PPEB)PEB_BASE;
}
VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
@ -459,7 +464,9 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
/* more initialization */
Teb.Cid.UniqueThread = Thread->Cid.UniqueThread;
Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess;
DPRINT("sizeof(NT_TEB) %x\n", sizeof(NT_TEB));
/* write TEB data into teb page */
Status = NtWriteVirtualMemory(ProcessHandle,
TebBase,

View file

@ -194,7 +194,8 @@ VOID PiDeleteProcess(PVOID ObjectBody)
}
static NTSTATUS PsCreatePeb(HANDLE ProcessHandle)
static NTSTATUS PsCreatePeb(HANDLE ProcessHandle,
PVOID ImageBase)
{
NTSTATUS Status;
PVOID PebBase;
@ -202,6 +203,9 @@ static NTSTATUS PsCreatePeb(HANDLE ProcessHandle)
PEB Peb;
ULONG BytesWritten;
memset(&Peb, 0, sizeof(Peb));
Peb.ImageBaseAddress = ImageBase;
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000;
Status = NtAllocateVirtualMemory(ProcessHandle,
@ -215,8 +219,6 @@ static NTSTATUS PsCreatePeb(HANDLE ProcessHandle)
return(Status);
}
memset(&Peb, 0, sizeof(Peb));
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)PEB_BASE,
&Peb,
@ -294,6 +296,7 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
NTSTATUS Status;
KIRQL oldIrql;
PVOID LdrStartupAddr;
PVOID ImageBase;
DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
@ -339,29 +342,54 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
/*
* Now we have created the process proper
*/
/*
* Map ntdll
*/
Status = LdrpMapSystemDll(*ProcessHandle,
&LdrStartupAddr);
if (!NT_SUCCESS(Status))
{
DbgPrint("LdrpMapSystemDll failed (Status %x)\n", Status);
ObDereferenceObject(Process);
ObDereferenceObject(ParentProcess);
return(Status);
}
Status = PsCreatePeb(*ProcessHandle);
/*
* Map the process image
*/
if (SectionHandle != NULL)
{
DPRINT("Mapping process image\n");
Status = LdrpMapImage(*ProcessHandle,
SectionHandle,
&ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("LdrpMapImage failed (Status %x)\n", Status);
ObDereferenceObject(Process);
ObDereferenceObject(ParentProcess);
return(Status);
}
}
else
{
ImageBase = NULL;
}
/*
*
*/
DPRINT("Creating PEB\n");
Status = PsCreatePeb(*ProcessHandle,
ImageBase);
if (!NT_SUCCESS(Status))
{
DbgPrint("NtCreateProcess() Peb creation failed: Status %x\n",Status);
return(Status);
}
/*
* Map ntdll
*/
Status = LdrpMapSystemDll(*ProcessHandle,
&LdrStartupAddr);
/*
* FIXME: I don't what I'm supposed to know with a section handle
*/
if (SectionHandle != NULL)
{
DbgPrint("NtCreateProcess() non-NULL SectionHandle\n");
return(STATUS_UNSUCCESSFUL);
}
ObDereferenceObject(Process);
ObDereferenceObject(ParentProcess);
return(STATUS_SUCCESS);

View file

@ -1,4 +1,4 @@
/* $Id: init.c,v 1.9 2000/01/11 17:32:13 ekohl Exp $
/* $Id: init.c,v 1.10 2000/02/13 16:05:19 dwelch Exp $
*
* init.c - Session Manager initialization
*
@ -133,8 +133,9 @@ InitSessionManager (
DisplayString (L"SM: System Environment created\n");
#endif
RtlSetCurrentEnvironment (SmSystemEnvironment,
NULL);
// RtlSetCurrentEnvironment (SmSystemEnvironment,
// NULL);
#ifndef NDEBUG
DisplayString (L"System Environment set\n");
#endif

View file

@ -280,7 +280,8 @@ SERVICE_TABLE W32kServiceTable[] =
{12, (ULONG) W32kSetTextJustification},
{16, (ULONG) W32kSetViewportExtEx},
{16, (ULONG) W32kSetViewportOrgEx},
{4, (ULONG) W32kSetWinMetaFileBits},
// {4, (ULONG) W32kSetWinMetaFileBits},
{4, (ULONG)NULL},
{16, (ULONG) W32kSetWindowExtEx},
{16, (ULONG) W32kSetWindowOrgEx},
{8, (ULONG) W32kSetWorldTransform},

View file

@ -175,7 +175,8 @@ HMETAFILE W32kSetMetaFileBitsEx(UINT Size,
HENHMETAFILE W32kSetWinMetaFileBits(UINT BufSize,
CONST PBYTE Buffer,
HDC Ref,
CONST METAFILEPICT *mfp)
// CONST METAFILEPICT *mfp)
PVOID mfp)
{
UNIMPLEMENTED;
}