no message

svn path=/trunk/; revision=215
This commit is contained in:
David Welch 1999-02-06 18:34:14 +00:00
parent f8492b9ae3
commit e5dfcc9871
38 changed files with 694 additions and 514 deletions

View file

@ -1,9 +1,33 @@
extern void main(void); #include <windows.h>
void start(void) extern int main(int args, char* argv[], char* environ[]);
static unsigned int _argc = 0;
static char** _argv = NULL;
static char** _environ = NULL;
int mainCRTStartup(PWSTR args)
{ {
main(); int nRet;
for(;;);
KERNEL32_Init(args);
// SetUnhandledExceptionFilter(NULL);
// _fpreset();
// __GetMainArgs(&_argc, &_argv, &_environ, 0);
nRet = main(_argc, _argv, _environ);
// _cexit();
ExitProcess(nRet);
}
int WinMainCRTStartup()
{
return mainCRTStartup(NULL);
} }
void __main(void) void __main(void)

View file

@ -69,6 +69,11 @@ void ExecuteType(char* cmdline)
OPEN_EXISTING, OPEN_EXISTING,
0, 0,
NULL); NULL);
if (FileHandle == NULL)
{
debug_printf("Unknown file\n");
return;
}
while (ReadFile(FileHandle, while (ReadFile(FileHandle,
&c, &c,
1, 1,
@ -156,7 +161,6 @@ void ExecuteCommand(char* line)
} }
if (ExecuteProcess(cmd,tail)) if (ExecuteProcess(cmd,tail))
{ {
debug_printf("Done ExecuteProcess\n");
return; return;
} }
debug_printf("Unknown command\n"); debug_printf("Unknown command\n");
@ -202,8 +206,6 @@ void main()
{ {
static char line[255]; static char line[255];
KERNEL32_Init();
AllocConsole(); AllocConsole();
InputHandle = GetStdHandle(STD_INPUT_HANDLE); InputHandle = GetStdHandle(STD_INPUT_HANDLE);
OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE);

View file

@ -41,6 +41,7 @@ PVOID Ext2ProcessDirEntry(PDEVICE_EXTENSION DeviceExt,
{ {
PFILE_DIRECTORY_INFORMATION FDI; PFILE_DIRECTORY_INFORMATION FDI;
PFILE_NAMES_INFORMATION FNI; PFILE_NAMES_INFORMATION FNI;
PFILE_BOTH_DIRECTORY_INFORMATION FBI;
ULONG i; ULONG i;
PWSTR FileName; PWSTR FileName;
struct ext2_inode inode; struct ext2_inode inode;
@ -79,6 +80,19 @@ PVOID Ext2ProcessDirEntry(PDEVICE_EXTENSION DeviceExt,
Buffer = Buffer + FDI->NextEntryOffset; Buffer = Buffer + FDI->NextEntryOffset;
break; break;
case FileBothDirectoryInformation:
FBI = (PFILE_BOTH_DIRECTORY_INFORMATION)Buffer;
FBI->NextEntryOffset = sizeof(FileBothDirectoryInformation) +
dir_entry->name_len + 1;
FBI->FileIndex = FileIndex;
FBI->AllocationSize = FBI->EndOfFile = inode.i_size;
FBI->FileAttributes = 0;
FBI->FileNameLength = dir_entry->name_len;
Ext2ConvertName(FBI->FileName, dir_entry->name, dir_entry->name_len);
memset(FBI->ShortName, 0, sizeof(FBI->ShortName));
Buffer = Buffer + FBI->NextEntryOffset;
break;
default: default:
UNIMPLEMENTED; UNIMPLEMENTED;
} }
@ -280,7 +294,8 @@ NTSTATUS Ext2OpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
} }
current_inode = entry.inode; current_inode = entry.inode;
current_segment = strtok(NULL,"\\"); current_segment = strtok(NULL,"\\");
}; StartIndex = 0;
}
DPRINT("Found file\n"); DPRINT("Found file\n");
Ext2ReadInode(DeviceExt, Ext2ReadInode(DeviceExt,

View file

@ -24,16 +24,6 @@ static PDRIVER_OBJECT DriverObject;
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
NTSTATUS Ext2CloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject)
/*
* FUNCTION: Closes a file
*/
{
DPRINT("Ext2CloseFile(DeviceExt %x, FileObject %x)\n",
DeviceExt,FileObject);
return(STATUS_SUCCESS);
}
NTSTATUS Ext2Close(PDEVICE_OBJECT DeviceObject, PIRP Irp) NTSTATUS Ext2Close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{ {
PIO_STACK_LOCATION Stack; PIO_STACK_LOCATION Stack;
@ -46,8 +36,6 @@ NTSTATUS Ext2Close(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Stack = IoGetCurrentIrpStackLocation(Irp); Stack = IoGetCurrentIrpStackLocation(Irp);
FileObject = Stack->FileObject; FileObject = Stack->FileObject;
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
Status = Ext2CloseFile(DeviceExtension,FileObject);
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;

View file

@ -52,21 +52,13 @@ enum
BOOL ObAddObjectToNameSpace(PUNICODE_STRING path, POBJECT_HEADER Object); BOOL ObAddObjectToNameSpace(PUNICODE_STRING path, POBJECT_HEADER Object);
VOID ObRegisterType(CSHORT id, OBJECT_TYPE* type); VOID ObRegisterType(CSHORT id, OBJECT_TYPE* type);
VOID ObInitializeObjectHeader(POBJECT_TYPE Type, PWSTR name,
POBJECT_HEADER obj);
HANDLE ObInsertHandle(PKPROCESS Process, PVOID ObjectBody,
ACCESS_MASK GrantedAccess, BOOLEAN Inherit);
VOID ObDeleteHandle(HANDLE Handle); VOID ObDeleteHandle(HANDLE Handle);
NTSTATUS ObLookupObject(HANDLE rootdir, PWSTR string, PVOID* Object, NTSTATUS ObLookupObject(HANDLE rootdir, PWSTR string, PVOID* Object,
PWSTR* UnparsedSection, ULONG Attributes); PWSTR* UnparsedSection, ULONG Attributes);
PVOID ObCreateObject(PHANDLE Handle, PVOID ObCreateObject(PHANDLE Handle,
ACCESS_MASK DesiredAccess, ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_ATTRIBUTES ObjectAttributes,
POBJECT_TYPE Type); POBJECT_TYPE Type);
VOID ObInitializeHandleTable(PKPROCESS Parent, BOOLEAN Inherit,
PKPROCESS Process);
VOID ObRemoveEntry(POBJECT_HEADER Header); VOID ObRemoveEntry(POBJECT_HEADER Header);
/* /*
@ -103,4 +95,17 @@ typedef struct
PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h); PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h);
extern PDIRECTORY_OBJECT NameSpaceRoot; extern PDIRECTORY_OBJECT NameSpaceRoot;
VOID ObAddEntryDirectory(PDIRECTORY_OBJECT Parent,
POBJECT Object,
PWSTR Name);
NTSTATUS ObCreateHandle(PEPROCESS Process,
PVOID ObjectBody,
ACCESS_MASK GrantedAccess,
BOOLEAN Inherit,
PHANDLE Handle);
VOID ObCreateHandleTable(PEPROCESS Parent,
BOOLEAN Inherit,
PEPROCESS Process);
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */ #endif /* __INCLUDE_INTERNAL_OBJMGR_H */

View file

@ -29,58 +29,68 @@ char *** _environ_dll = &_environ;
char **environ; char **environ;
int __GetMainArgs(int *argc,char ***argv,char **env,int flag) int __GetMainArgs(int *argc,char ***argv,char **env,int flag)
{ {
char *cmdline; char *cmdline;
int i,afterlastspace; int i,afterlastspace;
DWORD version; DWORD version;
// acmdln_dll = cmdline = strdup( GetCommandLineA() ); // acmdln_dll = cmdline = strdup( GetCommandLineA() );
version = GetVersion(); version = GetVersion();
osver_dll = version >> 16; osver_dll = version >> 16;
winminor_dll = version & 0xFF; winminor_dll = version & 0xFF;
winmajor_dll = (version>>8) & 0xFF; winmajor_dll = (version>>8) & 0xFF;
winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8);
/* missing threading init */ /* missing threading init */
i=0; i=0;
cmdline = GetCommandLineA();
afterlastspace=0; afterlastspace=0;
while (cmdline[i]) {
if (cmdline[i]==' ') { dprintf("cmdline '%s'\n",cmdline);
__argc++;
cmdline[i]='\0'; while (cmdline[i])
__argv[__argc-1] = strdup( cmdline+afterlastspace); {
i++; if (cmdline[i]==' ')
while (cmdline[i]==' ') {
i++; dprintf("cmdline '%s'\n",cmdline);
if (cmdline[i]) __argc++;
afterlastspace=i; cmdline[i]='\0';
} else __argv[__argc-1] = strdup( cmdline+afterlastspace);
i++; i++;
} while (cmdline[i]==' ')
i++;
__argc++; if (cmdline[i])
cmdline[i]='\0'; afterlastspace=i;
__argv[__argc-1] = strdup( cmdline+afterlastspace); }
else
{
i++;
}
}
__argc++;
cmdline[i]='\0';
__argv[__argc-1] = strdup( cmdline+afterlastspace);
HeapValidate(GetProcessHeap(),0,NULL);
*argc = __argc; *argc = __argc;
*argv = __argv; *argv = __argv;
xenv = GetEnvironmentStringsA(); // xenv = GetEnvironmentStringsA();
_environ = &xenv; _environ = &xenv;
_environ_dll = &_environ; _environ_dll = &_environ;
environ = &xenv; environ = &xenv;
env = &xenv; env = &xenv;
return 0; return 0;
} }
int _chkstk() int _chkstk()
{ {
return 0; return 0;
} }

View file

@ -26,12 +26,8 @@ void* calloc(size_t _nmemb, size_t _size)
void* realloc(void* _ptr, size_t _size) void* realloc(void* _ptr, size_t _size)
{ {
ExFreePool(_ptr);
return ExAllocatePool(NonPagedPool,_size );
#if 0
return(HeapReAlloc(GetProcessHeap(), return(HeapReAlloc(GetProcessHeap(),
0, 0,
_ptr, _ptr,
_size)); _size));
#endif
} }

View file

@ -1,9 +1,7 @@
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
char * char* strcpy(char *to, const char *from);
strcpy(char *to, const char *from);
char * char* strcpy(char *to, const char *from)
strcpy(char *to, const char *from)
{ {
char *save = to; char *save = to;

View file

@ -1,3 +1,4 @@
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>

View file

@ -272,7 +272,7 @@ BOOL FindClose(HANDLE hFindFile)
DPRINT("FindClose(hFindFile %x)\n",hFindFile); DPRINT("FindClose(hFindFile %x)\n",hFindFile);
IData = (PKERNEL32_FIND_FILE_DATA)hFindFile; IData = (PKERNEL32_FIND_FILE_DATA)hFindFile;
NtClose(IData->DirectoryHandle); CloseHandle(IData->DirectoryHandle);
HeapFree(GetProcessHeap(), 0, IData); HeapFree(GetProcessHeap(), 0, IData);
return(TRUE); return(TRUE);
} }

View file

@ -2,7 +2,8 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <stdarg.h> #include <stdarg.h>
VOID KERNEL32_Init(VOID) VOID KERNEL32_Init(PWSTR Args)
{ {
InitializePeb(Args);
__HeapInit(0, 4*1024*1024, 4*1024*1024); __HeapInit(0, 4*1024*1024, 4*1024*1024);
} }

View file

@ -13,7 +13,7 @@ MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o
THREAD_OBJECTS = thread/thread.o THREAD_OBJECTS = thread/thread.o
PROCESS_OBJECTS = process/proc.o PROCESS_OBJECTS = process/proc.o process/cmdline.o
STRING_OBJECTS = string/lstring.o STRING_OBJECTS = string/lstring.o

View file

@ -35,6 +35,7 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define HEAP_VALIDATE
static HEAP_BUCKET __HeapDefaultBuckets[]= static HEAP_BUCKET __HeapDefaultBuckets[]=
{ {
@ -122,6 +123,11 @@ static LPVOID __HeapAlloc(PHEAP pheap, ULONG flags, ULONG size, ULONG tag)
DPRINT("__HeapAlloc(pheap %x, flags %x, size %d, tag %x)\n", DPRINT("__HeapAlloc(pheap %x, flags %x, size %d, tag %x)\n",
pheap,flags,size,tag); pheap,flags,size,tag);
if (size <= HEAP_ADMIN_SIZE)
{
size = size + HEAP_ADMIN_SIZE;
}
pfree=&(pheap->Start); pfree=&(pheap->Start);
allocsize=SIZE_ROUND(size); allocsize=SIZE_ROUND(size);
freesize=HEAP_SIZE(pfree); freesize=HEAP_SIZE(pfree);
@ -446,11 +452,17 @@ static LPVOID __HeapAllocFragment(PHEAP pheap, ULONG flags, ULONG size )
PHEAP_SUBALLOC psub; PHEAP_SUBALLOC psub;
PHEAP_FRAGMENT palloc; PHEAP_FRAGMENT palloc;
INT nalloc; INT nalloc;
DPRINT("__HeapAllocFragment(pheap %x, flags %d, size %d)\n",
pheap,flags,size);
size = size + HEAP_FRAG_ADMIN_SIZE;
/* get bucket size */ /* get bucket size */
pbucket=pheap->Bucket; pbucket=pheap->Bucket;
while(size>pbucket->Size) while(size>pbucket->Size)
{ {
DPRINT("pbucket->Size %d\n",pbucket->Size);
pbucket++; pbucket++;
} }
/* get suballoc */ /* get suballoc */
@ -681,9 +693,9 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size)
PHEAP pheap=hheap; PHEAP pheap=hheap;
LPVOID retval; LPVOID retval;
DPRINT("HeapAlloc( 0x%lX, 0x%lX, 0x%lX )\n", DPRINT("HeapAlloc(hheap 0x%lX, flags 0x%lX, size 0x%lX )\n",
(ULONG) hheap, flags, (ULONG) size ); (ULONG) hheap, flags, (ULONG) size );
#ifdef NOT #ifdef HEAP_VALIDATE
HeapValidate(hheap, 0, 0); HeapValidate(hheap, 0, 0);
#endif #endif
if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE ) if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE )
@ -698,6 +710,8 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size)
LeaveCriticalSection(&(pheap->Synchronize)); LeaveCriticalSection(&(pheap->Synchronize));
DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval); DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval);
HeapValidate(hheap, 0, 0);
return retval; return retval;
@ -715,7 +729,7 @@ LPVOID STDCALL HeapReAlloc(HANDLE hheap, DWORD flags, LPVOID ptr, DWORD size)
DPRINT("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n", DPRINT("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n",
(ULONG) hheap, flags, (ULONG) ptr, size ); (ULONG) hheap, flags, (ULONG) ptr, size );
#ifdef NOT #ifdef HEAP_VALIDATE
HeapValidate(hheap, 0, 0); HeapValidate(hheap, 0, 0);
#endif #endif
if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE ) if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE )
@ -748,7 +762,7 @@ WINBOOL STDCALL HeapFree(HANDLE hheap, DWORD flags, LPVOID ptr)
DPRINT("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n", DPRINT("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n",
(ULONG) hheap, flags, (ULONG) ptr ); (ULONG) hheap, flags, (ULONG) ptr );
#ifdef NOT #ifdef HEAP_VALIDATE
HeapValidate(hheap, 0, 0); HeapValidate(hheap, 0, 0);
#endif #endif
if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE ) if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE )

View file

@ -30,19 +30,18 @@ NT_TEB *Teb;
WINBOOL WINBOOL STDCALL DllMain (HANDLE hInst,
STDCALL ULONG ul_reason_for_call,
DllMain ( LPVOID lpReserved)
HANDLE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved )
{ {
switch( ul_reason_for_call ) { switch( ul_reason_for_call ) {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
{ {
GetCurrentPeb()->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS,8192,0); GetCurrentPeb()->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS,
8192,
0);
InitAtomTable(13); InitAtomTable(13);
SetCurrentDirectoryW(L"C:"); SetCurrentDirectoryW(L"C:");
// SetSystemDirectoryW(L"C:\\Reactos\\System"); // SetSystemDirectoryW(L"C:\\Reactos\\System");

View file

@ -21,7 +21,7 @@
/* GLOBALS ******************************************************************/ /* GLOBALS ******************************************************************/
unsigned char CommandLineA[MAX_PATH]; static unsigned char CommandLineA[MAX_PATH];
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/

View file

@ -18,14 +18,15 @@
#include <string.h> #include <string.h>
#include <ddk/rtl.h> #include <ddk/rtl.h>
#include <ddk/li.h> #include <ddk/li.h>
#include <internal/i386/segment.h>
#define NDEBUG #define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
/* GLOBALS *****************************************************************/ /* GLOBALS *****************************************************************/
static NT_PEB *CurrentPeb; static NT_PEB CurrentPeb;
static NT_PEB Peb; static PROCESSINFOW ProcessInfo;
WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle; WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle;
@ -35,12 +36,17 @@ VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle
WINBOOL STDCALL GetProcessId(HANDLE hProcess, LPDWORD lpProcessId); WINBOOL STDCALL GetProcessId(HANDLE hProcess, LPDWORD lpProcessId);
VOID InitializePeb(PWSTR CommandLine)
{
DPRINT("InitializePeb(CommandLine %x)\n",CommandLine);
DPRINT("ProcessInfo.CommandLine %x\n",ProcessInfo.CommandLine);
wcscpy(ProcessInfo.CommandLine, CommandLine);
CurrentPeb.StartupInfo = &ProcessInfo;
}
NT_PEB *GetCurrentPeb(VOID) NT_PEB *GetCurrentPeb(VOID)
{ {
if ( CurrentPeb != NULL ) return(&CurrentPeb);
return CurrentPeb;
else // hack to be able to return a process environment any time.
return &Peb;
} }
HANDLE STDCALL GetCurrentProcess(VOID) HANDLE STDCALL GetCurrentProcess(VOID)
@ -178,6 +184,103 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
lpProcessInformation); lpProcessInformation);
} }
HANDLE STDCALL CreateFirstThread(HANDLE hProcess,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
DWORD dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter,
DWORD dwCreationFlags,
LPDWORD lpThreadId,
PWSTR lpCommandLine)
{
NTSTATUS errCode;
HANDLE ThreadHandle;
OBJECT_ATTRIBUTES ObjectAttributes;
CLIENT_ID ClientId;
CONTEXT ThreadContext;
INITIAL_TEB InitialTeb;
BOOLEAN CreateSuspended = FALSE;
ULONG BaseAddress;
ULONG BytesWritten;
ULONG Temp;
ULONG CommandLineLen;
if (lpCommandLine == NULL)
{
lpCommandLine = "";
CommandLineLen = 1;
}
else
{
CommandLineLen = wcslen(lpCommandLine) + 1;
}
CommandLineLen = CommandLineLen * sizeof(WCHAR);
CommandLineLen = (CommandLineLen & (~0x3)) + 4;
DPRINT("CommandLineLen %d\n",CommandLineLen);
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = NULL;
ObjectAttributes.ObjectName = NULL;
ObjectAttributes.Attributes = 0;
if ( lpThreadAttributes != NULL ) {
if ( lpThreadAttributes->bInheritHandle )
ObjectAttributes.Attributes = OBJ_INHERIT;
ObjectAttributes.SecurityDescriptor = lpThreadAttributes->lpSecurityDescriptor;
}
ObjectAttributes.SecurityQualityOfService = NULL;
if ( ( dwCreationFlags & CREATE_SUSPENDED ) == CREATE_SUSPENDED )
CreateSuspended = TRUE;
else
CreateSuspended = FALSE;
BaseAddress = 0;
ZwAllocateVirtualMemory(hProcess,
&BaseAddress,
0,
&dwStackSize,
MEM_COMMIT,
PAGE_READWRITE);
memset(&ThreadContext,0,sizeof(CONTEXT));
ThreadContext.Eip = lpStartAddress;
ThreadContext.SegGs = USER_DS;
ThreadContext.SegFs = USER_DS;
ThreadContext.SegEs = USER_DS;
ThreadContext.SegDs = USER_DS;
ThreadContext.SegCs = USER_CS;
ThreadContext.SegSs = USER_DS;
ThreadContext.Esp = BaseAddress + dwStackSize - CommandLineLen - 8;
ThreadContext.EFlags = (1<<1) + (1<<9);
NtWriteVirtualMemory(hProcess,
BaseAddress + dwStackSize - CommandLineLen,
lpCommandLine,
CommandLineLen,
&BytesWritten);
Temp = BaseAddress + dwStackSize - CommandLineLen;
NtWriteVirtualMemory(hProcess,
BaseAddress + dwStackSize - CommandLineLen - 4,
&Temp,
sizeof(Temp),
&BytesWritten);
errCode = NtCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS,
&ObjectAttributes,
hProcess,
&ClientId,
&ThreadContext,
&InitialTeb,
CreateSuspended);
if ( lpThreadId != NULL )
memcpy(lpThreadId, &ClientId.UniqueThread,sizeof(ULONG));
return ThreadHandle;
}
WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName, WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
LPWSTR lpCommandLine, LPWSTR lpCommandLine,
@ -200,9 +303,10 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
LPTHREAD_START_ROUTINE lpStartAddress = NULL; LPTHREAD_START_ROUTINE lpStartAddress = NULL;
LPVOID lpParameter = NULL; LPVOID lpParameter = NULL;
PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
WCHAR TempApplicationName[255]; WCHAR TempApplicationName[256];
WCHAR TempFileName[255]; WCHAR TempFileName[256];
WCHAR TempDirectoryName[255]; WCHAR TempDirectoryName[256];
WCHAR TempCommandLine[256];
ULONG i; ULONG i;
ULONG BaseAddress; ULONG BaseAddress;
ULONG Size; ULONG Size;
@ -211,6 +315,8 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n", DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n",
lpApplicationName,lpCommandLine); lpApplicationName,lpCommandLine);
wcscpy(TempCommandLine, lpCommandLine);
hFile = NULL; hFile = NULL;
/* /*
@ -328,15 +434,17 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
&PriorityClass, &PriorityClass,
sizeof(KPRIORITY)); sizeof(KPRIORITY));
#endif #endif
DPRINT("Creating thread for process\n"); DPRINT("Creating thread for process\n");
lpStartAddress = BaseAddress; lpStartAddress = BaseAddress;
hThread = CreateRemoteThread(hProcess, hThread = CreateFirstThread(hProcess,
lpThreadAttributes, lpThreadAttributes,
4096, // 1 page ?? 16384, // 3 page ??
lpStartAddress, lpStartAddress,
lpParameter, lpParameter,
dwCreationFlags, dwCreationFlags,
&lpProcessInformation->dwThreadId); &lpProcessInformation->dwThreadId,
TempCommandLine);
if ( hThread == NULL ) if ( hThread == NULL )
return FALSE; return FALSE;

View file

@ -503,7 +503,7 @@ STUB(_atoi64)
STUB(_aulldiv) STUB(_aulldiv)
STUB(_aullrem) STUB(_aullrem)
STUB(_aullshr) STUB(_aullshr)
STUB(_chkstk) //STUB(_chkstk)
STUB(_fltused) STUB(_fltused)
STUB(_ftol) STUB(_ftol)
STUB(_i64toa) STUB(_i64toa)

View file

@ -33,7 +33,7 @@ LOADERS = dos
KERNEL_SERVICES = parallel keyboard blues null mouse serial sound ide test sdisk \ KERNEL_SERVICES = parallel keyboard blues null mouse serial sound ide test sdisk \
minix vfat ext2 minix vfat ext2
APPS = hello shell APPS = hello shell args
all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES) $(APPS) all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES) $(APPS)
@ -46,6 +46,9 @@ clean: dummy
hello: dummy hello: dummy
make -C apps/hello make -C apps/hello
args: dummy
make -C apps/args
cmd: dummy cmd: dummy
make -C apps/cmd make -C apps/cmd

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ex/fmutex.c * FILE: ntoskrnl/ex/fmutex.c
* PURPOSE: Implements fast mutexes * PURPOSE: Implements fast mutexes
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 22/05/98 * Created 22/05/98
*/ */

View file

@ -1,9 +1,9 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/bug.c * FILE: ntoskrnl/ex/locale.c
* PURPOSE: Graceful system shutdown if a bug is detected * PURPOSE: Locale support
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 22/05/98 * Created 22/05/98
*/ */

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/hal/x86/page.c * FILE: ntoskrnl/hal/x86/page.c
* PURPOSE: low level memory managment manipulation * PURPOSE: low level memory managment manipulation
* PROGRAMER: David Welch * PROGRAMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* 9/3/98: Created * 9/3/98: Created
*/ */
@ -39,24 +39,34 @@ static ULONG ProtectToPTE(ULONG flProtect)
} }
if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE) if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE)
{ {
Attributes = PA_WRITE; Attributes = PA_WRITE | PA_USER;
} }
if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE || if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE ||
flProtect & PAGE_EXECUTE_READ) flProtect & PAGE_EXECUTE_READ)
{ {
Attributes = PA_READ; Attributes = PA_READ | PA_USER;
} }
return(Attributes); return(Attributes);
} }
PULONG MmGetPageEntry(PEPROCESS Process, ULONG Address) PULONG MmGetPageEntry(PEPROCESS Process, ULONG Address)
{ {
unsigned int page_table; ULONG page_table;
unsigned int* page_tlb; PULONG page_tlb;
unsigned int* page_dir = linear_to_physical( PULONG page_dir;
Process->Pcb.PageTableDirectory);
DPRINT("MmGetPageEntry(Process %x, Address %x)\n",Process,Address);
DPRINT("vaddr %x ",vaddr);
if (Process != NULL)
{
page_dir = Process->Pcb.PageTableDirectory;
}
else
{
page_dir = get_page_directory();
}
DPRINT("page_dir %x\n",page_dir);
page_tlb = (unsigned int *)physical_to_linear( page_tlb = (unsigned int *)physical_to_linear(
PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(Address)])); PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(Address)]));
DPRINT("page_tlb %x\n",page_tlb); DPRINT("page_tlb %x\n",page_tlb);
@ -70,6 +80,7 @@ PULONG MmGetPageEntry(PEPROCESS Process, ULONG Address)
page_dir[VADDR_TO_PD_OFFSET(Address)]=page_table+0x7; page_dir[VADDR_TO_PD_OFFSET(Address)]=page_table+0x7;
} }
DPRINT("Returning %x\n",page_tlb[VADDR_TO_PT_OFFSET(Address)/4]);
return(&page_tlb[VADDR_TO_PT_OFFSET(Address)/4]); return(&page_tlb[VADDR_TO_PT_OFFSET(Address)/4]);
} }
@ -89,6 +100,7 @@ VOID MmSetPage(PEPROCESS Process,
Attributes = ProtectToPTE(flProtect); Attributes = ProtectToPTE(flProtect);
(*MmGetPageEntry(Process, Address)) = PhysicalAddress | Attributes; (*MmGetPageEntry(Process, Address)) = PhysicalAddress | Attributes;
FLUSH_TLB;
} }
VOID MmSetPageProtect(PEPROCESS Process, VOID MmSetPageProtect(PEPROCESS Process,
@ -102,100 +114,9 @@ VOID MmSetPageProtect(PEPROCESS Process,
PageEntry = MmGetPageEntry(Process,Address); PageEntry = MmGetPageEntry(Process,Address);
(*PageEntry) = PAGE_MASK(*PageEntry) | Attributes; (*PageEntry) = PAGE_MASK(*PageEntry) | Attributes;
FLUSH_TLB;
} }
/*
* The mark_page_xxxx manipulate the attributes of a page. Use the
* higher level functions for synchronization. These functions only work
* on present pages.
*/
void mark_page_not_present(unsigned int vaddr)
/*
* FUNCTION: Marks the page as not present
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_PRESENT,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_present(unsigned int vaddr)
/*
* FUNCTION: Marks the page as present
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_PRESENT,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_not_writable(unsigned int vaddr)
/*
* FUNCTION: Marks the page as not writable by any process
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_READWRITE,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_writable(unsigned int vaddr)
/*
* FUNCTION: Marks the page as writable by any process
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_READWRITE,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_user(unsigned int vaddr)
/*
* FUNCTION: Marks the page as user accessible
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
set_bit(PA_BIT_USER,get_page_entry(vaddr));
FLUSH_TLB;
}
void mark_page_system(unsigned int vaddr)
/*
* FUNCTION: Marks the page as system only
* ARGUMENTS:
* vaddr = The virtual address to affect
*/
{
clear_bit(PA_BIT_USER,get_page_entry(vaddr));
FLUSH_TLB;
}
void set_page(unsigned int vaddr, unsigned int attributes,
unsigned int physaddr)
/*
* FUNCTION: Set the page entry of a virtual address
* ARGUMENTS:
* vaddr = Virtual address
* attributes = Access attributes for the page
* physaddr = Physical address to map the virtual address to
* NOTE: In future this won't flush the TLB
*/
{
DPRINT("set_page(vaddr %x attributes %x physaddr %x)\n",vaddr,
attributes,physaddr);
*get_page_entry(vaddr)=physaddr | attributes;
FLUSH_TLB;
}
PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr) PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr)
/* /*
* FUNCTION: Returns the physical address corresponding to a virtual address * FUNCTION: Returns the physical address corresponding to a virtual address
@ -203,79 +124,10 @@ PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr)
{ {
PHYSICAL_ADDRESS p; PHYSICAL_ADDRESS p;
DPRINT("get_page_physical_address(vaddr %x)\n", vaddr); DPRINT("MmGetPhysicalAddress(vaddr %x)\n", vaddr);
SET_LARGE_INTEGER_HIGH_PART(p, 0); SET_LARGE_INTEGER_HIGH_PART(p, 0);
SET_LARGE_INTEGER_LOW_PART(p, PAGE_MASK( SET_LARGE_INTEGER_LOW_PART(p, PAGE_MASK(*MmGetPageEntry(NULL,vaddr)));
*get_page_entry((unsigned int) vaddr)));
return p; return p;
} }
BOOL is_page_present(unsigned int vaddr)
/*
* FUNCTION: Tests if a page is present at the address
* RETURNS:
* True: If an access to the page would happen without any page faults
* False: If an access to the page would involve page faults
* NOTES: The information is only guarrented to remain true if the caller has
* locked the page. The function does not have any side effects when used
* from an irq handler so it can be used as a 'sanity' test when accessing a
* buffer from an irq.
*/
{
unsigned int* page_dir = get_page_directory();
unsigned int* page_tlb = NULL;
/*
* Check the page directory exists
*/
if (!(page_dir[VADDR_TO_PD_OFFSET(vaddr)]&PA_PRESENT))
{
return(FALSE);
}
page_tlb = (unsigned int *)physical_to_linear(
PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)]));
if (!(page_tlb[VADDR_TO_PT_OFFSET(vaddr)/4]&PA_PRESENT))
{
return(FALSE);
}
return(TRUE);
}
unsigned int* get_page_entry(unsigned int vaddr)
/*
* FUNCTION: Returns a pointer to a page entry
* NOTE: This function will create a page table if none exists so just to
* check if mem exists use the is_page_present function
*/
{
unsigned int page_table;
unsigned int* page_tlb;
#if 0
unsigned int* page_dir = physical_to_linear(current_task->cr3);
#else
unsigned int* page_dir = get_page_directory();
#endif
DPRINT("vaddr %x ",vaddr);
page_tlb = (unsigned int *)physical_to_linear(
PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)]));
DPRINT("page_tlb %x\n",page_tlb);
if (PAGE_MASK(page_dir[VADDR_TO_PD_OFFSET(vaddr)])==0)
{
DPRINT("Creating new page directory\n",0);
page_table = get_free_page(); // Returns a physical address
page_tlb=(unsigned int *)physical_to_linear(page_table);
memset(page_tlb,0,PAGESIZE);
page_dir[VADDR_TO_PD_OFFSET(vaddr)]=page_table+0x7;
}
return(&page_tlb[VADDR_TO_PT_OFFSET(vaddr)/4]);
}

View file

@ -120,8 +120,17 @@ NTSTATUS ZwOpenSymbolicLinkObject(OUT PHANDLE LinkHandle,
{ {
return(Status); return(Status);
} }
*LinkHandle = ObInsertHandle(KeGetCurrentProcess(),Object,
DesiredAccess,FALSE); Status = ObCreateHandle(PsGetCurrentProcess(),
Object,
DesiredAccess,
FALSE,
LinkHandle);
if (!NT_SUCCESS(Status))
{
return(Status);
}
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -170,7 +179,6 @@ NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName,
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
HANDLE SymbolicLinkHandle; HANDLE SymbolicLinkHandle;
PSYMLNK_OBJECT SymbolicLink; PSYMLNK_OBJECT SymbolicLink;
PUNICODE_STRING TargetName;
DPRINT("IoCreateSymbolicLink(SymbolicLinkName %w, DeviceName %w)\n", DPRINT("IoCreateSymbolicLink(SymbolicLinkName %w, DeviceName %w)\n",
SymbolicLinkName->Buffer,DeviceName->Buffer); SymbolicLinkName->Buffer,DeviceName->Buffer);
@ -185,9 +193,10 @@ NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName,
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
ZwClose(SymbolicLinkHandle);
SymbolicLink->TargetName.Length = 0; SymbolicLink->TargetName.Length = 0;
SymbolicLink->TargetName.MaximumLength = SymbolicLink->TargetName.MaximumLength =
((wstrlen(DeviceName->Buffer) + 1) * sizeof(WCHAR)); ((wcslen(DeviceName->Buffer) + 1) * sizeof(WCHAR));
SymbolicLink->TargetName.Buffer = ExAllocatePool(NonPagedPool, SymbolicLink->TargetName.Buffer = ExAllocatePool(NonPagedPool,
SymbolicLink->TargetName.MaximumLength); SymbolicLink->TargetName.MaximumLength);
RtlCopyUnicodeString(&(SymbolicLink->TargetName), DeviceName); RtlCopyUnicodeString(&(SymbolicLink->TargetName), DeviceName);

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ke/apc.c * FILE: ntoskrnl/ke/apc.c
* PURPOSE: Possible implementation of APCs * PURPOSE: Possible implementation of APCs
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 22/05/98 * Created 22/05/98
*/ */

View file

@ -66,7 +66,10 @@ PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode)
{ {
DPRINT("Writing %x with physical address %x\n", DPRINT("Writing %x with physical address %x\n",
base+(i*PAGESIZE),mdl_pages[i]); base+(i*PAGESIZE),mdl_pages[i]);
set_page((DWORD)base+(i*PAGESIZE),PA_READ + PA_SYSTEM,mdl_pages[i]); MmSetPage(NULL,
(DWORD)base+(i*PAGESIZE),
PAGE_READWRITE,
mdl_pages[i]);
} }
DPRINT("base %x\n",base); DPRINT("base %x\n",base);
Mdl->MdlFlags = Mdl->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA; Mdl->MdlFlags = Mdl->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA;

View file

@ -67,6 +67,7 @@ void MmInitialize(boot_param* bp)
(get_page_directory())[0]=0; (get_page_directory())[0]=0;
FLUSH_TLB; FLUSH_TLB;
CHECKPOINT; CHECKPOINT;
/* /*
* Free all pages not used for kernel memory * Free all pages not used for kernel memory
* (we assume the kernel occupies a continuous range of physical * (we assume the kernel occupies a continuous range of physical
@ -107,15 +108,23 @@ void MmInitialize(boot_param* bp)
for (i=PAGE_ROUND_UP(((int)&stext)); for (i=PAGE_ROUND_UP(((int)&stext));
i<PAGE_ROUND_DOWN(((int)&etext));i=i+PAGESIZE) i<PAGE_ROUND_DOWN(((int)&etext));i=i+PAGESIZE)
{ {
mark_page_not_writable(i); MmSetPageProtect(NULL,
i,
PAGE_EXECUTE_READ);
} }
DPRINT("end %x\n",(int)&end); DPRINT("end %x\n",(int)&end);
for (i=PAGE_ROUND_UP(KERNEL_BASE+kernel_len); for (i=PAGE_ROUND_UP(KERNEL_BASE+kernel_len);
i<(KERNEL_BASE+PAGE_TABLE_SIZE);i=i+PAGESIZE) i<(KERNEL_BASE+PAGE_TABLE_SIZE);i=i+PAGESIZE)
{ {
set_page(i,0,0); MmSetPage(NULL,
i,
PAGE_NOACCESS,
0);
} }
set_page(0,0,0); MmSetPage(NULL,
0,
PAGE_NOACCESS,
0);
FLUSH_TLB; FLUSH_TLB;
CHECKPOINT; CHECKPOINT;
/* /*

View file

@ -429,8 +429,10 @@ static block_hdr* grow_kernel_pool(unsigned int size)
for (i=0;i<nr_pages;i++) for (i=0;i<nr_pages;i++)
{ {
set_page(start+(i*PAGESIZE),PA_SYSTEM | PA_WRITE | PA_READ, MmSetPage(NULL,
get_free_page()); start + (i*PAGESIZE),
PAGE_READWRITE,
get_free_page());
} }

View file

@ -149,7 +149,11 @@ NTSTATUS STDCALL ZwCreateSection(OUT PHANDLE SectionHandle,
DesiredAccess, DesiredAccess,
ObjectAttributes, ObjectAttributes,
MmSectionType); MmSectionType);
if (Section == NULL)
{
return(STATUS_UNSUCCESSFUL);
}
if (MaximumSize != NULL) if (MaximumSize != NULL)
{ {
Section->MaximumSize = *MaximumSize; Section->MaximumSize = *MaximumSize;
@ -215,11 +219,12 @@ NTSTATUS ZwOpenSection(PHANDLE SectionHandle,
return(Status); return(Status);
} }
*SectionHandle = ObInsertHandle(KeGetCurrentProcess(), Status = ObCreateHandle(PsGetCurrentProcess(),
Object, Object,
DesiredAccess, DesiredAccess,
FALSE); FALSE,
return(STATUS_SUCCESS); SectionHandle);
return(Status);
} }
NTSTATUS NtMapViewOfSection(HANDLE SectionHandle, NTSTATUS NtMapViewOfSection(HANDLE SectionHandle,

View file

@ -24,7 +24,6 @@ PVOID MmAllocateSection(ULONG Length)
MEMORY_AREA* marea; MEMORY_AREA* marea;
NTSTATUS Status; NTSTATUS Status;
ULONG i; ULONG i;
ULONG Attributes;
DPRINT("MmAllocateSection(Length %x)\n",Length); DPRINT("MmAllocateSection(Length %x)\n",Length);
@ -41,10 +40,12 @@ PVOID MmAllocateSection(ULONG Length)
return(NULL); return(NULL);
} }
DPRINT("Result %x\n",Result); DPRINT("Result %x\n",Result);
Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM;
for (i=0;i<=(Length/PAGESIZE);i++) for (i=0;i<=(Length/PAGESIZE);i++)
{ {
set_page(Result+(i*PAGESIZE),Attributes,get_free_page()); MmSetPage(NULL,
Result+(i*PAGESIZE),
PAGE_READWRITE,
get_free_page());
} }
return((PVOID)Result); return((PVOID)Result);
} }
@ -89,9 +90,10 @@ PVOID MmMapIoSpace(PHYSICAL_ADDRESS PhysicalAddress,
} }
for (i=0;i<=(NumberOfBytes/PAGESIZE);i++) for (i=0;i<=(NumberOfBytes/PAGESIZE);i++)
{ {
set_page(Result + (i * PAGESIZE), MmSetPage(NULL,
Attributes, Result + (i * PAGESIZE),
GET_LARGE_INTEGER_LOW_PART(PhysicalAddress)); PAGE_READWRITE,
GET_LARGE_INTEGER_LOW_PART(PhysicalAddress));
} }
return((PVOID)Result); return((PVOID)Result);
} }
@ -123,9 +125,10 @@ PVOID MmAllocateNonCachedMemory(ULONG NumberOfBytes)
} }
for (i=0;i<=(NumberOfBytes/PAGESIZE);i++) for (i=0;i<=(NumberOfBytes/PAGESIZE);i++)
{ {
set_page(Result+(i*PAGESIZE), MmSetPage(NULL,
PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM | PA_PCD | PA_PWT, Result+(i*PAGESIZE),
get_free_page()); PAGE_READWRITE,
get_free_page());
} }
return((PVOID)Result); return((PVOID)Result);
} }

View file

@ -95,7 +95,10 @@ void VirtualInit(boot_param* bp)
ULONG MmCommitedSectionHandleFault(MEMORY_AREA* MemoryArea, ULONG Address) ULONG MmCommitedSectionHandleFault(MEMORY_AREA* MemoryArea, ULONG Address)
{ {
set_page(Address,0x7,get_free_page()); MmSetPage(PsGetCurrentProcess(),
Address,
MemoryArea->Attributes,
get_free_page());
return(TRUE); return(TRUE);
} }
@ -107,7 +110,10 @@ NTSTATUS MmSectionHandleFault(MEMORY_AREA* MemoryArea, PVOID Address)
DPRINT("MmSectionHandleFault(MemoryArea %x, Address %x)\n", DPRINT("MmSectionHandleFault(MemoryArea %x, Address %x)\n",
MemoryArea,Address); MemoryArea,Address);
set_page((DWORD)Address,0x7,get_free_page()); MmSetPage(NULL,
Address,
MemoryArea->Attributes,
get_free_page());
LARGE_INTEGER_QUAD_PART(Offset) = (Address - MemoryArea->BaseAddress) + LARGE_INTEGER_QUAD_PART(Offset) = (Address - MemoryArea->BaseAddress) +
MemoryArea->Data.SectionData.ViewOffset; MemoryArea->Data.SectionData.ViewOffset;
@ -152,7 +158,7 @@ asmlinkage int page_fault_handler(unsigned int cs,
if (KeGetCurrentIrql()!=PASSIVE_LEVEL) if (KeGetCurrentIrql()!=PASSIVE_LEVEL)
{ {
DbgPrint("Recursive page fault detected\n"); DbgPrint("Page fault at high IRQL\n");
return(0); return(0);
// KeBugCheck(0); // KeBugCheck(0);
} }
@ -713,11 +719,16 @@ NTSTATUS STDCALL ZwWriteVirtualMemory(IN HANDLE ProcessHandle,
OUT PULONG NumberOfBytesWritten) OUT PULONG NumberOfBytesWritten)
{ {
PEPROCESS Process; PEPROCESS Process;
MEMORY_AREA* MemoryArea; PMEMORY_AREA InMemoryArea;
PMEMORY_AREA OutMemoryArea;
ULONG i; ULONG i;
NTSTATUS Status; NTSTATUS Status;
PULONG CurrentEntry; PULONG CurrentEntry;
DPRINT("ZwWriteVirtualMemory(ProcessHandle %x, BaseAddress %x, "
"Buffer %x, NumberOfBytesToWrite %d)\n",ProcessHandle,BaseAddress,
Buffer,NumberOfBytesToWrite);
Status = ObReferenceObjectByHandle(ProcessHandle, Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_VM_WRITE, PROCESS_VM_WRITE,
NULL, NULL,
@ -729,26 +740,52 @@ NTSTATUS STDCALL ZwWriteVirtualMemory(IN HANDLE ProcessHandle,
return(Status); return(Status);
} }
MemoryArea = MmOpenMemoryAreaByAddress(Process,BaseAddress); OutMemoryArea = MmOpenMemoryAreaByAddress(Process,BaseAddress);
if (OutMemoryArea == NULL)
if (MemoryArea == NULL)
{ {
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
if (MemoryArea->Length > NumberOfBytesToWrite)
{
NumberOfBytesToWrite = MemoryArea->Length;
}
*NumberOfBytesWritten = NumberOfBytesToWrite; *NumberOfBytesWritten = NumberOfBytesToWrite;
for (i=0; i<(NumberOfBytesToWrite/PAGESIZE); i++) DPRINT("*Buffer %x\n",((PULONG)Buffer)[0]);
for (i=0; i<(PAGE_ROUND_DOWN(NumberOfBytesToWrite)/PAGESIZE); i++)
{ {
CurrentEntry = MmGetPageEntry(Process, (DWORD)BaseAddress + (i*PAGESIZE)); if (!MmIsPagePresent(Process, BaseAddress + (i*PAGESIZE)))
RtlCopyMemory((PVOID)physical_to_linear(PAGE_MASK(*CurrentEntry)), {
DPRINT("OutMemoryArea->Attributes %x\n",
OutMemoryArea->Attributes);
MmSetPage(Process,
BaseAddress + (i*PAGESIZE),
OutMemoryArea->Attributes,
get_free_page());
}
CurrentEntry = MmGetPageEntry(Process, (DWORD)BaseAddress +
(i*PAGESIZE));
RtlCopyMemory((PVOID)physical_to_linear(PAGE_MASK(*CurrentEntry)) +
(((DWORD)BaseAddress)%PAGESIZE),
Buffer + (i*PAGESIZE), Buffer + (i*PAGESIZE),
PAGESIZE); PAGESIZE);
}
if ((NumberOfBytesToWrite % PAGESIZE) != 0)
{
if (!MmIsPagePresent(Process, BaseAddress + (i*PAGESIZE)))
{
MmSetPage(Process,
BaseAddress + (i*PAGESIZE),
OutMemoryArea->Attributes,
get_free_page());
}
CurrentEntry = MmGetPageEntry(Process,
BaseAddress + (i*PAGESIZE));
DPRINT("addr %x\n",
physical_to_linear(PAGE_MASK(*CurrentEntry)) +
(((DWORD)BaseAddress)%PAGESIZE));
RtlCopyMemory((PVOID)physical_to_linear(PAGE_MASK(*CurrentEntry)) +
(((DWORD)BaseAddress)%PAGESIZE),
Buffer + (i*PAGESIZE),
NumberOfBytesToWrite % PAGESIZE);
} }
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -136,10 +136,12 @@ NTSTATUS STDCALL ZwOpenEvent(OUT PHANDLE EventHandle,
return(Status); return(Status);
} }
*EventHandle = ObInsertHandle(KeGetCurrentProcess(), Status = ObCreateHandle(PsGetCurrentProcess(),
Event, Event,
DesiredAccess, DesiredAccess,
FALSE); FALSE,
EventHandle);
ObDereferenceObject(Event);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -63,8 +63,11 @@ NTSTATUS ZwOpenDirectoryObject(PHANDLE DirectoryHandle,
return(Status); return(Status);
} }
*DirectoryHandle = ObInsertHandle(KeGetCurrentProcess(),Object, Status = ObCreateHandle(PsGetCurrentProcess(),
DesiredAccess,FALSE); Object,
DesiredAccess,
FALSE,
DirectoryHandle);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -100,15 +100,19 @@ NTSTATUS STDCALL ZwDuplicateObject(IN HANDLE SourceProcessHandle,
(PVOID*)&TargetProcess, (PVOID*)&TargetProcess,
NULL); NULL);
SourceHandleRep = ObTranslateHandle(&SourceProcess->Pcb,*SourceHandle); SourceHandleRep = ObpGetObjectByHandle(SourceProcess,
*SourceHandle);
if (Options & DUPLICATE_SAME_ACCESS) if (Options & DUPLICATE_SAME_ACCESS)
{ {
DesiredAccess = SourceHandleRep->GrantedAccess; DesiredAccess = SourceHandleRep->GrantedAccess;
} }
*TargetHandle = ObInsertHandle(&TargetProcess,SourceHandleRep->ObjectBody, ObCreateHandle(TargetProcess,
DesiredAccess,InheritHandle); SourceHandleRep->ObjectBody,
DesiredAccess,
InheritHandle,
TargetHandle);
if (Options & DUPLICATE_CLOSE_SOURCE) if (Options & DUPLICATE_CLOSE_SOURCE)
{ {
@ -118,59 +122,65 @@ NTSTATUS STDCALL ZwDuplicateObject(IN HANDLE SourceProcessHandle,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
VOID ObDestroyHandleTable(PKPROCESS Process) VOID ObDeleteHandleTable(PEPROCESS Process)
/* /*
* FUNCTION: Destroys the current process's handle table * FUNCTION: Deletes the handle table associated with a process
* NOTE: No references to handles in the table should be made during this
* operation
*/ */
{ {
PLIST_ENTRY current=NULL; PLIST_ENTRY current = NULL;
unsigned int i; ULONG i;
PHANDLE_TABLE HandleTable = NULL;
current = ExInterlockedRemoveHeadList(&(Process->HandleTable.ListHead), HandleTable = &Process->Pcb.HandleTable;
&(Process->HandleTable.ListLock)); current = RemoveHeadList(&HandleTable->ListHead);
while (current!=NULL) while (current!=NULL)
{ {
HANDLE_BLOCK* blk = CONTAINING_RECORD(current,HANDLE_BLOCK,entry); HANDLE_BLOCK* HandleBlock = CONTAINING_RECORD(current,
HANDLE_BLOCK,
entry);
/* /*
* Deference every handle in block * Deference every handle in block
*/ */
for (i=0;i<HANDLE_BLOCK_ENTRIES;i++) for (i=0;i<HANDLE_BLOCK_ENTRIES;i++)
{ {
ObDereferenceObject(blk->handles[i].ObjectBody); if (HandleBlock->handles[i].ObjectBody != NULL)
{
ObDereferenceObject(HandleBlock->handles[i].ObjectBody);
}
} }
/* ExFreePool(HandleBlock);
* Free the block
*/
ExFreePool(blk);
current = ExInterlockedRemoveHeadList(&(Process->HandleTable.ListHead), current = RemoveHeadList(&HandleTable->ListHead);
&(Process->HandleTable.ListLock));
} }
} }
VOID ObInitializeHandleTable(PKPROCESS Parent, BOOLEAN Inherit, VOID ObCreateHandleTable(PEPROCESS Parent,
PKPROCESS Process) BOOLEAN Inherit,
PEPROCESS Process)
/* /*
* FUNCTION: Initializes a handle table * FUNCTION: Creates a handle table for a process
* ARGUMENTS: * ARGUMENTS:
* parent = Parent process (or NULL if this is the first process) * Parent = Parent process (or NULL if this is the first process)
* Inherit = True if the process should inherit its parents objects * Inherit = True if the process should inherit its parent's handles
* Process = Process whose handle table is to be initialized * Process = Process whose handle table is to be created
*/ */
{ {
DPRINT("ObInitializeHandleTable(parent %x, Inherit %d, Process %x)\n", DPRINT("ObCreateHandleTable(Parent %x, Inherit %d, Process %x)\n",
Parent,Inherit,Process); Parent,Inherit,Process);
InitializeListHead(&(Process->HandleTable.ListHead)); InitializeListHead(&(Process->Pcb.HandleTable.ListHead));
KeInitializeSpinLock(&(Process->HandleTable.ListLock)); KeInitializeSpinLock(&(Process->Pcb.HandleTable.ListLock));
if (Parent != NULL)
{
}
} }
PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h) static PHANDLE_REP ObpGetObjectByHandle(PEPROCESS Process,
HANDLE h)
/* /*
* FUNCTION: Get the data structure for a handle * FUNCTION: Get the data structure for a handle
* ARGUMENTS: * ARGUMENTS:
@ -186,15 +196,15 @@ PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h)
HANDLE_BLOCK* blk = NULL; HANDLE_BLOCK* blk = NULL;
unsigned int i; unsigned int i;
DPRINT("ObTranslateHandle(Process %x, h %x)\n",Process,h); DPRINT("ObpGetObjectByHandle(Process %x, h %x)\n",Process,h);
current = Process->HandleTable.ListHead.Flink; current = Process->Pcb.HandleTable.ListHead.Flink;
DPRINT("current %x\n",current); DPRINT("current %x\n",current);
for (i=0;i<count;i++) for (i=0;i<count;i++)
{ {
current = current->Flink; current = current->Flink;
if (current==(&(Process->HandleTable.ListHead))) if (current==(&(Process->Pcb.HandleTable.ListHead)))
{ {
return(NULL); return(NULL);
} }
@ -210,15 +220,16 @@ VOID ObDeleteHandle(HANDLE Handle)
DPRINT("ObDeleteHandle(Handle %x)\n",Handle); DPRINT("ObDeleteHandle(Handle %x)\n",Handle);
Rep = ObTranslateHandle(KeGetCurrentProcess(),Handle); Rep = ObpGetObjectByHandle(PsGetCurrentProcess(),Handle);
Rep->ObjectBody=NULL; Rep->ObjectBody=NULL;
DPRINT("Finished ObDeleteHandle()\n"); DPRINT("Finished ObDeleteHandle()\n");
} }
HANDLE ObInsertHandle(PKPROCESS Process, NTSTATUS ObCreateHandle(PEPROCESS Process,
PVOID ObjectBody, PVOID ObjectBody,
ACCESS_MASK GrantedAccess, ACCESS_MASK GrantedAccess,
BOOLEAN Inherit) BOOLEAN Inherit,
PHANDLE HandleReturn)
/* /*
* FUNCTION: Add a handle referencing an object * FUNCTION: Add a handle referencing an object
* ARGUMENTS: * ARGUMENTS:
@ -231,16 +242,21 @@ HANDLE ObInsertHandle(PKPROCESS Process,
unsigned int handle=1; unsigned int handle=1;
unsigned int i; unsigned int i;
HANDLE_BLOCK* new_blk = NULL; HANDLE_BLOCK* new_blk = NULL;
PHANDLE_TABLE HandleTable;
KIRQL oldlvl;
DPRINT("ObAddHandle(Process %x, obj %x)\n",Process,ObjectBody); DPRINT("ObAddHandle(Process %x, obj %x)\n",Process,ObjectBody);
current = Process->HandleTable.ListHead.Flink; HandleTable = &Process->Pcb.HandleTable;
KeAcquireSpinLock(&HandleTable->ListLock, &oldlvl);
current = HandleTable->ListHead.Flink;
/* /*
* Scan through the currently allocated handle blocks looking for a free * Scan through the currently allocated handle blocks looking for a free
* slot * slot
*/ */
while (current!=(&(Process->HandleTable.ListHead))) while (current != (&HandleTable->ListHead))
{ {
HANDLE_BLOCK* blk = CONTAINING_RECORD(current,HANDLE_BLOCK,entry); HANDLE_BLOCK* blk = CONTAINING_RECORD(current,HANDLE_BLOCK,entry);
@ -254,7 +270,9 @@ HANDLE ObInsertHandle(PKPROCESS Process,
blk->handles[i].ObjectBody = ObjectBody; blk->handles[i].ObjectBody = ObjectBody;
blk->handles[i].GrantedAccess = GrantedAccess; blk->handles[i].GrantedAccess = GrantedAccess;
blk->handles[i].Inherit = Inherit; blk->handles[i].Inherit = Inherit;
return((HANDLE)(handle+i)); KeReleaseSpinLock(&HandleTable->ListLock, oldlvl);
*HandleReturn = (HANDLE)(handle + i);
return(STATUS_SUCCESS);
} }
} }
@ -267,12 +285,124 @@ HANDLE ObInsertHandle(PKPROCESS Process,
*/ */
new_blk = (HANDLE_BLOCK *)ExAllocatePool(NonPagedPool,sizeof(HANDLE_BLOCK)); new_blk = (HANDLE_BLOCK *)ExAllocatePool(NonPagedPool,sizeof(HANDLE_BLOCK));
memset(new_blk,0,sizeof(HANDLE_BLOCK)); memset(new_blk,0,sizeof(HANDLE_BLOCK));
ExInterlockedInsertTailList(&(Process->HandleTable.ListHead), InsertTailList(&(Process->Pcb.HandleTable.ListHead),
&new_blk->entry, &new_blk->entry);
&(Process->HandleTable.ListLock)); KeReleaseSpinLock(&HandleTable->ListLock, oldlvl);
new_blk->handles[0].ObjectBody = ObjectBody; new_blk->handles[0].ObjectBody = ObjectBody;
new_blk->handles[0].GrantedAccess = GrantedAccess; new_blk->handles[0].GrantedAccess = GrantedAccess;
new_blk->handles[0].Inherit = Inherit; new_blk->handles[0].Inherit = Inherit;
return((HANDLE)handle); *HandleReturn = (HANDLE)handle;
return(STATUS_SUCCESS);
} }
NTSTATUS ObReferenceObjectByHandle(HANDLE Handle,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID* Object,
POBJECT_HANDLE_INFORMATION
HandleInformationPtr)
/*
* FUNCTION: Increments the reference count for an object and returns a
* pointer to its body
* ARGUMENTS:
* Handle = Handle for the object
* DesiredAccess = Desired access to the object
* ObjectType
* AccessMode
* Object (OUT) = Points to the object body on return
* HandleInformation (OUT) = Contains information about the handle
* on return
* RETURNS: Status
*/
{
PHANDLE_REP HandleRep;
POBJECT_HEADER ObjectHeader;
ASSERT_IRQL(PASSIVE_LEVEL);
DPRINT("ObReferenceObjectByHandle(Handle %x, DesiredAccess %x, "
"ObjectType %x, AccessMode %d, Object %x)\n",Handle,DesiredAccess,
ObjectType,AccessMode,Object);
if (Handle == NtCurrentProcess())
{
*Object = PsGetCurrentProcess();
return(STATUS_SUCCESS);
}
if (Handle == NtCurrentThread())
{
*Object = PsGetCurrentThread();
return(STATUS_SUCCESS);
}
HandleRep = ObpGetObjectByHandle(PsGetCurrentProcess(),
Handle);
if (HandleRep == NULL || HandleRep->ObjectBody == NULL)
{
return(STATUS_INVALID_HANDLE);
}
ObjectHeader = BODY_TO_HEADER(HandleRep->ObjectBody);
if (ObjectType != NULL && ObjectType != ObjectHeader->ObjectType)
{
return(STATUS_UNSUCCESSFUL);
}
if (!(HandleRep->GrantedAccess & DesiredAccess))
{
return(STATUS_ACCESS_DENIED);
}
ObjectHeader->RefCount++;
*Object = HandleRep->ObjectBody;
return(STATUS_SUCCESS);
}
NTSTATUS ZwClose(HANDLE Handle)
/*
* FUNCTION: Closes a handle reference to an object
* ARGUMENTS:
* Handle = handle to close
* RETURNS: Status
*/
{
PVOID ObjectBody;
POBJECT_HEADER Header;
PHANDLE_REP HandleRep;
assert_irql(PASSIVE_LEVEL);
DPRINT("ZwClose(Handle %x)\n",Handle);
HandleRep = ObpGetObjectByHandle(PsGetCurrentProcess(),
Handle);
if (HandleRep == NULL)
{
return(STATUS_INVALID_HANDLE);
}
ObjectBody = HandleRep->ObjectBody;
HandleRep->ObjectBody = NULL;
Header = BODY_TO_HEADER(ObjectBody);
Header->RefCount++;
Header->HandleCount--;
if (Header->ObjectType != NULL &&
Header->ObjectType->Close != NULL)
{
Header->ObjectType->Close(ObjectBody, Header->HandleCount);
}
Header->RefCount--;
ObPerformRetentionChecks(Header);
return(STATUS_SUCCESS);
}

View file

@ -104,45 +104,3 @@ NTSTATUS NtClose(HANDLE Handle)
return(ZwClose(Handle)); return(ZwClose(Handle));
} }
NTSTATUS ZwClose(HANDLE Handle)
/*
* FUNCTION: Closes a handle reference to an object
* ARGUMENTS:
* Handle = handle to close
* RETURNS: Status
*/
{
PVOID ObjectBody;
POBJECT_HEADER Header;
PHANDLE_REP HandleRep;
assert_irql(PASSIVE_LEVEL);
DPRINT("ZwClose(Handle %x)\n",Handle);
HandleRep = ObTranslateHandle(KeGetCurrentProcess(),Handle);
if (HandleRep == NULL)
{
return(STATUS_INVALID_HANDLE);
}
ObjectBody = HandleRep->ObjectBody;
HandleRep->ObjectBody = NULL;
Header = BODY_TO_HEADER(ObjectBody);
Header->RefCount++;
Header->HandleCount--;
if (Header->ObjectType != NULL &&
Header->ObjectType->Close != NULL)
{
Header->ObjectType->Close(ObjectBody, Header->HandleCount);
}
Header->RefCount--;
ObPerformRetentionChecks(Header);
return(STATUS_SUCCESS);
}

View file

@ -33,10 +33,11 @@ VOID ObInitializeObject(POBJECT_HEADER ObjectHeader,
RtlInitUnicodeString(&(ObjectHeader->Name),NULL); RtlInitUnicodeString(&(ObjectHeader->Name),NULL);
if (Handle != NULL) if (Handle != NULL)
{ {
*Handle = ObInsertHandle(KeGetCurrentProcess(), ObCreateHandle(PsGetCurrentProcess(),
HEADER_TO_BODY(ObjectHeader), HEADER_TO_BODY(ObjectHeader),
DesiredAccess, DesiredAccess,
FALSE); FALSE,
Handle);
} }
} }
@ -241,69 +242,3 @@ VOID ObDereferenceObject(PVOID ObjectBody)
Header->RefCount--; Header->RefCount--;
ObPerformRetentionChecks(Header); ObPerformRetentionChecks(Header);
} }
NTSTATUS ObReferenceObjectByHandle(HANDLE Handle,
ACCESS_MASK DesiredAccess,
POBJECT_TYPE ObjectType,
KPROCESSOR_MODE AccessMode,
PVOID* Object,
POBJECT_HANDLE_INFORMATION
HandleInformationPtr)
/*
* FUNCTION: Increments the reference count for an object and returns a
* pointer to its body
* ARGUMENTS:
* Handle = Handle for the object
* DesiredAccess = Desired access to the object
* ObjectType
* AccessMode
* Object (OUT) = Points to the object body on return
* HandleInformation (OUT) = Contains information about the handle
* on return
* RETURNS: Status
*/
{
PHANDLE_REP HandleRep;
POBJECT_HEADER ObjectHeader;
ASSERT_IRQL(PASSIVE_LEVEL);
DPRINT("ObReferenceObjectByHandle(Handle %x, DesiredAccess %x, "
"ObjectType %x, AccessMode %d, Object %x)\n",Handle,DesiredAccess,
ObjectType,AccessMode,Object);
if (Handle == NtCurrentProcess())
{
*Object = PsGetCurrentProcess();
return(STATUS_SUCCESS);
}
if (Handle == NtCurrentThread())
{
*Object = PsGetCurrentThread();
return(STATUS_SUCCESS);
}
HandleRep = ObTranslateHandle(KeGetCurrentProcess(),Handle);
if (HandleRep == NULL || HandleRep->ObjectBody == NULL)
{
return(STATUS_INVALID_HANDLE);
}
ObjectHeader = BODY_TO_HEADER(HandleRep->ObjectBody);
if (ObjectType != NULL && ObjectType != ObjectHeader->ObjectType)
{
return(STATUS_UNSUCCESSFUL);
}
if (!(HandleRep->GrantedAccess & DesiredAccess))
{
return(STATUS_ACCESS_DENIED);
}
ObjectHeader->RefCount++;
*Object = HandleRep->ObjectBody;
return(STATUS_SUCCESS);
}

View file

@ -23,6 +23,9 @@ extern ULONG PiNrThreads;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID PsTerminateCurrentThread(NTSTATUS ExitStatus) VOID PsTerminateCurrentThread(NTSTATUS ExitStatus)
/*
* FUNCTION: Terminates the current thread
*/
{ {
KIRQL oldlvl; KIRQL oldlvl;
PETHREAD CurrentThread; PETHREAD CurrentThread;
@ -42,6 +45,9 @@ VOID PsTerminateCurrentThread(NTSTATUS ExitStatus)
} }
VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus) VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus)
/*
* FUNCTION: Terminate a thread when calling from that thread's context
*/
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }
@ -117,6 +123,7 @@ NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle,
{ {
PsTerminateOtherThread(Thread, ExitStatus); PsTerminateOtherThread(Thread, ExitStatus);
} }
return(STATUS_SUCCESS);
} }
VOID PsReleaseThread(PETHREAD Thread) VOID PsReleaseThread(PETHREAD Thread)
@ -144,6 +151,7 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus)
*/ */
{ {
PsTerminateCurrentThread(ExitStatus); PsTerminateCurrentThread(ExitStatus);
return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort)

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ps/process.c * FILE: ntoskrnl/ps/process.c
* PURPOSE: Process managment * PURPOSE: Process managment
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* REVISION HISTORY: * REVISION HISTORY:
* 21/07/98: Created * 21/07/98: Created
*/ */
@ -27,6 +27,11 @@ POBJECT_TYPE PsProcessType = NULL;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
PEPROCESS PsGetSystemProcess(VOID)
{
return(SystemProcess);
}
VOID PsInitProcessManagment(VOID) VOID PsInitProcessManagment(VOID)
{ {
ANSI_STRING AnsiString; ANSI_STRING AnsiString;
@ -64,11 +69,14 @@ VOID PsInitProcessManagment(VOID)
KProcess = &SystemProcess->Pcb; KProcess = &SystemProcess->Pcb;
InitializeListHead(&(KProcess->MemoryAreaList)); InitializeListHead(&(KProcess->MemoryAreaList));
ObInitializeHandleTable(NULL,FALSE,KProcess); ObCreateHandleTable(NULL,FALSE,SystemProcess);
KProcess->PageTableDirectory = get_page_directory(); KProcess->PageTableDirectory = get_page_directory();
SystemProcessHandle = ObInsertHandle(KProcess,SystemProcess, ObCreateHandle(SystemProcess,
PROCESS_ALL_ACCESS,FALSE); SystemProcess,
PROCESS_ALL_ACCESS,
FALSE,
&SystemProcessHandle);
} }
PKPROCESS KeGetCurrentProcess(VOID) PKPROCESS KeGetCurrentProcess(VOID)
@ -84,8 +92,8 @@ struct _EPROCESS* PsGetCurrentProcess(VOID)
* FUNCTION: Returns a pointer to the current process * FUNCTION: Returns a pointer to the current process
*/ */
{ {
if (PsGetCurrentThread()==NULL if (PsGetCurrentThread() == NULL ||
|| PsGetCurrentThread()->ThreadsProcess==NULL) PsGetCurrentThread()->ThreadsProcess == NULL)
{ {
return(SystemProcess); return(SystemProcess);
} }
@ -163,7 +171,7 @@ NTSTATUS STDCALL ZwCreateProcess(
PROCESS_CREATE_PROCESS, PROCESS_CREATE_PROCESS,
PsProcessType, PsProcessType,
UserMode, UserMode,
&ParentProcessHandle, (PVOID*)&ParentProcess,
NULL); NULL);
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
@ -183,7 +191,9 @@ NTSTATUS STDCALL ZwCreateProcess(
KProcess = &(Process->Pcb); KProcess = &(Process->Pcb);
InitializeListHead(&(KProcess->MemoryAreaList)); InitializeListHead(&(KProcess->MemoryAreaList));
ObInitializeHandleTable(KProcess,InheritObjectTable,KProcess); ObCreateHandleTable(ParentProcess,
InheritObjectTable,
Process);
PageDirectory = physical_to_linear((ULONG)get_free_page()); PageDirectory = physical_to_linear((ULONG)get_free_page());
KProcess->PageTableDirectory = PageDirectory; KProcess->PageTableDirectory = PageDirectory;
@ -308,5 +318,45 @@ NTSTATUS STDCALL ZwSetInformationProcess(IN HANDLE ProcessHandle,
IN PVOID ProcessInformation, IN PVOID ProcessInformation,
IN ULONG ProcessInformationLength) IN ULONG ProcessInformationLength)
{ {
UNIMPLEMENTED; PEPROCESS Process;
NTSTATUS Status;
Status = ObReferenceObjectByHandle(ProcessHandle,
PROCESS_SET_INFORMATION,
PsProcessType,
UserMode,
&ProcessHandle,
NULL);
if (Status != STATUS_SUCCESS)
{
return(Status);
}
switch (ProcessInformationClass)
{
case ProcessBasicInformation:
case ProcessQuotaLimits:
case ProcessIoCounters:
case ProcessVmCounters:
case ProcessTimes:
case ProcessBasePriority:
case ProcessRaisePriority:
case ProcessDebugPort:
case ProcessExceptionPort:
case ProcessAccessToken:
case ProcessLdtInformation:
case ProcessLdtSize:
case ProcessDefaultHardErrorMode:
case ProcessIoPortHandlers:
case ProcessWorkingSetWatch:
case ProcessUserModeIOPL:
case ProcessEnableAlignmentFaultFixup:
case ProcessPriorityClass:
case ProcessWx86Information:
case ProcessHandleCount:
case ProcessAffinityMask:
default:
Status = STATUS_NOT_IMPLEMENTED;
}
return(Status);
} }

View file

@ -11,9 +11,9 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <internal/string.h> #include <internal/string.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
@ -49,7 +49,10 @@ VOID RtlCopyBytes(PVOID Destination,
VOID RtlCopyMemory(VOID* Destination, VOID* Source, ULONG Length) VOID RtlCopyMemory(VOID* Destination, VOID* Source, ULONG Length)
{ {
DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n",
Destination,Source,Length);
memcpy(Destination,Source,Length); memcpy(Destination,Source,Length);
DPRINT("*Destination %x\n",*(PULONG)Destination);
} }
VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill) VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill)

View file

@ -42,6 +42,7 @@ VOID ExExecuteShell(VOID)
ULONG Size, StackSize; ULONG Size, StackSize;
CONTEXT Context; CONTEXT Context;
NTSTATUS Status; NTSTATUS Status;
ULONG Temp,BytesWritten;
ZwCreateProcess(&ShellHandle, ZwCreateProcess(&ShellHandle,
PROCESS_ALL_ACCESS, PROCESS_ALL_ACCESS,
@ -87,7 +88,7 @@ VOID ExExecuteShell(VOID)
memset(&Context,0,sizeof(CONTEXT)); memset(&Context,0,sizeof(CONTEXT));
Context.SegSs = USER_DS; Context.SegSs = USER_DS;
Context.Esp = 0x2000; Context.Esp = 0xf000 - 12;
Context.EFlags = 0x202; Context.EFlags = 0x202;
Context.SegCs = USER_CS; Context.SegCs = USER_CS;
Context.Eip = 0x10000; Context.Eip = 0x10000;
@ -97,14 +98,20 @@ VOID ExExecuteShell(VOID)
Context.SegGs = USER_DS; Context.SegGs = USER_DS;
BaseAddress = 0x1000; BaseAddress = 0x1000;
StackSize = 0x1000; StackSize = 0xe000;
ZwAllocateVirtualMemory(ShellHandle, ZwAllocateVirtualMemory(ShellHandle,
&BaseAddress, &BaseAddress,
0, 0,
&StackSize, &StackSize,
MEM_COMMIT, MEM_COMMIT,
PAGE_READWRITE); PAGE_READWRITE);
Temp = 0xf000 - 4;
ZwWriteVirtualMemory(ShellHandle,
0xf000 - 8,
&Temp,
sizeof(Temp),
&BytesWritten);
ZwCreateThread(&ThreadHandle, ZwCreateThread(&ThreadHandle,
THREAD_ALL_ACCESS, THREAD_ALL_ACCESS,