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();
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)

View file

@ -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);

View file

@ -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,

View file

@ -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;

View file

@ -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 */

View file

@ -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;
}
}

View file

@ -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
}

View file

@ -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;

View file

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

View file

@ -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);
}

View file

@ -2,7 +2,8 @@
#include <ddk/ntddk.h>
#include <stdarg.h>
VOID KERNEL32_Init(VOID)
VOID KERNEL32_Init(PWSTR Args)
{
InitializePeb(Args);
__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
PROCESS_OBJECTS = process/proc.o
PROCESS_OBJECTS = process/proc.o process/cmdline.o
STRING_OBJECTS = string/lstring.o

View file

@ -35,6 +35,7 @@
#include <ddk/ntddk.h>
#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 )

View file

@ -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");

View file

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

View file

@ -18,14 +18,15 @@
#include <string.h>
#include <ddk/rtl.h>
#include <ddk/li.h>
#include <internal/i386/segment.h>
#define NDEBUG
#include <kernel32/kernel32.h>
/* 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;

View file

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

View file

@ -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

View file

@ -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
*/

View file

@ -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
*/

View file

@ -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]);
}

View file

@ -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);

View file

@ -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
*/

View file

@ -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;

View file

@ -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));
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);
for (i=PAGE_ROUND_UP(KERNEL_BASE+kernel_len);
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;
CHECKPOINT;
/*

View file

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

View file

@ -149,7 +149,11 @@ NTSTATUS STDCALL ZwCreateSection(OUT PHANDLE SectionHandle,
DesiredAccess,
ObjectAttributes,
MmSectionType);
if (Section == NULL)
{
return(STATUS_UNSUCCESSFUL);
}
if (MaximumSize != NULL)
{
Section->MaximumSize = *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,

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;i<HANDLE_BLOCK_ENTRIES;i++)
{
ObDereferenceObject(blk->handles[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;i<count;i++)
{
current = current->Flink;
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);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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)

View file

@ -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);
}

View file

@ -11,9 +11,9 @@
/* INCLUDES *****************************************************************/
#include <internal/string.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* 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)

View file

@ -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,