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 # 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 # DEVICE_DRIVERS = beep event floppy ide_test mouse sound test test1
FS_DRIVERS = vfat FS_DRIVERS = vfat
# FS_DRIVERS = minix ext2 template # FS_DRIVERS = minix ext2 template

View file

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

View file

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

View file

@ -91,10 +91,12 @@ HENHMETAFILE W32kSetEnhMetaFileBits(UINT BufSize,
HMETAFILE W32kSetMetaFileBitsEx(UINT Size, HMETAFILE W32kSetMetaFileBitsEx(UINT Size,
CONST PBYTE Data); CONST PBYTE Data);
#if 0
HENHMETAFILE W32kSetWinMetaFileBits(UINT BufSize, HENHMETAFILE W32kSetWinMetaFileBits(UINT BufSize,
CONST PBYTE Buffer, CONST PBYTE Buffer,
HDC Ref, HDC Ref,
CONST METAFILEPICT *mfp); CONST METAFILEPICT *mfp);
#endif
#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/ide/ide.sys $1
cp services/dd/keyboard/keyboard.sys $1/reactos/system32/drivers cp services/dd/keyboard/keyboard.sys $1/reactos/system32/drivers
cp services/dd/blue/blue.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 apps/shell/shell.exe $1/reactos/system32
cp lib/ntdll/ntdll.dll $1/reactos/system32 cp lib/ntdll/ntdll.dll $1/reactos/system32
cp lib/kernel32/kernel32.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 * reactos/lib/gdi32/misc/stubs.c
* *
@ -2221,7 +2221,8 @@ SetWinMetaFileBits(
UINT a0, UINT a0,
CONST BYTE *a1, CONST BYTE *a1,
HDC a2, HDC a2,
CONST METAFILEPICT *a3 // CONST METAFILEPICT *a3
PVOID a3
) )
{ {
SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 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 # ReactOS Operating System
# #
@ -156,5 +156,5 @@ else
$(CP) $(TARGET).dll ../../$(DIST_DIR)/dlls/$(TARGET).dll $(CP) $(TARGET).dll ../../$(DIST_DIR)/dlls/$(TARGET).dll
endif 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -89,16 +89,12 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
#define STACK_TOP (0xb0000000) #define STACK_TOP (0xb0000000)
HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle, HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
LPSECURITY_ATTRIBUTES lpThreadAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize, DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, LPTHREAD_START_ROUTINE lpStartAddress,
PPEB Peb, DWORD dwCreationFlags,
DWORD dwCreationFlags, LPDWORD lpThreadId)
LPDWORD lpThreadId,
HANDLE NTDllSectionHandle,
HANDLE SectionHandle,
PVOID ImageBase)
{ {
NTSTATUS Status; NTSTATUS Status;
HANDLE ThreadHandle; HANDLE ThreadHandle;
@ -108,8 +104,6 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
INITIAL_TEB InitialTeb; INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE; BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress; PVOID BaseAddress;
ULONG BytesWritten;
HANDLE DupNTDllSectionHandle, DupSectionHandle;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
@ -155,67 +149,29 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip); DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip);
NtDuplicateObject(NtCurrentProcess(), Status = NtCreateThread(&ThreadHandle,
&SectionHandle, THREAD_ALL_ACCESS,
ProcessHandle, &ObjectAttributes,
&DupSectionHandle, ProcessHandle,
0, &ClientId,
FALSE, &ThreadContext,
DUPLICATE_SAME_ACCESS); &InitialTeb,
NtDuplicateObject(NtCurrentProcess(), CreateSuspended);
&NTDllSectionHandle, if (lpThreadId != NULL)
ProcessHandle, {
&DupNTDllSectionHandle, memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
0, }
FALSE,
DUPLICATE_SAME_ACCESS);
NtWriteVirtualMemory(ProcessHandle, return(ThreadHandle);
(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;
} }
HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName, HANDLE KlMapFile(LPCWSTR lpApplicationName,
LPCWSTR lpCommandLine, LPCWSTR lpCommandLine)
PIMAGE_NT_HEADERS Headers,
PIMAGE_DOS_HEADER DosHeader)
{ {
WCHAR TempApplicationName[256]; WCHAR TempApplicationName[256];
WCHAR TempFileName[256]; WCHAR TempFileName[256];
HANDLE hFile; HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
LARGE_INTEGER FileOffset;
ULONG i; ULONG i;
WCHAR TempDirectoryName[256]; WCHAR TempDirectoryName[256];
UNICODE_STRING ApplicationNameString; UNICODE_STRING ApplicationNameString;
@ -293,40 +249,6 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
return(NULL); 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, Status = NtCreateSection(&hSection,
SECTION_ALL_ACCESS, SECTION_ALL_ACCESS,
NULL, NULL,
@ -345,20 +267,15 @@ HANDLE KERNEL32_MapFile(LPCWSTR lpApplicationName,
return(hSection); return(hSection);
} }
static NTSTATUS static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
CreatePeb ( PRTL_USER_PROCESS_PARAMETERS Ppb)
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{ {
NTSTATUS Status; NTSTATUS Status;
PVOID PebBase;
ULONG PebSize;
PEB Peb;
PVOID PpbBase; PVOID PpbBase;
ULONG PpbSize; ULONG PpbSize;
ULONG BytesWritten; ULONG BytesWritten;
ULONG Offset;
/* create the PPB */ /* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO; PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize; PpbSize = Ppb->TotalSize;
@ -381,33 +298,16 @@ CreatePeb (
&BytesWritten); &BytesWritten);
/* create the PEB */ /* create the PPB */
PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000; Offset = FIELD_OFFSET(PEB, ProcessParameters);
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;
NtWriteVirtualMemory(ProcessHandle, NtWriteVirtualMemory(ProcessHandle,
PebBase, PEB_BASE + Offset,
&Peb, &PpbBase,
sizeof(Peb), sizeof(PpbBase),
&BytesWritten); &BytesWritten);
*PebPtr = (PPEB)PebBase;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -438,11 +338,14 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
DWORD len = 0; DWORD len = 0;
PRTL_USER_PROCESS_PARAMETERS Ppb; PRTL_USER_PROCESS_PARAMETERS Ppb;
UNICODE_STRING CommandLine_U; UNICODE_STRING CommandLine_U;
PPEB Peb;
DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n", DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n",
lpApplicationName,lpCommandLine); lpApplicationName,lpCommandLine);
/*
* Process the application name and command line
*/
if (lpApplicationName[1] != ':') if (lpApplicationName[1] != ':')
{ {
len = GetCurrentDirectoryW(MAX_PATH,TempCommandLine); len = GetCurrentDirectoryW(MAX_PATH,TempCommandLine);
@ -461,39 +364,49 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
wcscat(TempCommandLine, L" "); wcscat(TempCommandLine, L" ");
wcscat(TempCommandLine, lpCommandLine); wcscat(TempCommandLine, lpCommandLine);
} }
/*
* Create the PPB
*/
RtlInitUnicodeString(&CommandLine_U, TempCommandLine);
RtlInitUnicodeString ( DPRINT("CommandLine_U %w\n", CommandLine_U.Buffer);
&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);
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, Status = NtCreateProcess(&hProcess,
PROCESS_ALL_ACCESS, PROCESS_ALL_ACCESS,
NULL, NULL,
NtCurrentProcess(), NtCurrentProcess(),
bInheritHandles, bInheritHandles,
NULL, hSection,
NULL, NULL,
NULL); NULL);
/*
* Get some information about the process
*/
ZwQueryInformationProcess(hProcess, ZwQueryInformationProcess(hProcess,
ProcessBasicInformation, ProcessBasicInformation,
&ProcessBasicInfo, &ProcessBasicInfo,
@ -503,36 +416,11 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
ProcessBasicInfo.UniqueProcessId); ProcessBasicInfo.UniqueProcessId);
lpProcessInformation->dwProcessId = 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 * Create Process Environment Block
*/ */
DPRINT("Creating peb\n"); DPRINT("Creating peb\n");
CreatePeb(&Peb, hProcess, Ppb); KlInitPeb(hProcess, Ppb);
RtlDestroyProcessParameters (Ppb); RtlDestroyProcessParameters (Ppb);
@ -541,19 +429,19 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))-> ((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
AddressOfEntryPoint + AddressOfEntryPoint +
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase; ((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase;
hThread = CreateFirstThread(hProcess,
lpThreadAttributes, hThread = KlCreateFirstThread(hProcess,
Headers.OptionalHeader.SizeOfStackReserve, lpThreadAttributes,
lpStartAddress, // Headers.OptionalHeader.SizeOfStackReserve,
Peb, 0x200000,
dwCreationFlags, lpStartAddress,
&lpProcessInformation->dwThreadId, dwCreationFlags,
NTDllSection, &lpProcessInformation->dwThreadId);
hSection,
(PVOID)Headers.OptionalHeader.ImageBase); if (hThread == NULL)
{
if ( hThread == NULL ) return FALSE;
return FALSE; }
lpProcessInformation->hProcess = hProcess; lpProcessInformation->hProcess = hProcess;
lpProcessInformation->hThread = hThread; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -20,11 +20,9 @@
#include <wchar.h> #include <wchar.h>
#include <ntdll/ldr.h> #include <ntdll/ldr.h>
#include <ntdll/rtl.h> #include <ntdll/rtl.h>
#include <csrss/csrss.h>
//#define DBG_NTDLL_LDR_STARTUP
#ifndef DBG_NTDLL_LDR_STARTUP
#define NDEBUG #define NDEBUG
#endif
#include <ntdll/ntdll.h> #include <ntdll/ntdll.h>
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
@ -36,45 +34,45 @@ extern HANDLE __ProcessHeap;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID LdrStartup(VOID)
/* 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)
{ {
PEPFUNC EntryPoint; PEPFUNC EntryPoint;
PIMAGE_DOS_HEADER PEDosHeader; PIMAGE_DOS_HEADER PEDosHeader;
NTSTATUS Status; NTSTATUS Status;
PIMAGE_NT_HEADERS NTHeaders; PIMAGE_NT_HEADERS NTHeaders;
PVOID ImageBase;
DPRINT("LdrStartup(Peb %x SectionHandle %x, ImageBase %x, " PPEB Peb;
"NTDllSectionHandle %x )\n",
Peb, SectionHandle, ImageBase, NTDllSectionHandle); DPRINT("LdrStartup()\n");
LdrDllListHead.BaseAddress = (PVOID)&_image_base__; LdrDllListHead.BaseAddress = (PVOID)&_image_base__;
LdrDllListHead.Prev = &LdrDllListHead; LdrDllListHead.Prev = &LdrDllListHead;
LdrDllListHead.Next = &LdrDllListHead; LdrDllListHead.Next = &LdrDllListHead;
LdrDllListHead.SectionHandle = NTDllSectionHandle; LdrDllListHead.SectionHandle = NULL;
PEDosHeader = (PIMAGE_DOS_HEADER)LdrDllListHead.BaseAddress; PEDosHeader = (PIMAGE_DOS_HEADER)LdrDllListHead.BaseAddress;
LdrDllListHead.Headers = (PIMAGE_NT_HEADERS)(LdrDllListHead.BaseAddress + LdrDllListHead.Headers = (PIMAGE_NT_HEADERS)(LdrDllListHead.BaseAddress +
PEDosHeader->e_lfanew); 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); DPRINT("PEDosHeader %x\n", PEDosHeader);
if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC || if (PEDosHeader->e_magic != IMAGE_DOS_MAGIC ||
PEDosHeader->e_lfanew == 0L || PEDosHeader->e_lfanew == 0L ||
*(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC) *(PULONG)((PUCHAR)ImageBase + PEDosHeader->e_lfanew) != IMAGE_PE_MAGIC)
{ {
DbgPrint("Image has bad header\n"); DbgPrint("Image has bad header\n");
ZwTerminateProcess(NULL, ZwTerminateProcess(NULL, STATUS_UNSUCCESSFUL);
STATUS_UNSUCCESSFUL);
} }
/* normalize process parameters */ /* normalize process parameters */
@ -87,7 +85,7 @@ VOID LdrStartup(PPEB Peb,
NTHeaders->OptionalHeader.SizeOfHeapReserve, NTHeaders->OptionalHeader.SizeOfHeapReserve,
NULL, NULL,
NULL); NULL);
EntryPoint = LdrPEStartup((PVOID)ImageBase, SectionHandle); EntryPoint = LdrPEStartup((PVOID)ImageBase, NULL);
if (EntryPoint == NULL) if (EntryPoint == NULL)
{ {
@ -104,8 +102,8 @@ VOID LdrStartup(PPEB Peb,
DbgPrint("Failed to connect to csrss.exe: expect trouble\n"); DbgPrint("Failed to connect to csrss.exe: expect trouble\n");
} }
// DbgPrint("Transferring control to image at %x\n",EntryPoint); DbgPrint("Transferring control to image at %x\n",EntryPoint);
Status = EntryPoint(Peb); Status = EntryPoint(NULL);
ZwTerminateProcess(NtCurrentProcess(),Status); 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -819,7 +819,7 @@ static NTSTATUS LdrFixupImports(PIMAGE_NT_HEADERS NTHeaders,
* *
*/ */
PEPFUNC LdrPEStartup (PVOID ImageBase, PEPFUNC LdrPEStartup (PVOID ImageBase,
HANDLE SectionHandle) HANDLE SectionHandle)
{ {
NTSTATUS Status; NTSTATUS Status;
PEPFUNC EntryPoint; PEPFUNC EntryPoint;
@ -837,10 +837,13 @@ PEPFUNC LdrPEStartup (PVOID ImageBase,
/* /*
* Initialize image sections. * Initialize image sections.
*/ */
LdrMapSections(NtCurrentProcess(), if (SectionHandle != NULL)
ImageBase, {
SectionHandle, LdrMapSections(NtCurrentProcess(),
NTHeaders); ImageBase,
SectionHandle,
NTHeaders);
}
/* /*
* If the base address is different from the * 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 # ReactOS Operating System
# #
@ -6,7 +6,6 @@ TARGET=ntdll
BASE_CFLAGS = -I../../include -D__NTDLL__ BASE_CFLAGS = -I../../include -D__NTDLL__
include ../../rules.mak
IMAGE_BASE = 0x77f60000 IMAGE_BASE = 0x77f60000
ifneq ($(HOST),mingw32-windows) 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_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/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 STDIO_OBJECTS = stdio/sprintf.o stdio/swprintf.o
@ -131,4 +130,4 @@ else
endif endif
#WARNINGS_ARE_ERRORS = yes #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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -16,7 +16,7 @@
#include <internal/teb.h> #include <internal/teb.h>
#include <string.h> #include <string.h>
#define NDEBUG //#define NDEBUG
#include <ntdll/ntdll.h> #include <ntdll/ntdll.h>
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -107,6 +107,7 @@ RtlDestroyEnvironment (
} }
NTSTATUS NTSTATUS
STDCALL STDCALL
RtlExpandEnvironmentStrings_U ( 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -22,51 +22,40 @@
#include <ntdll/base.h> #include <ntdll/base.h>
#include <ntdll/rtl.h> #include <ntdll/rtl.h>
#define NDEBUG //#define NDEBUG
#include <ntdll/ntdll.h> #include <ntdll/ntdll.h>
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
#define STACK_TOP (0xb0000000) #define STACK_TOP (0xb0000000)
static HANDLE STDCALL HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
RtlpCreateFirstThread(HANDLE ProcessHandle, DWORD dwStackSize,
PSECURITY_DESCRIPTOR SecurityDescriptor, LPTHREAD_START_ROUTINE lpStartAddress,
DWORD dwStackSize, DWORD dwCreationFlags,
LPTHREAD_START_ROUTINE lpStartAddress, PCLIENT_ID ClientId)
PPEB Peb, {
DWORD dwCreationFlags,
LPDWORD lpThreadId,
HANDLE NTDllSectionHandle,
HANDLE SectionHandle,
PVOID ImageBase)
{
NTSTATUS Status; NTSTATUS Status;
HANDLE ThreadHandle; HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
CONTEXT ThreadContext; CONTEXT ThreadContext;
INITIAL_TEB InitialTeb; INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE; BOOLEAN CreateSuspended = FALSE;
PVOID BaseAddress; PVOID BaseAddress;
ULONG BytesWritten; CLIENT_ID Cid;
HANDLE DupNTDllSectionHandle, DupSectionHandle;
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES); ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL; ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL; ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0; ObjectAttributes.Attributes = 0;
// ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = SecurityDescriptor;
ObjectAttributes.SecurityQualityOfService = NULL; ObjectAttributes.SecurityQualityOfService = NULL;
if ((dwCreationFlags & CREATE_SUSPENDED) == CREATE_SUSPENDED) if (dwCreationFlags & CREATE_SUSPENDED)
CreateSuspended = TRUE; CreateSuspended = TRUE;
else else
CreateSuspended = FALSE; CreateSuspended = FALSE;
/* create the process stack (first thead) */
BaseAddress = (PVOID)(STACK_TOP - dwStackSize); BaseAddress = (PVOID)(STACK_TOP - dwStackSize);
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&BaseAddress, &BaseAddress,
@ -76,10 +65,10 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Failed to allocate stack\n");
return(NULL); return(NULL);
} }
memset(&ThreadContext,0,sizeof(CONTEXT)); memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = (ULONG)lpStartAddress; ThreadContext.Eip = (ULONG)lpStartAddress;
ThreadContext.SegGs = USER_DS; ThreadContext.SegGs = USER_DS;
@ -93,312 +82,198 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
DPRINT("ThreadContext.Eip %x\n",ThreadContext.Eip); 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, Status = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS, THREAD_ALL_ACCESS,
&ObjectAttributes, &ObjectAttributes,
ProcessHandle, ProcessHandle,
&ClientId, &Cid,
&ThreadContext, &ThreadContext,
&InitialTeb, &InitialTeb,
CreateSuspended); CreateSuspended);
if ( lpThreadId != NULL ) if (ClientId != NULL)
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG)); {
memcpy(&ClientId->UniqueThread, &Cid.UniqueThread, sizeof(ULONG));
}
return ThreadHandle; return(ThreadHandle);
} }
static NTSTATUS RtlpMapFile(PUNICODE_STRING ApplicationName,
static NTSTATUS PHANDLE Section)
RtlpMapFile(PUNICODE_STRING ApplicationName,
PIMAGE_NT_HEADERS Headers,
PIMAGE_DOS_HEADER DosHeader,
PHANDLE Section)
{ {
HANDLE hFile; HANDLE hFile;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
LARGE_INTEGER FileOffset; OBJECT_ATTRIBUTES ObjectAttributes;
OBJECT_ATTRIBUTES ObjectAttributes; PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; NTSTATUS Status;
NTSTATUS Status;
hFile = NULL; hFile = NULL;
*Section = NULL;
InitializeObjectAttributes(&ObjectAttributes,
ApplicationName,
OBJ_CASE_INSENSITIVE,
NULL,
SecurityDescriptor);
DPRINT("ApplicationName %w\n", ApplicationName->Buffer); /*
* Try to open the executable
*/
InitializeObjectAttributes(&ObjectAttributes, Status = NtOpenFile(&hFile,
ApplicationName,
OBJ_CASE_INSENSITIVE,
NULL,
SecurityDescriptor);
/*
* Try to open the executable
*/
Status = NtOpenFile(&hFile,
SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA, SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
&ObjectAttributes, &ObjectAttributes,
&IoStatusBlock, &IoStatusBlock,
FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_SHARE_DELETE|FILE_SHARE_READ,
FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE); FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
if (!NT_SUCCESS(Status))
return Status;
Status = NtReadFile(hFile, if (!NT_SUCCESS(Status))
NULL, {
NULL, return(Status);
NULL, }
&IoStatusBlock,
DosHeader,
sizeof(IMAGE_DOS_HEADER),
NULL,
NULL);
if (!NT_SUCCESS(Status))
return Status;
FileOffset.u.LowPart = DosHeader->e_lfanew; Status = NtCreateSection(Section,
FileOffset.u.HighPart = 0; SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_EXECUTE,
SEC_IMAGE,
hFile);
NtClose(hFile);
Status = NtReadFile(hFile, if (!NT_SUCCESS(Status))
NULL, {
NULL, return(Status);
NULL, }
&IoStatusBlock,
Headers,
sizeof(IMAGE_NT_HEADERS),
&FileOffset,
NULL);
if (!NT_SUCCESS(Status))
return Status;
Status = NtCreateSection(Section, return(STATUS_SUCCESS);
SECTION_ALL_ACCESS,
NULL,
NULL,
PAGE_EXECUTE,
SEC_IMAGE,
hFile);
NtClose(hFile);
if (!NT_SUCCESS(Status))
return Status;
return STATUS_SUCCESS;
} }
static NTSTATUS KlInitPeb (HANDLE ProcessHandle,
static NTSTATUS PRTL_USER_PROCESS_PARAMETERS Ppb)
RtlpCreatePpbAndPeb (
PPEB *PebPtr,
HANDLE ProcessHandle,
PRTL_USER_PROCESS_PARAMETERS Ppb)
{ {
NTSTATUS Status; NTSTATUS Status;
ULONG BytesWritten; PVOID PpbBase;
PVOID PebBase; ULONG PpbSize;
ULONG PebSize; ULONG BytesWritten;
PEB Peb; ULONG Offset;
PVOID PpbBase;
ULONG PpbSize;
/* create the PPB */ /* create the PPB */
PpbBase = (PVOID)PEB_STARTUPINFO; PpbBase = (PVOID)PEB_STARTUPINFO;
PpbSize = Ppb->TotalSize; PpbSize = Ppb->TotalSize;
Status = NtAllocateVirtualMemory (ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
&PpbBase, &PpbBase,
0, 0,
&PpbSize, &PpbSize,
MEM_COMMIT, MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
return(Status); {
return(Status);
}
DPRINT("Ppb size %x\n", PpbSize); DPRINT("Ppb->TotalSize %x\n", Ppb->TotalSize);
NtWriteVirtualMemory (ProcessHandle, NtWriteVirtualMemory(ProcessHandle,
PpbBase, PpbBase,
Ppb, Ppb,
Ppb->TotalSize, Ppb->TotalSize,
&BytesWritten); &BytesWritten);
Offset = FIELD_OFFSET(PEB, ProcessParameters);
NtWriteVirtualMemory(ProcessHandle,
(PVOID)(PEB_BASE + Offset),
&PpbBase,
sizeof(PpbBase),
&BytesWritten);
/* create the PEB */ return(STATUS_SUCCESS);
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;
} }
NTSTATUS STDCALL RtlCreateUserProcess(PUNICODE_STRING CommandLine,
NTSTATUS ULONG Unknown1,
STDCALL PRTL_USER_PROCESS_PARAMETERS Ppb,
RtlCreateUserProcess ( PSECURITY_DESCRIPTOR ProcessSd,
PUNICODE_STRING CommandLine, PSECURITY_DESCRIPTOR ThreadSd,
ULONG Unknown1, WINBOOL bInheritHandles,
PRTL_USER_PROCESS_PARAMETERS Ppb, DWORD dwCreationFlags,
PSECURITY_DESCRIPTOR ProcessSd, PCLIENT_ID ClientId,
PSECURITY_DESCRIPTOR ThreadSd, PHANDLE ProcessHandle,
WINBOOL bInheritHandles, PHANDLE ThreadHandle)
DWORD dwCreationFlags,
PCLIENT_ID ClientId,
PHANDLE ProcessHandle,
PHANDLE ThreadHandle)
{ {
HANDLE hSection, hProcess, hThread; HANDLE hSection;
HANDLE hThread;
NTSTATUS Status; NTSTATUS Status;
LPTHREAD_START_ROUTINE lpStartAddress = NULL; LPTHREAD_START_ROUTINE lpStartAddress = NULL;
WCHAR TempCommandLine[256];
PVOID BaseAddress; PVOID BaseAddress;
LARGE_INTEGER SectionOffset; LARGE_INTEGER SectionOffset;
IMAGE_NT_HEADERS Headers;
IMAGE_DOS_HEADER DosHeader;
HANDLE NTDllSection;
ULONG InitialViewSize; ULONG InitialViewSize;
PROCESS_BASIC_INFORMATION ProcessBasicInfo; PROCESS_BASIC_INFORMATION ProcessBasicInfo;
CLIENT_ID LocalClientId;
ULONG retlen; ULONG retlen;
PPEB Peb; DWORD len = 0;
DPRINT ("RtlCreateUserProcess(CommandLine '%w')\n", DPRINT("CreateProcessW(CommandLine '%w')\n", CommandLine->Buffer);
CommandLine->Buffer);
Status = RtlpMapFile(CommandLine,
Status = RtlpMapFile(CommandLine, &hSection);
&Headers,
&DosHeader, /*
&hSection); * Create a new process
*/
Status = NtCreateProcess(&hProcess,
PROCESS_ALL_ACCESS, Status = NtCreateProcess(ProcessHandle,
NULL, PROCESS_ALL_ACCESS,
NtCurrentProcess(), NULL,
bInheritHandles, NtCurrentProcess(),
NULL, bInheritHandles,
NULL, hSection,
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);
if (!NT_SUCCESS(Status)) 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"); DPRINT("Creating peb\n");
RtlpCreatePpbAndPeb (&Peb, hProcess, Ppb); KlInitPeb(*ProcessHandle, Ppb);
DPRINT("Creating thread for process\n"); DPRINT("Creating thread for process\n");
lpStartAddress = (LPTHREAD_START_ROUTINE) lpStartAddress = (LPTHREAD_START_ROUTINE)
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))-> ((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
AddressOfEntryPoint + AddressOfEntryPoint +
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase; ((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->ImageBase;
hThread = RtlpCreateFirstThread (
hProcess, hThread = KlCreateFirstThread(*ProcessHandle,
ThreadSd, // Headers.OptionalHeader.SizeOfStackReserve,
Headers.OptionalHeader.SizeOfStackReserve, 0x200000,
lpStartAddress, lpStartAddress,
Peb, dwCreationFlags,
dwCreationFlags, ClientId);
&LocalClientId.UniqueThread, if (hThread == NULL)
NTDllSection, {
hSection, DPRINT("Failed to create thread\n");
(PVOID)Headers.OptionalHeader.ImageBase); return(STATUS_UNSUCCESSFUL);
}
if ( hThread == NULL ) return(STATUS_SUCCESS);
return Status;
if (ClientId)
{
ClientId->UniqueProcess = LocalClientId.UniqueProcess;
ClientId->UniqueThread = LocalClientId.UniqueThread;
}
if (ProcessHandle)
*ProcessHandle = hProcess;
if (ThreadHandle)
*ThreadHandle = hThread;
return STATUS_SUCCESS;
} }
@ -507,7 +382,6 @@ RtlCreateProcessParameters (
CurrentDirectory->Length); CurrentDirectory->Length);
Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length); Dest = (PWCHAR)(((PBYTE)Dest) + CurrentDirectory->Length);
} }
*Dest = 0;
Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS) + Dest = (PWCHAR)(((PBYTE)Param) + sizeof(RTL_USER_PROCESS_PARAMETERS) +
/* (256 * sizeof(WCHAR)) + */ (MAX_PATH * sizeof(WCHAR))); /* (256 * sizeof(WCHAR)) + */ (MAX_PATH * sizeof(WCHAR)));
@ -587,133 +461,6 @@ RtlCreateProcessParameters (
*Ppb = Param; *Ppb = Param;
RtlReleasePebLock (); 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 */ /* 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -26,8 +26,7 @@ __asm__ ("\n\t.global _DbgService\n\t"
"int $0x2D\n\t" "int $0x2D\n\t"
"ret\n\t"); "ret\n\t");
ULONG ULONG DbgPrint(PCH Format, ...)
DbgPrint(PCH Format, ...)
{ {
ANSI_STRING DebugString; ANSI_STRING DebugString;
CHAR Buffer[512]; CHAR Buffer[512];
@ -41,8 +40,8 @@ DbgPrint(PCH Format, ...)
DebugString.Length = vsprintf (Buffer, Format, ap); DebugString.Length = vsprintf (Buffer, Format, ap);
va_end (ap); va_end (ap);
DbgService (1, &DebugString, NULL); HalDisplayString(Buffer);
return (ULONG)DebugString.Length; return (ULONG)DebugString.Length;
} }

View file

@ -31,6 +31,26 @@ static KSPIN_LOCK GdtLock;
/* FUNCTIONS *****************************************************************/ /* 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) VOID KeDumpGdtSelector(ULONG Entry)
{ {
} }

View file

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

View file

@ -42,37 +42,18 @@ VOID HalTaskSwitch(PKTHREAD thread)
* ARGUMENTS: * ARGUMENTS:
* thread = Thread to switch to * thread = Thread to switch to
* NOTE: This function will not return until the current thread is scheduled * NOTE: This function will not return until the current thread is scheduled
* again (possibly never); * again (possibly never)
*/ */
{ {
DPRINT("Scheduling thread %x\n",thread); #if 0
DPRINT("Scheduling thread %x\n",thread->Context.nr); PETHREAD Thread;
DPRINT("previous task %x reserved1 %x esp0 %x ss0 %x\n", Thread = CONTAINING_RECORD(thread, ETHREAD, Tcb);
thread->Context.previous_task,thread->Context.reserved1, if (Thread->Cid.UniqueThread != (HANDLE)1)
thread->Context.esp0,thread->Context.ss0); {
DPRINT("reserved2 %x esp1 %x ss1 %x reserved3 %x esp2 %x ss2 %x\n", DPRINT1("Scheduling thread %x (id %d)\n",Thread,
thread->Context.reserved2,thread->Context.esp1,thread->Context.ss1, Thread->Cid.UniqueThread);
thread->Context.reserved3,thread->Context.esp2,thread->Context.ss2); }
DPRINT("reserved4 %x cr3 %x eip %x eflags %x eax %x\n", #endif
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);
__asm__("pushfl\n\t" __asm__("pushfl\n\t"
"cli\n\t" "cli\n\t"
"ljmp %0\n\t" "ljmp %0\n\t"

View file

@ -30,308 +30,151 @@
#include <internal/teb.h> #include <internal/teb.h>
#include <internal/ldr.h> #include <internal/ldr.h>
//#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#include "syspath.h" #include "syspath.h"
/* GLOBALS *******************************************************************/
/* FUNCTIONS ****************************************************************/
#define STACK_TOP (0xb0000000) #define STACK_TOP (0xb0000000)
static NTSTATUS LdrCreateUserProcessParameters ( /* FUNCTIONS *****************************************************************/
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);
Status = ZwAllocateVirtualMemory (ProcessHandle, /*
(PVOID*)&PpbBase, * FIXME: The location of the initial process should be configurable,
0, * from command line or registry
&PpbSize, */
MEM_COMMIT, NTSTATUS LdrLoadInitialProcess (VOID)
PAGE_READWRITE); {
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)) 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; return Status;
} }
/* initialize the ppb */ /*
memset (&Ppb, 0, sizeof(RTL_USER_PROCESS_PARAMETERS)); * Create initial stack and thread
*/
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;
/* /*
* Aargh! * Aargh!
*/ */
LdrStartupAddr = (DWORD)LdrpGetSystemDllEntryPoint(); LdrStartupAddr = (PVOID)LdrpGetSystemDllEntryPoint();
DPRINT("LdrStartupAddr %x\n", LdrStartupAddr); 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 * Create page backed section for stack
*/ */
DPRINT("Allocating stack\n"); 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; StackSize = NTHeaders->OptionalHeader.SizeOfStackReserve;
DPRINT("StackSize %x\n", StackSize);
KeDetachProcess();
DPRINT("Dereferencing process\n");
// ObDereferenceObject(Process);
DbgPrint ("Stack size %x\n", StackSize); DbgPrint ("Stack size %x\n", StackSize);
DPRINT("Allocating virtual memory\n");
Status = ZwAllocateVirtualMemory(ProcessHandle, Status = ZwAllocateVirtualMemory(ProcessHandle,
(PVOID*)&StackBase, (PVOID*)&StackBase,
0, 0,
@ -340,42 +183,22 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
PAGE_READWRITE); PAGE_READWRITE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT("Stack allocation failed "); DPRINT("Stack allocation failed (Status %x)", Status);
DbgPrintErrorMessage(Status);
/* FIXME: unmap the section here */
/* FIXME: destroy the section here */
return Status; return Status;
} }
ZwDuplicateObject(NtCurrentProcess(), DPRINT("Attaching to process\n");
&SectionHandle, KeAttachProcess(Process);
ProcessHandle, Peb = (PPEB)PEB_BASE;
&DupSectionHandle, DPRINT("Peb %x\n", Peb);
0, DPRINT("CurrentProcess %x Peb->ImageBaseAddress %x\n",
FALSE, PsGetCurrentProcess(),
DUPLICATE_SAME_ACCESS); Peb->ImageBaseAddress);
KeDetachProcess();
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 8),
&ImageBase,
sizeof (ImageBase),
&BytesWritten);
ZwWriteVirtualMemory(ProcessHandle,
(PVOID)(STACK_TOP - 12),
&DupSectionHandle,
sizeof (DupSectionHandle),
&BytesWritten);
/* 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); DbgPrint ("NTOSKRNL: Peb = %x\n", Peb);
/* /*
* Initialize context to point to LdrStartup * Initialize context to point to LdrStartup
*/ */
@ -384,13 +207,14 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
Context.Esp = STACK_TOP - 20; Context.Esp = STACK_TOP - 20;
Context.EFlags = 0x202; Context.EFlags = 0x202;
Context.SegCs = USER_CS; Context.SegCs = USER_CS;
Context.Eip = LdrStartupAddr; Context.Eip = (ULONG)LdrStartupAddr;
Context.SegDs = USER_DS; Context.SegDs = USER_DS;
Context.SegEs = USER_DS; Context.SegEs = USER_DS;
Context.SegFs = USER_DS; Context.SegFs = USER_DS;
Context.SegGs = USER_DS; Context.SegGs = USER_DS;
DPRINT("LdrStartupAddr %x\n",LdrStartupAddr); DPRINT("LdrStartupAddr %x\n",LdrStartupAddr);
/* /*
* FIXME: Create process and let 'er rip * FIXME: Create process and let 'er rip
*/ */
@ -413,50 +237,17 @@ NTSTATUS LdrLoadImage(HANDLE ProcessHandle,
return 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);
KeDetachProcess();
return STATUS_SUCCESS; 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 */ /* 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -190,15 +190,13 @@ static VOID LdrLoadAutoConfigDriver (LPWSTR RelativeDriverName)
Status = LdrLoadDriver(&DriverName); Status = LdrLoadDriver(&DriverName);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("driver load failed, status;%d(%x)\n", Status, Status); DbgPrint("driver load failed, status (%x)\n", Status);
DbgPrintErrorMessage(Status);
KeBugCheck(0); KeBugCheck(0);
} }
} }
VOID VOID LdrLoadAutoConfigDrivers (VOID)
LdrLoadAutoConfigDrivers (VOID)
{ {
/* /*
* Keyboard driver * Keyboard driver
@ -248,8 +246,7 @@ LdrCreateModule(PVOID ObjectBody,
* RETURNS: Status * RETURNS: Status
*/ */
NTSTATUS NTSTATUS LdrLoadDriver(PUNICODE_STRING Filename)
LdrLoadDriver(PUNICODE_STRING Filename)
{ {
PMODULE_OBJECT ModuleObject; PMODULE_OBJECT ModuleObject;

View file

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

View file

@ -23,7 +23,7 @@
#include <internal/symbol.h> #include <internal/symbol.h>
#include <internal/teb.h> #include <internal/teb.h>
//#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
#include "syspath.h" #include "syspath.h"
@ -132,11 +132,13 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
DPRINT("ImageBase %x\n",ImageBase); DPRINT("ImageBase %x\n",ImageBase);
*LdrStartupAddr = *LdrStartupAddr =
(PVOID)ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint; (PVOID)ImageBase + NTHeaders->OptionalHeader.AddressOfEntryPoint;
DPRINT("LdrStartupAddr %x\n", LdrStartupAddr);
SystemDllEntryPoint = *LdrStartupAddr; SystemDllEntryPoint = *LdrStartupAddr;
/* /*
* Create a section for NTDLL * Create a section for NTDLL
*/ */
DPRINT("Creating section\n");
Status = ZwCreateSection(&NTDllSectionHandle, Status = ZwCreateSection(&NTDllSectionHandle,
SECTION_ALL_ACCESS, SECTION_ALL_ACCESS,
NULL, NULL,
@ -158,6 +160,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
InitialViewSize = DosHeader->e_lfanew + InitialViewSize = DosHeader->e_lfanew +
sizeof (IMAGE_NT_HEADERS) + sizeof (IMAGE_NT_HEADERS) +
(sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections); (sizeof (IMAGE_SECTION_HEADER) * NTHeaders->FileHeader.NumberOfSections);
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(NTDllSectionHandle, Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle, ProcessHandle,
(PVOID*)&ImageBase, (PVOID*)&ImageBase,
@ -181,17 +184,21 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
LARGE_INTEGER Offset; LARGE_INTEGER Offset;
ULONG Base; ULONG Base;
DPRINT("Mapping view of section %d\n", i);
Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(BlockBuffer); Sections = (PIMAGE_SECTION_HEADER) SECHDROFFSET(BlockBuffer);
DPRINT("Sections %x\n", Sections);
Base = Sections[i].VirtualAddress + ImageBase; Base = Sections[i].VirtualAddress + ImageBase;
DPRINT("Base %x\n", Base);
Offset.u.LowPart = Sections[i].PointerToRawData; Offset.u.LowPart = Sections[i].PointerToRawData;
Offset.u.HighPart = 0; Offset.u.HighPart = 0;
DPRINT("Mapping view of section\n");
Status = ZwMapViewOfSection(NTDllSectionHandle, Status = ZwMapViewOfSection(NTDllSectionHandle,
ProcessHandle, ProcessHandle,
(PVOID *) & Base, (PVOID*)&Base,
0, 0,
Sections[i].Misc.VirtualSize, Sections[i].Misc.VirtualSize,
&Offset, &Offset,
(PULONG) & Sections[i].Misc.VirtualSize, (PULONG)&Sections[i].Misc.VirtualSize,
0, 0,
MEM_COMMIT, MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
@ -202,6 +209,7 @@ NTSTATUS LdrpMapSystemDll(HANDLE ProcessHandle,
return(Status); return(Status);
} }
} }
DPRINT("Finished mapping\n");
ZwClose(NTDllSectionHandle); ZwClose(NTDllSectionHandle);
return(STATUS_SUCCESS); 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 # ReactOS Operating System
# #
@ -65,7 +65,8 @@ CM_OBJECTS = cm/registry.o
DBG_OBJECTS = dbg/brkpoint.o dbg/errinfo.o dbg/print.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 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 * Get the address for the page fault
*/ */
__asm__("movl %%cr2,%0\n\t" : "=d" (cr2)); __asm__("movl %%cr2,%0\n\t" : "=d" (cr2));
// DbgPrint("Page fault address %x eip %x process %x code %x\n",cr2,eip, DPRINT("Page fault address %x eip %x process %x code %x\n",cr2,eip,
// PsGetCurrentProcess(), error_code); PsGetCurrentProcess(), error_code);
MmSetPageProtect(PsGetCurrentProcess(), MmSetPageProtect(PsGetCurrentProcess(),
(PVOID)PAGE_ROUND_DOWN(PsGetCurrentProcess()), (PVOID)PAGE_ROUND_DOWN(PsGetCurrentProcess()),
@ -259,7 +259,7 @@ ULONG MmPageFault(ULONG cs, ULONG eip, ULONG error_code)
if (error_code & 0x1) 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); 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -430,6 +430,7 @@ NTSTATUS STDCALL NtMapViewOfSection(HANDLE SectionHandle,
DPRINT("*BaseAddress %x\n",*BaseAddress); DPRINT("*BaseAddress %x\n",*BaseAddress);
ObDereferenceObject(Process); ObDereferenceObject(Process);
DPRINT("NtMapViewOfSection() returning (Status %x)\n", STATUS_SUCCESS);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -472,13 +473,24 @@ NTSTATUS STDCALL NtUnmapViewOfSection (HANDLE ProcessHandle,
NTSTATUS Status; NTSTATUS Status;
PMEMORY_AREA MemoryArea; PMEMORY_AREA MemoryArea;
DPRINT("NtUnmapViewOfSection(ProcessHandle %x, BaseAddress %x)\n",
ProcessHandle, BaseAddress);
DPRINT("Referencing process\n");
Status = ObReferenceObjectByHandle(ProcessHandle, Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_OPERATION, PROCESS_VM_OPERATION,
PsProcessType, PsProcessType,
UserMode, UserMode,
(PVOID*)&Process, (PVOID*)&Process,
NULL); 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); MemoryArea = MmOpenMemoryAreaByAddress(Process, BaseAddress);
if (MemoryArea == NULL) 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -251,7 +251,10 @@ PACCESS_TOKEN PsReferenceImpersonationToken(PETHREAD Thread,
return(Thread->ImpersonationInfo->Token); 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 // wake up the thread, and tell it it timed out
NTSTATUS Status = STATUS_TIMEOUT; NTSTATUS Status = STATUS_TIMEOUT;
@ -263,10 +266,12 @@ static VOID PiTimeoutThread( struct _KDPC *dpc, PVOID Context, PVOID arg1, PVOID
VOID PiBeforeBeginThread(VOID) VOID PiBeforeBeginThread(VOID)
{ {
PPEB Peb;
DPRINT("PiBeforeBeginThread()\n"); DPRINT("PiBeforeBeginThread()\n");
//KeReleaseSpinLock(&PiThreadListLock, PASSIVE_LEVEL); //KeReleaseSpinLock(&PiThreadListLock, PASSIVE_LEVEL);
KeLowerIrql(PASSIVE_LEVEL); KeLowerIrql(PASSIVE_LEVEL);
DPRINT("KeGetCurrentIrql() %d\n", KeGetCurrentIrql()); Peb = (PPEB)PEB_BASE;
} }
VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext) VOID PsBeginThread(PKSTART_ROUTINE StartRoutine, PVOID StartContext)
@ -459,7 +464,9 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle,
/* more initialization */ /* more initialization */
Teb.Cid.UniqueThread = Thread->Cid.UniqueThread; Teb.Cid.UniqueThread = Thread->Cid.UniqueThread;
Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess; Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess;
DPRINT("sizeof(NT_TEB) %x\n", sizeof(NT_TEB));
/* write TEB data into teb page */ /* write TEB data into teb page */
Status = NtWriteVirtualMemory(ProcessHandle, Status = NtWriteVirtualMemory(ProcessHandle,
TebBase, 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; NTSTATUS Status;
PVOID PebBase; PVOID PebBase;
@ -202,6 +203,9 @@ static NTSTATUS PsCreatePeb(HANDLE ProcessHandle)
PEB Peb; PEB Peb;
ULONG BytesWritten; ULONG BytesWritten;
memset(&Peb, 0, sizeof(Peb));
Peb.ImageBaseAddress = ImageBase;
PebBase = (PVOID)PEB_BASE; PebBase = (PVOID)PEB_BASE;
PebSize = 0x1000; PebSize = 0x1000;
Status = NtAllocateVirtualMemory(ProcessHandle, Status = NtAllocateVirtualMemory(ProcessHandle,
@ -215,8 +219,6 @@ static NTSTATUS PsCreatePeb(HANDLE ProcessHandle)
return(Status); return(Status);
} }
memset(&Peb, 0, sizeof(Peb));
ZwWriteVirtualMemory(ProcessHandle, ZwWriteVirtualMemory(ProcessHandle,
(PVOID)PEB_BASE, (PVOID)PEB_BASE,
&Peb, &Peb,
@ -294,6 +296,7 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
NTSTATUS Status; NTSTATUS Status;
KIRQL oldIrql; KIRQL oldIrql;
PVOID LdrStartupAddr; PVOID LdrStartupAddr;
PVOID ImageBase;
DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes); DPRINT("NtCreateProcess(ObjectAttributes %x)\n",ObjectAttributes);
@ -339,29 +342,54 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
/* /*
* Now we have created the process proper * 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)) if (!NT_SUCCESS(Status))
{ {
DbgPrint("NtCreateProcess() Peb creation failed: Status %x\n",Status); DbgPrint("NtCreateProcess() Peb creation failed: Status %x\n",Status);
return(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(Process);
ObDereferenceObject(ParentProcess); ObDereferenceObject(ParentProcess);
return(STATUS_SUCCESS); 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 * init.c - Session Manager initialization
* *
@ -133,8 +133,9 @@ InitSessionManager (
DisplayString (L"SM: System Environment created\n"); DisplayString (L"SM: System Environment created\n");
#endif #endif
RtlSetCurrentEnvironment (SmSystemEnvironment, // RtlSetCurrentEnvironment (SmSystemEnvironment,
NULL); // NULL);
#ifndef NDEBUG #ifndef NDEBUG
DisplayString (L"System Environment set\n"); DisplayString (L"System Environment set\n");
#endif #endif

View file

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

View file

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