From e5dfcc98716782d0c1b951bdf10b203d9f90a268 Mon Sep 17 00:00:00 2001 From: David Welch Date: Sat, 6 Feb 1999 18:34:14 +0000 Subject: [PATCH] no message svn path=/trunk/; revision=215 --- reactos/apps/common/crt0.c | 32 +++- reactos/apps/utils/shell/shell.c | 8 +- reactos/drivers/fs/ext2/dir.c | 17 +- reactos/drivers/fs/ext2/super.c | 12 -- reactos/include/internal/ob.h | 21 ++- reactos/lib/crtdll/misc/GetArgs.c | 106 ++++++------ reactos/lib/crtdll/stdlib/malloc.c | 4 - reactos/lib/crtdll/string/strcpy.c | 6 +- reactos/lib/crtdll/string/strdup.c | 1 + reactos/lib/kernel32/file/find.c | 2 +- reactos/lib/kernel32/internal/init.c | 3 +- reactos/lib/kernel32/makefile | 2 +- reactos/lib/kernel32/mem/heap.c | 24 ++- reactos/lib/kernel32/misc/dllmain.c | 13 +- reactos/lib/kernel32/process/cmdline.c | 2 +- reactos/lib/kernel32/process/proc.c | 140 ++++++++++++++-- reactos/lib/ntdll/stubs/stubs.c | 2 +- reactos/makefile_rex | 5 +- reactos/ntoskrnl/ex/fmutex.c | 2 +- reactos/ntoskrnl/ex/locale.c | 6 +- reactos/ntoskrnl/hal/x86/page.c | 202 +++-------------------- reactos/ntoskrnl/io/symlink.c | 17 +- reactos/ntoskrnl/ke/apc.c | 2 +- reactos/ntoskrnl/mm/mdl.c | 5 +- reactos/ntoskrnl/mm/mm.c | 15 +- reactos/ntoskrnl/mm/npool.c | 6 +- reactos/ntoskrnl/mm/section.c | 17 +- reactos/ntoskrnl/mm/special.c | 21 ++- reactos/ntoskrnl/mm/virtual.c | 69 ++++++-- reactos/ntoskrnl/nt/ntevent.c | 10 +- reactos/ntoskrnl/ob/dirobj.c | 7 +- reactos/ntoskrnl/ob/handle.c | 218 ++++++++++++++++++++----- reactos/ntoskrnl/ob/ntobj.c | 42 ----- reactos/ntoskrnl/ob/object.c | 75 +-------- reactos/ntoskrnl/ps/kill.c | 8 + reactos/ntoskrnl/ps/process.c | 68 +++++++- reactos/ntoskrnl/rtl/mem.c | 5 +- reactos/ntoskrnl/tst/test.c | 13 +- 38 files changed, 694 insertions(+), 514 deletions(-) diff --git a/reactos/apps/common/crt0.c b/reactos/apps/common/crt0.c index bcb1777254b..860e27c2159 100644 --- a/reactos/apps/common/crt0.c +++ b/reactos/apps/common/crt0.c @@ -1,9 +1,33 @@ -extern void main(void); +#include -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(); - for(;;); + int nRet; + + 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) diff --git a/reactos/apps/utils/shell/shell.c b/reactos/apps/utils/shell/shell.c index 851b1745f62..91ef78953cd 100644 --- a/reactos/apps/utils/shell/shell.c +++ b/reactos/apps/utils/shell/shell.c @@ -69,6 +69,11 @@ void ExecuteType(char* cmdline) OPEN_EXISTING, 0, NULL); + if (FileHandle == NULL) + { + debug_printf("Unknown file\n"); + return; + } while (ReadFile(FileHandle, &c, 1, @@ -156,7 +161,6 @@ void ExecuteCommand(char* line) } if (ExecuteProcess(cmd,tail)) { - debug_printf("Done ExecuteProcess\n"); return; } debug_printf("Unknown command\n"); @@ -202,8 +206,6 @@ void main() { static char line[255]; - KERNEL32_Init(); - AllocConsole(); InputHandle = GetStdHandle(STD_INPUT_HANDLE); OutputHandle = GetStdHandle(STD_OUTPUT_HANDLE); diff --git a/reactos/drivers/fs/ext2/dir.c b/reactos/drivers/fs/ext2/dir.c index 7240ad04332..50948cdae65 100644 --- a/reactos/drivers/fs/ext2/dir.c +++ b/reactos/drivers/fs/ext2/dir.c @@ -41,6 +41,7 @@ PVOID Ext2ProcessDirEntry(PDEVICE_EXTENSION DeviceExt, { PFILE_DIRECTORY_INFORMATION FDI; PFILE_NAMES_INFORMATION FNI; + PFILE_BOTH_DIRECTORY_INFORMATION FBI; ULONG i; PWSTR FileName; struct ext2_inode inode; @@ -79,6 +80,19 @@ PVOID Ext2ProcessDirEntry(PDEVICE_EXTENSION DeviceExt, Buffer = Buffer + FDI->NextEntryOffset; 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: UNIMPLEMENTED; } @@ -280,7 +294,8 @@ NTSTATUS Ext2OpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, } current_inode = entry.inode; current_segment = strtok(NULL,"\\"); - }; + StartIndex = 0; + } DPRINT("Found file\n"); Ext2ReadInode(DeviceExt, diff --git a/reactos/drivers/fs/ext2/super.c b/reactos/drivers/fs/ext2/super.c index b1cf9d6095b..81f13988a0b 100644 --- a/reactos/drivers/fs/ext2/super.c +++ b/reactos/drivers/fs/ext2/super.c @@ -24,16 +24,6 @@ static PDRIVER_OBJECT DriverObject; /* 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) { PIO_STACK_LOCATION Stack; @@ -46,8 +36,6 @@ NTSTATUS Ext2Close(PDEVICE_OBJECT DeviceObject, PIRP Irp) Stack = IoGetCurrentIrpStackLocation(Irp); FileObject = Stack->FileObject; DeviceExtension = DeviceObject->DeviceExtension; - - Status = Ext2CloseFile(DeviceExtension,FileObject); Irp->IoStatus.Status = Status; Irp->IoStatus.Information = 0; diff --git a/reactos/include/internal/ob.h b/reactos/include/internal/ob.h index a328ced9510..bb13ff60154 100644 --- a/reactos/include/internal/ob.h +++ b/reactos/include/internal/ob.h @@ -52,21 +52,13 @@ enum BOOL ObAddObjectToNameSpace(PUNICODE_STRING path, POBJECT_HEADER Object); 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); NTSTATUS ObLookupObject(HANDLE rootdir, PWSTR string, PVOID* Object, PWSTR* UnparsedSection, ULONG Attributes); - PVOID ObCreateObject(PHANDLE Handle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_TYPE Type); -VOID ObInitializeHandleTable(PKPROCESS Parent, BOOLEAN Inherit, - PKPROCESS Process); VOID ObRemoveEntry(POBJECT_HEADER Header); /* @@ -103,4 +95,17 @@ typedef struct PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h); 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 */ diff --git a/reactos/lib/crtdll/misc/GetArgs.c b/reactos/lib/crtdll/misc/GetArgs.c index 974ab363920..b6e6f5da59d 100644 --- a/reactos/lib/crtdll/misc/GetArgs.c +++ b/reactos/lib/crtdll/misc/GetArgs.c @@ -29,58 +29,68 @@ char *** _environ_dll = &_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; - int i,afterlastspace; - DWORD version; - -// acmdln_dll = cmdline = strdup( GetCommandLineA() ); - - version = GetVersion(); - osver_dll = version >> 16; - winminor_dll = version & 0xFF; - winmajor_dll = (version>>8) & 0xFF; - winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); - - - /* missing threading init */ - - i=0; - - afterlastspace=0; - while (cmdline[i]) { - if (cmdline[i]==' ') { - __argc++; - cmdline[i]='\0'; - __argv[__argc-1] = strdup( cmdline+afterlastspace); - i++; - while (cmdline[i]==' ') - i++; - if (cmdline[i]) - afterlastspace=i; - } else - i++; - } - - __argc++; - cmdline[i]='\0'; - __argv[__argc-1] = strdup( cmdline+afterlastspace); - + char *cmdline; + int i,afterlastspace; + DWORD version; + + // acmdln_dll = cmdline = strdup( GetCommandLineA() ); + + version = GetVersion(); + osver_dll = version >> 16; + winminor_dll = version & 0xFF; + winmajor_dll = (version>>8) & 0xFF; + winver_dll = ((version >> 8) & 0xFF) + ((version & 0xFF) << 8); + + + /* missing threading init */ + + i=0; + cmdline = GetCommandLineA(); + afterlastspace=0; + + dprintf("cmdline '%s'\n",cmdline); + + while (cmdline[i]) + { + if (cmdline[i]==' ') + { + dprintf("cmdline '%s'\n",cmdline); + __argc++; + cmdline[i]='\0'; + __argv[__argc-1] = strdup( cmdline+afterlastspace); + i++; + while (cmdline[i]==' ') + i++; + if (cmdline[i]) + afterlastspace=i; + } + else + { + i++; + } + } + + + __argc++; + cmdline[i]='\0'; + __argv[__argc-1] = strdup( cmdline+afterlastspace); + HeapValidate(GetProcessHeap(),0,NULL); - *argc = __argc; - *argv = __argv; - - - xenv = GetEnvironmentStringsA(); - _environ = &xenv; - _environ_dll = &_environ; - environ = &xenv; - env = &xenv; - return 0; + *argc = __argc; + *argv = __argv; + + +// xenv = GetEnvironmentStringsA(); + _environ = &xenv; + _environ_dll = &_environ; + environ = &xenv; + env = &xenv; + return 0; } int _chkstk() { return 0; -} \ No newline at end of file +} diff --git a/reactos/lib/crtdll/stdlib/malloc.c b/reactos/lib/crtdll/stdlib/malloc.c index 7789287c277..bfc854715bb 100644 --- a/reactos/lib/crtdll/stdlib/malloc.c +++ b/reactos/lib/crtdll/stdlib/malloc.c @@ -26,12 +26,8 @@ void* calloc(size_t _nmemb, size_t _size) void* realloc(void* _ptr, size_t _size) { - ExFreePool(_ptr); - return ExAllocatePool(NonPagedPool,_size ); -#if 0 return(HeapReAlloc(GetProcessHeap(), 0, _ptr, _size)); -#endif } diff --git a/reactos/lib/crtdll/string/strcpy.c b/reactos/lib/crtdll/string/strcpy.c index 4813be8e477..cf77c546e6a 100644 --- a/reactos/lib/crtdll/string/strcpy.c +++ b/reactos/lib/crtdll/string/strcpy.c @@ -1,9 +1,7 @@ /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */ -char * -strcpy(char *to, const char *from); +char* strcpy(char *to, const char *from); -char * -strcpy(char *to, const char *from) +char* strcpy(char *to, const char *from) { char *save = to; diff --git a/reactos/lib/crtdll/string/strdup.c b/reactos/lib/crtdll/string/strdup.c index 70180f42d52..695d89eba3d 100644 --- a/reactos/lib/crtdll/string/strdup.c +++ b/reactos/lib/crtdll/string/strdup.c @@ -1,3 +1,4 @@ + /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ #include #include diff --git a/reactos/lib/kernel32/file/find.c b/reactos/lib/kernel32/file/find.c index e9fb899d519..dcc1ddb725e 100644 --- a/reactos/lib/kernel32/file/find.c +++ b/reactos/lib/kernel32/file/find.c @@ -272,7 +272,7 @@ BOOL FindClose(HANDLE hFindFile) DPRINT("FindClose(hFindFile %x)\n",hFindFile); IData = (PKERNEL32_FIND_FILE_DATA)hFindFile; - NtClose(IData->DirectoryHandle); + CloseHandle(IData->DirectoryHandle); HeapFree(GetProcessHeap(), 0, IData); return(TRUE); } diff --git a/reactos/lib/kernel32/internal/init.c b/reactos/lib/kernel32/internal/init.c index c95b261e570..d6107852aaa 100644 --- a/reactos/lib/kernel32/internal/init.c +++ b/reactos/lib/kernel32/internal/init.c @@ -2,7 +2,8 @@ #include #include -VOID KERNEL32_Init(VOID) +VOID KERNEL32_Init(PWSTR Args) { + InitializePeb(Args); __HeapInit(0, 4*1024*1024, 4*1024*1024); } diff --git a/reactos/lib/kernel32/makefile b/reactos/lib/kernel32/makefile index 401ebd19a34..f602ffb31ba 100644 --- a/reactos/lib/kernel32/makefile +++ b/reactos/lib/kernel32/makefile @@ -13,7 +13,7 @@ MEM_OBJECTS = mem/virtual.o mem/heap.o mem/utils.o THREAD_OBJECTS = thread/thread.o -PROCESS_OBJECTS = process/proc.o +PROCESS_OBJECTS = process/proc.o process/cmdline.o STRING_OBJECTS = string/lstring.o diff --git a/reactos/lib/kernel32/mem/heap.c b/reactos/lib/kernel32/mem/heap.c index c84bf6cf141..7c0c6ed1292 100644 --- a/reactos/lib/kernel32/mem/heap.c +++ b/reactos/lib/kernel32/mem/heap.c @@ -35,6 +35,7 @@ #include +#define HEAP_VALIDATE 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", pheap,flags,size,tag); + if (size <= HEAP_ADMIN_SIZE) + { + size = size + HEAP_ADMIN_SIZE; + } + pfree=&(pheap->Start); allocsize=SIZE_ROUND(size); freesize=HEAP_SIZE(pfree); @@ -446,11 +452,17 @@ static LPVOID __HeapAllocFragment(PHEAP pheap, ULONG flags, ULONG size ) PHEAP_SUBALLOC psub; PHEAP_FRAGMENT palloc; INT nalloc; - + + DPRINT("__HeapAllocFragment(pheap %x, flags %d, size %d)\n", + pheap,flags,size); + + size = size + HEAP_FRAG_ADMIN_SIZE; + /* get bucket size */ pbucket=pheap->Bucket; while(size>pbucket->Size) { + DPRINT("pbucket->Size %d\n",pbucket->Size); pbucket++; } /* get suballoc */ @@ -681,9 +693,9 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size) PHEAP pheap=hheap; 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 ); -#ifdef NOT +#ifdef HEAP_VALIDATE HeapValidate(hheap, 0, 0); #endif if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE ) @@ -698,6 +710,8 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size) LeaveCriticalSection(&(pheap->Synchronize)); DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval); + + HeapValidate(hheap, 0, 0); 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", (ULONG) hheap, flags, (ULONG) ptr, size ); -#ifdef NOT +#ifdef HEAP_VALIDATE HeapValidate(hheap, 0, 0); #endif 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", (ULONG) hheap, flags, (ULONG) ptr ); -#ifdef NOT +#ifdef HEAP_VALIDATE HeapValidate(hheap, 0, 0); #endif if(( flags | pheap->Flags) & HEAP_NO_SERIALIZE ) diff --git a/reactos/lib/kernel32/misc/dllmain.c b/reactos/lib/kernel32/misc/dllmain.c index e1af10b457e..4289dfc9738 100644 --- a/reactos/lib/kernel32/misc/dllmain.c +++ b/reactos/lib/kernel32/misc/dllmain.c @@ -30,19 +30,18 @@ NT_TEB *Teb; -WINBOOL -STDCALL -DllMain ( - HANDLE hInst, - ULONG ul_reason_for_call, - LPVOID lpReserved ) +WINBOOL STDCALL DllMain (HANDLE hInst, + ULONG ul_reason_for_call, + LPVOID lpReserved) { switch( ul_reason_for_call ) { case DLL_PROCESS_ATTACH: { - GetCurrentPeb()->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS,8192,0); + GetCurrentPeb()->ProcessHeap = HeapCreate(HEAP_GENERATE_EXCEPTIONS, + 8192, + 0); InitAtomTable(13); SetCurrentDirectoryW(L"C:"); // SetSystemDirectoryW(L"C:\\Reactos\\System"); diff --git a/reactos/lib/kernel32/process/cmdline.c b/reactos/lib/kernel32/process/cmdline.c index a764d852cb7..6198dffae50 100644 --- a/reactos/lib/kernel32/process/cmdline.c +++ b/reactos/lib/kernel32/process/cmdline.c @@ -21,7 +21,7 @@ /* GLOBALS ******************************************************************/ -unsigned char CommandLineA[MAX_PATH]; +static unsigned char CommandLineA[MAX_PATH]; /* FUNCTIONS ****************************************************************/ diff --git a/reactos/lib/kernel32/process/proc.c b/reactos/lib/kernel32/process/proc.c index 0221eaecd93..e6b22d33334 100644 --- a/reactos/lib/kernel32/process/proc.c +++ b/reactos/lib/kernel32/process/proc.c @@ -18,14 +18,15 @@ #include #include #include +#include #define NDEBUG #include /* GLOBALS *****************************************************************/ -static NT_PEB *CurrentPeb; -static NT_PEB Peb; +static NT_PEB CurrentPeb; +static PROCESSINFOW ProcessInfo; WaitForInputIdleType lpfnGlobalRegisterWaitForInputIdle; @@ -35,12 +36,17 @@ VOID RegisterWaitForInputIdle(WaitForInputIdleType lpfnRegisterWaitForInputIdle 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) { - if ( CurrentPeb != NULL ) - return CurrentPeb; - else // hack to be able to return a process environment any time. - return &Peb; + return(&CurrentPeb); } HANDLE STDCALL GetCurrentProcess(VOID) @@ -178,6 +184,103 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName, 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, LPWSTR lpCommandLine, @@ -200,9 +303,10 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName, LPTHREAD_START_ROUTINE lpStartAddress = NULL; LPVOID lpParameter = NULL; PSECURITY_DESCRIPTOR SecurityDescriptor = NULL; - WCHAR TempApplicationName[255]; - WCHAR TempFileName[255]; - WCHAR TempDirectoryName[255]; + WCHAR TempApplicationName[256]; + WCHAR TempFileName[256]; + WCHAR TempDirectoryName[256]; + WCHAR TempCommandLine[256]; ULONG i; ULONG BaseAddress; ULONG Size; @@ -211,6 +315,8 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName, DPRINT("CreateProcessW(lpApplicationName '%w', lpCommandLine '%w')\n", lpApplicationName,lpCommandLine); + wcscpy(TempCommandLine, lpCommandLine); + hFile = NULL; /* @@ -328,15 +434,17 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName, &PriorityClass, sizeof(KPRIORITY)); #endif + DPRINT("Creating thread for process\n"); lpStartAddress = BaseAddress; - hThread = CreateRemoteThread(hProcess, - lpThreadAttributes, - 4096, // 1 page ?? - lpStartAddress, - lpParameter, - dwCreationFlags, - &lpProcessInformation->dwThreadId); + hThread = CreateFirstThread(hProcess, + lpThreadAttributes, + 16384, // 3 page ?? + lpStartAddress, + lpParameter, + dwCreationFlags, + &lpProcessInformation->dwThreadId, + TempCommandLine); if ( hThread == NULL ) return FALSE; diff --git a/reactos/lib/ntdll/stubs/stubs.c b/reactos/lib/ntdll/stubs/stubs.c index 354bbd475d7..7e37b37e25f 100644 --- a/reactos/lib/ntdll/stubs/stubs.c +++ b/reactos/lib/ntdll/stubs/stubs.c @@ -503,7 +503,7 @@ STUB(_atoi64) STUB(_aulldiv) STUB(_aullrem) STUB(_aullshr) -STUB(_chkstk) +//STUB(_chkstk) STUB(_fltused) STUB(_ftol) STUB(_i64toa) diff --git a/reactos/makefile_rex b/reactos/makefile_rex index 2470f210746..fd101114d65 100644 --- a/reactos/makefile_rex +++ b/reactos/makefile_rex @@ -33,7 +33,7 @@ LOADERS = dos KERNEL_SERVICES = parallel keyboard blues null mouse serial sound ide test sdisk \ minix vfat ext2 -APPS = hello shell +APPS = hello shell args all: $(COMPONENTS) $(LOADERS) $(KERNEL_SERVICES) $(APPS) @@ -46,6 +46,9 @@ clean: dummy hello: dummy make -C apps/hello +args: dummy + make -C apps/args + cmd: dummy make -C apps/cmd diff --git a/reactos/ntoskrnl/ex/fmutex.c b/reactos/ntoskrnl/ex/fmutex.c index 2aaa60011de..ec82d0e7a78 100644 --- a/reactos/ntoskrnl/ex/fmutex.c +++ b/reactos/ntoskrnl/ex/fmutex.c @@ -3,7 +3,7 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/ex/fmutex.c * PURPOSE: Implements fast mutexes - * PROGRAMMER: David Welch (welch@mcmail.com) + * PROGRAMMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * Created 22/05/98 */ diff --git a/reactos/ntoskrnl/ex/locale.c b/reactos/ntoskrnl/ex/locale.c index 8a9854855ee..d526ba9d0ab 100644 --- a/reactos/ntoskrnl/ex/locale.c +++ b/reactos/ntoskrnl/ex/locale.c @@ -1,9 +1,9 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected - * PROGRAMMER: David Welch (welch@mcmail.com) + * FILE: ntoskrnl/ex/locale.c + * PURPOSE: Locale support + * PROGRAMMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * Created 22/05/98 */ diff --git a/reactos/ntoskrnl/hal/x86/page.c b/reactos/ntoskrnl/hal/x86/page.c index 68dd2d60b89..d9209521453 100644 --- a/reactos/ntoskrnl/hal/x86/page.c +++ b/reactos/ntoskrnl/hal/x86/page.c @@ -3,7 +3,7 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/hal/x86/page.c * PURPOSE: low level memory managment manipulation - * PROGRAMER: David Welch + * PROGRAMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * 9/3/98: Created */ @@ -39,24 +39,34 @@ static ULONG ProtectToPTE(ULONG flProtect) } if (flProtect & PAGE_READWRITE || flProtect & PAGE_EXECUTE_READWRITE) { - Attributes = PA_WRITE; + Attributes = PA_WRITE | PA_USER; } if (flProtect & PAGE_READONLY || flProtect & PAGE_EXECUTE || flProtect & PAGE_EXECUTE_READ) { - Attributes = PA_READ; - } + Attributes = PA_READ | PA_USER; + } return(Attributes); } PULONG MmGetPageEntry(PEPROCESS Process, ULONG Address) { - unsigned int page_table; - unsigned int* page_tlb; - unsigned int* page_dir = linear_to_physical( - Process->Pcb.PageTableDirectory); - - DPRINT("vaddr %x ",vaddr); + ULONG page_table; + PULONG page_tlb; + PULONG page_dir; + + DPRINT("MmGetPageEntry(Process %x, Address %x)\n",Process,Address); + + 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_MASK(page_dir[VADDR_TO_PD_OFFSET(Address)])); 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; } + DPRINT("Returning %x\n",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); (*MmGetPageEntry(Process, Address)) = PhysicalAddress | Attributes; + FLUSH_TLB; } VOID MmSetPageProtect(PEPROCESS Process, @@ -102,100 +114,9 @@ VOID MmSetPageProtect(PEPROCESS Process, PageEntry = MmGetPageEntry(Process,Address); (*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) /* * FUNCTION: Returns the physical address corresponding to a virtual address @@ -203,79 +124,10 @@ PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr) { 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_LOW_PART(p, PAGE_MASK( - *get_page_entry((unsigned int) vaddr))); - + SET_LARGE_INTEGER_LOW_PART(p, PAGE_MASK(*MmGetPageEntry(NULL,vaddr))); + 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]); -} - - diff --git a/reactos/ntoskrnl/io/symlink.c b/reactos/ntoskrnl/io/symlink.c index d31ab708e3a..33c2b8501fc 100644 --- a/reactos/ntoskrnl/io/symlink.c +++ b/reactos/ntoskrnl/io/symlink.c @@ -120,8 +120,17 @@ NTSTATUS ZwOpenSymbolicLinkObject(OUT PHANDLE LinkHandle, { return(Status); } - *LinkHandle = ObInsertHandle(KeGetCurrentProcess(),Object, - DesiredAccess,FALSE); + + Status = ObCreateHandle(PsGetCurrentProcess(), + Object, + DesiredAccess, + FALSE, + LinkHandle); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + return(STATUS_SUCCESS); } @@ -170,7 +179,6 @@ NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName, OBJECT_ATTRIBUTES ObjectAttributes; HANDLE SymbolicLinkHandle; PSYMLNK_OBJECT SymbolicLink; - PUNICODE_STRING TargetName; DPRINT("IoCreateSymbolicLink(SymbolicLinkName %w, DeviceName %w)\n", SymbolicLinkName->Buffer,DeviceName->Buffer); @@ -185,9 +193,10 @@ NTSTATUS IoCreateSymbolicLink(PUNICODE_STRING SymbolicLinkName, return(STATUS_UNSUCCESSFUL); } + ZwClose(SymbolicLinkHandle); SymbolicLink->TargetName.Length = 0; SymbolicLink->TargetName.MaximumLength = - ((wstrlen(DeviceName->Buffer) + 1) * sizeof(WCHAR)); + ((wcslen(DeviceName->Buffer) + 1) * sizeof(WCHAR)); SymbolicLink->TargetName.Buffer = ExAllocatePool(NonPagedPool, SymbolicLink->TargetName.MaximumLength); RtlCopyUnicodeString(&(SymbolicLink->TargetName), DeviceName); diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 2df5411d387..e2b5bdc9dcc 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -3,7 +3,7 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/apc.c * PURPOSE: Possible implementation of APCs - * PROGRAMMER: David Welch (welch@mcmail.com) + * PROGRAMMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * Created 22/05/98 */ diff --git a/reactos/ntoskrnl/mm/mdl.c b/reactos/ntoskrnl/mm/mdl.c index 424b3d1347f..d8446cb66f3 100644 --- a/reactos/ntoskrnl/mm/mdl.c +++ b/reactos/ntoskrnl/mm/mdl.c @@ -66,7 +66,10 @@ PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode) { DPRINT("Writing %x with physical address %x\n", 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); Mdl->MdlFlags = Mdl->MdlFlags | MDL_MAPPED_TO_SYSTEM_VA; diff --git a/reactos/ntoskrnl/mm/mm.c b/reactos/ntoskrnl/mm/mm.c index a1ea644fb61..53a5c6cf7a2 100644 --- a/reactos/ntoskrnl/mm/mm.c +++ b/reactos/ntoskrnl/mm/mm.c @@ -67,6 +67,7 @@ void MmInitialize(boot_param* bp) (get_page_directory())[0]=0; FLUSH_TLB; CHECKPOINT; + /* * Free all pages not used for kernel memory * (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)); iMaximumSize = *MaximumSize; @@ -215,11 +219,12 @@ NTSTATUS ZwOpenSection(PHANDLE SectionHandle, return(Status); } - *SectionHandle = ObInsertHandle(KeGetCurrentProcess(), - Object, - DesiredAccess, - FALSE); - return(STATUS_SUCCESS); + Status = ObCreateHandle(PsGetCurrentProcess(), + Object, + DesiredAccess, + FALSE, + SectionHandle); + return(Status); } NTSTATUS NtMapViewOfSection(HANDLE SectionHandle, diff --git a/reactos/ntoskrnl/mm/special.c b/reactos/ntoskrnl/mm/special.c index 86fdaf89236..2da8bca5425 100644 --- a/reactos/ntoskrnl/mm/special.c +++ b/reactos/ntoskrnl/mm/special.c @@ -24,7 +24,6 @@ PVOID MmAllocateSection(ULONG Length) MEMORY_AREA* marea; NTSTATUS Status; ULONG i; - ULONG Attributes; DPRINT("MmAllocateSection(Length %x)\n",Length); @@ -41,10 +40,12 @@ PVOID MmAllocateSection(ULONG Length) return(NULL); } DPRINT("Result %x\n",Result); - Attributes = PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM; 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); } @@ -89,9 +90,10 @@ PVOID MmMapIoSpace(PHYSICAL_ADDRESS PhysicalAddress, } for (i=0;i<=(NumberOfBytes/PAGESIZE);i++) { - set_page(Result + (i * PAGESIZE), - Attributes, - GET_LARGE_INTEGER_LOW_PART(PhysicalAddress)); + MmSetPage(NULL, + Result + (i * PAGESIZE), + PAGE_READWRITE, + GET_LARGE_INTEGER_LOW_PART(PhysicalAddress)); } return((PVOID)Result); } @@ -123,9 +125,10 @@ PVOID MmAllocateNonCachedMemory(ULONG NumberOfBytes) } for (i=0;i<=(NumberOfBytes/PAGESIZE);i++) { - set_page(Result+(i*PAGESIZE), - PA_WRITE | PA_READ | PA_EXECUTE | PA_SYSTEM | PA_PCD | PA_PWT, - get_free_page()); + MmSetPage(NULL, + Result+(i*PAGESIZE), + PAGE_READWRITE, + get_free_page()); } return((PVOID)Result); } diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index 3df1b75481b..8eb74148501 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -95,7 +95,10 @@ void VirtualInit(boot_param* bp) ULONG MmCommitedSectionHandleFault(MEMORY_AREA* MemoryArea, ULONG Address) { - set_page(Address,0x7,get_free_page()); + MmSetPage(PsGetCurrentProcess(), + Address, + MemoryArea->Attributes, + get_free_page()); return(TRUE); } @@ -107,7 +110,10 @@ NTSTATUS MmSectionHandleFault(MEMORY_AREA* MemoryArea, PVOID Address) DPRINT("MmSectionHandleFault(MemoryArea %x, Address %x)\n", 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) + MemoryArea->Data.SectionData.ViewOffset; @@ -152,7 +158,7 @@ asmlinkage int page_fault_handler(unsigned int cs, if (KeGetCurrentIrql()!=PASSIVE_LEVEL) { - DbgPrint("Recursive page fault detected\n"); + DbgPrint("Page fault at high IRQL\n"); return(0); // KeBugCheck(0); } @@ -713,11 +719,16 @@ NTSTATUS STDCALL ZwWriteVirtualMemory(IN HANDLE ProcessHandle, OUT PULONG NumberOfBytesWritten) { PEPROCESS Process; - MEMORY_AREA* MemoryArea; + PMEMORY_AREA InMemoryArea; + PMEMORY_AREA OutMemoryArea; ULONG i; NTSTATUS Status; PULONG CurrentEntry; + DPRINT("ZwWriteVirtualMemory(ProcessHandle %x, BaseAddress %x, " + "Buffer %x, NumberOfBytesToWrite %d)\n",ProcessHandle,BaseAddress, + Buffer,NumberOfBytesToWrite); + Status = ObReferenceObjectByHandle(ProcessHandle, PROCESS_VM_WRITE, NULL, @@ -729,26 +740,52 @@ NTSTATUS STDCALL ZwWriteVirtualMemory(IN HANDLE ProcessHandle, return(Status); } - MemoryArea = MmOpenMemoryAreaByAddress(Process,BaseAddress); - - if (MemoryArea == NULL) + OutMemoryArea = MmOpenMemoryAreaByAddress(Process,BaseAddress); + if (OutMemoryArea == NULL) { return(STATUS_UNSUCCESSFUL); } - if (MemoryArea->Length > NumberOfBytesToWrite) - { - NumberOfBytesToWrite = MemoryArea->Length; - } - + *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)); - RtlCopyMemory((PVOID)physical_to_linear(PAGE_MASK(*CurrentEntry)), + if (!MmIsPagePresent(Process, BaseAddress + (i*PAGESIZE))) + { + 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), 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); } diff --git a/reactos/ntoskrnl/nt/ntevent.c b/reactos/ntoskrnl/nt/ntevent.c index 7bb4bc9128f..6550fba7047 100644 --- a/reactos/ntoskrnl/nt/ntevent.c +++ b/reactos/ntoskrnl/nt/ntevent.c @@ -136,10 +136,12 @@ NTSTATUS STDCALL ZwOpenEvent(OUT PHANDLE EventHandle, return(Status); } - *EventHandle = ObInsertHandle(KeGetCurrentProcess(), - Event, - DesiredAccess, - FALSE); + Status = ObCreateHandle(PsGetCurrentProcess(), + Event, + DesiredAccess, + FALSE, + EventHandle); + ObDereferenceObject(Event); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/ob/dirobj.c b/reactos/ntoskrnl/ob/dirobj.c index 09c1fd973fe..cc6bd8e1ede 100644 --- a/reactos/ntoskrnl/ob/dirobj.c +++ b/reactos/ntoskrnl/ob/dirobj.c @@ -63,8 +63,11 @@ NTSTATUS ZwOpenDirectoryObject(PHANDLE DirectoryHandle, return(Status); } - *DirectoryHandle = ObInsertHandle(KeGetCurrentProcess(),Object, - DesiredAccess,FALSE); + Status = ObCreateHandle(PsGetCurrentProcess(), + Object, + DesiredAccess, + FALSE, + DirectoryHandle); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/ob/handle.c b/reactos/ntoskrnl/ob/handle.c index aea54358d2e..15d6ad9ed10 100644 --- a/reactos/ntoskrnl/ob/handle.c +++ b/reactos/ntoskrnl/ob/handle.c @@ -100,15 +100,19 @@ NTSTATUS STDCALL ZwDuplicateObject(IN HANDLE SourceProcessHandle, (PVOID*)&TargetProcess, NULL); - SourceHandleRep = ObTranslateHandle(&SourceProcess->Pcb,*SourceHandle); + SourceHandleRep = ObpGetObjectByHandle(SourceProcess, + *SourceHandle); if (Options & DUPLICATE_SAME_ACCESS) { DesiredAccess = SourceHandleRep->GrantedAccess; } - *TargetHandle = ObInsertHandle(&TargetProcess,SourceHandleRep->ObjectBody, - DesiredAccess,InheritHandle); + ObCreateHandle(TargetProcess, + SourceHandleRep->ObjectBody, + DesiredAccess, + InheritHandle, + TargetHandle); if (Options & DUPLICATE_CLOSE_SOURCE) { @@ -118,59 +122,65 @@ NTSTATUS STDCALL ZwDuplicateObject(IN HANDLE SourceProcessHandle, return(STATUS_SUCCESS); } -VOID ObDestroyHandleTable(PKPROCESS Process) +VOID ObDeleteHandleTable(PEPROCESS Process) /* - * FUNCTION: Destroys the current process's handle table - * NOTE: No references to handles in the table should be made during this - * operation + * FUNCTION: Deletes the handle table associated with a process */ { - PLIST_ENTRY current=NULL; - unsigned int i; + PLIST_ENTRY current = NULL; + ULONG i; + PHANDLE_TABLE HandleTable = NULL; - current = ExInterlockedRemoveHeadList(&(Process->HandleTable.ListHead), - &(Process->HandleTable.ListLock)); + HandleTable = &Process->Pcb.HandleTable; + current = RemoveHeadList(&HandleTable->ListHead); 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 */ for (i=0;ihandles[i].ObjectBody); + if (HandleBlock->handles[i].ObjectBody != NULL) + { + ObDereferenceObject(HandleBlock->handles[i].ObjectBody); + } } - /* - * Free the block - */ - ExFreePool(blk); + ExFreePool(HandleBlock); - current = ExInterlockedRemoveHeadList(&(Process->HandleTable.ListHead), - &(Process->HandleTable.ListLock)); + current = RemoveHeadList(&HandleTable->ListHead); } } -VOID ObInitializeHandleTable(PKPROCESS Parent, BOOLEAN Inherit, - PKPROCESS Process) +VOID ObCreateHandleTable(PEPROCESS Parent, + BOOLEAN Inherit, + PEPROCESS Process) /* - * FUNCTION: Initializes a handle table + * FUNCTION: Creates a handle table for a process * ARGUMENTS: - * parent = Parent process (or NULL if this is the first process) - * Inherit = True if the process should inherit its parents objects - * Process = Process whose handle table is to be initialized + * Parent = Parent process (or NULL if this is the first process) + * Inherit = True if the process should inherit its parent's handles + * 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); - InitializeListHead(&(Process->HandleTable.ListHead)); - KeInitializeSpinLock(&(Process->HandleTable.ListLock)); + InitializeListHead(&(Process->Pcb.HandleTable.ListHead)); + 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 * ARGUMENTS: @@ -186,15 +196,15 @@ PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h) HANDLE_BLOCK* blk = NULL; 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); for (i=0;iFlink; - if (current==(&(Process->HandleTable.ListHead))) + if (current==(&(Process->Pcb.HandleTable.ListHead))) { return(NULL); } @@ -210,15 +220,16 @@ VOID ObDeleteHandle(HANDLE Handle) DPRINT("ObDeleteHandle(Handle %x)\n",Handle); - Rep = ObTranslateHandle(KeGetCurrentProcess(),Handle); + Rep = ObpGetObjectByHandle(PsGetCurrentProcess(),Handle); Rep->ObjectBody=NULL; DPRINT("Finished ObDeleteHandle()\n"); } -HANDLE ObInsertHandle(PKPROCESS Process, - PVOID ObjectBody, - ACCESS_MASK GrantedAccess, - BOOLEAN Inherit) +NTSTATUS ObCreateHandle(PEPROCESS Process, + PVOID ObjectBody, + ACCESS_MASK GrantedAccess, + BOOLEAN Inherit, + PHANDLE HandleReturn) /* * FUNCTION: Add a handle referencing an object * ARGUMENTS: @@ -231,16 +242,21 @@ HANDLE ObInsertHandle(PKPROCESS Process, unsigned int handle=1; unsigned int i; HANDLE_BLOCK* new_blk = NULL; + PHANDLE_TABLE HandleTable; + KIRQL oldlvl; 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 * slot */ - while (current!=(&(Process->HandleTable.ListHead))) + while (current != (&HandleTable->ListHead)) { 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].GrantedAccess = GrantedAccess; 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)); memset(new_blk,0,sizeof(HANDLE_BLOCK)); - ExInterlockedInsertTailList(&(Process->HandleTable.ListHead), - &new_blk->entry, - &(Process->HandleTable.ListLock)); + InsertTailList(&(Process->Pcb.HandleTable.ListHead), + &new_blk->entry); + KeReleaseSpinLock(&HandleTable->ListLock, oldlvl); new_blk->handles[0].ObjectBody = ObjectBody; new_blk->handles[0].GrantedAccess = GrantedAccess; 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); +} diff --git a/reactos/ntoskrnl/ob/ntobj.c b/reactos/ntoskrnl/ob/ntobj.c index 3db3fbb52b1..31651f5681f 100644 --- a/reactos/ntoskrnl/ob/ntobj.c +++ b/reactos/ntoskrnl/ob/ntobj.c @@ -104,45 +104,3 @@ NTSTATUS NtClose(HANDLE 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); -} diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index c3abfcad27a..d0a32783764 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -33,10 +33,11 @@ VOID ObInitializeObject(POBJECT_HEADER ObjectHeader, RtlInitUnicodeString(&(ObjectHeader->Name),NULL); if (Handle != NULL) { - *Handle = ObInsertHandle(KeGetCurrentProcess(), - HEADER_TO_BODY(ObjectHeader), - DesiredAccess, - FALSE); + ObCreateHandle(PsGetCurrentProcess(), + HEADER_TO_BODY(ObjectHeader), + DesiredAccess, + FALSE, + Handle); } } @@ -241,69 +242,3 @@ VOID ObDereferenceObject(PVOID ObjectBody) Header->RefCount--; 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); -} diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index bad5ee8dac9..187877eb7a4 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -23,6 +23,9 @@ extern ULONG PiNrThreads; /* FUNCTIONS *****************************************************************/ VOID PsTerminateCurrentThread(NTSTATUS ExitStatus) +/* + * FUNCTION: Terminates the current thread + */ { KIRQL oldlvl; PETHREAD CurrentThread; @@ -42,6 +45,9 @@ VOID PsTerminateCurrentThread(NTSTATUS ExitStatus) } VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus) +/* + * FUNCTION: Terminate a thread when calling from that thread's context + */ { UNIMPLEMENTED; } @@ -117,6 +123,7 @@ NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle, { PsTerminateOtherThread(Thread, ExitStatus); } + return(STATUS_SUCCESS); } VOID PsReleaseThread(PETHREAD Thread) @@ -144,6 +151,7 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) */ { PsTerminateCurrentThread(ExitStatus); + return(STATUS_SUCCESS); } NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 3b6ee2f67c3..a8e6b7d508c 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -3,7 +3,7 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/ps/process.c * PURPOSE: Process managment - * PROGRAMMER: David Welch (welch@mcmail.com) + * PROGRAMMER: David Welch (welch@cwcom.net) * REVISION HISTORY: * 21/07/98: Created */ @@ -27,6 +27,11 @@ POBJECT_TYPE PsProcessType = NULL; /* FUNCTIONS *****************************************************************/ +PEPROCESS PsGetSystemProcess(VOID) +{ + return(SystemProcess); +} + VOID PsInitProcessManagment(VOID) { ANSI_STRING AnsiString; @@ -64,11 +69,14 @@ VOID PsInitProcessManagment(VOID) KProcess = &SystemProcess->Pcb; InitializeListHead(&(KProcess->MemoryAreaList)); - ObInitializeHandleTable(NULL,FALSE,KProcess); + ObCreateHandleTable(NULL,FALSE,SystemProcess); KProcess->PageTableDirectory = get_page_directory(); - SystemProcessHandle = ObInsertHandle(KProcess,SystemProcess, - PROCESS_ALL_ACCESS,FALSE); + ObCreateHandle(SystemProcess, + SystemProcess, + PROCESS_ALL_ACCESS, + FALSE, + &SystemProcessHandle); } PKPROCESS KeGetCurrentProcess(VOID) @@ -84,8 +92,8 @@ struct _EPROCESS* PsGetCurrentProcess(VOID) * FUNCTION: Returns a pointer to the current process */ { - if (PsGetCurrentThread()==NULL - || PsGetCurrentThread()->ThreadsProcess==NULL) + if (PsGetCurrentThread() == NULL || + PsGetCurrentThread()->ThreadsProcess == NULL) { return(SystemProcess); } @@ -163,7 +171,7 @@ NTSTATUS STDCALL ZwCreateProcess( PROCESS_CREATE_PROCESS, PsProcessType, UserMode, - &ParentProcessHandle, + (PVOID*)&ParentProcess, NULL); if (Status != STATUS_SUCCESS) @@ -183,7 +191,9 @@ NTSTATUS STDCALL ZwCreateProcess( KProcess = &(Process->Pcb); InitializeListHead(&(KProcess->MemoryAreaList)); - ObInitializeHandleTable(KProcess,InheritObjectTable,KProcess); + ObCreateHandleTable(ParentProcess, + InheritObjectTable, + Process); PageDirectory = physical_to_linear((ULONG)get_free_page()); KProcess->PageTableDirectory = PageDirectory; @@ -308,5 +318,45 @@ NTSTATUS STDCALL ZwSetInformationProcess(IN HANDLE ProcessHandle, IN PVOID ProcessInformation, 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); } diff --git a/reactos/ntoskrnl/rtl/mem.c b/reactos/ntoskrnl/rtl/mem.c index 23c312154ee..26d9aa715e7 100644 --- a/reactos/ntoskrnl/rtl/mem.c +++ b/reactos/ntoskrnl/rtl/mem.c @@ -11,9 +11,9 @@ /* INCLUDES *****************************************************************/ #include - #include +#define NDEBUG #include /* FUNCTIONS *****************************************************************/ @@ -49,7 +49,10 @@ VOID RtlCopyBytes(PVOID Destination, VOID RtlCopyMemory(VOID* Destination, VOID* Source, ULONG Length) { + DPRINT("RtlCopyMemory(Destination %x Source %x Length %d\n", + Destination,Source,Length); memcpy(Destination,Source,Length); + DPRINT("*Destination %x\n",*(PULONG)Destination); } VOID RtlFillMemory(PVOID Destination, ULONG Length, UCHAR Fill) diff --git a/reactos/ntoskrnl/tst/test.c b/reactos/ntoskrnl/tst/test.c index d430bcc66ee..a4a3550ee3f 100644 --- a/reactos/ntoskrnl/tst/test.c +++ b/reactos/ntoskrnl/tst/test.c @@ -42,6 +42,7 @@ VOID ExExecuteShell(VOID) ULONG Size, StackSize; CONTEXT Context; NTSTATUS Status; + ULONG Temp,BytesWritten; ZwCreateProcess(&ShellHandle, PROCESS_ALL_ACCESS, @@ -87,7 +88,7 @@ VOID ExExecuteShell(VOID) memset(&Context,0,sizeof(CONTEXT)); Context.SegSs = USER_DS; - Context.Esp = 0x2000; + Context.Esp = 0xf000 - 12; Context.EFlags = 0x202; Context.SegCs = USER_CS; Context.Eip = 0x10000; @@ -97,14 +98,20 @@ VOID ExExecuteShell(VOID) Context.SegGs = USER_DS; BaseAddress = 0x1000; - StackSize = 0x1000; + StackSize = 0xe000; ZwAllocateVirtualMemory(ShellHandle, &BaseAddress, 0, &StackSize, MEM_COMMIT, PAGE_READWRITE); - + + Temp = 0xf000 - 4; + ZwWriteVirtualMemory(ShellHandle, + 0xf000 - 8, + &Temp, + sizeof(Temp), + &BytesWritten); ZwCreateThread(&ThreadHandle, THREAD_ALL_ACCESS,