Created bugs in wait and timer code

svn path=/trunk/; revision=152
This commit is contained in:
David Welch 1999-01-04 23:01:18 +00:00
parent 4850652d25
commit 36902d624f
34 changed files with 1708 additions and 824 deletions

View file

@ -6,5 +6,5 @@
void main() void main()
{ {
NtDisplayString("Hello world\n"); NtDisplayString("Hello world\n");
ExitThread(0); ExitProcess(0);
} }

View file

@ -142,7 +142,7 @@ void ExecuteCommand(char* line)
} }
cmd = line; cmd = line;
debug_printf("cmd '%s' tail '%s'\n",cmd,tail); // debug_printf("cmd '%s' tail '%s'\n",cmd,tail);
if (cmd==NULL) if (cmd==NULL)
{ {
@ -194,6 +194,11 @@ void ReadLine(char* line)
line++; line++;
} }
} while (!(KeyEvent.bKeyDown && KeyEvent.AsciiChar == '\n')); } while (!(KeyEvent.bKeyDown && KeyEvent.AsciiChar == '\n'));
ReadFile(KeyboardHandle,
&KeyEvent,
sizeof(KEY_EVENT_RECORD),
&Result,
NULL);
line--; line--;
*line = 0; *line = 0;
} }

View file

@ -418,7 +418,7 @@ static VOID KbdDpcRoutine(PKDPC Dpc,
CHECKPOINT; CHECKPOINT;
DPRINT("KbdDpcRoutine(DeviceObject %x, Irp %x)\n", DPRINT("KbdDpcRoutine(DeviceObject %x, Irp %x)\n",
DeviceObject,Irp); DeviceObject,Irp);
Irp->IoStatus.Status = STATUS_SUCCESS; Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp,IO_NO_INCREMENT); IoCompleteRequest(Irp,IO_NO_INCREMENT);
@ -479,7 +479,12 @@ static unsigned int KeyboardHandler(unsigned int irq)
ProcessScanCode(thisKey,isDown); 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) if (CurrentIrp!=NULL)
{ {

View file

@ -1,171 +1,171 @@
/*
* COPYRIGHT: See COPYING in the top level directory
/* * PROJECT: ReactOS kernel
* COPYRIGHT: See COPYING in the top level directory * FILE: services/fs/vfat/blockdev.c
* PROJECT: ReactOS kernel * PURPOSE: Temporary sector reading support
* FILE: services/fs/vfat/blockdev.c * PROGRAMMER: David Welch (welch@mcmail.com)
* PURPOSE: Temporary sector reading support * UPDATE HISTORY:
* PROGRAMMER: David Welch (welch@mcmail.com) */
* UPDATE HISTORY:
*/ /* INCLUDES *****************************************************************/
/* INCLUDES *****************************************************************/ #include <ddk/ntddk.h>
#include <internal/string.h>
#include <ddk/ntddk.h> #include <wstring.h>
#include <internal/string.h>
#include <wstring.h> #define NDEBUG
#include <internal/debug.h>
#define NDEBUG
#include <internal/debug.h> #include "vfat.h"
#include "vfat.h" /* FUNCTIONS ***************************************************************/
//#include "dbgpool.c"
/* FUNCTIONS ***************************************************************/ BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject, IN ULONG SectorCount,
IN ULONG DiskSector, IN UCHAR* Buffer)
IN ULONG SectorCount, {
IN UCHAR* Buffer) LARGE_INTEGER sectorNumber;
{ PIRP irp;
LARGE_INTEGER sectorNumber; IO_STATUS_BLOCK ioStatus;
PIRP irp; KEVENT event;
IO_STATUS_BLOCK ioStatus; NTSTATUS status;
KEVENT event; ULONG sectorSize;
NTSTATUS status;
ULONG sectorSize; SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
PULONG mbr; SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
KeInitializeEvent(&event, NotificationEvent, FALSE);
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d,count %d, Buffer %x)\n", sectorSize = BLOCKSIZE * SectorCount;
pDeviceObject,DiskSector,SectorCount,Buffer);
/* FIXME: this routine does not need to alloc mem and copy */
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
KeInitializeEvent(&event, NotificationEvent, FALSE); pDeviceObject,
DiskSector,
sectorSize = BLOCKSIZE*SectorCount; Buffer);
DPRINT("sectorNumber %08lx:%08lx sectorSize %ld\n",
DPRINT("SectorCount=%d,sectorSize=%d,BLOCKSIZE=%d\n",SectorCount,sectorSize,BLOCKSIZE); (unsigned long int)GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
mbr = ExAllocatePool(NonPagedPool, sectorSize); (unsigned long int)GET_LARGE_INTEGER_LOW_PART(sectorNumber),
if (!mbr) { sectorSize);
return FALSE;
}
DPRINT("Building synchronous FSD Request...\n");
irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
pDeviceObject, pDeviceObject,
mbr, Buffer,
sectorSize, sectorSize,
&sectorNumber, &sectorNumber,
&event, &event,
&ioStatus ); &ioStatus );
if (!irp) { if (!irp) {
DbgPrint("READ failed!!!\n"); DbgPrint("READ failed!!!\n");
ExFreePool(mbr); return FALSE;
return FALSE; }
}
DPRINT("Calling IO Driver...\n");
status = IoCallDriver(pDeviceObject, status = IoCallDriver(pDeviceObject,
irp); irp);
if (status == STATUS_PENDING) { DPRINT("Waiting for IO Operation...\n");
KeWaitForSingleObject(&event, if (status == STATUS_PENDING) {
Suspended, KeWaitForSingleObject(&event,
KernelMode, Suspended,
FALSE, KernelMode,
NULL); FALSE,
status = ioStatus.Status; 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", if (!NT_SUCCESS(status)) {
pDeviceObject, DbgPrint("IO failed!!! VFATREadSectors : Error code: %x\n", status);
DiskSector, DbgPrint("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
Buffer, pDeviceObject,
GET_LARGE_INTEGER_HIGH_PART(sectorNumber), DiskSector,
GET_LARGE_INTEGER_LOW_PART(sectorNumber)); Buffer,
ExFreePool(mbr); GET_LARGE_INTEGER_HIGH_PART(sectorNumber),
return FALSE; GET_LARGE_INTEGER_LOW_PART(sectorNumber));
} return FALSE;
}
RtlCopyMemory(Buffer,mbr,sectorSize);
DPRINT("Copying memory...\n");
ExFreePool(mbr); DPRINT("Block request succeeded\n");
return TRUE; return TRUE;
} }
BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject, BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector, IN ULONG DiskSector,
IN ULONG SectorCount, IN ULONG SectorCount,
IN UCHAR* Buffer) IN UCHAR* Buffer)
{ {
LARGE_INTEGER sectorNumber; LARGE_INTEGER sectorNumber;
PIRP irp; PIRP irp;
IO_STATUS_BLOCK ioStatus; IO_STATUS_BLOCK ioStatus;
KEVENT event; KEVENT event;
NTSTATUS status; NTSTATUS status;
ULONG sectorSize; ULONG sectorSize;
PULONG mbr; PULONG mbr;
DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, count %d, Buffer %x)\n", DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject,DiskSector,SectorCount,Buffer); pDeviceObject,DiskSector,Buffer);
SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23); SET_LARGE_INTEGER_LOW_PART(sectorNumber, DiskSector << 9);
SET_LARGE_INTEGER_HIGH_PART(sectorNumber, DiskSector >> 23);
KeInitializeEvent(&event, NotificationEvent, FALSE);
KeInitializeEvent(&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE*SectorCount;
sectorSize = BLOCKSIZE*SectorCount;
mbr = ExAllocatePool(NonPagedPool, sectorSize);
mbr = ExAllocatePool(NonPagedPool, sectorSize);
if (!mbr) {
return FALSE; if (!mbr) {
} return FALSE;
memcpy(mbr,Buffer,sectorSize); }
DPRINT("Building synchronous FSD Request...\n");
irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE, DPRINT("Building synchronous FSD Request...\n");
pDeviceObject, irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
mbr, pDeviceObject,
sectorSize, mbr,
&sectorNumber, sectorSize,
&event, &sectorNumber,
&ioStatus ); &event,
&ioStatus );
if (!irp) {
DbgPrint("WRITE failed!!!\n"); if (!irp) {
ExFreePool(mbr); DbgPrint("WRITE failed!!!\n");
return FALSE; ExFreePool(mbr);
} return FALSE;
}
DPRINT("Calling IO Driver...\n");
status = IoCallDriver(pDeviceObject, DPRINT("Calling IO Driver...\n");
irp); status = IoCallDriver(pDeviceObject,
irp);
DPRINT("Waiting for IO Operation...\n");
if (status == STATUS_PENDING) { DPRINT("Waiting for IO Operation...\n");
KeWaitForSingleObject(&event, if (status == STATUS_PENDING) {
Suspended, KeWaitForSingleObject(&event,
KernelMode, Suspended,
FALSE, KernelMode,
NULL); FALSE,
DPRINT("Getting IO Status...\n"); NULL);
status = ioStatus.Status; DPRINT("Getting IO Status...\n");
} status = ioStatus.Status;
}
if (!NT_SUCCESS(status)) {
DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status); if (!NT_SUCCESS(status)) {
ExFreePool(mbr); DbgPrint("IO failed!!! VFATWriteSectors : Error code: %x\n", status);
return FALSE; ExFreePool(mbr);
} return FALSE;
}
DPRINT("Copying memory...\n");
RtlCopyMemory(Buffer,mbr,sectorSize); DPRINT("Copying memory...\n");
RtlCopyMemory(Buffer,mbr,sectorSize);
ExFreePool(mbr);
DPRINT("Block request succeeded\n"); ExFreePool(mbr);
return TRUE; DPRINT("Block request succeeded\n");
} return TRUE;
}

View file

@ -73,7 +73,7 @@ ULONG Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
Block=(PUSHORT)DeviceExt->FAT; Block=(PUSHORT)DeviceExt->FAT;
CurrentCluster = Block[CurrentCluster]; CurrentCluster = Block[CurrentCluster];
if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff) if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff)
CurrentCluster = 0xffffffff; CurrentCluster = 0xffffffff;
DPRINT("Returning %x\n",CurrentCluster); DPRINT("Returning %x\n",CurrentCluster);
return(CurrentCluster); return(CurrentCluster);
} }
@ -821,7 +821,14 @@ NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL); Status = FindFile(DeviceExt,Fcb,ParentFcb,current,NULL,NULL);
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
/* FIXME: should the VfatFCB be freed here? */ if (Fcb != NULL)
{
ExFreePool(Fcb);
}
if (ParentFcb != NULL)
{
ExFreePool(ParentFcb);
}
return(Status); return(Status);
} }
Temp = Fcb; Temp = Fcb;
@ -863,7 +870,7 @@ BOOLEAN FsdHasFileSystem(PDEVICE_OBJECT DeviceToMount)
*/ */
{ {
BootSector* Boot; BootSector* Boot;
Boot = ExAllocatePool(NonPagedPool,512); Boot = ExAllocatePool(NonPagedPool,512);
VFATReadSectors(DeviceToMount, 0, 1, (UCHAR *)Boot); VFATReadSectors(DeviceToMount, 0, 1, (UCHAR *)Boot);

View file

@ -1,271 +1,274 @@
#ifndef __INCLUDE_DDK_PSTYPES_H #ifndef __INCLUDE_DDK_PSTYPES_H
#define __INCLUDE_DDK_PSTYPES_H #define __INCLUDE_DDK_PSTYPES_H
#undef WIN32_LEAN_AND_MEAN #undef WIN32_LEAN_AND_MEAN
#include <windows.h> // might be redundant #include <windows.h> // might be redundant
#include <kernel32/heap.h> #include <kernel32/heap.h>
#include <kernel32/atom.h> #include <kernel32/atom.h>
#include <internal/hal.h> #include <internal/hal.h>
#ifndef TLS_MINIMUM_AVAILABLE #ifndef TLS_MINIMUM_AVAILABLE
#define TLS_MINIMUM_AVAILABLE (64) #define TLS_MINIMUM_AVAILABLE (64)
#endif #endif
#ifndef MAX_PATH #ifndef MAX_PATH
#define MAX_PATH (260) #define MAX_PATH (260)
#endif #endif
typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext); typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext);
typedef struct _STACK_INFORMATION typedef struct _STACK_INFORMATION
{ {
PVOID BaseAddress; PVOID BaseAddress;
PVOID UpperAddress; PVOID UpperAddress;
} STACK_INFORMATION, *PSTACK_INFORMATION; } STACK_INFORMATION, *PSTACK_INFORMATION;
typedef struct linux_sigcontext { typedef struct linux_sigcontext {
int sc_gs; int sc_gs;
int sc_fs; int sc_fs;
int sc_es; int sc_es;
int sc_ds; int sc_ds;
int sc_edi; int sc_edi;
int sc_esi; int sc_esi;
int sc_ebp; int sc_ebp;
int sc_esp; int sc_esp;
int sc_ebx; int sc_ebx;
int sc_edx; int sc_edx;
int sc_ecx; int sc_ecx;
int sc_eax; int sc_eax;
int sc_trapno; int sc_trapno;
int sc_err; int sc_err;
int sc_eip; int sc_eip;
int sc_cs; int sc_cs;
int sc_eflags; int sc_eflags;
int sc_esp_at_signal; int sc_esp_at_signal;
int sc_ss; int sc_ss;
int sc_387; int sc_387;
int sc_mask; int sc_mask;
int sc_cr2; int sc_cr2;
} TRAP_FRAME, *PTRAP_FRAME; } TRAP_FRAME, *PTRAP_FRAME;
typedef ULONG THREADINFOCLASS; typedef ULONG THREADINFOCLASS;
typedef struct _STARTUPINFOW { typedef struct _STARTUPINFOW {
DWORD cb; DWORD cb;
WCHAR WindowTitle[MAX_PATH]; WCHAR WindowTitle[MAX_PATH];
WCHAR ImageFile[MAX_PATH]; WCHAR ImageFile[MAX_PATH];
WCHAR CommandLine[MAX_PATH]; WCHAR CommandLine[MAX_PATH];
WCHAR DllPath[MAX_PATH]; WCHAR DllPath[MAX_PATH];
LPWSTR Reserved[MAX_PATH]; LPWSTR Reserved[MAX_PATH];
LPWSTR Desktop[MAX_PATH]; LPWSTR Desktop[MAX_PATH];
LPWSTR Title[MAX_PATH]; LPWSTR Title[MAX_PATH];
DWORD dwX; DWORD dwX;
DWORD dwY; DWORD dwY;
DWORD dwXSize; DWORD dwXSize;
DWORD dwYSize; DWORD dwYSize;
DWORD dwXCountChars; DWORD dwXCountChars;
DWORD dwYCountChars; DWORD dwYCountChars;
DWORD dwFillAttribute; DWORD dwFillAttribute;
DWORD dwFlags; DWORD dwFlags;
WORD wShowWindow; WORD wShowWindow;
WORD cbReserved2; WORD cbReserved2;
unsigned char * lpReserved2; unsigned char * lpReserved2;
HANDLE hStdInput; HANDLE hStdInput;
HANDLE hStdOutput; HANDLE hStdOutput;
HANDLE hStdError; HANDLE hStdError;
} PROCESSINFOW, *PPROCESSINFOW; } PROCESSINFOW, *PPROCESSINFOW;
typedef struct _LDR { typedef struct _LDR {
UCHAR Initialized; UCHAR Initialized;
UCHAR InInitializationOrderModuleList; UCHAR InInitializationOrderModuleList;
PVOID InLoadOrderModuleList; PVOID InLoadOrderModuleList;
PVOID InMemoryOrderModuleList; PVOID InMemoryOrderModuleList;
} LDR, *PLDR; } LDR, *PLDR;
typedef struct _NT_PEB typedef struct _NT_PEB
{ {
UCHAR InheritedAddressSpace; UCHAR InheritedAddressSpace;
UCHAR ReadImageFileExecOptions; UCHAR ReadImageFileExecOptions;
UCHAR BeingDebugged; UCHAR BeingDebugged;
LONG ImageBaseAddress; LONG ImageBaseAddress;
LDR Ldr; LDR Ldr;
WORD NumberOfProcessors; WORD NumberOfProcessors;
WORD NtGlobalFlag; WORD NtGlobalFlag;
PPROCESSINFOW StartupInfo; PPROCESSINFOW StartupInfo;
PHEAP ProcessHeap; PHEAP ProcessHeap;
ATOMTABLE LocalAtomTable; ATOMTABLE LocalAtomTable;
LPCRITICAL_SECTION CriticalSection; LPCRITICAL_SECTION CriticalSection;
DWORD CriticalSectionTimeout; DWORD CriticalSectionTimeout;
WORD MajorVersion; WORD MajorVersion;
WORD MinorVersion; WORD MinorVersion;
WORD BuildNumber; WORD BuildNumber;
WORD PlatformId; WORD PlatformId;
} NT_PEB, *PNT_PEB; } NT_PEB, *PNT_PEB;
typedef struct _CLIENT_ID typedef struct _CLIENT_ID
{ {
HANDLE UniqueProcess; HANDLE UniqueProcess;
HANDLE UniqueThread; HANDLE UniqueThread;
} CLIENT_ID, *PCLIENT_ID; } CLIENT_ID, *PCLIENT_ID;
typedef struct _NT_TIB { typedef struct _NT_TIB {
struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList;
PVOID StackBase; PVOID StackBase;
PVOID StackLimit; PVOID StackLimit;
PVOID SubSystemTib; PVOID SubSystemTib;
union { union {
PVOID FiberData; PVOID FiberData;
ULONG Version; ULONG Version;
} Fib; } Fib;
PVOID ArbitraryUserPointer; PVOID ArbitraryUserPointer;
struct _NT_TIB *Self; struct _NT_TIB *Self;
} NT_TIB, *PNT_TIB; } NT_TIB, *PNT_TIB;
typedef struct _NT_TEB typedef struct _NT_TEB
{ {
NT_TIB Tib; NT_TIB Tib;
CLIENT_ID Cid; CLIENT_ID Cid;
HANDLE RPCHandle; HANDLE RPCHandle;
PVOID TlsData[TLS_MINIMUM_AVAILABLE]; PVOID TlsData[TLS_MINIMUM_AVAILABLE];
DWORD dwTlsIndex; DWORD dwTlsIndex;
NT_PEB *Peb; NT_PEB *Peb;
DWORD LastErrorCode; DWORD LastErrorCode;
NTSTATUS LastStatusValue; NTSTATUS LastStatusValue;
DWORD LockCount; DWORD LockCount;
UCHAR HardErrorMode; UCHAR HardErrorMode;
} NT_TEB; } NT_TEB;
typedef struct _KTHREAD typedef struct _KTHREAD
{ {
DISPATCHER_HEADER DispatcherHeader; DISPATCHER_HEADER DispatcherHeader;
TIME ElapsedTime; TIME ElapsedTime;
TIME KernelTime; TIME KernelTime;
TIME UserTime; TIME UserTime;
STACK_INFORMATION StackInformation; STACK_INFORMATION StackInformation;
PVOID ServiceDescriptorTable; // points to KeServiceDescriptorTable PVOID ServiceDescriptorTable; // points to KeServiceDescriptorTable
KAFFINITY Affinity; KAFFINITY Affinity;
KPRIORITY CurrentPriority; KPRIORITY CurrentPriority;
KPRIORITY BasePriority; KPRIORITY BasePriority;
ULONG Quantum; ULONG Quantum;
UCHAR ThreadState; //Thread state is a typeless enum, otherwise it should be const integer UCHAR ThreadState; //Thread state is a typeless enum, otherwise it should be const integer
ULONG FreezeCount; ULONG FreezeCount;
LONG SuspendCount; LONG SuspendCount;
PTRAP_FRAME TrapFrame; PTRAP_FRAME TrapFrame;
PVOID *Tls; PVOID *Tls;
KWAIT_BLOCK WaitBlock[4]; KWAIT_BLOCK WaitBlock[4];
struct _KMUTANT* MutantList; struct _KMUTANT* MutantList;
PLIST_ENTRY ApcList; PLIST_ENTRY ApcList;
UCHAR KernelApcDisable; UCHAR KernelApcDisable;
KTIMER TimerBlock; KTIMER TimerBlock;
KDEVICE_QUEUE DeviceQueue; KDEVICE_QUEUE DeviceQueue;
NT_TEB* Teb; NT_TEB* Teb;
/* /*
* PURPOSE: CPU state * PURPOSE: CPU state
* NOTE: I have temporarily added this to give somewhere to store * NOTE: I have temporarily added this to give somewhere to store
* cpu state when the thread isn't running * cpu state when the thread isn't running
*/ */
hal_thread_state Context; hal_thread_state Context;
LIST_ENTRY Entry; LIST_ENTRY Entry;
ULONG LastTick; ULONG LastTick;
} KTHREAD, *PKTHREAD; } KTHREAD, *PKTHREAD;
// According to documentation the stack should have a commited [ 1 page ] and // 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. // a reserved part [ 1 M ] but can be specified otherwise in the image file.
typedef struct _INITIAL_TEB { typedef struct _INITIAL_TEB {
PVOID StackBase; PVOID StackBase;
PVOID StackLimit; PVOID StackLimit;
PVOID StackCommit; PVOID StackCommit;
PVOID StackCommitMax; PVOID StackCommitMax;
PVOID StackReserved; PVOID StackReserved;
} INITIAL_TEB, *PINITIAL_TEB; } INITIAL_TEB, *PINITIAL_TEB;
// TopLevelIrp can be one of the following values: // TopLevelIrp can be one of the following values:
// FIXME I belong somewhere else // FIXME I belong somewhere else
#define FSRTL_FSP_TOP_LEVEL_IRP (0x01) #define FSRTL_FSP_TOP_LEVEL_IRP (0x01)
#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02) #define FSRTL_CACHE_TOP_LEVEL_IRP (0x02)
#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03) #define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03)
#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04) #define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04)
#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04) #define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04)
typedef struct _TOP_LEVEL_IRP typedef struct _TOP_LEVEL_IRP
{ {
PIRP TopLevelIrp; PIRP TopLevelIrp;
ULONG TopLevelIrpConst; ULONG TopLevelIrpConst;
} TOP_LEVEL_IRP; } TOP_LEVEL_IRP;
typedef struct _ETHREAD { typedef struct _ETHREAD {
KTHREAD Tcb; KTHREAD Tcb;
TIME CreateTime; TIME CreateTime;
TIME ExitTime; TIME ExitTime;
NTSTATUS ExitStatus; NTSTATUS ExitStatus;
LIST_ENTRY PostBlockList; LIST_ENTRY PostBlockList;
LIST_ENTRY TerminationPortList; LIST_ENTRY TerminationPortList;
ULONG ActiveTimerListLock; ULONG ActiveTimerListLock;
PVOID ActiveTimerListHead; PVOID ActiveTimerListHead;
CLIENT_ID Cid; CLIENT_ID Cid;
PLARGE_INTEGER LpcReplySemaphore; PLARGE_INTEGER LpcReplySemaphore;
PVOID LpcReplyMessage; PVOID LpcReplyMessage;
PLARGE_INTEGER LpcReplyMessageId; PLARGE_INTEGER LpcReplyMessageId;
PVOID ImpersonationInfo; PVOID ImpersonationInfo;
LIST_ENTRY IrpList; // LIST_ENTRY IrpList; //
TOP_LEVEL_IRP TopLevelIrp; TOP_LEVEL_IRP TopLevelIrp;
ULONG ReadClusterSize; ULONG ReadClusterSize;
UCHAR ForwardClusterOnly; UCHAR ForwardClusterOnly;
UCHAR DisablePageFaultClustering; UCHAR DisablePageFaultClustering;
UCHAR DeadThread; UCHAR DeadThread;
UCHAR HasTerminated; UCHAR HasTerminated;
ACCESS_MASK GrantedAccess; ACCESS_MASK GrantedAccess;
struct _EPROCESS* ThreadsProcess; struct _EPROCESS* ThreadsProcess;
PKSTART_ROUTINE StartAddress; PKSTART_ROUTINE StartAddress;
LPTHREAD_START_ROUTINE Win32StartAddress; // Should Specify a win32 start func LPTHREAD_START_ROUTINE Win32StartAddress; // Should Specify a win32 start func
UCHAR LpcExitThreadCalled; UCHAR LpcExitThreadCalled;
UCHAR HardErrorsAreDisabled; UCHAR HardErrorsAreDisabled;
} ETHREAD, *PETHREAD; } ETHREAD, *PETHREAD;
typedef struct _KPROCESS typedef struct _KPROCESS
{ {
DISPATCHER_HEADER DispatcherHeader; DISPATCHER_HEADER DispatcherHeader;
PVOID PageTableDirectory; // FIXME: I shoud point to a PTD PVOID PageTableDirectory; // FIXME: I shoud point to a PTD
TIME ElapsedTime; TIME ElapsedTime;
TIME KernelTime; TIME KernelTime;
TIME UserTime; TIME UserTime;
LIST_ENTRY InMemoryList; LIST_ENTRY InMemoryList;
LIST_ENTRY SwappedOutList; LIST_ENTRY SwappedOutList;
KSPIN_LOCK SpinLock; KSPIN_LOCK SpinLock;
KAFFINITY Affinity; KAFFINITY Affinity;
ULONG StackCount; ULONG StackCount;
KPRIORITY BasePriority; KPRIORITY BasePriority;
ULONG DefaultThreadQuantum; ULONG DefaultThreadQuantum;
UCHAR ProcessState; UCHAR ProcessState;
ULONG ThreadSeed; ULONG ThreadSeed;
UCHAR DisableBoost; UCHAR DisableBoost;
/* /*
* Added by David Welch (welch@mcmail.com) * Added by David Welch (welch@mcmail.com)
*/ */
LIST_ENTRY MemoryAreaList; LIST_ENTRY MemoryAreaList;
HANDLE_TABLE HandleTable; HANDLE_TABLE HandleTable;
} KPROCESS, *PKPROCESS; } KPROCESS, *PKPROCESS;
typedef struct _EPROCESS typedef struct _EPROCESS
{ {
KPROCESS Pcb; KPROCESS Pcb;
} EPROCESS, *PEPROCESS; } EPROCESS, *PEPROCESS;
#endif /* __INCLUDE_DDK_PSTYPES_H */ #define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2)
#endif /* __INCLUDE_DDK_PSTYPES_H */

View file

@ -1,57 +1,58 @@
#ifndef __INCLUDE_INTERNAL_PSMGR_H #ifndef __INCLUDE_INTERNAL_PSMGR_H
#define __INCLUDE_INTERNAL_PSMGR_H #define __INCLUDE_INTERNAL_PSMGR_H
#include <internal/hal.h> #include <internal/hal.h>
extern PEPROCESS SystemProcess; extern PEPROCESS SystemProcess;
extern HANDLE SystemProcessHandle; extern HANDLE SystemProcessHandle;
extern POBJECT_TYPE PsThreadType; extern POBJECT_TYPE PsThreadType;
extern POBJECT_TYPE PsProcessType; extern POBJECT_TYPE PsProcessType;
void PsInitThreadManagment(void); void PsInitThreadManagment(void);
VOID PsInitProcessManagment(VOID); VOID PsInitProcessManagment(VOID);
VOID PsInitIdleThread(VOID); VOID PsInitIdleThread(VOID);
VOID PsDispatchThread(VOID); VOID PsDispatchThread(VOID);
VOID PiTerminateProcessThreads(PEPROCESS Process, NTSTATUS ExitStatus);
/*
* PURPOSE: Thread states /*
*/ * PURPOSE: Thread states
enum */
{ enum
/* {
* PURPOSE: Don't touch /*
*/ * PURPOSE: Don't touch
THREAD_STATE_INVALID, */
THREAD_STATE_INVALID,
/*
* PURPOSE: Waiting to be dispatched /*
*/ * PURPOSE: Waiting to be dispatched
THREAD_STATE_RUNNABLE, */
THREAD_STATE_RUNNABLE,
/*
* PURPOSE: Currently running /*
*/ * PURPOSE: Currently running
THREAD_STATE_RUNNING, */
THREAD_STATE_RUNNING,
/*
* PURPOSE: Doesn't want to run /*
*/ * PURPOSE: Doesn't want to run
THREAD_STATE_SUSPENDED, */
THREAD_STATE_SUSPENDED,
/*
* Waiting to be freed /*
*/ * Waiting to be freed
THREAD_STATE_TERMINATED, */
}; THREAD_STATE_TERMINATED,
};
/*
* Functions the HAL must provide /*
*/ * Functions the HAL must provide
*/
void HalInitFirstTask(PETHREAD thread);
BOOLEAN HalInitTask(PETHREAD thread, PKSTART_ROUTINE fn, PVOID StartContext); void HalInitFirstTask(PETHREAD thread);
void HalTaskSwitch(PKTHREAD thread); BOOLEAN HalInitTask(PETHREAD thread, PKSTART_ROUTINE fn, PVOID StartContext);
NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context); void HalTaskSwitch(PKTHREAD thread);
NTSTATUS HalInitTaskWithContext(PETHREAD Thread, PCONTEXT Context);
#endif
#endif

View file

@ -1,5 +1,11 @@
#include <windows.h> #include <windows.h>
#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 dprintf(char* fmt, ...);
void aprintf(char* fmt, ...); void aprintf(char* fmt, ...);

View file

@ -1,51 +1,52 @@
/* /*
* Adapted from linux for the reactos kernel, march 1998 -- David Welch * Adapted from linux for the reactos kernel, march 1998 -- David Welch
* Added wide character string functions, june 1998 -- Boudewijn Dekker * Added wide character string functions, june 1998 -- Boudewijn Dekker
* Removed extern specifier from ___wcstok, june 1998 -- Boudewijn Dekker * Removed extern specifier from ___wcstok, june 1998 -- Boudewijn Dekker
* Added wcsicmp and wcsnicmp -- Boudewijn Dekker * Added wcsicmp and wcsnicmp -- Boudewijn Dekker
*/ */
#ifndef _LINUX_WSTRING_H_ #ifndef _LINUX_WSTRING_H_
#define _LINUX_WSTRING_H_ #define _LINUX_WSTRING_H_
#include <types.h> /* for size_t */ #include <types.h> /* for size_t */
typedef unsigned short wchar_t; typedef unsigned short wchar_t;
#ifndef NULL #ifndef NULL
#define NULL ((void *) 0) #define NULL ((void *) 0)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern wchar_t * ___wcstok; wchar_t* wstrdup(const wchar_t* src);
extern wchar_t * wcscpy(wchar_t *,const wchar_t *); extern wchar_t * ___wcstok;
extern wchar_t * wcsncpy(wchar_t *,const wchar_t *, __kernel_size_t); extern wchar_t * wcscpy(wchar_t *,const wchar_t *);
extern wchar_t * wcscat(wchar_t *, const wchar_t *); extern wchar_t * wcsncpy(wchar_t *,const wchar_t *, __kernel_size_t);
extern wchar_t * wcsncat(wchar_t *, const wchar_t *, __kernel_size_t); extern wchar_t * wcscat(wchar_t *, const wchar_t *);
extern int wcscmp(const wchar_t *,const wchar_t *); extern wchar_t * wcsncat(wchar_t *, const wchar_t *, __kernel_size_t);
extern int wcsncmp(const wchar_t *,const wchar_t *,__kernel_size_t); extern int wcscmp(const wchar_t *,const wchar_t *);
wchar_t* wcschr(const wchar_t* str, wchar_t ch); extern int wcsncmp(const wchar_t *,const wchar_t *,__kernel_size_t);
extern wchar_t * wcsrchr(const wchar_t *,wchar_t); wchar_t* wcschr(const wchar_t* str, wchar_t ch);
extern wchar_t * wcspbrk(const wchar_t *,const wchar_t *); extern wchar_t * wcsrchr(const wchar_t *,wchar_t);
extern wchar_t * wcstok(wchar_t *,const wchar_t *); extern wchar_t * wcspbrk(const wchar_t *,const wchar_t *);
extern wchar_t * wcsstr(const wchar_t *,const wchar_t *); extern wchar_t * wcstok(wchar_t *,const wchar_t *);
extern size_t wcsnlen(const wchar_t * s, size_t count); extern wchar_t * wcsstr(const wchar_t *,const wchar_t *);
extern int wcsicmp(const wchar_t* cs,const wchar_t * ct); extern size_t wcsnlen(const wchar_t * s, size_t count);
extern int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count); extern int wcsicmp(const wchar_t* cs,const wchar_t * ct);
extern size_t wcscspn(const wchar_t *, const wchar_t *); extern int wcsnicmp(const wchar_t* cs,const wchar_t * ct, size_t count);
extern size_t wcslen(const wchar_t *); extern size_t wcscspn(const wchar_t *, const wchar_t *);
extern size_t wcsspn(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); extern unsigned long wstrlen(PWSTR);
WCHAR wtolower(WCHAR c); WCHAR wtoupper(WCHAR c);
WCHAR wtolower(WCHAR c);
#ifdef __cplusplus
} #ifdef __cplusplus
#endif }
#endif
#endif
#endif

View file

@ -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 <colin@bird.fu.is.saga-u.ac.jp>
;
; 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

View file

@ -17,7 +17,7 @@ STDLIB_OBJECTS = stdlib/malloc.o
OBJECTS = $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS) OBJECTS = $(STRING_OBJECTS) $(STDIO_OBJECTS) $(STDLIB_OBJECTS)
crtdll.a: $(OBJECTS) crtdll.a: $(OBJECTS)
$(AR) vrcs crtdll.a $(OBJECTS) $(AR) rcs crtdll.a $(OBJECTS)
dummy: dummy:

View file

@ -2,15 +2,15 @@
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/kernel32/file/create.c * FILE: lib/kernel32/file/create.c
* PURPOSE: Directory functions * PURPOSE: File create/open functions
* PROGRAMMER: Ariadne ( ariadne@xs4all.nl) * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
GetTempFileName is modified from WINE [ Alexandre Juiliard ] * GetTempFileName is modified from WINE [ Alexandre Juiliard ]
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 01/11/98 * Created 01/11/98
*/ */
/* INCLUDES *****************************************************************/
#undef WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <wstring.h> #include <wstring.h>
@ -18,6 +18,11 @@
#include <kernel32/li.h> #include <kernel32/li.h>
#include <ddk/rtl.h> #include <ddk/rtl.h>
#define NDEBUG
#include <kernel32/kernel32.h>
/* FUNCTIONS ****************************************************************/
HANDLE STDCALL CreateFileA(LPCSTR lpFileName, HANDLE STDCALL CreateFileA(LPCSTR lpFileName,
DWORD dwDesiredAccess, DWORD dwDesiredAccess,
DWORD dwShareMode, DWORD dwShareMode,
@ -30,7 +35,7 @@ HANDLE STDCALL CreateFileA(LPCSTR lpFileName,
WCHAR FileNameW[MAX_PATH]; WCHAR FileNameW[MAX_PATH];
ULONG i = 0; ULONG i = 0;
OutputDebugStringA("CreateFileA\n"); DPRINT("CreateFileA\n");
while ((*lpFileName)!=0 && i < MAX_PATH) while ((*lpFileName)!=0 && i < MAX_PATH)
{ {
@ -69,7 +74,7 @@ HANDLE STDCALL CreateFileW(LPCWSTR lpFileName,
UINT Len = 0; UINT Len = 0;
WCHAR CurrentDir[MAX_PATH]; WCHAR CurrentDir[MAX_PATH];
OutputDebugStringA("CreateFileW\n"); DPRINT("CreateFileW\n");
if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED)) if (!(dwFlagsAndAttributes & FILE_FLAG_OVERLAPPED))
{ {
@ -83,16 +88,16 @@ HANDLE STDCALL CreateFileW(LPCWSTR lpFileName,
PathNameW[3] = '\\'; PathNameW[3] = '\\';
PathNameW[4] = 0; PathNameW[4] = 0;
dprintf("Name %w\n",PathNameW); DPRINT("Name %w\n",PathNameW);
if (lpFileName[0] != L'\\' && lpFileName[1] != L':') if (lpFileName[0] != L'\\' && lpFileName[1] != L':')
{ {
Len = GetCurrentDirectoryW(MAX_PATH,CurrentDir); Len = GetCurrentDirectoryW(MAX_PATH,CurrentDir);
dprintf("CurrentDir %w\n",CurrentDir); DPRINT("CurrentDir %w\n",CurrentDir);
lstrcatW(PathNameW,CurrentDir); lstrcatW(PathNameW,CurrentDir);
dprintf("Name %w\n",PathNameW); DPRINT("Name %w\n",PathNameW);
} }
lstrcatW(PathNameW,lpFileName); lstrcatW(PathNameW,lpFileName);
dprintf("Name %w\n",PathNameW); DPRINT("Name %w\n",PathNameW);
FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR); FileNameString.Length = lstrlenW( PathNameW)*sizeof(WCHAR);

View file

@ -3,7 +3,6 @@
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
* FILE: lib/kernel32/file/curdir.c * FILE: lib/kernel32/file/curdir.c
* PURPOSE: Current directory functions * PURPOSE: Current directory functions
* PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 30/09/98 * Created 30/09/98
*/ */
@ -13,6 +12,9 @@
#include <windows.h> #include <windows.h>
#define NDEBUG
#include <kernel32/kernel32.h>
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
@ -46,7 +48,7 @@ DWORD STDCALL GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer)
{ {
UINT uSize; UINT uSize;
dprintf("CurrentDirectoryW %w\n",CurrentDirectoryW); DPRINT("CurrentDirectoryW %w\n",CurrentDirectoryW);
if ( lpBuffer == NULL ) if ( lpBuffer == NULL )
return 0; return 0;
@ -54,7 +56,7 @@ DWORD STDCALL GetCurrentDirectoryW(DWORD nBufferLength, LPWSTR lpBuffer)
if ( nBufferLength > uSize ) if ( nBufferLength > uSize )
lstrcpynW(lpBuffer,CurrentDirectoryW,uSize); lstrcpynW(lpBuffer,CurrentDirectoryW,uSize);
dprintf("GetCurrentDirectoryW() = %w\n",lpBuffer); DPRINT("GetCurrentDirectoryW() = %w\n",lpBuffer);
return uSize; return uSize;
} }
@ -63,7 +65,7 @@ BOOL STDCALL SetCurrentDirectoryA(LPCSTR lpPathName)
{ {
UINT i; UINT i;
dprintf("SetCurrentDirectoryA(lpPathName %s)\n",lpPathName); DPRINT("SetCurrentDirectoryA(lpPathName %s)\n",lpPathName);
if ( lpPathName == NULL ) if ( lpPathName == NULL )
return FALSE; return FALSE;
@ -77,17 +79,13 @@ BOOL STDCALL SetCurrentDirectoryA(LPCSTR lpPathName)
} }
CurrentDirectoryW[i] = 0; CurrentDirectoryW[i] = 0;
dprintf("CurrentDirectoryW = '%w'\n",CurrentDirectoryW); DPRINT("CurrentDirectoryW = '%w'\n",CurrentDirectoryW);
return(TRUE); return(TRUE);
} }
WINBOOL WINBOOL STDCALL SetCurrentDirectoryW(LPCWSTR lpPathName)
STDCALL
SetCurrentDirectoryW(
LPCWSTR lpPathName
)
{ {
if ( lpPathName == NULL ) if ( lpPathName == NULL )
return FALSE; return FALSE;

View file

@ -14,6 +14,9 @@
#include <wstring.h> #include <wstring.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <kernel32/kernel32.h>
/* TYPES ********************************************************************/ /* TYPES ********************************************************************/
typedef struct _KERNEL32_FIND_FILE_DATA typedef struct _KERNEL32_FIND_FILE_DATA
@ -74,7 +77,7 @@ WINBOOL STDCALL InternalFindNextFile(HANDLE hFindFile,
TRUE, TRUE,
&(IData->PatternStr), &(IData->PatternStr),
FALSE); FALSE);
dprintf("Found %w\n",IData->FileInfo.FileName); DPRINT("Found %w\n",IData->FileInfo.FileName);
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes;
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
@ -95,7 +98,7 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName,
UNICODE_STRING DirectoryNameStr; UNICODE_STRING DirectoryNameStr;
IO_STATUS_BLOCK IoStatusBlock; IO_STATUS_BLOCK IoStatusBlock;
dprintf("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n", DPRINT("FindFirstFileW(lpFileName %w, lpFindFileData %x)\n",
lpFileName, lpFindFileData); lpFileName, lpFindFileData);
GetCurrentDirectoryW(MAX_PATH, CurrentDirectory); GetCurrentDirectoryW(MAX_PATH, CurrentDirectory);
@ -104,17 +107,17 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName,
Directory[2] = '?'; Directory[2] = '?';
Directory[3] = '\\'; Directory[3] = '\\';
Directory[4] = 0; Directory[4] = 0;
dprintf("Directory %w\n",Directory); DPRINT("Directory %w\n",Directory);
wcscat(Directory, CurrentDirectory); wcscat(Directory, CurrentDirectory);
dprintf("Directory %w\n",Directory); DPRINT("Directory %w\n",Directory);
wcscat(Directory, lpFileName); wcscat(Directory, lpFileName);
dprintf("Directory %w\n",Directory); DPRINT("Directory %w\n",Directory);
End = wcsrchr(Directory, '\\'); End = wcsrchr(Directory, '\\');
*End = 0; *End = 0;
wcscpy(Pattern, End+1); wcscpy(Pattern, End+1);
dprintf("Directory %w Pattern %w\n",Directory,Pattern); DPRINT("Directory %w Pattern %w\n",Directory,Pattern);
IData = HeapAlloc(GetProcessHeap(), IData = HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY, HEAP_ZERO_MEMORY,
@ -151,7 +154,7 @@ HANDLE STDCALL InternalFindFirstFile(LPCWSTR lpFileName,
TRUE, TRUE,
&(IData->PatternStr), &(IData->PatternStr),
FALSE); FALSE);
dprintf("Found %w\n",IData->FileInfo.FileName); DPRINT("Found %w\n",IData->FileInfo.FileName);
lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes; lpFindFileData->dwFileAttributes = IData->FileInfo.FileAttributes;
return(IData); return(IData);

View file

@ -26,11 +26,16 @@
* Put the type definitions of the heap in a seperate header. Boudewijn Dekker * Put the type definitions of the heap in a seperate header. Boudewijn Dekker
*/ */
#include <kernel32/proc.h> /* INCLUDES *****************************************************************/
#define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
#include <kernel32/proc.h>
#include <kernel32/heap.h> #include <kernel32/heap.h>
#include <internal/string.h> #include <internal/string.h>
/* GLOBALS ******************************************************************/
static HEAP_BUCKET __HeapDefaultBuckets[]= static HEAP_BUCKET __HeapDefaultBuckets[]=
{ {
@ -46,6 +51,8 @@ static HEAP_BUCKET __HeapDefaultBuckets[]=
PHEAP __ProcessHeap = NULL; PHEAP __ProcessHeap = NULL;
/* FUNCTIONS ****************************************************************/
static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end); static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end);
static BOOL __HeapDecommit(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); 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) static BOOL __HeapCommit(PHEAP pheap, LPVOID start, LPVOID end)
{ {
dprintf("__HeapCommit( 0x%lX, 0x%lX, 0x%lX)\n", DPRINT("__HeapCommit( 0x%lX, 0x%lX, 0x%lX)\n",
(ULONG) pheap, (ULONG) start, (ULONG) end); (ULONG) pheap, (ULONG) start, (ULONG) end);
if(end >= pheap->LastBlock) if(end >= pheap->LastBlock)
pheap->LastBlock=end; 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) 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); (ULONG) pheap, (ULONG) start, (ULONG) end);
#ifdef NOT #ifdef NOT
__VirtualDump(); __VirtualDump();
@ -113,7 +120,7 @@ static LPVOID __HeapAlloc(PHEAP pheap, ULONG flags, ULONG size, ULONG tag)
ULONG freesize; ULONG freesize;
ULONG allocsize; 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); pheap,flags,size,tag);
pfree=&(pheap->Start); pfree=&(pheap->Start);
@ -235,7 +242,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size)
*/ */
if(size==0) if(size==0)
{ {
dprintf("__HeapReAlloc: freeing memory\n"); DPRINT("__HeapReAlloc: freeing memory\n");
__HeapFree(pheap, flags, pold); __HeapFree(pheap, flags, pold);
return NULL; return NULL;
} }
@ -251,7 +258,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size)
#endif #endif
else if(newsize < allocsize ) else if(newsize < allocsize )
{ {
dprintf("__HeapReAlloc: shrinking memory\n"); DPRINT("__HeapReAlloc: shrinking memory\n");
/* free remaining region of memory */ /* free remaining region of memory */
prealloc->Size=size | HEAP_NORMAL_TAG; prealloc->Size=size | HEAP_NORMAL_TAG;
pnext=HEAP_NEXT(prealloc); pnext=HEAP_NEXT(prealloc);
@ -267,7 +274,7 @@ static LPVOID __HeapReAlloc(PHEAP pheap, ULONG flags, LPVOID pold, DWORD size)
} }
else if(newsize == allocsize ) else if(newsize == allocsize )
{ {
dprintf("__HeapReAlloc: no changes\n"); DPRINT("__HeapReAlloc: no changes\n");
/* nothing to do */ /* nothing to do */
prealloc->Size= size | HEAP_NORMAL_TAG; prealloc->Size= size | HEAP_NORMAL_TAG;
return pold; 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) && if(((LPVOID) pnext< pheap->End)&& HEAP_ISFREE(pnext) &&
(HEAP_SIZE(pnext) + HEAP_ADMIN_SIZE >=newsize-allocsize)) (HEAP_SIZE(pnext) + HEAP_ADMIN_SIZE >=newsize-allocsize))
{ {
dprintf("__HeapReAlloc: joining memory\n"); DPRINT("__HeapReAlloc: joining memory\n");
oldsize=HEAP_SIZE(prealloc); oldsize=HEAP_SIZE(prealloc);
prealloc->Size=size | HEAP_NORMAL_TAG; 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) 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 */ /* alloc a new piece of memory */
oldsize=HEAP_SIZE(prealloc); oldsize=HEAP_SIZE(prealloc);
pmem=__HeapAlloc(pheap, flags, size, HEAP_NORMAL_TAG); 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; 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); base,minsize,maxsize,flags);
pheap->Magic=MAGIC_HEAP; pheap->Magic=MAGIC_HEAP;
@ -670,7 +677,7 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size)
PHEAP pheap=hheap; PHEAP pheap=hheap;
LPVOID retval; 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 ); (ULONG) hheap, flags, (ULONG) size );
#ifdef NOT #ifdef NOT
HeapValidate(hheap, 0, 0); HeapValidate(hheap, 0, 0);
@ -686,7 +693,7 @@ LPVOID STDCALL HeapAlloc(HANDLE hheap, DWORD flags, DWORD size)
if( (flags | pheap->Flags) & HEAP_NO_SERIALIZE ) if( (flags | pheap->Flags) & HEAP_NO_SERIALIZE )
LeaveCriticalSection(&(pheap->Synchronize)); LeaveCriticalSection(&(pheap->Synchronize));
aprintf("HeapAlloc returns 0x%lX\n", (ULONG) retval); DPRINT("HeapAlloc returns 0x%lX\n", (ULONG) retval);
return 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); PHEAP_BLOCK pfree=((PHEAP_BLOCK)ptr-1);
LPVOID retval; 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 ); (ULONG) hheap, flags, (ULONG) ptr, size );
#ifdef NOT #ifdef NOT
HeapValidate(hheap, 0, 0); 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); PHEAP_BLOCK pfree=(PHEAP_BLOCK)((LPVOID)ptr-HEAP_ADMIN_SIZE);
BOOL retval; 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 ); (ULONG) hheap, flags, (ULONG) ptr );
#ifdef NOT #ifdef NOT
HeapValidate(hheap, 0, 0); HeapValidate(hheap, 0, 0);
@ -756,7 +763,7 @@ WINBOOL STDCALL HeapFree(HANDLE hheap, DWORD flags, LPVOID ptr)
*********************************************************************/ *********************************************************************/
HANDLE WINAPI GetProcessHeap(VOID) HANDLE WINAPI GetProcessHeap(VOID)
{ {
aprintf("GetProcessHeap()\n"); DPRINT("GetProcessHeap()\n");
return (HANDLE) __ProcessHeap; return (HANDLE) __ProcessHeap;
} }
@ -771,7 +778,7 @@ DWORD WINAPI GetProcessHeaps(DWORD maxheaps, PHANDLE phandles )
DWORD retval; DWORD retval;
PHEAP pheap; PHEAP pheap;
aprintf("GetProcessHeaps( %u, 0x%lX )\n", maxheaps, (ULONG) phandles ); DPRINT("GetProcessHeaps( %u, 0x%lX )\n", maxheaps, (ULONG) phandles );
pheap= __ProcessHeap; pheap= __ProcessHeap;
retval=0; retval=0;
@ -801,7 +808,7 @@ BOOL WINAPI HeapLock(HANDLE hheap)
{ {
PHEAP pheap=hheap; PHEAP pheap=hheap;
aprintf("HeapLock( 0x%lX )\n", (ULONG) hheap ); DPRINT("HeapLock( 0x%lX )\n", (ULONG) hheap );
EnterCriticalSection(&(pheap->Synchronize)); EnterCriticalSection(&(pheap->Synchronize));
return TRUE; return TRUE;
@ -815,7 +822,7 @@ BOOL WINAPI HeapUnlock(HANDLE hheap)
{ {
PHEAP pheap=hheap; PHEAP pheap=hheap;
aprintf("HeapUnlock( 0x%lX )\n", (ULONG) hheap ); DPRINT("HeapUnlock( 0x%lX )\n", (ULONG) hheap );
LeaveCriticalSection(&(pheap->Synchronize)); LeaveCriticalSection(&(pheap->Synchronize));
return TRUE; return TRUE;
@ -866,7 +873,7 @@ DWORD WINAPI HeapSize(HANDLE hheap, DWORD flags, LPCVOID pmem)
PHEAP_BLOCK palloc=((PHEAP_BLOCK)pmem-1); PHEAP_BLOCK palloc=((PHEAP_BLOCK)pmem-1);
DWORD retval=0; 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 ); (ULONG) hheap, flags, (ULONG) pmem );
if(pheap->Magic!=MAGIC_HEAP) if(pheap->Magic!=MAGIC_HEAP)
@ -924,7 +931,7 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
pnext=HEAP_NEXT(pcheck); pnext=HEAP_NEXT(pcheck);
if((pprev)&&(HEAP_PREV(pcheck)!=pprev)) 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", " previous region 0x%lX, list says 0x%lX\n",
(ULONG)pcheck, (ULONG)pprev, (ULONG) HEAP_PREV(pcheck)); (ULONG)pcheck, (ULONG)pprev, (ULONG) HEAP_PREV(pcheck));
return FALSE; return FALSE;
@ -948,13 +955,13 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
pnextfrag=(PHEAP_FRAGMENT)((LPVOID)pfrag+add); pnextfrag=(PHEAP_FRAGMENT)((LPVOID)pfrag+add);
if(pfrag->Magic!=HEAP_FRAG_MAGIC) 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); " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev);
return FALSE; return FALSE;
} }
if(pfrag->Number!=i) 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); " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev);
return FALSE; return FALSE;
} }
@ -962,7 +969,7 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
number++; number++;
if(pfrag->Sub!=psub) 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); " previous region 0x%lX\n", i, (ULONG)pcheck, (ULONG)pprev);
return FALSE; return FALSE;
} }
@ -971,11 +978,11 @@ BOOL WINAPI HeapValidate(HANDLE hheap, DWORD flags, LPCVOID pmem)
} }
if(number!=psub->NumberFree) 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); " previous region 0x%lX\n", (ULONG)pcheck, (ULONG)pprev);
return FALSE; return FALSE;
} }
dprintf("HeapValidate: [0x%08lX-0x%08lX] suballocated," DPRINT("HeapValidate: [0x%08lX-0x%08lX] suballocated,"
" bucket size=%d, bitmap=0x%08lX\n", " bucket size=%d, bitmap=0x%08lX\n",
(ULONG) pcheck, (ULONG) pnext, pbucket->Size, psub->Bitmap); (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)) 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", " previous region 0x%lX\n",
(ULONG) pcheck, (ULONG) pprev); (ULONG) pcheck, (ULONG) pprev);
return FALSE; return FALSE;
} }
dprintf("HeapValidate: [0x%08lX-0x%08lX] free\n", DPRINT("HeapValidate: [0x%08lX-0x%08lX] free\n",
(ULONG) pcheck, (ULONG) pnext ); (ULONG) pcheck, (ULONG) pnext );
} }
else if(HEAP_ISNORMAL(pcheck)) 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 ); (ULONG) pcheck, (ULONG) pnext );
} }
else 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, " previous region 0x%lX\n", pcheck->Size>>28,
(ULONG)pcheck, (ULONG)pprev); (ULONG)pcheck, (ULONG)pprev);
return FALSE; return FALSE;

View file

@ -1,11 +1,13 @@
#include <windows.h> #include <windows.h>
#define NDEBUG
#include <kernel32/kernel32.h> #include <kernel32/kernel32.h>
VOID CopyMemory(PVOID Destination, CONST VOID* Source, DWORD Length) VOID CopyMemory(PVOID Destination, CONST VOID* Source, DWORD Length)
{ {
DWORD i; DWORD i;
dprintf("CopyMemory(Destination %x, Source %x, Length %d)\n", DPRINT("CopyMemory(Destination %x, Source %x, Length %d)\n",
Destination,Source,Length); Destination,Source,Length);
for (i=0; i<Length; i++) for (i=0; i<Length; i++)

View file

@ -584,19 +584,9 @@ FlushInstructionCache(
return TRUE; return TRUE;
} }
VOID VOID STDCALL ExitProcess(UINT uExitCode)
STDCALL {
ExitProcess( NtTerminateProcess(NtCurrentProcess() ,uExitCode);
UINT uExitCode
)
{
NtTerminateProcess(
NtCurrentProcess() ,
uExitCode
);
} }
VOID VOID

View file

@ -172,33 +172,33 @@ WaitForSingleObject(
return WaitForSingleObjectEx(hHandle,dwMilliseconds,FALSE); return WaitForSingleObjectEx(hHandle,dwMilliseconds,FALSE);
} }
DWORD DWORD STDCALL WaitForSingleObjectEx(HANDLE hHandle,
STDCALL DWORD dwMilliseconds,
WaitForSingleObjectEx( BOOL bAlertable)
HANDLE hHandle,
DWORD dwMilliseconds,
BOOL bAlertable
)
{ {
NTSTATUS errCode; NTSTATUS errCode;
LARGE_INTEGER Time; PLARGE_INTEGER TimePtr;
DWORD retCode; LARGE_INTEGER Time;
DWORD retCode;
if (dwMilliseconds == INFINITE)
{
TimePtr = NULL;
}
else
{
SET_LARGE_INTEGER_LOW_PART(Time,dwMilliseconds); SET_LARGE_INTEGER_LOW_PART(Time,dwMilliseconds);
TimePtr = &Time;
}
errCode = NtWaitForSingleObject( errCode = NtWaitForSingleObject(hHandle,
hHandle, (BOOLEAN) bAlertable,
(BOOLEAN) bAlertable, TimePtr);
&Time
); retCode = RtlNtStatusToDosError(errCode);
SetLastError(retCode);
retCode = RtlNtStatusToDosError(errCode); return retCode;
SetLastError(retCode);
return retCode;
} }
DWORD DWORD
@ -243,4 +243,4 @@ WaitForMultipleObjectsEx(
return retCode; return retCode;
} }

View file

@ -257,16 +257,22 @@ asmlinkage void exception_handler(unsigned int edi,
VOID KeDumpStackFrames(ULONG DummyArg) VOID KeDumpStackFrames(ULONG DummyArg)
{ {
PULONG Stack = ((PULONG)&DummyArg)[-1]; PULONG Stack = &((&DummyArg)[-1]);
ULONG i; ULONG i;
Stack = (PVOID)(((ULONG)Stack) & (~0x3));
DbgPrint("Frames:\n"); DbgPrint("Frames:\n");
for (i=0; i<32; i++) for (i=0; i<1024; i++)
{ {
if (Stack[i] > KERNEL_BASE) if (Stack[i] > KERNEL_BASE && Stack[i] < ((ULONG)&etext))
{ {
DbgPrint("%.8x ",Stack[i]); DbgPrint("%.8x ",Stack[i]);
} }
if (Stack[i] == 0xceafbeef)
{
DbgPrint("IRQ ");
}
} }
DbgPrint("\n"); DbgPrint("\n");
} }

View file

@ -19,6 +19,9 @@ _irq_handler_%1:
push ds push ds
push es push es
mov eax,0xceafbeef
push eax
; ;
; Load DS ; Load DS
; ;
@ -45,6 +48,9 @@ _irq_handler_%1:
; Restore stack, registers and return to interrupted routine ; Restore stack, registers and return to interrupted routine
; ;
pop eax pop eax
pop eax
pop es pop es
pop ds pop ds
popa popa
@ -59,12 +65,17 @@ _irq_handler_%1:
; ;
pusha pusha
push ds push ds
push es
mov eax,0xceafbeef
push eax
; ;
; Load DS ; Load DS
; ;
mov ax,KERNEL_DS mov ax,KERNEL_DS
mov ds,ax mov ds,ax
mov es,ax
; ;
; Mask the related vector at the PIC ; Mask the related vector at the PIC
@ -83,6 +94,10 @@ _irq_handler_%1:
; Restore stack, registers and return to the interrupted routine ; Restore stack, registers and return to the interrupted routine
; ;
pop eax pop eax
pop eax
pop es
pop ds pop ds
popa popa
iret iret

View file

@ -3,7 +3,7 @@
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/io/create.c * FILE: ntoskrnl/io/create.c
* PURPOSE: Handling file create/open apis * PURPOSE: Handling file create/open apis
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY: * UPDATE HISTORY:
* 24/05/98: Created * 24/05/98: Created
*/ */
@ -117,6 +117,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
if (Status != STATUS_SUCCESS && Status != STATUS_FS_QUERY_REQUIRED) if (Status != STATUS_SUCCESS && Status != STATUS_FS_QUERY_REQUIRED)
{ {
DPRINT("%s() = Failed to find object\n",__FUNCTION__); DPRINT("%s() = Failed to find object\n",__FUNCTION__);
ObDereferenceObject(FileObject);
ZwClose(*FileHandle); ZwClose(*FileHandle);
*FileHandle=0; *FileHandle=0;
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
@ -134,7 +135,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
FileObject->Flags = FileObject->Flags | FO_DIRECT_DEVICE_OPEN; FileObject->Flags = FileObject->Flags | FO_DIRECT_DEVICE_OPEN;
FileObject->FileName.Buffer = ExAllocatePool(NonPagedPool, FileObject->FileName.Buffer = ExAllocatePool(NonPagedPool,
ObjectAttributes->ObjectName->Length); ObjectAttributes->ObjectName->Length);
FileObject->FileName.Length = ObjectAttributes->Length; FileObject->FileName.Length = ObjectAttributes->ObjectName->Length;
RtlCopyUnicodeString(&(FileObject->FileName), RtlCopyUnicodeString(&(FileObject->FileName),
ObjectAttributes->ObjectName); ObjectAttributes->ObjectName);
} }
@ -146,7 +147,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
if (DeviceObject->DeviceType != FILE_DEVICE_FILE_SYSTEM && if (DeviceObject->DeviceType != FILE_DEVICE_FILE_SYSTEM &&
DeviceObject->DeviceType != FILE_DEVICE_DISK) DeviceObject->DeviceType != FILE_DEVICE_DISK)
{ {
CHECKPOINT; ObDereferenceObject(FileObject);
ZwClose(*FileHandle); ZwClose(*FileHandle);
*FileHandle=0; *FileHandle=0;
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
@ -158,7 +159,7 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
Status = IoTryToMountStorageDevice(DeviceObject); Status = IoTryToMountStorageDevice(DeviceObject);
if (Status!=STATUS_SUCCESS) if (Status!=STATUS_SUCCESS)
{ {
CHECKPOINT; ObDereferenceObject(FileObject);
ZwClose(*FileHandle); ZwClose(*FileHandle);
*FileHandle=0; *FileHandle=0;
return(Status); return(Status);
@ -167,13 +168,13 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
} }
DPRINT("Remainder %x\n",Remainder); DPRINT("Remainder %x\n",Remainder);
DPRINT("Remainder %w\n",Remainder); DPRINT("Remainder %w\n",Remainder);
FileObject->FileName.Buffer = ExAllocatePool(NonPagedPool, DPRINT("FileObject->FileName.Buffer %w\n",FileObject->FileName.Buffer);
wstrlen(Remainder)); RtlInitUnicodeString(&(FileObject->FileName),wstrdup(Remainder));
RtlInitUnicodeString(&(FileObject->FileName),Remainder);
DPRINT("FileObject->FileName.Buffer %x %w\n", DPRINT("FileObject->FileName.Buffer %x %w\n",
FileObject->FileName.Buffer,FileObject->FileName.Buffer); FileObject->FileName.Buffer,FileObject->FileName.Buffer);
} }
CHECKPOINT; CHECKPOINT;
DPRINT("FileObject->FileName.Buffer %x\n",FileObject->FileName.Buffer);
if (CreateOptions & FILE_SYNCHRONOUS_IO_ALERT) if (CreateOptions & FILE_SYNCHRONOUS_IO_ALERT)
{ {
@ -194,6 +195,8 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (Irp==NULL) if (Irp==NULL)
{ {
ExFreePool(FileObject->FileName.Buffer);
ObDereferenceObject(FileObject);
ZwClose(*FileHandle); ZwClose(*FileHandle);
*FileHandle=0; *FileHandle=0;
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
@ -215,6 +218,9 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle,
if (Status!=STATUS_SUCCESS) if (Status!=STATUS_SUCCESS)
{ {
DPRINT("FileObject->FileName.Buffer %x\n",FileObject->FileName.Buffer);
ExFreePool(FileObject->FileName.Buffer);
ObDereferenceObject(FileObject);
ZwClose(*FileHandle); ZwClose(*FileHandle);
*FileHandle=0; *FileHandle=0;
} }

View file

@ -58,9 +58,11 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
PIO_STACK_LOCATION StackPtr; PIO_STACK_LOCATION StackPtr;
KEVENT Event; KEVENT Event;
assert(KeGetCurrentIrql()==PASSIVE_LEVEL);
DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, " DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, "
"IoStatusBlock %x)\n", "IoStatusBlock %x)\n",
FileHandle,Buffer,Length,ByteOffset,IoStatusBlock); FileHandle,Buffer,Length,ByteOffset,IoStatusBlock);
Status = ObReferenceObjectByHandle(FileHandle, Status = ObReferenceObjectByHandle(FileHandle,
FILE_READ_DATA, FILE_READ_DATA,
@ -70,6 +72,8 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
NULL); NULL);
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
DPRINT("ZwReadFile() =");
DbgPrintErrorMessage(Status);
return(Status); return(Status);
} }
assert(FileObject != NULL); assert(FileObject != NULL);

View file

@ -33,7 +33,8 @@ NTSTATUS IoInitializeTimer(PDEVICE_OBJECT DeviceObject,
{ {
DeviceObject->Timer = ExAllocatePool(NonPagedPool,sizeof(IO_TIMER)); DeviceObject->Timer = ExAllocatePool(NonPagedPool,sizeof(IO_TIMER));
KeInitializeTimer(&(DeviceObject->Timer->timer)); KeInitializeTimer(&(DeviceObject->Timer->timer));
KeInitializeDpc(&(DeviceObject->Timer->dpc),(PKDEFERRED_ROUTINE)TimerRoutine,Context); KeInitializeDpc(&(DeviceObject->Timer->dpc),
(PKDEFERRED_ROUTINE)TimerRoutine,Context);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -21,7 +21,10 @@ VOID KiDispatchInterrupt(ULONG irq)
* level than DISPATCH_LEVEL * level than DISPATCH_LEVEL
*/ */
{ {
KeExpireTimers(); if (irq == 0)
{
KeExpireTimers();
}
KeDrainDpcQueue(); KeDrainDpcQueue();
PsDispatchThread(); PsDispatchThread();
} }

View file

@ -54,7 +54,9 @@ void KeDrainDpcQueue(void)
PLIST_ENTRY current_entry; PLIST_ENTRY current_entry;
PKDPC current; PKDPC current;
KIRQL oldlvl; KIRQL oldlvl;
DPRINT("KeDrainDpcQueue()\n");
KeAcquireSpinLockAtDpcLevel(&DpcQueueLock); KeAcquireSpinLockAtDpcLevel(&DpcQueueLock);
KeRaiseIrql(HIGH_LEVEL,&oldlvl); KeRaiseIrql(HIGH_LEVEL,&oldlvl);
current_entry = RemoveHeadList(&DpcQueueHead); current_entry = RemoveHeadList(&DpcQueueHead);

View file

@ -146,16 +146,20 @@ NTSTATUS STDCALL ZwQueryPerformanceCounter(IN PLARGE_INTEGER Counter,
} }
NTSTATUS NTSTATUS KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval)
KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval)
{ {
assert(Thread != NULL); assert(Thread != NULL);
assert(Interval != NULL); assert(Interval != NULL);
KeInitializeTimer(&(Thread->TimerBlock)); DPRINT("KeAddThreadTimeout(Thread %x, Interval %x)\n",Thread,Interval);
KeSetTimer(&(Thread->TimerBlock),*Interval,NULL);
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; KIRQL oldlvl;
DPRINT("KeSetTimerEx(Timer %x)\n",Timer);
KeAcquireSpinLock(&timer_list_lock,&oldlvl); KeAcquireSpinLock(&timer_list_lock,&oldlvl);
Timer->dpc=Dpc; Timer->dpc=Dpc;
@ -346,9 +352,11 @@ BOOLEAN KeSetTimerEx(PKTIMER Timer, LARGE_INTEGER DueTime, LONG Period,
if (Timer->running) if (Timer->running)
{ {
KeReleaseSpinLock(&timer_list_lock,oldlvl); KeReleaseSpinLock(&timer_list_lock,oldlvl);
return TRUE; 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); InsertTailList(&timer_list_head,&Timer->entry);
KeReleaseSpinLock(&timer_list_lock,oldlvl); KeReleaseSpinLock(&timer_list_lock,oldlvl);
@ -366,13 +374,17 @@ BOOLEAN KeCancelTimer(PKTIMER Timer)
{ {
KIRQL oldlvl; KIRQL oldlvl;
DPRINT("KeCancelTimer(Timer %x)\n",Timer);
KeAcquireSpinLock(&timer_list_lock,&oldlvl); KeAcquireSpinLock(&timer_list_lock,&oldlvl);
if (!Timer->running) if (!Timer->running)
{ {
KeReleaseSpinLock(&timer_list_lock,oldlvl);
return FALSE; return FALSE;
} }
RemoveEntryList(&Timer->entry); RemoveEntryList(&Timer->entry);
Timer->running = FALSE;
KeReleaseSpinLock(&timer_list_lock,oldlvl); KeReleaseSpinLock(&timer_list_lock,oldlvl);
return TRUE; return TRUE;
@ -423,6 +435,7 @@ VOID KeQueryTickCount(PLARGE_INTEGER TickCount)
static void HandleExpiredTimer(PKTIMER current) static void HandleExpiredTimer(PKTIMER current)
{ {
DPRINT("HandleExpiredTime(current %x)\n",current);
if (current->dpc!=NULL) if (current->dpc!=NULL)
{ {
DPRINT("current->dpc->DeferredRoutine %x\n", DPRINT("current->dpc->DeferredRoutine %x\n",
@ -431,6 +444,7 @@ static void HandleExpiredTimer(PKTIMER current)
current->dpc->DeferredContext, current->dpc->DeferredContext,
current->dpc->SystemArgument1, current->dpc->SystemArgument1,
current->dpc->SystemArgument2); current->dpc->SystemArgument2);
DPRINT("Finished dpc routine\n");
} }
current->signaled=TRUE; current->signaled=TRUE;
if (current->period != 0) if (current->period != 0)
@ -456,6 +470,12 @@ void KeExpireTimers(void)
PKTIMER current = CONTAINING_RECORD(current_entry,KTIMER,entry); PKTIMER current = CONTAINING_RECORD(current_entry,KTIMER,entry);
KIRQL oldlvl; 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); KeAcquireSpinLock(&timer_list_lock,&oldlvl);
while (current_entry!=(&timer_list_head)) while (current_entry!=(&timer_list_head))
@ -469,6 +489,7 @@ void KeExpireTimers(void)
current = CONTAINING_RECORD(current_entry,KTIMER,entry); current = CONTAINING_RECORD(current_entry,KTIMER,entry);
} }
KeReleaseSpinLock(&timer_list_lock,oldlvl); KeReleaseSpinLock(&timer_list_lock,oldlvl);
DPRINT("Finished KeExpireTimers()\n");
} }
extern unsigned int nr_used_blocks; extern unsigned int nr_used_blocks;
@ -511,8 +532,9 @@ BOOLEAN KiTimerInterrupt(VOID)
} }
// sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks); // sprintf(str,"%.8u %.8u",EiFreeNonPagedPool,ticks);
memset(str, 0, sizeof(str)); 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",EiFreeNonPagedPool,EiUsedNonPagedPool);
sprintf(str,"%.8u %.8u",PiNrThreads,KiTimerTicks);
for (i=0;i<17;i++) for (i=0;i<17;i++)
{ {
*vidmem=str[i]; *vidmem=str[i];

View file

@ -176,6 +176,11 @@ NTSTATUS KeWaitForSingleObject(PVOID Object,
// hdr->WaitListHead.Flink,hdr->WaitListHead.Blink); // hdr->WaitListHead.Flink,hdr->WaitListHead.Blink);
KeReleaseDispatcherDatabaseLock(FALSE); KeReleaseDispatcherDatabaseLock(FALSE);
PsSuspendThread(PsGetCurrentThread()); PsSuspendThread(PsGetCurrentThread());
if (Timeout!=NULL)
{
KeCancelTimer(&KeGetCurrentThread()->TimerBlock);
}
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }

View file

@ -28,7 +28,7 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#if 1 #if 0
#define VALIDATE_POOL validate_kernel_pool() #define VALIDATE_POOL validate_kernel_pool()
#else #else
#define VALIDATE_POOL #define VALIDATE_POOL
@ -99,7 +99,8 @@ static void validate_free_list(void)
if (current->magic != BLOCK_HDR_MAGIC) 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); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
} }
@ -146,7 +147,8 @@ static void validate_used_list(void)
if (current->magic != BLOCK_HDR_MAGIC) 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); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
} }
if (base_addr < (kernel_pool_base) || if (base_addr < (kernel_pool_base) ||
@ -189,7 +191,8 @@ static void check_duplicates(block_hdr* blk)
{ {
if (current->magic != BLOCK_HDR_MAGIC) 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); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
} }
@ -538,8 +541,8 @@ asmlinkage VOID ExFreePool(PVOID block)
if (blk->magic != BLOCK_HDR_MAGIC) if (blk->magic != BLOCK_HDR_MAGIC)
{ {
DbgPrint("ExFreePool of non-allocated address\n"); DbgPrint("ExFreePool of non-allocated address %x\n",block);
for(;;); KeBugCheck(0);
return; return;
} }
@ -622,7 +625,8 @@ PVOID ExAllocateNonPagedPoolWithTag(ULONG type, ULONG size, ULONG Tag)
current->next); current->next);
if (current->magic != BLOCK_HDR_MAGIC) 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); KeBugCheck(KBUG_POOL_FREE_LIST_CORRUPT);
} }
if (current->size>=size) if (current->size>=size)

View file

@ -95,6 +95,9 @@ PVOID ObGenericCreateObject(PHANDLE Handle,
ACCESS_MASK DesiredAccess, ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes, POBJECT_ATTRIBUTES ObjectAttributes,
POBJECT_TYPE Type) POBJECT_TYPE Type)
/*
* FUNCTION: Creates a new object
*/
{ {
POBJECT_HEADER hdr = NULL; POBJECT_HEADER hdr = NULL;
PWSTR path; PWSTR path;
@ -206,13 +209,12 @@ VOID ObInitializeObjectHeader(POBJECT_TYPE Type, PWSTR name,
*/ */
{ {
PWSTR temp_name; PWSTR temp_name;
extern unsigned long long ticks;
DPRINT("ObInitializeObjectHeader(id %x name %w obj %x)\n",Type, DPRINT("ObInitializeObjectHeader(id %x name %w obj %x)\n",Type,
name,ObjectHeader); name,ObjectHeader);
ObjectHeader->HandleCount = 0; ObjectHeader->HandleCount = 1;
ObjectHeader->RefCount = 0; ObjectHeader->RefCount = 1;
ObjectHeader->ObjectType = Type; ObjectHeader->ObjectType = Type;
ObjectHeader->Permanent = FALSE; ObjectHeader->Permanent = FALSE;
if (name==NULL) if (name==NULL)

View file

@ -12,6 +12,7 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLOBALS *******************************************************************/ /* GLOBALS *******************************************************************/
@ -27,7 +28,7 @@ static VOID PsIdleThreadMain(PVOID Context)
for(;;) for(;;)
{ {
// DbgPrint("Idling.... "); DPRINT("Idling.... DpcQueueSize %d\n",DpcQueueSize);
if (DpcQueueSize > 0) if (DpcQueueSize > 0)
{ {
KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);

View file

@ -1,100 +1,144 @@
/* /*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
* FILE: ntoskrnl/ps/kill.c * FILE: ntoskrnl/ps/kill.c
* PURPOSE: Terminating a thread * PURPOSE: Terminating a thread
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY: * UPDATE HISTORY:
* Created 22/05/98 * Created 22/05/98
*/ */
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <internal/ps.h> #include <internal/ps.h>
#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* GLBOALS *******************************************************************/ /* GLBOALS *******************************************************************/
extern ULONG PiNrThreads; extern ULONG PiNrThreads;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle, NTSTATUS STDCALL NtTerminateProcess(IN HANDLE ProcessHandle,
IN NTSTATUS ExitStatus) IN NTSTATUS ExitStatus)
{ {
return(ZwTerminateThread(ThreadHandle,ExitStatus)); return(ZwTerminateProcess(ProcessHandle,ExitStatus));
} }
NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle, NTSTATUS STDCALL ZwTerminateProcess(IN HANDLE ProcessHandle,
IN NTSTATUS ExitStatus) IN NTSTATUS ExitStatus)
{ {
PETHREAD Thread; PETHREAD Thread;
NTSTATUS Status; NTSTATUS Status;
PEPROCESS Process;
Status = ObReferenceObjectByHandle(ThreadHandle, KIRQL oldlvl;
THREAD_TERMINATE,
PsThreadType, Status = ObReferenceObjectByHandle(ProcessHandle,
UserMode, PROCESS_TERMINATE,
(PVOID*)&Thread, PsProcessType,
NULL); UserMode,
if (Status != STATUS_SUCCESS) (PVOID*)&Process,
{ NULL);
return(Status); if (Status != STATUS_SUCCESS)
} {
return(Status);
if (Thread == PsGetCurrentThread()) }
{
PsTerminateSystemThread(ExitStatus); PiTerminateProcessThreads(Process, ExitStatus);
} KeRaiseIrql(DISPATCH_LEVEL, &oldlvl);
else KeDispatcherObjectWakeAll(&Process->Pcb.DispatcherHeader);
{ Process->Pcb.ProcessState = PROCESS_STATE_TERMINATED;
UNIMPLEMENTED; if (PsGetCurrentThread()->ThreadsProcess == Process)
} {
} KeLowerIrql(oldlvl);
PsTerminateSystemThread(ExitStatus);
VOID PsReleaseThread(PETHREAD Thread) }
{ KeLowerIrql(oldlvl);
DPRINT("PsReleaseThread(Thread %x)\n",Thread); return(STATUS_SUCCESS);
}
RemoveEntryList(&Thread->Tcb.Entry);
ObDereferenceObject(Thread);
} NTSTATUS STDCALL NtTerminateThread(IN HANDLE ThreadHandle,
IN NTSTATUS ExitStatus)
{
NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) return(ZwTerminateThread(ThreadHandle,ExitStatus));
/* }
* FUNCTION: Terminates the current thread
* ARGUMENTS: NTSTATUS STDCALL ZwTerminateThread(IN HANDLE ThreadHandle,
* ExitStatus = Status to pass to the creater IN NTSTATUS ExitStatus)
* RETURNS: Doesn't {
*/ PETHREAD Thread;
{ NTSTATUS Status;
KIRQL oldlvl;
PETHREAD CurrentThread; Status = ObReferenceObjectByHandle(ThreadHandle,
THREAD_TERMINATE,
PiNrThreads--; PsThreadType,
UserMode,
CurrentThread = PsGetCurrentThread(); (PVOID*)&Thread,
NULL);
CurrentThread->ExitStatus = ExitStatus; if (Status != STATUS_SUCCESS)
{
DPRINT("terminating %x\n",CurrentThread); return(Status);
ObDereferenceObject(CurrentThread->ThreadsProcess); }
KeRaiseIrql(DISPATCH_LEVEL,&oldlvl);
CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED; PsTerminateThread(Thread);
ZwYieldExecution(); }
for(;;);
} VOID PsTerminateThread(PETHREAD Thread, NTSTATUS ExitStatus)
{
NTSTATUS STDCALL NtRegisterThreadTerminatePort(HANDLE TerminationPort) if (Thread == PsGetCurrentThread())
{ {
return(ZwRegisterThreadTerminatePort(TerminationPort)); PsTerminateSystemThread(ExitStatus);
} }
else
NTSTATUS STDCALL ZwRegisterThreadTerminatePort(HANDLE TerminationPort) {
{ UNIMPLEMENTED;
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;
}

View file

@ -204,24 +204,13 @@ NTSTATUS STDCALL ZwCreateProcess(
DbgPrint("ZwCreateProcess() non-NULL SectionHandle\n"); DbgPrint("ZwCreateProcess() non-NULL SectionHandle\n");
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
Process->Pcb.ProcessState = PROCESS_STATE_ACTIVE;
return(STATUS_SUCCESS); 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, NTSTATUS STDCALL NtOpenProcess (OUT PHANDLE ProcessHandle,
IN ACCESS_MASK DesiredAccess, IN ACCESS_MASK DesiredAccess,
IN POBJECT_ATTRIBUTES ObjectAttributes, IN POBJECT_ATTRIBUTES ObjectAttributes,
@ -241,8 +230,7 @@ NTSTATUS STDCALL ZwOpenProcess (OUT PHANDLE ProcessHandle,
UNIMPLEMENTED; UNIMPLEMENTED;
} }
NTSTATUS STDCALL NtQueryInformationProcess( NTSTATUS STDCALL NtQueryInformationProcess(IN HANDLE ProcessHandle,
IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass, IN CINT ProcessInformationClass,
OUT PVOID ProcessInformation, OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength, IN ULONG ProcessInformationLength,
@ -255,8 +243,7 @@ NTSTATUS STDCALL NtQueryInformationProcess(
ReturnLength)); ReturnLength));
} }
NTSTATUS STDCALL ZwQueryInformationProcess( NTSTATUS STDCALL ZwQueryInformationProcess(IN HANDLE ProcessHandle,
IN HANDLE ProcessHandle,
IN CINT ProcessInformationClass, IN CINT ProcessInformationClass,
OUT PVOID ProcessInformation, OUT PVOID ProcessInformation,
IN ULONG ProcessInformationLength, IN ULONG ProcessInformationLength,
@ -305,14 +292,10 @@ NTSTATUS STDCALL ZwQueryInformationProcess(
return(Status); return(Status);
} }
NTSTATUS NTSTATUS STDCALL NtSetInformationProcess(IN HANDLE ProcessHandle,
STDCALL IN CINT ProcessInformationClass,
NtSetInformationProcess( IN PVOID ProcessInformation,
IN HANDLE ProcessHandle, IN ULONG ProcessInformationLength)
IN CINT ProcessInformationClass,
IN PVOID ProcessInformation,
IN ULONG ProcessInformationLength
)
{ {
return(ZwSetInformationProcess(ProcessHandle, return(ZwSetInformationProcess(ProcessHandle,
ProcessInformationClass, ProcessInformationClass,
@ -320,14 +303,10 @@ NtSetInformationProcess(
ProcessInformationLength)); ProcessInformationLength));
} }
NTSTATUS NTSTATUS STDCALL ZwSetInformationProcess(IN HANDLE ProcessHandle,
STDCALL IN CINT ProcessInformationClass,
ZwSetInformationProcess( IN PVOID ProcessInformation,
IN HANDLE ProcessHandle, IN ULONG ProcessInformationLength)
IN CINT ProcessInformationClass,
IN PVOID ProcessInformation,
IN ULONG ProcessInformationLength
)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
} }

View file

@ -46,6 +46,7 @@ static KSPIN_LOCK ThreadListLock = {0,};
static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},}; static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},};
static BOOLEAN DoneInitYet = FALSE; static BOOLEAN DoneInitYet = FALSE;
ULONG PiNrThreads = 0; ULONG PiNrThreads = 0;
ULONG PiNrRunnableThreads = 0;
static PETHREAD CurrentThread = NULL; static PETHREAD CurrentThread = NULL;
@ -63,6 +64,33 @@ PETHREAD PsGetCurrentThread(VOID)
return((PETHREAD)KeGetCurrentThread()); 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; i<NR_THREAD_PRIORITY_LEVELS; i++)
{
current_entry = PriorityListHead[i].Flink;
while (current_entry != &PriorityListHead[i])
{
current = CONTAINING_RECORD(current_entry,ETHREAD,Tcb.Entry);
if (current->ThreadsProcess == Process &&
current != PsGetCurrentThread())
{
PsTerminateThread(current, ExitStatus);
}
current_entry = current_entry->Flink;
}
}
KeReleaseSpinLock(&ThreadListLock, oldlvl);
}
static VOID PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread) static VOID PsInsertIntoThreadList(KPRIORITY Priority, PETHREAD Thread)
{ {
KIRQL oldlvl; KIRQL oldlvl;
@ -148,7 +176,7 @@ VOID PsDispatchThread(VOID)
Candidate = PsScanThreadList(CurrentPriority); Candidate = PsScanThreadList(CurrentPriority);
if (Candidate == CurrentThread) if (Candidate == CurrentThread)
{ {
// DbgPrint("Scheduling current thread\n"); DPRINT("Scheduling current thread\n");
KeQueryTickCount(&TickCount); KeQueryTickCount(&TickCount);
CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount); CurrentThread->Tcb.LastTick = GET_LARGE_INTEGER_LOW_PART(TickCount);
CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING; CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING;
@ -157,7 +185,7 @@ VOID PsDispatchThread(VOID)
} }
if (Candidate != NULL) if (Candidate != NULL)
{ {
// DbgPrint("Scheduling %x\n",Candidate); DPRINT("Scheduling %x\n",Candidate);
Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING; Candidate->Tcb.ThreadState = THREAD_STATE_RUNNING;
@ -171,6 +199,8 @@ VOID PsDispatchThread(VOID)
return; return;
} }
} }
DbgPrint("CRITICAL: No threads are runnable\n");
KeBugCheck(0);
} }
NTSTATUS PsInitializeThread(HANDLE ProcessHandle, NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
@ -207,6 +237,7 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
NULL); NULL);
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
DPRINT("Failed at %s:%d\n",__FILE__,__LINE__);
return(Status); return(Status);
} }
} }

View file

@ -14,12 +14,22 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <wstring.h> #include <wstring.h>
#define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
wchar_t * ___wcstok = NULL; wchar_t * ___wcstok = NULL;
/* FUNCTIONS *****************************************************************/ /* 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 * wchar_t *
wcscat(wchar_t *dest, const wchar_t *src) 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* wcscpy(wchar_t* str1, const wchar_t* str2)
{ {
wchar_t* s = str1; 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) while ((*str2)!=0)
{ {
*s = *str2; *s = *str2;
s++; s++;
str2++; str2++;
} }
*s = 0;
return(str1); return(str1);
} }