From 36902d624f4d65d08ade076cac3435bc498c0149 Mon Sep 17 00:00:00 2001 From: David Welch Date: Mon, 4 Jan 1999 23:01:18 +0000 Subject: [PATCH] Created bugs in wait and timer code svn path=/trunk/; revision=152 --- reactos/apps/tests/hello/hello.c | 2 +- reactos/apps/utils/shell/shell.c | 7 +- reactos/drivers/dd/keyboard/keyboard.c | 9 +- reactos/drivers/fs/vfat/blockdev.c | 342 ++++++------ reactos/drivers/fs/vfat/iface.c | 13 +- reactos/include/ddk/pstypes.h | 545 +++++++++---------- reactos/include/internal/ps.h | 115 ++-- reactos/include/kernel32/kernel32.h | 6 + reactos/include/wstring.h | 103 ++-- reactos/lib/crtdll/crtdll.def | 715 +++++++++++++++++++++++++ reactos/lib/crtdll/makefile | 2 +- reactos/lib/kernel32/file/create.c | 23 +- reactos/lib/kernel32/file/curdir.c | 18 +- reactos/lib/kernel32/file/find.c | 17 +- reactos/lib/kernel32/mem/heap.c | 67 +-- reactos/lib/kernel32/mem/utils.c | 4 +- reactos/lib/kernel32/process/proc.c | 16 +- reactos/lib/kernel32/synch/wait.c | 50 +- reactos/ntoskrnl/hal/x86/exp.c | 12 +- reactos/ntoskrnl/hal/x86/irqhand.asm | 15 + reactos/ntoskrnl/io/create.c | 20 +- reactos/ntoskrnl/io/rw.c | 6 +- reactos/ntoskrnl/io/timer.c | 3 +- reactos/ntoskrnl/ke/dispatch.c | 5 +- reactos/ntoskrnl/ke/dpc.c | 4 +- reactos/ntoskrnl/ke/timer.c | 40 +- reactos/ntoskrnl/ke/wait.c | 5 + reactos/ntoskrnl/mm/npool.c | 18 +- reactos/ntoskrnl/ob/object.c | 8 +- reactos/ntoskrnl/ps/idle.c | 3 +- reactos/ntoskrnl/ps/kill.c | 244 +++++---- reactos/ntoskrnl/ps/process.c | 47 +- reactos/ntoskrnl/ps/thread.c | 35 +- reactos/ntoskrnl/rtl/wstring.c | 13 +- 34 files changed, 1708 insertions(+), 824 deletions(-) create mode 100644 reactos/lib/crtdll/crtdll.def diff --git a/reactos/apps/tests/hello/hello.c b/reactos/apps/tests/hello/hello.c index ec06d8c0b78..ccdd76542d7 100644 --- a/reactos/apps/tests/hello/hello.c +++ b/reactos/apps/tests/hello/hello.c @@ -6,5 +6,5 @@ void main() { NtDisplayString("Hello world\n"); - ExitThread(0); + ExitProcess(0); } diff --git a/reactos/apps/utils/shell/shell.c b/reactos/apps/utils/shell/shell.c index 8a8c4c99e79..6b7fee632c8 100644 --- a/reactos/apps/utils/shell/shell.c +++ b/reactos/apps/utils/shell/shell.c @@ -142,7 +142,7 @@ void ExecuteCommand(char* line) } cmd = line; - debug_printf("cmd '%s' tail '%s'\n",cmd,tail); +// debug_printf("cmd '%s' tail '%s'\n",cmd,tail); if (cmd==NULL) { @@ -194,6 +194,11 @@ void ReadLine(char* line) line++; } } while (!(KeyEvent.bKeyDown && KeyEvent.AsciiChar == '\n')); + ReadFile(KeyboardHandle, + &KeyEvent, + sizeof(KEY_EVENT_RECORD), + &Result, + NULL); line--; *line = 0; } diff --git a/reactos/drivers/dd/keyboard/keyboard.c b/reactos/drivers/dd/keyboard/keyboard.c index 1404429c25b..b2654d505d3 100644 --- a/reactos/drivers/dd/keyboard/keyboard.c +++ b/reactos/drivers/dd/keyboard/keyboard.c @@ -418,7 +418,7 @@ static VOID KbdDpcRoutine(PKDPC Dpc, CHECKPOINT; DPRINT("KbdDpcRoutine(DeviceObject %x, Irp %x)\n", - DeviceObject,Irp); + DeviceObject,Irp); Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp,IO_NO_INCREMENT); @@ -479,7 +479,12 @@ static unsigned int KeyboardHandler(unsigned int irq) ProcessScanCode(thisKey,isDown); - DPRINT("Key: '%c'\n",VirtualToAscii(ScanToVirtual(thisKey),isDown)); +// DbgPrint("Key: %c\n",VirtualToAscii(ScanToVirtual(thisKey),isDown)); +// DbgPrint("Key: %x\n",ScanToVirtual(thisKey)); + if (ScanToVirtual(thisKey)==0x2a) + { + KeBugCheck(0); + } if (CurrentIrp!=NULL) { diff --git a/reactos/drivers/fs/vfat/blockdev.c b/reactos/drivers/fs/vfat/blockdev.c index 8e3019b56ae..6cd951f65d8 100644 --- a/reactos/drivers/fs/vfat/blockdev.c +++ b/reactos/drivers/fs/vfat/blockdev.c @@ -1,171 +1,171 @@ - - -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: services/fs/vfat/blockdev.c - * PURPOSE: Temporary sector reading support - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - */ - -/* INCLUDES *****************************************************************/ - -#include -#include -#include - -#define NDEBUG -#include - -#include "vfat.h" -//#include "dbgpool.c" -/* FUNCTIONS ***************************************************************/ - -BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, - IN ULONG DiskSector, - IN ULONG SectorCount, - IN UCHAR* Buffer) -{ - LARGE_INTEGER sectorNumber; - PIRP irp; - IO_STATUS_BLOCK ioStatus; - KEVENT event; - NTSTATUS status; - ULONG sectorSize; - PULONG mbr; - - DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d,count %d, Buffer %x)\n", - pDeviceObject,DiskSector,SectorCount,Buffer); - - SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9); - SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23); - - KeInitializeEvent(&event, NotificationEvent, FALSE); - - sectorSize = BLOCKSIZE*SectorCount; - -DPRINT("SectorCount=%d,sectorSize=%d,BLOCKSIZE=%d\n",SectorCount,sectorSize,BLOCKSIZE); - mbr = ExAllocatePool(NonPagedPool, sectorSize); - if (!mbr) { - return FALSE; - } - - irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, - pDeviceObject, - mbr, - sectorSize, - §orNumber, - &event, - &ioStatus ); - - if (!irp) { - DbgPrint("READ failed!!!\n"); - ExFreePool(mbr); - return FALSE; - } - - status = IoCallDriver(pDeviceObject, - irp); - - if (status == STATUS_PENDING) { - KeWaitForSingleObject(&event, - Suspended, - KernelMode, - FALSE, - NULL); - status = ioStatus.Status; - } - - if (!NT_SUCCESS(status)) { - DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status); - DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n", - pDeviceObject, - DiskSector, - Buffer, - GET_LARGE_INTEGER_HIGH_PART(sectorNumber), - GET_LARGE_INTEGER_LOW_PART(sectorNumber)); - ExFreePool(mbr); - return FALSE; - } - - RtlCopyMemory(Buffer,mbr,sectorSize); - - ExFreePool(mbr); - return TRUE; -} - -BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject, - IN ULONG DiskSector, - IN ULONG SectorCount, - IN UCHAR* Buffer) -{ - LARGE_INTEGER sectorNumber; - PIRP irp; - IO_STATUS_BLOCK ioStatus; - KEVENT event; - NTSTATUS status; - ULONG sectorSize; - PULONG mbr; - - DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, count %d, Buffer %x)\n", - pDeviceObject,DiskSector,SectorCount,Buffer); - SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9); - SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23); - - KeInitializeEvent(&event, NotificationEvent, FALSE); - - sectorSize = BLOCKSIZE*SectorCount; - - mbr = ExAllocatePool(NonPagedPool, sectorSize); - - if (!mbr) { - return FALSE; - } - memcpy(mbr,Buffer,sectorSize); - - DPRINT("Building synchronous FSD Request...\n"); - irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE, - pDeviceObject, - mbr, - sectorSize, - §orNumber, - &event, - &ioStatus ); - - if (!irp) { - DbgPrint("WRITE failed!!!\n"); - ExFreePool(mbr); - return FALSE; - } - - DPRINT("Calling IO Driver...\n"); - status = IoCallDriver(pDeviceObject, - irp); - - DPRINT("Waiting for IO Operation...\n"); - if (status == STATUS_PENDING) { - KeWaitForSingleObject(&event, - Suspended, - KernelMode, - FALSE, - NULL); - DPRINT("Getting IO Status...\n"); - status = ioStatus.Status; - } - - if (!NT_SUCCESS(status)) { - DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status); - ExFreePool(mbr); - return FALSE; - } - - DPRINT("Copying memory...\n"); - RtlCopyMemory(Buffer,mbr,sectorSize); - - ExFreePool(mbr); - DPRINT("Block request succeeded\n"); - return TRUE; -} - - +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: services/fs/vfat/blockdev.c + * PURPOSE: Temporary sector reading support + * PROGRAMMER: David Welch (welch@mcmail.com) + * UPDATE HISTORY: + */ + +/* INCLUDES *****************************************************************/ + +#include +#include +#include + +#define NDEBUG +#include + +#include "vfat.h" + +/* FUNCTIONS ***************************************************************/ + +BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, + IN ULONG DiskSector, + IN ULONG SectorCount, + IN UCHAR* Buffer) +{ + LARGE_INTEGER sectorNumber; + PIRP irp; + IO_STATUS_BLOCK ioStatus; + KEVENT event; + NTSTATUS status; + ULONG sectorSize; + + SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9); + SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23); + KeInitializeEvent(&event, NotificationEvent, FALSE); + sectorSize = BLOCKSIZE * SectorCount; + + /* FIXME: this routine does not need to alloc mem and copy */ + + + DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n", + pDeviceObject, + DiskSector, + Buffer); + DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n", + (unsigned long int)GET_LARGE_INTEGER_HIGH_PART(sectorNumber), + (unsigned long int)GET_LARGE_INTEGER_LOW_PART(sectorNumber), + sectorSize); + + + DPRINT("Building synchronous FSD Request...\n"); + irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, + pDeviceObject, + Buffer, + sectorSize, + §orNumber, + &event, + &ioStatus ); + + if (!irp) { + DbgPrint("READ failed!!!\n"); + return FALSE; + } + + DPRINT("Calling IO Driver...\n"); + status = IoCallDriver(pDeviceObject, + irp); + + DPRINT("Waiting for IO Operation...\n"); + if (status == STATUS_PENDING) { + KeWaitForSingleObject(&event, + Suspended, + KernelMode, + FALSE, + NULL); + DPRINT("Getting IO Status...\n"); + status = ioStatus.Status; + } + + if (!NT_SUCCESS(status)) { + DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status); + DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n", + pDeviceObject, + DiskSector, + Buffer, + GET_LARGE_INTEGER_HIGH_PART(sectorNumber), + GET_LARGE_INTEGER_LOW_PART(sectorNumber)); + return FALSE; + } + + DPRINT("Copying memory...\n"); + DPRINT("Block request succeeded\n"); + return TRUE; +} + +BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject, + IN ULONG DiskSector, + IN ULONG SectorCount, + IN UCHAR* Buffer) +{ + LARGE_INTEGER sectorNumber; + PIRP irp; + IO_STATUS_BLOCK ioStatus; + KEVENT event; + NTSTATUS status; + ULONG sectorSize; + PULONG mbr; + + DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n", + pDeviceObject,DiskSector,Buffer); + + SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9); + SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23); + + KeInitializeEvent(&event, NotificationEvent, FALSE); + + sectorSize = BLOCKSIZE*SectorCount; + + mbr = ExAllocatePool(NonPagedPool, sectorSize); + + if (!mbr) { + return FALSE; + } + + + DPRINT("Building synchronous FSD Request...\n"); + irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE, + pDeviceObject, + mbr, + sectorSize, + §orNumber, + &event, + &ioStatus ); + + if (!irp) { + DbgPrint("WRITE failed!!!\n"); + ExFreePool(mbr); + return FALSE; + } + + DPRINT("Calling IO Driver...\n"); + status = IoCallDriver(pDeviceObject, + irp); + + DPRINT("Waiting for IO Operation...\n"); + if (status == STATUS_PENDING) { + KeWaitForSingleObject(&event, + Suspended, + KernelMode, + FALSE, + NULL); + DPRINT("Getting IO Status...\n"); + status = ioStatus.Status; + } + + if (!NT_SUCCESS(status)) { + DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status); + ExFreePool(mbr); + return FALSE; + } + + DPRINT("Copying memory...\n"); + RtlCopyMemory(Buffer,mbr,sectorSize); + + ExFreePool(mbr); + DPRINT("Block request succeeded\n"); + return TRUE; +} + diff --git a/reactos/drivers/fs/vfat/iface.c b/reactos/drivers/fs/vfat/iface.c index 7b7bec766e0..7cd05a9c112 100644 --- a/reactos/drivers/fs/vfat/iface.c +++ b/reactos/drivers/fs/vfat/iface.c @@ -73,7 +73,7 @@ ULONG Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster) Block=(PUSHORT)DeviceExt->FAT; CurrentCluster = Block[CurrentCluster]; if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff) - CurrentCluster = 0xffffffff; + CurrentCluster = 0xffffffff; DPRINT("Returning %x\n",CurrentCluster); return(CurrentCluster); } @@ -821,7 +821,14 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL); if (Status != STATUS_SUCCESS) { - /* FIXME: should the VfatFCB be freed here? */ + if (Fcb != NULL) + { + ExFreePool(Fcb); + } + if (ParentFcb != NULL) + { + ExFreePool(ParentFcb); + } return(Status); } Temp = Fcb; @@ -863,7 +870,7 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount) */ { BootSector* Boot; - + Boot = ExAllocatePool(NonPagedPool,512); VFATReadSectors(DeviceToMount, 0, 1, (UCHAR *)Boot); diff --git a/reactos/include/ddk/pstypes.h b/reactos/include/ddk/pstypes.h index 0dc179b92f8..5f5610168a9 100644 --- a/reactos/include/ddk/pstypes.h +++ b/reactos/include/ddk/pstypes.h @@ -1,271 +1,274 @@ -#ifndef __INCLUDE_DDK_PSTYPES_H -#define __INCLUDE_DDK_PSTYPES_H - -#undef WIN32_LEAN_AND_MEAN -#include // might be redundant -#include -#include -#include - -#ifndef TLS_MINIMUM_AVAILABLE - #define TLS_MINIMUM_AVAILABLE (64) -#endif -#ifndef MAX_PATH - #define MAX_PATH (260) -#endif - -typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext); - -typedef struct _STACK_INFORMATION -{ - PVOID BaseAddress; - PVOID UpperAddress; -} STACK_INFORMATION, *PSTACK_INFORMATION; - -typedef struct linux_sigcontext { - int sc_gs; - int sc_fs; - int sc_es; - int sc_ds; - int sc_edi; - int sc_esi; - int sc_ebp; - int sc_esp; - int sc_ebx; - int sc_edx; - int sc_ecx; - int sc_eax; - int sc_trapno; - int sc_err; - int sc_eip; - int sc_cs; - int sc_eflags; - int sc_esp_at_signal; - int sc_ss; - int sc_387; - int sc_mask; - int sc_cr2; -} TRAP_FRAME, *PTRAP_FRAME; - -typedef ULONG THREADINFOCLASS; - -typedef struct _STARTUPINFOW { - DWORD cb; - WCHAR WindowTitle[MAX_PATH]; - WCHAR ImageFile[MAX_PATH]; - WCHAR CommandLine[MAX_PATH]; - WCHAR DllPath[MAX_PATH]; - LPWSTR Reserved[MAX_PATH]; - LPWSTR Desktop[MAX_PATH]; - LPWSTR Title[MAX_PATH]; - DWORD dwX; - DWORD dwY; - DWORD dwXSize; - DWORD dwYSize; - DWORD dwXCountChars; - DWORD dwYCountChars; - DWORD dwFillAttribute; - DWORD dwFlags; - WORD wShowWindow; - WORD cbReserved2; - unsigned char * lpReserved2; - HANDLE hStdInput; - HANDLE hStdOutput; - HANDLE hStdError; -} PROCESSINFOW, *PPROCESSINFOW; - - - -typedef struct _LDR { - UCHAR Initialized; - UCHAR InInitializationOrderModuleList; - PVOID InLoadOrderModuleList; - PVOID InMemoryOrderModuleList; -} LDR, *PLDR; - - -typedef struct _NT_PEB -{ - UCHAR InheritedAddressSpace; - UCHAR ReadImageFileExecOptions; - UCHAR BeingDebugged; - LONG ImageBaseAddress; - LDR Ldr; - - WORD NumberOfProcessors; - WORD NtGlobalFlag; - - PPROCESSINFOW StartupInfo; - PHEAP ProcessHeap; - ATOMTABLE LocalAtomTable; - LPCRITICAL_SECTION CriticalSection; - DWORD CriticalSectionTimeout; - WORD MajorVersion; - WORD MinorVersion; - WORD BuildNumber; - WORD PlatformId; -} NT_PEB, *PNT_PEB; - -typedef struct _CLIENT_ID -{ - HANDLE UniqueProcess; - HANDLE UniqueThread; -} CLIENT_ID, *PCLIENT_ID; - -typedef struct _NT_TIB { - struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; - PVOID StackBase; - PVOID StackLimit; - PVOID SubSystemTib; - union { - PVOID FiberData; - ULONG Version; - } Fib; - PVOID ArbitraryUserPointer; - struct _NT_TIB *Self; -} NT_TIB, *PNT_TIB; - -typedef struct _NT_TEB -{ - - NT_TIB Tib; - CLIENT_ID Cid; - HANDLE RPCHandle; - PVOID TlsData[TLS_MINIMUM_AVAILABLE]; - DWORD dwTlsIndex; - NT_PEB *Peb; - DWORD LastErrorCode; - NTSTATUS LastStatusValue; - DWORD LockCount; - UCHAR HardErrorMode; - -} NT_TEB; - -typedef struct _KTHREAD -{ - DISPATCHER_HEADER DispatcherHeader; - TIME ElapsedTime; - TIME KernelTime; - TIME UserTime; - STACK_INFORMATION StackInformation; - PVOID ServiceDescriptorTable; // points to KeServiceDescriptorTable - KAFFINITY Affinity; - KPRIORITY CurrentPriority; - KPRIORITY BasePriority; - ULONG Quantum; - UCHAR ThreadState; //Thread state is a typeless enum, otherwise it should be const integer - ULONG FreezeCount; - LONG SuspendCount; - PTRAP_FRAME TrapFrame; - PVOID *Tls; - KWAIT_BLOCK WaitBlock[4]; - struct _KMUTANT* MutantList; - PLIST_ENTRY ApcList; - UCHAR KernelApcDisable; - KTIMER TimerBlock; - KDEVICE_QUEUE DeviceQueue; - NT_TEB* Teb; - - /* - * PURPOSE: CPU state - * NOTE: I have temporarily added this to give somewhere to store - * cpu state when the thread isn't running - */ - hal_thread_state Context; - LIST_ENTRY Entry; - ULONG LastTick; -} KTHREAD, *PKTHREAD; - - -// According to documentation the stack should have a commited [ 1 page ] and -// a reserved part [ 1 M ] but can be specified otherwise in the image file. - -typedef struct _INITIAL_TEB { - PVOID StackBase; - PVOID StackLimit; - PVOID StackCommit; - PVOID StackCommitMax; - PVOID StackReserved; -} INITIAL_TEB, *PINITIAL_TEB; - - - - - - -// TopLevelIrp can be one of the following values: -// FIXME I belong somewhere else - -#define FSRTL_FSP_TOP_LEVEL_IRP (0x01) -#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02) -#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03) -#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04) -#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04) - -typedef struct _TOP_LEVEL_IRP -{ - PIRP TopLevelIrp; - ULONG TopLevelIrpConst; -} TOP_LEVEL_IRP; - -typedef struct _ETHREAD { - KTHREAD Tcb; - TIME CreateTime; - TIME ExitTime; - NTSTATUS ExitStatus; - LIST_ENTRY PostBlockList; - LIST_ENTRY TerminationPortList; - ULONG ActiveTimerListLock; - PVOID ActiveTimerListHead; - CLIENT_ID Cid; - PLARGE_INTEGER LpcReplySemaphore; - PVOID LpcReplyMessage; - PLARGE_INTEGER LpcReplyMessageId; - PVOID ImpersonationInfo; - LIST_ENTRY IrpList; // - TOP_LEVEL_IRP TopLevelIrp; - ULONG ReadClusterSize; - UCHAR ForwardClusterOnly; - UCHAR DisablePageFaultClustering; - UCHAR DeadThread; - UCHAR HasTerminated; - ACCESS_MASK GrantedAccess; - struct _EPROCESS* ThreadsProcess; - PKSTART_ROUTINE StartAddress; - LPTHREAD_START_ROUTINE Win32StartAddress; // Should Specify a win32 start func - UCHAR LpcExitThreadCalled; - UCHAR HardErrorsAreDisabled; -} ETHREAD, *PETHREAD; - - -typedef struct _KPROCESS -{ - DISPATCHER_HEADER DispatcherHeader; - PVOID PageTableDirectory; // FIXME: I shoud point to a PTD - TIME ElapsedTime; - TIME KernelTime; - TIME UserTime; - LIST_ENTRY InMemoryList; - LIST_ENTRY SwappedOutList; - KSPIN_LOCK SpinLock; - KAFFINITY Affinity; - ULONG StackCount; - KPRIORITY BasePriority; - ULONG DefaultThreadQuantum; - UCHAR ProcessState; - ULONG ThreadSeed; - UCHAR DisableBoost; - - /* - * Added by David Welch (welch@mcmail.com) - */ - LIST_ENTRY MemoryAreaList; - HANDLE_TABLE HandleTable; -} KPROCESS, *PKPROCESS; - -typedef struct _EPROCESS -{ - KPROCESS Pcb; -} EPROCESS, *PEPROCESS; - -#endif /* __INCLUDE_DDK_PSTYPES_H */ +#ifndef __INCLUDE_DDK_PSTYPES_H +#define __INCLUDE_DDK_PSTYPES_H + +#undef WIN32_LEAN_AND_MEAN +#include // might be redundant +#include +#include +#include + +#ifndef TLS_MINIMUM_AVAILABLE + #define TLS_MINIMUM_AVAILABLE (64) +#endif +#ifndef MAX_PATH + #define MAX_PATH (260) +#endif + +typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext); + +typedef struct _STACK_INFORMATION +{ + PVOID BaseAddress; + PVOID UpperAddress; +} STACK_INFORMATION, *PSTACK_INFORMATION; + +typedef struct linux_sigcontext { + int sc_gs; + int sc_fs; + int sc_es; + int sc_ds; + int sc_edi; + int sc_esi; + int sc_ebp; + int sc_esp; + int sc_ebx; + int sc_edx; + int sc_ecx; + int sc_eax; + int sc_trapno; + int sc_err; + int sc_eip; + int sc_cs; + int sc_eflags; + int sc_esp_at_signal; + int sc_ss; + int sc_387; + int sc_mask; + int sc_cr2; +} TRAP_FRAME, *PTRAP_FRAME; + +typedef ULONG THREADINFOCLASS; + +typedef struct _STARTUPINFOW { + DWORD cb; + WCHAR WindowTitle[MAX_PATH]; + WCHAR ImageFile[MAX_PATH]; + WCHAR CommandLine[MAX_PATH]; + WCHAR DllPath[MAX_PATH]; + LPWSTR Reserved[MAX_PATH]; + LPWSTR Desktop[MAX_PATH]; + LPWSTR Title[MAX_PATH]; + DWORD dwX; + DWORD dwY; + DWORD dwXSize; + DWORD dwYSize; + DWORD dwXCountChars; + DWORD dwYCountChars; + DWORD dwFillAttribute; + DWORD dwFlags; + WORD wShowWindow; + WORD cbReserved2; + unsigned char * lpReserved2; + HANDLE hStdInput; + HANDLE hStdOutput; + HANDLE hStdError; +} PROCESSINFOW, *PPROCESSINFOW; + + + +typedef struct _LDR { + UCHAR Initialized; + UCHAR InInitializationOrderModuleList; + PVOID InLoadOrderModuleList; + PVOID InMemoryOrderModuleList; +} LDR, *PLDR; + + +typedef struct _NT_PEB +{ + UCHAR InheritedAddressSpace; + UCHAR ReadImageFileExecOptions; + UCHAR BeingDebugged; + LONG ImageBaseAddress; + LDR Ldr; + + WORD NumberOfProcessors; + WORD NtGlobalFlag; + + PPROCESSINFOW StartupInfo; + PHEAP ProcessHeap; + ATOMTABLE LocalAtomTable; + LPCRITICAL_SECTION CriticalSection; + DWORD CriticalSectionTimeout; + WORD MajorVersion; + WORD MinorVersion; + WORD BuildNumber; + WORD PlatformId; +} NT_PEB, *PNT_PEB; + +typedef struct _CLIENT_ID +{ + HANDLE UniqueProcess; + HANDLE UniqueThread; +} CLIENT_ID, *PCLIENT_ID; + +typedef struct _NT_TIB { + struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; + PVOID StackBase; + PVOID StackLimit; + PVOID SubSystemTib; + union { + PVOID FiberData; + ULONG Version; + } Fib; + PVOID ArbitraryUserPointer; + struct _NT_TIB *Self; +} NT_TIB, *PNT_TIB; + +typedef struct _NT_TEB +{ + + NT_TIB Tib; + CLIENT_ID Cid; + HANDLE RPCHandle; + PVOID TlsData[TLS_MINIMUM_AVAILABLE]; + DWORD dwTlsIndex; + NT_PEB *Peb; + DWORD LastErrorCode; + NTSTATUS LastStatusValue; + DWORD LockCount; + UCHAR HardErrorMode; + +} NT_TEB; + +typedef struct _KTHREAD +{ + DISPATCHER_HEADER DispatcherHeader; + TIME ElapsedTime; + TIME KernelTime; + TIME UserTime; + STACK_INFORMATION StackInformation; + PVOID ServiceDescriptorTable; // points to KeServiceDescriptorTable + KAFFINITY Affinity; + KPRIORITY CurrentPriority; + KPRIORITY BasePriority; + ULONG Quantum; + UCHAR ThreadState; //Thread state is a typeless enum, otherwise it should be const integer + ULONG FreezeCount; + LONG SuspendCount; + PTRAP_FRAME TrapFrame; + PVOID *Tls; + KWAIT_BLOCK WaitBlock[4]; + struct _KMUTANT* MutantList; + PLIST_ENTRY ApcList; + UCHAR KernelApcDisable; + KTIMER TimerBlock; + KDEVICE_QUEUE DeviceQueue; + NT_TEB* Teb; + + /* + * PURPOSE: CPU state + * NOTE: I have temporarily added this to give somewhere to store + * cpu state when the thread isn't running + */ + hal_thread_state Context; + LIST_ENTRY Entry; + ULONG LastTick; +} KTHREAD, *PKTHREAD; + + +// According to documentation the stack should have a commited [ 1 page ] and +// a reserved part [ 1 M ] but can be specified otherwise in the image file. + +typedef struct _INITIAL_TEB { + PVOID StackBase; + PVOID StackLimit; + PVOID StackCommit; + PVOID StackCommitMax; + PVOID StackReserved; +} INITIAL_TEB, *PINITIAL_TEB; + + + + + + +// TopLevelIrp can be one of the following values: +// FIXME I belong somewhere else + +#define FSRTL_FSP_TOP_LEVEL_IRP (0x01) +#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02) +#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03) +#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04) +#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04) + +typedef struct _TOP_LEVEL_IRP +{ + PIRP TopLevelIrp; + ULONG TopLevelIrpConst; +} TOP_LEVEL_IRP; + +typedef struct _ETHREAD { + KTHREAD Tcb; + TIME CreateTime; + TIME ExitTime; + NTSTATUS ExitStatus; + LIST_ENTRY PostBlockList; + LIST_ENTRY TerminationPortList; + ULONG ActiveTimerListLock; + PVOID ActiveTimerListHead; + CLIENT_ID Cid; + PLARGE_INTEGER LpcReplySemaphore; + PVOID LpcReplyMessage; + PLARGE_INTEGER LpcReplyMessageId; + PVOID ImpersonationInfo; + LIST_ENTRY IrpList; // + TOP_LEVEL_IRP TopLevelIrp; + ULONG ReadClusterSize; + UCHAR ForwardClusterOnly; + UCHAR DisablePageFaultClustering; + UCHAR DeadThread; + UCHAR HasTerminated; + ACCESS_MASK GrantedAccess; + struct _EPROCESS* ThreadsProcess; + PKSTART_ROUTINE StartAddress; + LPTHREAD_START_ROUTINE Win32StartAddress; // Should Specify a win32 start func + UCHAR LpcExitThreadCalled; + UCHAR HardErrorsAreDisabled; +} ETHREAD, *PETHREAD; + + +typedef struct _KPROCESS +{ + DISPATCHER_HEADER DispatcherHeader; + PVOID PageTableDirectory; // FIXME: I shoud point to a PTD + TIME ElapsedTime; + TIME KernelTime; + TIME UserTime; + LIST_ENTRY InMemoryList; + LIST_ENTRY SwappedOutList; + KSPIN_LOCK SpinLock; + KAFFINITY Affinity; + ULONG StackCount; + KPRIORITY BasePriority; + ULONG DefaultThreadQuantum; + UCHAR ProcessState; + ULONG ThreadSeed; + UCHAR DisableBoost; + + /* + * Added by David Welch (welch@mcmail.com) + */ + LIST_ENTRY MemoryAreaList; + HANDLE_TABLE HandleTable; +} KPROCESS, *PKPROCESS; + +typedef struct _EPROCESS +{ + KPROCESS Pcb; +} EPROCESS, *PEPROCESS; + +#define PROCESS_STATE_TERMINATED (1) +#define PROCESS_STATE_ACTIVE (2) + +#endif /* __INCLUDE_DDK_PSTYPES_H */ diff --git a/reactos/include/internal/ps.h b/reactos/include/internal/ps.h index 623c2006516..c6ee283e29a 100644 --- a/reactos/include/internal/ps.h +++ b/reactos/include/internal/ps.h @@ -1,57 +1,58 @@ -#ifndef __INCLUDE_INTERNAL_PSMGR_H -#define __INCLUDE_INTERNAL_PSMGR_H - -#include - -extern PEPROCESS SystemProcess; -extern HANDLE SystemProcessHandle; - -extern POBJECT_TYPE PsThreadType; -extern POBJECT_TYPE PsProcessType; - -void PsInitThreadManagment(void); -VOID PsInitProcessManagment(VOID); -VOID PsInitIdleThread(VOID); -VOID PsDispatchThread(VOID); - -/* - * PURPOSE: Thread states - */ -enum -{ - /* - * PURPOSE: Don't touch - */ - THREAD_STATE_INVALID, - - /* - * PURPOSE: Waiting to be dispatched - */ - THREAD_STATE_RUNNABLE, - - /* - * PURPOSE: Currently running - */ - THREAD_STATE_RUNNING, - - /* - * PURPOSE: Doesn't want to run - */ - THREAD_STATE_SUSPENDED, - - /* - * Waiting to be freed - */ - THREAD_STATE_TERMINATED, -}; - -/* - * Functions the HAL must provide - */ - -void HalInitFirstTask(PETHREAD thread); -BOOLEAN HalInitTask(PETHREAD thread, PKSTART_ROUTINE fn, PVOID StartContext); -void HalTaskSwitch(PKTHREAD thread); -NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context); - -#endif +#ifndef __INCLUDE_INTERNAL_PSMGR_H +#define __INCLUDE_INTERNAL_PSMGR_H + +#include + +extern PEPROCESS SystemProcess; +extern HANDLE SystemProcessHandle; + +extern POBJECT_TYPE PsThreadType; +extern POBJECT_TYPE PsProcessType; + +void PsInitThreadManagment(void); +VOID PsInitProcessManagment(VOID); +VOID PsInitIdleThread(VOID); +VOID PsDispatchThread(VOID); +VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus); + +/* + * PURPOSE: Thread states + */ +enum +{ + /* + * PURPOSE: Don't touch + */ + THREAD_STATE_INVALID, + + /* + * PURPOSE: Waiting to be dispatched + */ + THREAD_STATE_RUNNABLE, + + /* + * PURPOSE: Currently running + */ + THREAD_STATE_RUNNING, + + /* + * PURPOSE: Doesn't want to run + */ + THREAD_STATE_SUSPENDED, + + /* + * Waiting to be freed + */ + THREAD_STATE_TERMINATED, +}; + +/* + * Functions the HAL must provide + */ + +void HalInitFirstTask(PETHREAD thread); +BOOLEAN HalInitTask(PETHREAD thread, PKSTART_ROUTINE fn, PVOID StartContext); +void HalTaskSwitch(PKTHREAD thread); +NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context); + +#endif diff --git a/reactos/include/kernel32/kernel32.h b/reactos/include/kernel32/kernel32.h index 3c8f63fda04..0d81a2e9228 100644 --- a/reactos/include/kernel32/kernel32.h +++ b/reactos/include/kernel32/kernel32.h @@ -1,5 +1,11 @@ #include +#ifdef NDEBUG +#define DPRINT(args...) +#else +#define DPRINT(args...) do { dprintf("(KERNEL32:%s:%d) ",__FILE__,__LINE__); dprintf(args); } while(0); +#endif + void dprintf(char* fmt, ...); void aprintf(char* fmt, ...); diff --git a/reactos/include/wstring.h b/reactos/include/wstring.h index a1c8524007d..91182a84963 100644 --- a/reactos/include/wstring.h +++ b/reactos/include/wstring.h @@ -1,51 +1,52 @@ -/* - * Adapted from linux for the reactos kernel, march 1998 -- David Welch - * Added wide character string functions, june 1998 -- Boudewijn Dekker - * Removed extern specifier from ___wcstok, june 1998 -- Boudewijn Dekker - * Added wcsicmp and wcsnicmp -- Boudewijn Dekker - */ - -#ifndef _LINUX_WSTRING_H_ -#define _LINUX_WSTRING_H_ - -#include /* for size_t */ - -typedef unsigned short wchar_t; - -#ifndef NULL -#define NULL ((void *) 0) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -extern wchar_t * ___wcstok; -extern wchar_t * wcscpy(wchar_t *,const wchar_t *); -extern wchar_t * wcsncpy(wchar_t *,const wchar_t *, __kernel_size_t); -extern wchar_t * wcscat(wchar_t *, const wchar_t *); -extern wchar_t * wcsncat(wchar_t *, const wchar_t *, __kernel_size_t); -extern int wcscmp(const wchar_t *,const wchar_t *); -extern int wcsncmp(const wchar_t *,const wchar_t *,__kernel_size_t); -wchar_t* wcschr(const wchar_t* str, wchar_t ch); -extern wchar_t * wcsrchr(const wchar_t *,wchar_t); -extern wchar_t * wcspbrk(const wchar_t *,const wchar_t *); -extern wchar_t * wcstok(wchar_t *,const wchar_t *); -extern wchar_t * wcsstr(const wchar_t *,const wchar_t *); -extern size_t wcsnlen(const wchar_t * s, size_t count); -extern int wcsicmp(const wchar_t* cs,const wchar_t * ct); -extern int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count); -extern size_t wcscspn(const wchar_t *, const wchar_t *); -extern size_t wcslen(const wchar_t *); -extern size_t wcsspn(const wchar_t *, const wchar_t *); - -extern unsigned long wstrlen(PWSTR); -WCHAR wtoupper(WCHAR c); -WCHAR wtolower(WCHAR c); - -#ifdef __cplusplus -} -#endif - -#endif - +/* + * Adapted from linux for the reactos kernel, march 1998 -- David Welch + * Added wide character string functions, june 1998 -- Boudewijn Dekker + * Removed extern specifier from ___wcstok, june 1998 -- Boudewijn Dekker + * Added wcsicmp and wcsnicmp -- Boudewijn Dekker + */ + +#ifndef _LINUX_WSTRING_H_ +#define _LINUX_WSTRING_H_ + +#include /* for size_t */ + +typedef unsigned short wchar_t; + +#ifndef NULL +#define NULL ((void *) 0) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +wchar_t* wstrdup(const wchar_t* src); +extern wchar_t * ___wcstok; +extern wchar_t * wcscpy(wchar_t *,const wchar_t *); +extern wchar_t * wcsncpy(wchar_t *,const wchar_t *, __kernel_size_t); +extern wchar_t * wcscat(wchar_t *, const wchar_t *); +extern wchar_t * wcsncat(wchar_t *, const wchar_t *, __kernel_size_t); +extern int wcscmp(const wchar_t *,const wchar_t *); +extern int wcsncmp(const wchar_t *,const wchar_t *,__kernel_size_t); +wchar_t* wcschr(const wchar_t* str, wchar_t ch); +extern wchar_t * wcsrchr(const wchar_t *,wchar_t); +extern wchar_t * wcspbrk(const wchar_t *,const wchar_t *); +extern wchar_t * wcstok(wchar_t *,const wchar_t *); +extern wchar_t * wcsstr(const wchar_t *,const wchar_t *); +extern size_t wcsnlen(const wchar_t * s, size_t count); +extern int wcsicmp(const wchar_t* cs,const wchar_t * ct); +extern int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count); +extern size_t wcscspn(const wchar_t *, const wchar_t *); +extern size_t wcslen(const wchar_t *); +extern size_t wcsspn(const wchar_t *, const wchar_t *); + +extern unsigned long wstrlen(PWSTR); +WCHAR wtoupper(WCHAR c); +WCHAR wtolower(WCHAR c); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/reactos/lib/crtdll/crtdll.def b/reactos/lib/crtdll/crtdll.def new file mode 100644 index 00000000000..f3d1bba61e5 --- /dev/null +++ b/reactos/lib/crtdll/crtdll.def @@ -0,0 +1,715 @@ +; +; crtdll.def +; +; Exports from crtdll.dll from Windows 95 SYSTEM directory. Hopefully this +; should also work with the crtdll provided with Windows NT. +; +; Contributors: +; Created by Colin Peters +; +; THIS SOFTWARE IS NOT COPYRIGHTED +; +; This source code is offered for use in the public domain. You may +; use, modify or distribute it freely. +; +; This code is distributed in the hope that it will be useful but +; WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY +; DISCLAMED. This includes but is not limited to warrenties of +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +; +; $Revision: 1.1 $ +; $Author: dwelch $ +; $Date: 1999/01/04 23:01:18 $ +; +; These three functions appear to be name mangled in some way, so GCC is +; probably not going to be able to use them in any case. +; +; ??2@YAPAXI@Z +; ??3@YAXPAX@Z +; ?_set_new_handler@@YAP6AHI@ZP6AHI@Z@Z +; +; These are functions for which I have not yet written prototypes or +; otherwise set up (they are still included below though unlike those +; first three). +; +; _CIacos +; _CIasin +; _CIatan +; _CIatan2 +; _CIcos +; _CIcosh +; _CIexp +; _CIfmod +; _CIlog +; _CIlog10 +; _CIpow +; _CIsin +; _CIsinh +; _CIsqrt +; _CItan +; _CItanh +; __dllonexit +; __mb_cur_max_dll +; __threadhandle +; __threadid +; _abnormal_termination +; _acmdln_dll +; _aexit_rtn_dll +; _amsg_exit +; _commit +; _commode_dll +; _cpumode_dll +; _ctype +; _daylight_dll +; _environ_dll +; _expand +; _fcloseall +; _filbuf +; _fileinfo_dll +; _flsbuf +; _flushall +; _fmode_dll +; _fpieee_flt +; _fsopen +; _ftol +; _getdiskfree +; _getdllprocaddr +; _getdrive +; _getdrives +; _getsystime +; _getw +; _initterm +; _ismbbalnum +; _ismbbalpha +; _ismbbgraph +; _ismbbkalnum +; _ismbbkana +; _ismbbkpunct +; _ismbblead +; _ismbbprint +; _ismbbpunct +; _ismbbtrail +; _ismbcalpha +; _ismbcdigit +; _ismbchira +; _ismbckata +; _ismbcl0 +; _ismbcl1 +; _ismbcl2 +; _ismbclegal +; _ismbclower +; _ismbcprint +; _ismbcspace +; _ismbcsymbol +; _ismbcupper +; _ismbslead +; _ismbstrail +; _lfind +; _loaddll +; _lrotl +; _lrotr +; _lsearch +; _makepath +; _matherr +; _mbbtombc +; _mbbtype +; _mbccpy +; _mbcjistojms +; _mbcjmstojis +; _mbclen +; _mbctohira +; _mbctokata +; _mbctolower +; _mbctombb +; _mbctoupper +; _mbctype +; _mbsbtype +; _mbscat +; _mbscmp +; _mbscpy +; _mbscspn +; _mbsdec +; _mbsdup +; _mbsicmp +; _mbsinc +; _mbslen +; _mbslwr +; _mbsnbcat +; _mbsnbcmp +; _mbsnbcnt +; _mbsnbcpy +; _mbsnbicmp +; _mbsnbset +; _mbsnccnt +; _mbsncmp +; _mbsncpy +; _mbsnextc +; _mbsnicmp +; _mbsninc +; _mbsnset +; _mbspbrk +; _mbsrchr +; _mbsrev +; _mbsset +; _mbsspn +; _mbsspnp +; _mbsstr +; _mbstrlen +; _mbsupr +; _onexit +; _osver_dll +; _osversion_dll +; _pctype_dll +; _purecall +; _putw +; _pwctype_dll +; _rmtmp +; _rotl +; _rotr +; _setsystime +; _snprintf +; _snwprintf +; _splitpath +; _strdate +; _strdec +; _strinc +; _strncnt +; _strnextc +; _strninc +; _strspnp +; _strtime +; _tempnam +; _timezone_dll +; _tzname +; _tzset +; _ultoa +; _unloaddll +; _vsnprintf +; _vsnwprintf +; _winmajor_dll +; _winminor_dll +; _winver_dll +; _wtoi +; _wtol +; +EXPORTS +_CIacos +_CIasin +_CIatan +_CIatan2 +_CIcos +_CIcosh +_CIexp +_CIfmod +_CIlog +_CIlog10 +_CIpow +_CIsin +_CIsinh +_CIsqrt +_CItan +_CItanh +_HUGE_dll +_XcptFilter +__GetMainArgs +__argc_dll +__argv_dll +__dllonexit +__doserrno +__fpecode +__isascii +__iscsym +__iscsymf +__mb_cur_max_dll +__pxcptinfoptrs +__threadhandle +__threadid +__toascii +_abnormal_termination +_access +_acmdln_dll +_aexit_rtn_dll +_amsg_exit +_assert +_basemajor_dll +_baseminor_dll +_baseversion_dll +_beep +_beginthread +_c_exit +_cabs +_cexit +_cgets +_chdir +_chdrive +_chgsign +_chmod +_chsize +_clearfp +_close +_commit +_commode_dll +_control87 +_controlfp +_copysign +_cprintf +_cpumode_dll +_cputs +_creat +_cscanf +_ctype +_cwait +_daylight_dll +_dup +_dup2 +_ecvt +_endthread +_environ_dll +_eof +_errno +_except_handler2 +_execl +_execle +_execlp +_execlpe +_execv +_execve +_execvp +_execvpe +_exit +_expand +_fcloseall +_fcvt +_fdopen +_fgetchar +_fgetwchar +_filbuf +_fileinfo_dll +_filelength +_fileno +_findclose +_findfirst +_findnext +_finite +_flsbuf +_flushall +_fmode_dll +_fpclass +_fpieee_flt +_fpreset +_fputchar +_fputwchar +_fsopen +_fstat +_ftime +_ftol +_fullpath +_futime +_gcvt +_get_osfhandle +_getch +_getche +_getcwd +_getdcwd +_getdiskfree +_getdllprocaddr +_getdrive +_getdrives +_getpid +_getsystime +_getw +_global_unwind2 +_heapchk +_heapmin +_heapset +_heapwalk +_hypot +_initterm +_iob +_isatty +_isctype +_ismbbalnum +_ismbbalpha +_ismbbgraph +_ismbbkalnum +_ismbbkana +_ismbbkpunct +_ismbblead +_ismbbprint +_ismbbpunct +_ismbbtrail +_ismbcalpha +_ismbcdigit +_ismbchira +_ismbckata +_ismbcl0 +_ismbcl1 +_ismbcl2 +_ismbclegal +_ismbclower +_ismbcprint +_ismbcspace +_ismbcsymbol +_ismbcupper +_ismbslead +_ismbstrail +_isnan +_itoa +_j0 +_j1 +_jn +_kbhit +_lfind +_loaddll +_local_unwind2 +_locking +_logb +_lrotl +_lrotr +_lsearch +_lseek +_ltoa +_makepath +_matherr +_mbbtombc +_mbbtype +_mbccpy +_mbcjistojms +_mbcjmstojis +_mbclen +_mbctohira +_mbctokata +_mbctolower +_mbctombb +_mbctoupper +_mbctype +_mbsbtype +_mbscat +_mbschr +_mbscmp +_mbscpy +_mbscspn +_mbsdec +_mbsdup +_mbsicmp +_mbsinc +_mbslen +_mbslwr +_mbsnbcat +_mbsnbcmp +_mbsnbcnt +_mbsnbcpy +_mbsnbicmp +_mbsnbset +_mbsncat +_mbsnccnt +_mbsncmp +_mbsncpy +_mbsnextc +_mbsnicmp +_mbsninc +_mbsnset +_mbspbrk +_mbsrchr +_mbsrev +_mbsset +_mbsspn +_mbsspnp +_mbsstr +_mbstok +_mbstrlen +_mbsupr +_memccpy +_memicmp +_mkdir +_mktemp +_msize +_nextafter +_onexit +_open +_open_osfhandle +_osmajor_dll +_osminor_dll +_osmode_dll +_osver_dll +_osversion_dll +_pclose +_pctype_dll +_pgmptr_dll +_pipe +_popen +_purecall +_putch +_putenv +_putw +_pwctype_dll +_read +_rmdir +_rmtmp +_rotl +_rotr +_scalb +_searchenv +_seterrormode +_setjmp +_setmode +_setsystime +_sleep +_snprintf +_snwprintf +_sopen +_spawnl +_spawnle +_spawnlp +_spawnlpe +_spawnv +_spawnve +_spawnvp +_spawnvpe +_splitpath +_stat +_statusfp +_strcmpi +_strdate +_strdec +_strdup +_strerror +_stricmp +_stricoll +_strinc +_strlwr +_strncnt +_strnextc +_strnicmp +_strninc +_strnset +_strrev +_strset +_strspnp +_strtime +_strupr +_swab +_sys_errlist +_sys_nerr_dll +_tell +_tempnam +_timezone_dll +_tolower +_toupper +_tzname +_tzset +_ultoa +_umask +_ungetch +_unlink +_unloaddll +_utime +_vsnprintf +_vsnwprintf +_wcsdup +_wcsicmp +_wcsicoll +_wcslwr +_wcsnicmp +_wcsnset +_wcsrev +_wcsset +_wcsupr +_winmajor_dll +_winminor_dll +_winver_dll +_write +_wtoi +_wtol +_y0 +_y1 +_yn +abort +abs +acos +asctime +asin +atan +atan2 +atexit +atof +atoi +atol +bsearch +calloc +ceil +clearerr +clock +cos +cosh +ctime +difftime +div +exit +exp +fabs +fclose +feof +ferror +fflush +fgetc +fgetpos +fgets +fgetwc +floor +fmod +fopen +fprintf +fputc +fputs +fputwc +fread +free +freopen +frexp +fscanf +fseek +fsetpos +ftell +fwprintf +fwrite +fwscanf +getc +getchar +getenv +gets +gmtime +is_wctype +isalnum +isalpha +iscntrl +isdigit +isgraph +isleadbyte +islower +isprint +ispunct +isspace +isupper +iswalnum +iswalpha +iswascii +iswcntrl +iswctype +iswdigit +iswgraph +iswlower +iswprint +iswpunct +iswspace +iswupper +iswxdigit +isxdigit +labs +ldexp +ldiv +localeconv +localtime +log +log10 +longjmp +malloc +mblen +mbstowcs +mbtowc +memchr +memcmp +memcpy +memmove +memset +mktime +modf +perror +pow +printf +putc +putchar +puts +qsort +raise +rand +realloc +remove +rename +rewind +scanf +setbuf +setlocale +setvbuf +signal +sin +sinh +sprintf +sqrt +srand +sscanf +strcat +strchr +strcmp +strcoll +strcpy +strcspn +strerror +strftime +strlen +strncat +strncmp +strncpy +strpbrk +strrchr +strspn +strstr +strtod +strtok +strtol +strtoul +strxfrm +swprintf +swscanf +system +tan +tanh +time +tmpfile +tmpnam +tolower +toupper +towlower +towupper +ungetc +ungetwc +vfprintf +vfwprintf +vprintf +vsprintf +vswprintf +vwprintf +wcscat +wcschr +wcscmp +wcscoll +wcscpy +wcscspn +wcsftime +wcslen +wcsncat +wcsncmp +wcsncpy +wcspbrk +wcsrchr +wcsspn +wcsstr +wcstod +wcstok +wcstol +wcstombs +wcstoul +wcsxfrm +wctomb +wprintf +wscanf diff --git a/reactos/lib/crtdll/makefile b/reactos/lib/crtdll/makefile index 83c73f4887f..8428531d3d6 100644 --- a/reactos/lib/crtdll/makefile +++ b/reactos/lib/crtdll/makefile @@ -17,7 +17,7 @@ STDLIB_OBJECTS = stdlib/malloc.o OBJECTS = $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) crtdll.a: $(OBJECTS) - $(AR) vrcs crtdll.a $(OBJECTS) + $(AR) rcs crtdll.a $(OBJECTS) dummy: diff --git a/reactos/lib/kernel32/file/create.c b/reactos/lib/kernel32/file/create.c index b2b1de2efad..be924deb218 100644 --- a/reactos/lib/kernel32/file/create.c +++ b/reactos/lib/kernel32/file/create.c @@ -2,15 +2,15 @@ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/create.c - * PURPOSE: Directory functions + * PURPOSE: File create/open functions * PROGRAMMER: Ariadne ( ariadne@xs4all.nl) - GetTempFileName is modified from WINE [ Alexandre Juiliard ] + * GetTempFileName is modified from WINE [ Alexandre Juiliard ] * UPDATE HISTORY: * Created 01/11/98 */ +/* INCLUDES *****************************************************************/ -#undef WIN32_LEAN_AND_MEAN #include #include #include @@ -18,6 +18,11 @@ #include #include +#define NDEBUG +#include + +/* FUNCTIONS ****************************************************************/ + HANDLE STDCALL CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, @@ -30,7 +35,7 @@ HANDLE STDCALL CreateFileA(LPCSTR lpFileName, WCHAR FileNameW[MAX_PATH]; ULONG i = 0; - OutputDebugStringA("CreateFileA\n"); + DPRINT("CreateFileA\n"); while ((*lpFileName)!=0 && i < MAX_PATH) { @@ -69,7 +74,7 @@ HANDLE STDCALL CreateFileW(LPCWSTR lpFileName, UINT Len = 0; WCHAR CurrentDir[MAX_PATH]; - OutputDebugStringA("CreateFileW\n"); + DPRINT("CreateFileW\n"); if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) { @@ -83,16 +88,16 @@ HANDLE STDCALL CreateFileW(LPCWSTR lpFileName, PathNameW[3] = '\\'; PathNameW[4] = 0; - dprintf("Name %w\n",PathNameW); + DPRINT("Name %w\n",PathNameW); if (lpFileName[0] != L'\\' && lpFileName[1] != L':') { Len = GetCurrentDirectoryW(MAX_PATH,CurrentDir); - dprintf("CurrentDir %w\n",CurrentDir); + DPRINT("CurrentDir %w\n",CurrentDir); lstrcatW(PathNameW,CurrentDir); - dprintf("Name %w\n",PathNameW); + DPRINT("Name %w\n",PathNameW); } lstrcatW(PathNameW,lpFileName); - dprintf("Name %w\n",PathNameW); + DPRINT("Name %w\n",PathNameW); FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR); diff --git a/reactos/lib/kernel32/file/curdir.c b/reactos/lib/kernel32/file/curdir.c index 0f4698ddbbe..7f59a1cae39 100644 --- a/reactos/lib/kernel32/file/curdir.c +++ b/reactos/lib/kernel32/file/curdir.c @@ -3,7 +3,6 @@ * PROJECT: ReactOS system libraries * FILE: lib/kernel32/file/curdir.c * PURPOSE: Current directory functions - * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 30/09/98 */ @@ -13,6 +12,9 @@ #include +#define NDEBUG +#include + /* GLOBALS *******************************************************************/ @@ -46,7 +48,7 @@ DWORD STDCALL GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer) { UINT uSize; - dprintf("CurrentDirectoryW %w\n",CurrentDirectoryW); + DPRINT("CurrentDirectoryW %w\n",CurrentDirectoryW); if ( lpBuffer == NULL ) return 0; @@ -54,7 +56,7 @@ DWORD STDCALL GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer) if ( nBufferLength > uSize ) lstrcpynW(lpBuffer,CurrentDirectoryW,uSize); - dprintf("GetCurrentDirectoryW() = %w\n",lpBuffer); + DPRINT("GetCurrentDirectoryW() = %w\n",lpBuffer); return uSize; } @@ -63,7 +65,7 @@ BOOL STDCALL SetCurrentDirectoryA(LPCSTR lpPathName) { UINT i; - dprintf("SetCurrentDirectoryA(lpPathName %s)\n",lpPathName); + DPRINT("SetCurrentDirectoryA(lpPathName %s)\n",lpPathName); if ( lpPathName == NULL ) return FALSE; @@ -77,17 +79,13 @@ BOOL STDCALL SetCurrentDirectoryA(LPCSTR lpPathName) } CurrentDirectoryW[i] = 0; - dprintf("CurrentDirectoryW = '%w'\n",CurrentDirectoryW); + DPRINT("CurrentDirectoryW = '%w'\n",CurrentDirectoryW); return(TRUE); } -WINBOOL -STDCALL -SetCurrentDirectoryW( - LPCWSTR lpPathName - ) +WINBOOL STDCALL SetCurrentDirectoryW(LPCWSTR lpPathName) { if ( lpPathName == NULL ) return FALSE; diff --git a/reactos/lib/kernel32/file/find.c b/reactos/lib/kernel32/file/find.c index 083f912e39e..026f0d3a41e 100644 --- a/reactos/lib/kernel32/file/find.c +++ b/reactos/lib/kernel32/file/find.c @@ -14,6 +14,9 @@ #include #include +#define NDEBUG +#include + /* TYPES ********************************************************************/ typedef struct _KERNEL32_FIND_FILE_DATA @@ -74,7 +77,7 @@ WINBOOL STDCALL InternalFindNextFile(HANDLE hFindFile, TRUE, &(IData->PatternStr), FALSE); - dprintf("Found %w\n",IData->FileInfo.FileName); + DPRINT("Found %w\n",IData->FileInfo.FileName); lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; if (Status != STATUS_SUCCESS) { @@ -95,7 +98,7 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName, UNICODE_STRING DirectoryNameStr; IO_STATUS_BLOCK IoStatusBlock; - dprintf("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n", + DPRINT("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n", lpFileName, lpFindFileData); GetCurrentDirectoryW(MAX_PATH, CurrentDirectory); @@ -104,17 +107,17 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName, Directory[2] = '?'; Directory[3] = '\\'; Directory[4] = 0; - dprintf("Directory %w\n",Directory); + DPRINT("Directory %w\n",Directory); wcscat(Directory, CurrentDirectory); - dprintf("Directory %w\n",Directory); + DPRINT("Directory %w\n",Directory); wcscat(Directory, lpFileName); - dprintf("Directory %w\n",Directory); + DPRINT("Directory %w\n",Directory); End = wcsrchr(Directory, '\\'); *End = 0; wcscpy(Pattern, End+1); - dprintf("Directory %w Pattern %w\n",Directory,Pattern); + DPRINT("Directory %w Pattern %w\n",Directory,Pattern); IData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, @@ -151,7 +154,7 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName, TRUE, &(IData->PatternStr), FALSE); - dprintf("Found %w\n",IData->FileInfo.FileName); + DPRINT("Found %w\n",IData->FileInfo.FileName); lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; return(IData); diff --git a/reactos/lib/kernel32/mem/heap.c b/reactos/lib/kernel32/mem/heap.c index 053415ca6a5..36a3b62e109 100644 --- a/reactos/lib/kernel32/mem/heap.c +++ b/reactos/lib/kernel32/mem/heap.c @@ -26,11 +26,16 @@ * Put the type definitions of the heap in a seperate header. Boudewijn Dekker */ -#include +/* INCLUDES *****************************************************************/ + +#define NDEBUG #include + +#include #include #include +/* GLOBALS ******************************************************************/ static HEAP_BUCKET __HeapDefaultBuckets[]= { @@ -46,6 +51,8 @@ static HEAP_BUCKET __HeapDefaultBuckets[]= PHEAP __ProcessHeap = NULL; +/* FUNCTIONS ****************************************************************/ + static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end); static BOOL __HeapDecommit(PHEAP pheap, LPVOID start, LPVOID end); static LPVOID __HeapAlloc(PHEAP pheap, ULONG flags, ULONG size, ULONG tag); @@ -68,8 +75,8 @@ static PHEAP __HeapPrepare(LPVOID base, ULONG minsize, ULONG maxsize, *********************************************************************/ static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end) { - dprintf("__HeapCommit( 0x%lX, 0x%lX, 0x%lX)\n", - (ULONG) pheap, (ULONG) start, (ULONG) end); + DPRINT("__HeapCommit( 0x%lX, 0x%lX, 0x%lX)\n", + (ULONG) pheap, (ULONG) start, (ULONG) end); if(end >= pheap->LastBlock) pheap->LastBlock=end; @@ -87,7 +94,7 @@ static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end) *********************************************************************/ static BOOL __HeapDecommit(PHEAP pheap, LPVOID start, LPVOID end) { - dprintf("__HeapDecommit( 0x%lX, 0x%lX, 0x%lX)\n", + DPRINT("__HeapDecommit( 0x%lX, 0x%lX, 0x%lX)\n", (ULONG) pheap, (ULONG) start, (ULONG) end); #ifdef NOT __VirtualDump(); @@ -113,7 +120,7 @@ static LPVOID __HeapAlloc(PHEAP pheap, ULONG flags, ULONG size, ULONG tag) ULONG freesize; ULONG allocsize; - dprintf("__HeapAlloc(pheap %x, flags %x, size %d, tag %x)\n", + DPRINT("__HeapAlloc(pheap %x, flags %x, size %d, tag %x)\n", pheap,flags,size,tag); pfree=&(pheap->Start); @@ -235,7 +242,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size) */ if(size==0) { - dprintf("__HeapReAlloc: freeing memory\n"); + DPRINT("__HeapReAlloc: freeing memory\n"); __HeapFree(pheap, flags, pold); return NULL; } @@ -251,7 +258,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size) #endif else if(newsize < allocsize ) { - dprintf("__HeapReAlloc: shrinking memory\n"); + DPRINT("__HeapReAlloc: shrinking memory\n"); /* free remaining region of memory */ prealloc->Size=size | HEAP_NORMAL_TAG; pnext=HEAP_NEXT(prealloc); @@ -267,7 +274,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size) } else if(newsize == allocsize ) { - dprintf("__HeapReAlloc: no changes\n"); + DPRINT("__HeapReAlloc: no changes\n"); /* nothing to do */ prealloc->Size= size | HEAP_NORMAL_TAG; return pold; @@ -280,7 +287,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size) if(((LPVOID) pnext< pheap->End)&& HEAP_ISFREE(pnext) && (HEAP_SIZE(pnext) + HEAP_ADMIN_SIZE >=newsize-allocsize)) { - dprintf("__HeapReAlloc: joining memory\n"); + DPRINT("__HeapReAlloc: joining memory\n"); oldsize=HEAP_SIZE(prealloc); prealloc->Size=size | HEAP_NORMAL_TAG; @@ -304,7 +311,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size) { if((flags&HEAP_REALLOC_IN_PLACE_ONLY)==0) { - dprintf("__HeapReAlloc: allocating new memory\n"); + DPRINT("__HeapReAlloc: allocating new memory\n"); /* alloc a new piece of memory */ oldsize=HEAP_SIZE(prealloc); pmem=__HeapAlloc(pheap, flags, size, HEAP_NORMAL_TAG); @@ -590,7 +597,7 @@ PHEAP __HeapPrepare(LPVOID base, ULONG minsize, ULONG maxsize, ULONG flags) { PHEAP pheap=(PHEAP) base; - dprintf("__HeapPrepare(base %x, minsize %d, maxsize %d, flags %x)\n", + DPRINT("__HeapPrepare(base %x, minsize %d, maxsize %d, flags %x)\n", base,minsize,maxsize,flags); pheap->Magic=MAGIC_HEAP; @@ -670,7 +677,7 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size) PHEAP pheap=hheap; LPVOID retval; - aprintf("HeapAlloc( 0x%lX, 0x%lX, 0x%lX )\n", + DPRINT("HeapAlloc( 0x%lX, 0x%lX, 0x%lX )\n", (ULONG) hheap, flags, (ULONG) size ); #ifdef NOT HeapValidate(hheap, 0, 0); @@ -686,7 +693,7 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size) if( (flags | pheap->Flags) & HEAP_NO_SERIALIZE ) LeaveCriticalSection(&(pheap->Synchronize)); - aprintf("HeapAlloc returns 0x%lX\n", (ULONG) retval); + DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval); return retval; } @@ -700,7 +707,7 @@ LPVOID STDCALL HeapReAlloc(HANDLE hheap, DWORD flags, LPVOID ptr, DWORD size) PHEAP_BLOCK pfree=((PHEAP_BLOCK)ptr-1); LPVOID retval; - aprintf("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n", + DPRINT("HeapReAlloc( 0x%lX, 0x%lX, 0x%lX, 0x%lX )\n", (ULONG) hheap, flags, (ULONG) ptr, size ); #ifdef NOT HeapValidate(hheap, 0, 0); @@ -730,7 +737,7 @@ WINBOOL STDCALL HeapFree(HANDLE hheap, DWORD flags, LPVOID ptr) PHEAP_BLOCK pfree=(PHEAP_BLOCK)((LPVOID)ptr-HEAP_ADMIN_SIZE); BOOL retval; - aprintf("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n", + DPRINT("HeapFree( 0x%lX, 0x%lX, 0x%lX )\n", (ULONG) hheap, flags, (ULONG) ptr ); #ifdef NOT HeapValidate(hheap, 0, 0); @@ -756,7 +763,7 @@ WINBOOL STDCALL HeapFree(HANDLE hheap, DWORD flags, LPVOID ptr) *********************************************************************/ HANDLE WINAPI GetProcessHeap(VOID) { - aprintf("GetProcessHeap()\n"); + DPRINT("GetProcessHeap()\n"); return (HANDLE) __ProcessHeap; } @@ -771,7 +778,7 @@ DWORD WINAPI GetProcessHeaps(DWORD maxheaps, PHANDLE phandles ) DWORD retval; PHEAP pheap; - aprintf("GetProcessHeaps( %u, 0x%lX )\n", maxheaps, (ULONG) phandles ); + DPRINT("GetProcessHeaps( %u, 0x%lX )\n", maxheaps, (ULONG) phandles ); pheap= __ProcessHeap; retval=0; @@ -801,7 +808,7 @@ BOOL WINAPI HeapLock(HANDLE hheap) { PHEAP pheap=hheap; - aprintf("HeapLock( 0x%lX )\n", (ULONG) hheap ); + DPRINT("HeapLock( 0x%lX )\n", (ULONG) hheap ); EnterCriticalSection(&(pheap->Synchronize)); return TRUE; @@ -815,7 +822,7 @@ BOOL WINAPI HeapUnlock(HANDLE hheap) { PHEAP pheap=hheap; - aprintf("HeapUnlock( 0x%lX )\n", (ULONG) hheap ); + DPRINT("HeapUnlock( 0x%lX )\n", (ULONG) hheap ); LeaveCriticalSection(&(pheap->Synchronize)); return TRUE; @@ -866,7 +873,7 @@ DWORD WINAPI HeapSize(HANDLE hheap, DWORD flags, LPCVOID pmem) PHEAP_BLOCK palloc=((PHEAP_BLOCK)pmem-1); DWORD retval=0; - aprintf("HeapSize( 0x%lX, 0x%lX, 0x%lX )\n", + DPRINT("HeapSize( 0x%lX, 0x%lX, 0x%lX )\n", (ULONG) hheap, flags, (ULONG) pmem ); if(pheap->Magic!=MAGIC_HEAP) @@ -924,7 +931,7 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem) pnext=HEAP_NEXT(pcheck); if((pprev)&&(HEAP_PREV(pcheck)!=pprev)) { - dprintf("HeapValidate: linked list invalid, region 0x%lX," + DPRINT("HeapValidate: linked list invalid, region 0x%lX," " previous region 0x%lX, list says 0x%lX\n", (ULONG)pcheck, (ULONG)pprev, (ULONG) HEAP_PREV(pcheck)); return FALSE; @@ -948,13 +955,13 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem) pnextfrag=(PHEAP_FRAGMENT)((LPVOID)pfrag+add); if(pfrag->Magic!=HEAP_FRAG_MAGIC) { - dprintf("HeapValidate: fragment %d magic invalid, region 0x%lX," + DPRINT("HeapValidate: fragment %d magic invalid, region 0x%lX," " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev); return FALSE; } if(pfrag->Number!=i) { - dprintf("HeapValidate: fragment %d number invalid, region 0x%lX," + DPRINT("HeapValidate: fragment %d number invalid, region 0x%lX," " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev); return FALSE; } @@ -962,7 +969,7 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem) number++; if(pfrag->Sub!=psub) { - dprintf("HeapValidate: fragment %d suballoc invalid, region 0x%lX," + DPRINT("HeapValidate: fragment %d suballoc invalid, region 0x%lX," " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev); return FALSE; } @@ -971,11 +978,11 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem) } if(number!=psub->NumberFree) { - dprintf("HeapValidate: invalid number of free fragments, region 0x%lX," + DPRINT("HeapValidate: invalid number of free fragments, region 0x%lX," " previous region 0x%lX\n", (ULONG)pcheck, (ULONG)pprev); return FALSE; } - dprintf("HeapValidate: [0x%08lX-0x%08lX] suballocated," + DPRINT("HeapValidate: [0x%08lX-0x%08lX] suballocated," " bucket size=%d, bitmap=0x%08lX\n", (ULONG) pcheck, (ULONG) pnext, pbucket->Size, psub->Bitmap); } @@ -983,22 +990,22 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem) { if(HEAP_RSIZE(pcheck)!=HEAP_SIZE(pcheck)) { - dprintf("HeapValidate: invalid size of free region 0x%lX," + DPRINT("HeapValidate: invalid size of free region 0x%lX," " previous region 0x%lX\n", (ULONG) pcheck, (ULONG) pprev); return FALSE; } - dprintf("HeapValidate: [0x%08lX-0x%08lX] free\n", + DPRINT("HeapValidate: [0x%08lX-0x%08lX] free\n", (ULONG) pcheck, (ULONG) pnext ); } else if(HEAP_ISNORMAL(pcheck)) { - dprintf("HeapValidate: [0x%08lX-0x%08lX] allocated\n", + DPRINT("HeapValidate: [0x%08lX-0x%08lX] allocated\n", (ULONG) pcheck, (ULONG) pnext ); } else { - dprintf("HeapValidate: invalid tag %x, region 0x%lX," + DPRINT("HeapValidate: invalid tag %x, region 0x%lX," " previous region 0x%lX\n", pcheck->Size>>28, (ULONG)pcheck, (ULONG)pprev); return FALSE; diff --git a/reactos/lib/kernel32/mem/utils.c b/reactos/lib/kernel32/mem/utils.c index 9ca717d75c0..3d2e37ab6a3 100644 --- a/reactos/lib/kernel32/mem/utils.c +++ b/reactos/lib/kernel32/mem/utils.c @@ -1,11 +1,13 @@ #include + +#define NDEBUG #include VOID CopyMemory(PVOID Destination, CONST VOID* Source, DWORD Length) { DWORD i; - dprintf("CopyMemory(Destination %x, Source %x, Length %d)\n", + DPRINT("CopyMemory(Destination %x, Source %x, Length %d)\n", Destination,Source,Length); for (i=0; i KERNEL_BASE) + if (Stack[i] > KERNEL_BASE && Stack[i] < ((ULONG)&etext)) { DbgPrint("%.8x ",Stack[i]); } + if (Stack[i] == 0xceafbeef) + { + DbgPrint("IRQ "); + } } DbgPrint("\n"); } diff --git a/reactos/ntoskrnl/hal/x86/irqhand.asm b/reactos/ntoskrnl/hal/x86/irqhand.asm index eb6220b30e1..90fe1dda3ca 100644 --- a/reactos/ntoskrnl/hal/x86/irqhand.asm +++ b/reactos/ntoskrnl/hal/x86/irqhand.asm @@ -19,6 +19,9 @@ _irq_handler_%1: push ds push es + mov eax,0xceafbeef + push eax + ; ; Load DS ; @@ -45,6 +48,9 @@ _irq_handler_%1: ; Restore stack, registers and return to interrupted routine ; pop eax + + pop eax + pop es pop ds popa @@ -59,12 +65,17 @@ _irq_handler_%1: ; pusha push ds + push es + + mov eax,0xceafbeef + push eax ; ; Load DS ; mov ax,KERNEL_DS mov ds,ax + mov es,ax ; ; Mask the related vector at the PIC @@ -83,6 +94,10 @@ _irq_handler_%1: ; Restore stack, registers and return to the interrupted routine ; pop eax + + pop eax + + pop es pop ds popa iret diff --git a/reactos/ntoskrnl/io/create.c b/reactos/ntoskrnl/io/create.c index 827d1c8066e..3e3aef4248f 100644 --- a/reactos/ntoskrnl/io/create.c +++ b/reactos/ntoskrnl/io/create.c @@ -3,7 +3,7 @@ * PROJECT: ReactOS kernel * FILE: ntoskrnl/io/create.c * PURPOSE: Handling file create/open apis - * PROGRAMMER: David Welch (welch@mcmail.com) + * PROGRAMMER: David Welch (welch@cwcom.net) * UPDATE HISTORY: * 24/05/98: Created */ @@ -117,6 +117,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, if (Status != STATUS_SUCCESS && Status != STATUS_FS_QUERY_REQUIRED) { DPRINT("%s() = Failed to find object\n",__FUNCTION__); + ObDereferenceObject(FileObject); ZwClose(*FileHandle); *FileHandle=0; return(STATUS_UNSUCCESSFUL); @@ -134,7 +135,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, FileObject->Flags = FileObject->Flags | FO_DIRECT_DEVICE_OPEN; FileObject->FileName.Buffer = ExAllocatePool(NonPagedPool, ObjectAttributes->ObjectName->Length); - FileObject->FileName.Length = ObjectAttributes->Length; + FileObject->FileName.Length = ObjectAttributes->ObjectName->Length; RtlCopyUnicodeString(&(FileObject->FileName), ObjectAttributes->ObjectName); } @@ -146,7 +147,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, if (DeviceObject->DeviceType != FILE_DEVICE_FILE_SYSTEM && DeviceObject->DeviceType != FILE_DEVICE_DISK) { - CHECKPOINT; + ObDereferenceObject(FileObject); ZwClose(*FileHandle); *FileHandle=0; return(STATUS_UNSUCCESSFUL); @@ -158,7 +159,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, Status = IoTryToMountStorageDevice(DeviceObject); if (Status!=STATUS_SUCCESS) { - CHECKPOINT; + ObDereferenceObject(FileObject); ZwClose(*FileHandle); *FileHandle=0; return(Status); @@ -167,13 +168,13 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, } DPRINT("Remainder %x\n",Remainder); DPRINT("Remainder %w\n",Remainder); - FileObject->FileName.Buffer = ExAllocatePool(NonPagedPool, - wstrlen(Remainder)); - RtlInitUnicodeString(&(FileObject->FileName),Remainder); + DPRINT("FileObject->FileName.Buffer %w\n",FileObject->FileName.Buffer); + RtlInitUnicodeString(&(FileObject->FileName),wstrdup(Remainder)); DPRINT("FileObject->FileName.Buffer %x %w\n", FileObject->FileName.Buffer,FileObject->FileName.Buffer); } CHECKPOINT; + DPRINT("FileObject->FileName.Buffer %x\n",FileObject->FileName.Buffer); if (CreateOptions & FILE_SYNCHRONOUS_IO_ALERT) { @@ -194,6 +195,8 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); if (Irp==NULL) { + ExFreePool(FileObject->FileName.Buffer); + ObDereferenceObject(FileObject); ZwClose(*FileHandle); *FileHandle=0; return(STATUS_UNSUCCESSFUL); @@ -215,6 +218,9 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, if (Status!=STATUS_SUCCESS) { + DPRINT("FileObject->FileName.Buffer %x\n",FileObject->FileName.Buffer); + ExFreePool(FileObject->FileName.Buffer); + ObDereferenceObject(FileObject); ZwClose(*FileHandle); *FileHandle=0; } diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index bfe7e3537c1..64a87acf02e 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -58,9 +58,11 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, PIO_STACK_LOCATION StackPtr; KEVENT Event; + assert(KeGetCurrentIrql()==PASSIVE_LEVEL); + DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, " "IoStatusBlock %x)\n", - FileHandle,Buffer,Length,ByteOffset,IoStatusBlock); + FileHandle,Buffer,Length,ByteOffset,IoStatusBlock); Status = ObReferenceObjectByHandle(FileHandle, FILE_READ_DATA, @@ -70,6 +72,8 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, NULL); if (Status != STATUS_SUCCESS) { + DPRINT("ZwReadFile() ="); + DbgPrintErrorMessage(Status); return(Status); } assert(FileObject != NULL); diff --git a/reactos/ntoskrnl/io/timer.c b/reactos/ntoskrnl/io/timer.c index c169296283f..f0112e28f9e 100644 --- a/reactos/ntoskrnl/io/timer.c +++ b/reactos/ntoskrnl/io/timer.c @@ -33,7 +33,8 @@ NTSTATUS IoInitializeTimer(PDEVICE_OBJECT DeviceObject, { DeviceObject->Timer = ExAllocatePool(NonPagedPool,sizeof(IO_TIMER)); KeInitializeTimer(&(DeviceObject->Timer->timer)); - KeInitializeDpc(&(DeviceObject->Timer->dpc),(PKDEFERRED_ROUTINE)TimerRoutine,Context); + KeInitializeDpc(&(DeviceObject->Timer->dpc), + (PKDEFERRED_ROUTINE)TimerRoutine,Context); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/ke/dispatch.c b/reactos/ntoskrnl/ke/dispatch.c index eb42af01881..15a5b4c37ff 100644 --- a/reactos/ntoskrnl/ke/dispatch.c +++ b/reactos/ntoskrnl/ke/dispatch.c @@ -21,7 +21,10 @@ VOID KiDispatchInterrupt(ULONG irq) * level than DISPATCH_LEVEL */ { - KeExpireTimers(); + if (irq == 0) + { + KeExpireTimers(); + } KeDrainDpcQueue(); PsDispatchThread(); } diff --git a/reactos/ntoskrnl/ke/dpc.c b/reactos/ntoskrnl/ke/dpc.c index ce73885fd6f..a75006f386c 100644 --- a/reactos/ntoskrnl/ke/dpc.c +++ b/reactos/ntoskrnl/ke/dpc.c @@ -54,7 +54,9 @@ void KeDrainDpcQueue(void) PLIST_ENTRY current_entry; PKDPC current; KIRQL oldlvl; - + + DPRINT("KeDrainDpcQueue()\n"); + KeAcquireSpinLockAtDpcLevel(&DpcQueueLock); KeRaiseIrql(HIGH_LEVEL,&oldlvl); current_entry = RemoveHeadList(&DpcQueueHead); diff --git a/reactos/ntoskrnl/ke/timer.c b/reactos/ntoskrnl/ke/timer.c index 47ca7ad433f..8b2ec201023 100644 --- a/reactos/ntoskrnl/ke/timer.c +++ b/reactos/ntoskrnl/ke/timer.c @@ -146,16 +146,20 @@ NTSTATUS STDCALL ZwQueryPerformanceCounter(IN PLARGE_INTEGER Counter, } -NTSTATUS -KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval) +NTSTATUS KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval) { - assert(Thread != NULL); - assert(Interval != NULL); + assert(Thread != NULL); + assert(Interval != NULL); - KeInitializeTimer(&(Thread->TimerBlock)); - KeSetTimer(&(Thread->TimerBlock),*Interval,NULL); + DPRINT("KeAddThreadTimeout(Thread %x, Interval %x)\n",Thread,Interval); + + KeInitializeTimer(&(Thread->TimerBlock)); + KeSetTimer(&(Thread->TimerBlock),*Interval,NULL); - return STATUS_SUCCESS; + DPRINT("Thread->TimerBlock.entry.Flink %x\n", + Thread->TimerBlock.entry.Flink); + + return STATUS_SUCCESS; } @@ -327,6 +331,8 @@ BOOLEAN KeSetTimerEx(PKTIMER Timer, LARGE_INTEGER DueTime, LONG Period, { KIRQL oldlvl; + DPRINT("KeSetTimerEx(Timer %x)\n",Timer); + KeAcquireSpinLock(&timer_list_lock,&oldlvl); Timer->dpc=Dpc; @@ -346,9 +352,11 @@ BOOLEAN KeSetTimerEx(PKTIMER Timer, LARGE_INTEGER DueTime, LONG Period, if (Timer->running) { KeReleaseSpinLock(&timer_list_lock,oldlvl); - return TRUE; } + DPRINT("Inserting %x in list\n",&Timer->entry); + DPRINT("Timer->entry.Flink %x\n",Timer->entry.Flink); + Timer->running=TRUE; InsertTailList(&timer_list_head,&Timer->entry); KeReleaseSpinLock(&timer_list_lock,oldlvl); @@ -366,13 +374,17 @@ BOOLEAN KeCancelTimer(PKTIMER Timer) { KIRQL oldlvl; + DPRINT("KeCancelTimer(Timer %x)\n",Timer); + KeAcquireSpinLock(&timer_list_lock,&oldlvl); if (!Timer->running) { + KeReleaseSpinLock(&timer_list_lock,oldlvl); return FALSE; } RemoveEntryList(&Timer->entry); + Timer->running = FALSE; KeReleaseSpinLock(&timer_list_lock,oldlvl); return TRUE; @@ -423,6 +435,7 @@ VOID KeQueryTickCount(PLARGE_INTEGER TickCount) static void HandleExpiredTimer(PKTIMER current) { + DPRINT("HandleExpiredTime(current %x)\n",current); if (current->dpc!=NULL) { DPRINT("current->dpc->DeferredRoutine %x\n", @@ -431,6 +444,7 @@ static void HandleExpiredTimer(PKTIMER current) current->dpc->DeferredContext, current->dpc->SystemArgument1, current->dpc->SystemArgument2); + DPRINT("Finished dpc routine\n"); } current->signaled=TRUE; if (current->period != 0) @@ -456,6 +470,12 @@ void KeExpireTimers(void) PKTIMER current = CONTAINING_RECORD(current_entry,KTIMER,entry); KIRQL oldlvl; + DPRINT("KeExpireTimers()\n"); + DPRINT("&timer_list_head %x\n",&timer_list_head); + DPRINT("current_entry %x\n",current_entry); + DPRINT("current_entry->Flink %x\n",current_entry->Flink); + DPRINT("current_entry->Flink->Flink %x\n",current_entry->Flink->Flink); + KeAcquireSpinLock(&timer_list_lock,&oldlvl); while (current_entry!=(&timer_list_head)) @@ -469,6 +489,7 @@ void KeExpireTimers(void) current = CONTAINING_RECORD(current_entry,KTIMER,entry); } KeReleaseSpinLock(&timer_list_lock,oldlvl); + DPRINT("Finished KeExpireTimers()\n"); } extern unsigned int nr_used_blocks; @@ -511,8 +532,9 @@ BOOLEAN KiTimerInterrupt(VOID) } // sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks); memset(str, 0, sizeof(str)); - sprintf(str,"%.8u %.8u",EiNrUsedBlocks,KiTimerTicks); +// sprintf(str,"%.8u %.8u",EiNrUsedBlocks,KiTimerTicks); // sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,EiUsedNonPagedPool); + sprintf(str,"%.8u %.8u",PiNrThreads,KiTimerTicks); for (i=0;i<17;i++) { *vidmem=str[i]; diff --git a/reactos/ntoskrnl/ke/wait.c b/reactos/ntoskrnl/ke/wait.c index 474b292c5ff..a68b24fb011 100644 --- a/reactos/ntoskrnl/ke/wait.c +++ b/reactos/ntoskrnl/ke/wait.c @@ -176,6 +176,11 @@ NTSTATUS KeWaitForSingleObject(PVOID Object, // hdr->WaitListHead.Flink,hdr->WaitListHead.Blink); KeReleaseDispatcherDatabaseLock(FALSE); PsSuspendThread(PsGetCurrentThread()); + + if (Timeout!=NULL) + { + KeCancelTimer(&KeGetCurrentThread()->TimerBlock); + } return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/mm/npool.c b/reactos/ntoskrnl/mm/npool.c index c59f3d10dec..ae44671b093 100644 --- a/reactos/ntoskrnl/mm/npool.c +++ b/reactos/ntoskrnl/mm/npool.c @@ -28,7 +28,7 @@ #include -#if 1 +#if 0 #define VALIDATE_POOL validate_kernel_pool() #else #define VALIDATE_POOL @@ -99,7 +99,8 @@ static void validate_free_list(void) if (current->magic != BLOCK_HDR_MAGIC) { - DbgPrint("Bad block magic (probable pool corruption)\n"); + DbgPrint("Bad block magic (probable pool corruption) at %x\n", + current); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT); } @@ -146,7 +147,8 @@ static void validate_used_list(void) if (current->magic != BLOCK_HDR_MAGIC) { - DbgPrint("Bad block magic (probable pool corruption)\n"); + DbgPrint("Bad block magic (probable pool corruption) at %x\n", + current); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT); } if (base_addr < (kernel_pool_base) || @@ -189,7 +191,8 @@ static void check_duplicates(block_hdr* blk) { if (current->magic != BLOCK_HDR_MAGIC) { - DbgPrint("Bad block magic (probable pool corruption)\n"); + DbgPrint("Bad block magic (probable pool corruption) at %x\n", + current); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT); } @@ -538,8 +541,8 @@ asmlinkage VOID ExFreePool(PVOID block) if (blk->magic != BLOCK_HDR_MAGIC) { - DbgPrint("ExFreePool of non-allocated address\n"); - for(;;); + DbgPrint("ExFreePool of non-allocated address %x\n",block); + KeBugCheck(0); return; } @@ -622,7 +625,8 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type, ULONG size, ULONG Tag) current->next); if (current->magic != BLOCK_HDR_MAGIC) { - DbgPrint("Bad block magic (probable pool corruption)\n"); + DbgPrint("Bad block magic (probable pool corruption) at %x\n", + current); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT); } if (current->size>=size) diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index ff0cd3846d8..a5717bda745 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -95,6 +95,9 @@ PVOID ObGenericCreateObject(PHANDLE Handle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_TYPE Type) +/* + * FUNCTION: Creates a new object + */ { POBJECT_HEADER hdr = NULL; PWSTR path; @@ -206,13 +209,12 @@ VOID ObInitializeObjectHeader(POBJECT_TYPE Type, PWSTR name, */ { PWSTR temp_name; - extern unsigned long long ticks; DPRINT("ObInitializeObjectHeader(id %x name %w obj %x)\n",Type, name,ObjectHeader); - ObjectHeader->HandleCount = 0; - ObjectHeader->RefCount = 0; + ObjectHeader->HandleCount = 1; + ObjectHeader->RefCount = 1; ObjectHeader->ObjectType = Type; ObjectHeader->Permanent = FALSE; if (name==NULL) diff --git a/reactos/ntoskrnl/ps/idle.c b/reactos/ntoskrnl/ps/idle.c index d156ecf90ef..da3d0049707 100644 --- a/reactos/ntoskrnl/ps/idle.c +++ b/reactos/ntoskrnl/ps/idle.c @@ -12,6 +12,7 @@ #include +#define NDEBUG #include /* GLOBALS *******************************************************************/ @@ -27,7 +28,7 @@ static VOID PsIdleThreadMain(PVOID Context) for(;;) { -// DbgPrint("Idling.... "); + DPRINT("Idling.... DpcQueueSize %d\n",DpcQueueSize); if (DpcQueueSize > 0) { KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); diff --git a/reactos/ntoskrnl/ps/kill.c b/reactos/ntoskrnl/ps/kill.c index 7e021da8836..c547eddffaa 100644 --- a/reactos/ntoskrnl/ps/kill.c +++ b/reactos/ntoskrnl/ps/kill.c @@ -1,100 +1,144 @@ -/* - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ps/kill.c - * PURPOSE: Terminating a thread - * PROGRAMMER: David Welch (welch@mcmail.com) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include -#include - -#define NDEBUG -#include - -/* GLBOALS *******************************************************************/ - -extern ULONG PiNrThreads; - -/* FUNCTIONS *****************************************************************/ - -NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle, - IN NTSTATUS ExitStatus) -{ - return(ZwTerminateThread(ThreadHandle,ExitStatus)); -} - -NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle, - IN NTSTATUS ExitStatus) -{ - PETHREAD Thread; - NTSTATUS Status; - - Status = ObReferenceObjectByHandle(ThreadHandle, - THREAD_TERMINATE, - PsThreadType, - UserMode, - (PVOID*)&Thread, - NULL); - if (Status != STATUS_SUCCESS) - { - return(Status); - } - - if (Thread == PsGetCurrentThread()) - { - PsTerminateSystemThread(ExitStatus); - } - else - { - UNIMPLEMENTED; - } -} - -VOID PsReleaseThread(PETHREAD Thread) -{ - DPRINT("PsReleaseThread(Thread %x)\n",Thread); - - RemoveEntryList(&Thread->Tcb.Entry); - ObDereferenceObject(Thread); -} - - -NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) -/* - * FUNCTION: Terminates the current thread - * ARGUMENTS: - * ExitStatus = Status to pass to the creater - * RETURNS: Doesn't - */ -{ - KIRQL oldlvl; - PETHREAD CurrentThread; - - PiNrThreads--; - - CurrentThread = PsGetCurrentThread(); - - CurrentThread->ExitStatus = ExitStatus; - - DPRINT("terminating %x\n",CurrentThread); - ObDereferenceObject(CurrentThread->ThreadsProcess); - KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); - CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED; - ZwYieldExecution(); - for(;;); -} - -NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) -{ - return(ZwRegisterThreadTerminatePort(TerminationPort)); -} - -NTSTATUS STDCALL ZwRegisterThreadTerminatePort(HANDLE TerminationPort) -{ - UNIMPLEMENTED; -} +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/ps/kill.c + * PURPOSE: Terminating a thread + * PROGRAMMER: David Welch (welch@mcmail.com) + * UPDATE HISTORY: + * Created 22/05/98 + */ + +/* INCLUDES *****************************************************************/ + +#include +#include + +#define NDEBUG +#include + +/* GLBOALS *******************************************************************/ + +extern ULONG PiNrThreads; + +/* FUNCTIONS *****************************************************************/ + +NTSTATUS STDCALL NtTerminateProcess(IN HANDLE ProcessHandle, + IN NTSTATUS ExitStatus) +{ + return(ZwTerminateProcess(ProcessHandle,ExitStatus)); +} + +NTSTATUS STDCALL ZwTerminateProcess(IN HANDLE ProcessHandle, + IN NTSTATUS ExitStatus) +{ + PETHREAD Thread; + NTSTATUS Status; + PEPROCESS Process; + KIRQL oldlvl; + + Status = ObReferenceObjectByHandle(ProcessHandle, + PROCESS_TERMINATE, + PsProcessType, + UserMode, + (PVOID*)&Process, + NULL); + if (Status != STATUS_SUCCESS) + { + return(Status); + } + + PiTerminateProcessThreads(Process, ExitStatus); + KeRaiseIrql(DISPATCH_LEVEL, &oldlvl); + KeDispatcherObjectWakeAll(&Process->Pcb.DispatcherHeader); + Process->Pcb.ProcessState = PROCESS_STATE_TERMINATED; + if (PsGetCurrentThread()->ThreadsProcess == Process) + { + KeLowerIrql(oldlvl); + PsTerminateSystemThread(ExitStatus); + } + KeLowerIrql(oldlvl); + return(STATUS_SUCCESS); +} + + +NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle, + IN NTSTATUS ExitStatus) +{ + return(ZwTerminateThread(ThreadHandle,ExitStatus)); +} + +NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle, + IN NTSTATUS ExitStatus) +{ + PETHREAD Thread; + NTSTATUS Status; + + Status = ObReferenceObjectByHandle(ThreadHandle, + THREAD_TERMINATE, + PsThreadType, + UserMode, + (PVOID*)&Thread, + NULL); + if (Status != STATUS_SUCCESS) + { + return(Status); + } + + PsTerminateThread(Thread); +} + +VOID PsTerminateThread(PETHREAD Thread, NTSTATUS ExitStatus) +{ + if (Thread == PsGetCurrentThread()) + { + PsTerminateSystemThread(ExitStatus); + } + else + { + UNIMPLEMENTED; + } +} + +VOID PsReleaseThread(PETHREAD Thread) +{ + DPRINT("PsReleaseThread(Thread %x)\n",Thread); + + RemoveEntryList(&Thread->Tcb.Entry); + ObDereferenceObject(Thread); +} + + +NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) +/* + * FUNCTION: Terminates the current thread + * ARGUMENTS: + * ExitStatus = Status to pass to the creater + * RETURNS: Doesn't + */ +{ + KIRQL oldlvl; + PETHREAD CurrentThread; + + PiNrThreads--; + + CurrentThread = PsGetCurrentThread(); + + CurrentThread->ExitStatus = ExitStatus; + + DPRINT("terminating %x\n",CurrentThread); + ObDereferenceObject(CurrentThread->ThreadsProcess); + KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); + CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED; + ZwYieldExecution(); + for(;;); +} + +NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) +{ + return(ZwRegisterThreadTerminatePort(TerminationPort)); +} + +NTSTATUS STDCALL ZwRegisterThreadTerminatePort(HANDLE TerminationPort) +{ + UNIMPLEMENTED; +} diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index b4ebf11a1ec..1a811ab1ce4 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -204,24 +204,13 @@ NTSTATUS STDCALL ZwCreateProcess( DbgPrint("ZwCreateProcess() non-NULL SectionHandle\n"); return(STATUS_UNSUCCESSFUL); } - + + Process->Pcb.ProcessState = PROCESS_STATE_ACTIVE; + return(STATUS_SUCCESS); } -NTSTATUS STDCALL NtTerminateProcess(IN HANDLE ProcessHandle, - IN NTSTATUS ExitStatus) -{ - return(ZwTerminateProcess(ProcessHandle,ExitStatus)); -} - -NTSTATUS STDCALL ZwTerminateProcess(IN HANDLE ProcessHandle, - IN NTSTATUS ExitStatus) -{ - UNIMPLEMENTED; -} - - NTSTATUS STDCALL NtOpenProcess (OUT PHANDLE ProcessHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, @@ -241,8 +230,7 @@ NTSTATUS STDCALL ZwOpenProcess (OUT PHANDLE ProcessHandle, UNIMPLEMENTED; } -NTSTATUS STDCALL NtQueryInformationProcess( - IN HANDLE ProcessHandle, +NTSTATUS STDCALL NtQueryInformationProcess(IN HANDLE ProcessHandle, IN CINT ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, @@ -255,8 +243,7 @@ NTSTATUS STDCALL NtQueryInformationProcess( ReturnLength)); } -NTSTATUS STDCALL ZwQueryInformationProcess( - IN HANDLE ProcessHandle, +NTSTATUS STDCALL ZwQueryInformationProcess(IN HANDLE ProcessHandle, IN CINT ProcessInformationClass, OUT PVOID ProcessInformation, IN ULONG ProcessInformationLength, @@ -305,14 +292,10 @@ NTSTATUS STDCALL ZwQueryInformationProcess( return(Status); } -NTSTATUS -STDCALL -NtSetInformationProcess( - IN HANDLE ProcessHandle, - IN CINT ProcessInformationClass, - IN PVOID ProcessInformation, - IN ULONG ProcessInformationLength - ) +NTSTATUS STDCALL NtSetInformationProcess(IN HANDLE ProcessHandle, + IN CINT ProcessInformationClass, + IN PVOID ProcessInformation, + IN ULONG ProcessInformationLength) { return(ZwSetInformationProcess(ProcessHandle, ProcessInformationClass, @@ -320,14 +303,10 @@ NtSetInformationProcess( ProcessInformationLength)); } -NTSTATUS -STDCALL -ZwSetInformationProcess( - IN HANDLE ProcessHandle, - IN CINT ProcessInformationClass, - IN PVOID ProcessInformation, - IN ULONG ProcessInformationLength - ) +NTSTATUS STDCALL ZwSetInformationProcess(IN HANDLE ProcessHandle, + IN CINT ProcessInformationClass, + IN PVOID ProcessInformation, + IN ULONG ProcessInformationLength) { UNIMPLEMENTED; } diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 6602e3bba44..82747c91c75 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -46,6 +46,7 @@ static KSPIN_LOCK ThreadListLock = {0,}; static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},}; static BOOLEAN DoneInitYet = FALSE; ULONG PiNrThreads = 0; +ULONG PiNrRunnableThreads = 0; static PETHREAD CurrentThread = NULL; @@ -63,6 +64,33 @@ PETHREAD PsGetCurrentThread(VOID) return((PETHREAD)KeGetCurrentThread()); } +VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus) +{ + KIRQL oldlvl; + PLIST_ENTRY current_entry; + PETHREAD current; + ULONG i; + + KeAcquireSpinLock(&ThreadListLock, &oldlvl); + + for (i=0; iThreadsProcess == Process && + current != PsGetCurrentThread()) + { + PsTerminateThread(current, ExitStatus); + } + current_entry = current_entry->Flink; + } + } + + KeReleaseSpinLock(&ThreadListLock, oldlvl); +} + static VOID PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread) { KIRQL oldlvl; @@ -148,7 +176,7 @@ VOID PsDispatchThread(VOID) Candidate = PsScanThreadList(CurrentPriority); if (Candidate == CurrentThread) { -// DbgPrint("Scheduling current thread\n"); + DPRINT("Scheduling current thread\n"); KeQueryTickCount(&TickCount); CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount); CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING; @@ -157,7 +185,7 @@ VOID PsDispatchThread(VOID) } if (Candidate != NULL) { -// DbgPrint("Scheduling %x\n",Candidate); + DPRINT("Scheduling %x\n",Candidate); Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING; @@ -171,6 +199,8 @@ VOID PsDispatchThread(VOID) return; } } + DbgPrint("CRITICAL: No threads are runnable\n"); + KeBugCheck(0); } NTSTATUS PsInitializeThread(HANDLE ProcessHandle, @@ -207,6 +237,7 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle, NULL); if (Status != STATUS_SUCCESS) { + DPRINT("Failed at %s:%d\n",__FILE__,__LINE__); return(Status); } } diff --git a/reactos/ntoskrnl/rtl/wstring.c b/reactos/ntoskrnl/rtl/wstring.c index 920bf814ee4..4dae5b13c80 100644 --- a/reactos/ntoskrnl/rtl/wstring.c +++ b/reactos/ntoskrnl/rtl/wstring.c @@ -14,12 +14,22 @@ #include #include +#define NDEBUG #include wchar_t * ___wcstok = NULL; /* FUNCTIONS *****************************************************************/ +wchar_t* wstrdup(const wchar_t* src) +{ + wchar_t* dest; + + dest = ExAllocatePool(NonPagedPool, (wstrlen(src)+1)*2); + wcscpy(dest,src); + return(dest); +} + wchar_t * wcscat(wchar_t *dest, const wchar_t *src) { @@ -86,13 +96,14 @@ int wcscmp(const wchar_t *cs, const wchar_t *ct) wchar_t* wcscpy(wchar_t* str1, const wchar_t* str2) { wchar_t* s = str1; - DbgPrint("wcscpy(str1 %w, str2 %w)\n",str1,str2); + DPRINT("wcscpy(str1 %w, str2 %w)\n",str1,str2); while ((*str2)!=0) { *s = *str2; s++; str2++; } + *s = 0; return(str1); }