diff --git a/reactos/include/ddk/defines.h b/reactos/include/ddk/defines.h index 861c0682cdb..07c7c8af4ae 100644 --- a/reactos/include/ddk/defines.h +++ b/reactos/include/ddk/defines.h @@ -32,157 +32,6 @@ enum PagedPool, PagedPoolCacheAligned, }; - -/* - * Possible status codes - * FIXME: These may not be the actual values used by NT - */ -enum -{ - STATUS_SUCCESS = 0x0, - STATUS_INSUFFICIENT_RESOURCES = 0x80000000, - STATUS_OBJECT_NAME_EXISTS, - STATUS_OBJECT_NAME_COLLISION, -// STATUS_DATATYPE_MISALIGNMENT, - STATUS_CTL_FILE_NOT_SUPPORTED, -// STATUS_ACCESS_VIOLATION, - STATUS_PORT_ALREADY_SET, - STATUS_SECTION_NOT_IMAGE, - STATUS_BAD_WORKING_SET_LIMIT, - STATUS_INCOMPATIBLE_FILE_MAP, - STATUS_HANDLE_NOT_WAITABLE, - STATUS_PORT_DISCONNECTED, - STATUS_NOT_LOCKED, - STATUS_NOT_MAPPED_VIEW, - STATUS_UNABLE_TO_FREE_VM, - STATUS_UNABLE_TO_DELETE_SECTION, - STATUS_MORE_PROCESSING_REQUIRED, - STATUS_INVALID_CID, - STATUS_BAD_INITIAL_STACK, - STATUS_INVALID_VOLUME_LABEL, - STATUS_SECTION_NOT_EXTENDED, - STATUS_NOT_MAPPED_DATA, - STATUS_INFO_LENGTH_MISMATCH, - STATUS_INVALID_INFO_CLASS, - STATUS_SUSPEND_COUNT_EXCEEDED, - STATUS_NOTIFY_ENUM_DIR, - STATUS_REGISTRY_RECOVERED, - STATUS_REGISTRY_IO_FAILED, - STATUS_KEY_DELETED, - STATUS_NO_LOG_SPACE, - STATUS_KEY_HAS_CHILDREN, - STATUS_CHILD_MUST_BE_VOLATILE, - STATUS_REGISTRY_CORRUPT, - STATUS_DLL_NOT_FOUND, - STATUS_DLL_INIT_FAILED, - STATUS_ORDINAL_NOT_FOUND, - STATUS_ENTRYPOINT_NOT_FOUND, -// STATUS_PENDING, - STATUS_MORE_ENTRIES, -// STATUS_INTEGER_OVERFLOW, - STATUS_BUFFER_OVERFLOW, - STATUS_NO_MORE_FILES, - STATUS_NO_INHERITANCE, - STATUS_NO_MORE_EAS, - STATUS_NO_MORE_ENTRIES, - STATUS_GUIDS_EXHAUSTED, - STATUS_AGENTS_EXHAUSTED, - STATUS_UNSUCCESSFUL, - STATUS_NOT_IMPLEMENTED, - STATUS_ILLEGAL_FUNCTION, -// STATUS_IN_PAGE_ERROR, - STATUS_PAGEFILE_QUOTA, - STATUS_COMMITMENT_LIMIT, - STATUS_SECTION_TOO_BIG, - RPC_NT_SS_IN_NULL_CONTEXT, - RPC_NT_INVALID_BINDING, -// STATUS_INVALID_HANDLE, - STATUS_OBJECT_FILE_MISMATCH, - STATUS_FILE_CLOSED, - STATUS_INVALID_PORT_HANDLE, - STATUS_NOT_COMMITTED, - STATUS_INVALID_PARAMETER, - STATUS_INVALID_PARAMETER_1, - STATUS_INVALID_PARAMETER_2, - STATUS_INVALID_PARAMETER_3, - STATUS_INVALID_PARAMETER_4, - STATUS_INVALID_PARAMETER_5, - STATUS_INVALID_PARAMETER_6, - STATUS_INVALID_PARAMETER_7, - STATUS_INVALID_PARAMETER_8, - STATUS_INVALID_PARAMETER_9, - STATUS_INVALID_PARAMETER_10, - STATUS_INVALID_PARAMETER_11, - STATUS_INVALID_PARAMETER_12, - STATUS_INVALID_PARAMETER_MAX, - STATUS_INVALID_PAGE_PROTECTION, - STATUS_RESOURCE_DATA_NOT_FOUND, - STATUS_RESOURCE_TYPE_NOT_FOUND, - STATUS_RESOURCE_NAME_NOT_FOUND, - STATUS_RESOURCE_LANG_NOT_FOUND, - STATUS_NO_SUCH_DEVICE, - STATUS_NO_SUCH_FILE, - STATUS_INVALID_DEVICE_REQUEST, - STATUS_END_OF_FILE, - STATUS_FILE_FORCED_CLOSED, - STATUS_WRONG_VOLUME, - STATUS_NO_MEDIA, - STATUS_NO_MEDIA_IN_DEVICE, - STATUS_NONEXISTENT_SECTOR, - STATUS_WORKING_SET_QUOTA, -// STATUS_NO_MEMORY, - STATUS_CONFLICTING_ADDRESS, - STATUS_INVALID_SYSTEM_SERVICE, - STATUS_THREAD_IS_TERMINATING, - STATUS_PROCESS_IS_TERMINATING, - STATUS_INVALID_LOCK_SEQUENCE, - STATUS_INVALID_VIEW_SIZE, - STATUS_ALREADY_COMMITTED, - STATUS_ACCESS_DENIED, - STATUS_FILE_IS_A_DIRECTORY, - STATUS_CANNOT_DELETE, - STATUS_INVALID_COMPUTER_NAME, - STATUS_FILE_DELETED, - STATUS_DELETE_PENDING, - STATUS_PORT_CONNECTION_REFUSED, - STATUS_NO_SUCH_PRIVILEGE, - STATUS_PRIVILEGE_NOT_HELD, - STATUS_CANNOT_IMPERSONATE, - STATUS_LOGON_FAILURE, - STATUS_ACCOUNT_RESTRICTION, - STATUS_INVALID_LOGON_HOURS, - STATUS_INVALID_WORKSTATION, - STATUS_BUFFER_TOO_SMALL, - STATUS_UNABLE_TO_DECOMMIT_VM, - STATUS_DISK_CORRUPT_ERROR, - STATUS_OBJECT_NAME_INVALID, - STATUS_OBJECT_NAME_NOT_FOUND, -// STATUS_OBJECT_NAME_COLLISION, - STATUS_OBJECT_PATH_INVALID, - STATUS_OBJECT_PATH_NOT_FOUND, - STATUS_DFS_EXIT_PATH_FOUND, - STATUS_OBJECT_PATH_SYNTAX_BAD, - STATUS_DATA_OVERRUN, - STATUS_DATA_LATE_ERROR, - STATUS_DATA_ERROR, - STATUS_CRC_ERROR, - STATUS_SHARING_VIOLATION, - STATUS_QUOTA_EXCEEDED, - STATUS_MUTANT_NOT_OWNED, - STATUS_SEMAPHORE_LIMIT_EXCEEDED, - STATUS_DISK_FULL, - STATUS_LOCK_NOT_GRANTED, - - STATUS_DEVICE_NOT_READY, - STATUS_IO_TIMEOUT, - STATUS_MEDIA_WRITE_PROTECTED, - STATUS_NO_MEDIA_IN_DRIVE, - STATUS_VERIFY_REQUIRED, - STATUS_UNRECOGNIZED_MEDIA, - STATUS_UNRECOGNIZED_VOLUME, -// STATUS_WRONG_VOLUME, - STATUS_FS_DRIVER_REQUIRED, -}; /* * This is a list of bug check types (not MS's) @@ -336,7 +185,7 @@ enum enum { NotificationTimer, - SynchronizationTimer, + SynchronizationTimer, }; /* diff --git a/reactos/include/ddk/extypes.h b/reactos/include/ddk/extypes.h index 35e4e0290a4..29b3587c85b 100644 --- a/reactos/include/ddk/extypes.h +++ b/reactos/include/ddk/extypes.h @@ -39,7 +39,7 @@ typedef struct _ERESOURCE typedef struct { LONG Count; - PKTHREAD Owner; + struct _KTHREAD* Owner; ULONG Contention; KEVENT Event; ULONG OldIrql; diff --git a/reactos/include/ddk/iodef.h b/reactos/include/ddk/iodef.h index 392ffce583d..ec064340461 100644 --- a/reactos/include/ddk/iodef.h +++ b/reactos/include/ddk/iodef.h @@ -1,3 +1,6 @@ +#ifndef __INCLUDE_DDK_IODEF_H +#define __INCLUDE_DDK_IODEF_H + typedef enum _IO_QUERY_DEVICE_DESCRIPTION { IoQueryDeviceIdentifier = 0, @@ -282,3 +285,17 @@ enum IRP_MJ_MAXIMUM_FUNCTION, }; +enum +/* + * PURPOSE: Details about the result of a file open or create + */ +{ + FILE_CREATED, +// FILE_OPENED, + FILE_OVERWRITTEN, + FILE_SUPERSEDED, + FILE_EXISTS, + FILE_DOES_NOT_EXIST, +}; + +#endif diff --git a/reactos/include/ddk/iofuncs.h b/reactos/include/ddk/iofuncs.h index b735640bab1..02a927a97d1 100644 --- a/reactos/include/ddk/iofuncs.h +++ b/reactos/include/ddk/iofuncs.h @@ -325,7 +325,7 @@ PCONFIGURATION_INFORMATION IoGetConfigurationInformation(VOID); */ PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(IRP* irp); -PEPROCESS IoGetCurrentProcess(VOID); +struct _EPROCESS* IoGetCurrentProcess(VOID); NTSTATUS IoGetDeviceObjectPointer(PUNICODE_STRING ObjectName, ACCESS_MASK DesiredAccess, diff --git a/reactos/include/ddk/iotypes.h b/reactos/include/ddk/iotypes.h index 8463ca11572..c7ce1961178 100644 --- a/reactos/include/ddk/iotypes.h +++ b/reactos/include/ddk/iotypes.h @@ -61,6 +61,10 @@ typedef VOID (*PIO_APC_ROUTINE) (PVOID ApcContext, /* STRUCTURE TYPES ***********************************************************/ +typedef struct _ADAPTER_OBJECT +{ +} ADAPTER_OBJECT, *PADAPTER_OBJECT; + /* * PURPOSE: Special timer associated with each device * NOTES: This is a guess @@ -282,7 +286,7 @@ typedef struct _IRP struct { KDEVICE_QUEUE_ENTRY DeviceQueueEntry; - PETHREAD Thread; + struct _ETHREAD* Thread; PCHAR AuxiliaryBuffer; LIST_ENTRY ListEntry; struct _IO_STACK_LOCATION* CurrentStackLocation; diff --git a/reactos/include/ddk/kedef.h b/reactos/include/ddk/kedef.h index 573f81e96a9..9afe3e58816 100644 --- a/reactos/include/ddk/kedef.h +++ b/reactos/include/ddk/kedef.h @@ -8,6 +8,7 @@ typedef enum _EVENT_TYPE { NotificationEvent, SynchronizationEvent, + SemaphoreType, } EVENT_TYPE; typedef enum _KWAIT_REASON diff --git a/reactos/include/ddk/kefuncs.h b/reactos/include/ddk/kefuncs.h index c73c1b1f42c..57be2f4cdf4 100644 --- a/reactos/include/ddk/kefuncs.h +++ b/reactos/include/ddk/kefuncs.h @@ -3,11 +3,25 @@ /* KERNEL FUNCTIONS ********************************************************/ +struct _KAPC; + +void KeInitializeApc( + struct _KAPC *Apc, + PKTHREAD Thread, + UCHAR StateIndex, + PKKERNEL_ROUTINE KernelRoutine, + PKRUNDOWN_ROUTINE RundownRoutine, + PKNORMAL_ROUTINE NormalRoutine, + UCHAR Mode, + PVOID Context + ); + +void KeInsertQueueApc(struct _KAPC *Apc, PVOID SystemArgument1, + PVOID SystemArgument2, UCHAR Mode); +void KeAttachProcess(struct _EPROCESS* Process); +void KeDetachProcess(VOID); VOID KeDrainApcQueue(VOID); -VOID KeInitializeApc(PKAPC Apc, PKNORMAL_ROUTINE NormalRoutine, - PVOID NormalContext, - PKTHREAD TargetThread); -BOOLEAN KeInsertQueueApc(PKAPC Apc); +PKPROCESS KeGetCurrentProcess(VOID); /* * FUNCTION: Acquires a spinlock so the caller can synchronize access to diff --git a/reactos/include/ddk/ketypes.h b/reactos/include/ddk/ketypes.h index 3ccdcbbd9b4..f994625ccb7 100644 --- a/reactos/include/ddk/ketypes.h +++ b/reactos/include/ddk/ketypes.h @@ -3,6 +3,8 @@ #ifndef __INCLUDE_DDK_KETYPES_H #define __INCLUDE_DDK_KETYPES_H +struct _KMUTANT; + typedef LONG KPRIORITY; typedef VOID (*PKBUGCHECK_CALLBACK_ROUTINE)(PVOID Buffer, ULONG Length); @@ -34,9 +36,75 @@ typedef struct USHORT WaitType; } KWAIT_BLOCK, *PKWAIT_BLOCK; +typedef struct _DISPATCHER_HEADER +{ + UCHAR Type; + UCHAR Absolute; + UCHAR Size; + UCHAR Inserted; + LONG SignalState; + LIST_ENTRY WaitListHead; +} DISPATCHER_HEADER; + +struct _KDPC; + +typedef struct _KTIMER +{ + /* + * Pointers to maintain the linked list of activated timers + */ + LIST_ENTRY entry; + + /* + * Absolute expiration time in system time units + */ + signed long long expire_time; + + /* + * Optional dpc associated with the timer + */ + struct _KDPC* dpc; + + /* + * True if the timer is signaled + */ + BOOLEAN signaled; + + /* + * True if the timer is in the system timer queue + */ + BOOLEAN running; + + /* + * Type of the timer either Notification or Synchronization + */ + TIMER_TYPE type; + + /* + * Period of the timer in milliseconds (zero if once-only) + */ + ULONG period; + +} KTIMER, *PKTIMER; + +struct _KSPIN_LOCK; + +typedef struct _KSPIN_LOCK +{ + KIRQL irql; +} KSPIN_LOCK, *PKSPIN_LOCK; + +typedef struct _KDEVICE_QUEUE +{ + LIST_ENTRY ListHead; + BOOLEAN Busy; + KSPIN_LOCK Lock; +} KDEVICE_QUEUE, *PKDEVICE_QUEUE; + +#if RIGHT_DEFINITION_PROVIDED_ABOVE #define _KTHREAD _ETHREAD -typedef struct _ETHREAD +typedef struct _KTHREAD /* * PURPOSE: Describes a thread of execution */ @@ -84,17 +152,14 @@ typedef struct _ETHREAD */ hal_thread_state context; + /* + * PURPOSE: Timeout for the thread to be woken up + */ + signed long long int wake_time; + } KTHREAD, *PKTHREAD, *PETHREAD; - -typedef struct _DISPATCHER_HEADER -{ - UCHAR Type; - UCHAR Absolute; - UCHAR Size; - UCHAR Inserted; - LONG SignalState; - LIST_ENTRY WaitListHead; -} DISPATCHER_HEADER; +#endif + typedef struct _KAPC { @@ -152,10 +217,6 @@ typedef struct _KEVENT } KEVENT, *PKEVENT; -typedef struct _KSPIN_LOCK -{ - KIRQL irql; -} KSPIN_LOCK, *PKSPIN_LOCK; typedef VOID (*PDRIVER_ADD_DEVICE)(VOID); @@ -206,12 +267,6 @@ typedef struct _KDPC } KDPC, *PKDPC; -typedef struct _KDEVICE_QUEUE -{ - LIST_ENTRY ListHead; - BOOLEAN Busy; - KSPIN_LOCK Lock; -} KDEVICE_QUEUE, *PKDEVICE_QUEUE; typedef struct _KDEVICE_QUEUE_ENTRY { @@ -223,46 +278,6 @@ typedef struct _WAIT_CONTEXT_BLOCK { } WAIT_CONTEXT_BLOCK, *PWAIT_CONTEXT_BLOCK; - -typedef struct _KTIMER -{ - /* - * Pointers to maintain the linked list of activated timers - */ - LIST_ENTRY entry; - - /* - * Absolute expiration time in system time units - */ - unsigned long long expire_time; - - /* - * Optional dpc associated with the timer - */ - PKDPC dpc; - - /* - * True if the timer is signaled - */ - BOOLEAN signaled; - - /* - * True if the timer is in the system timer queue - */ - BOOLEAN running; - - /* - * Type of the timer either Notification or Synchronization - */ - TIMER_TYPE type; - - /* - * Period of the timer in milliseconds (zero if once-only) - */ - ULONG period; - -} KTIMER, *PKTIMER; - struct _KINTERRUPT; typedef BOOLEAN (*PKSERVICE_ROUTINE)(struct _KINTERRUPT* Interrupt, diff --git a/reactos/include/ddk/mmfuncs.h b/reactos/include/ddk/mmfuncs.h index dac198a8207..2cdbd268848 100644 --- a/reactos/include/ddk/mmfuncs.h +++ b/reactos/include/ddk/mmfuncs.h @@ -294,3 +294,4 @@ VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle); VOID MmUnmapIoSpace(PVOID BaseAddress, ULONG NumberOfBytes); VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList); +PVOID MmAllocateSection(ULONG Length); diff --git a/reactos/include/ddk/ntddk.h b/reactos/include/ddk/ntddk.h index 0f52a2c50a0..70278e8c84e 100644 --- a/reactos/include/ddk/ntddk.h +++ b/reactos/include/ddk/ntddk.h @@ -20,40 +20,28 @@ extern "C" #include -#define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0) -#define NTKERNELAPI - - #define CTL_CODE(Dev, Func, Meth, Acc) ( ((Dev)<<16) | ((Acc)<<14) | ((Func)<<2) | (Meth)) - -// IOCTL Parameter buffering methods -#define METHOD_BUFFERED 0 -#define METHOD_IN_DIRECT 1 -#define METHOD_OUT_DIRECT 2 -#define METHOD_NEITHER 3 - -// IOCTL File access type -#define FILE_ANY_ACCESS 0 -#define FILE_READ_ACCESS 1 -#define FILE_WRITE_ACCESS 2 - #define QUAD_PART(LI) (*(LONGLONG *)(&LI)) -enum { - STATUS_NOT_SUPPORTED = 9999, - STATUS_DISK_OPERATION_FAILED -}; #define IO_DISK_INCREMENT 4 #define FILE_WORD_ALIGNMENT 0x0001 #define FILE_OPENED 0x0001 - + +#include +#include #include #include -#include +#include +#include +#include +#include +#include +#include +#include #include - +#include #include #include diff --git a/reactos/include/ddk/obtypes.h b/reactos/include/ddk/obtypes.h index 9678c3114b5..23500fcc970 100644 --- a/reactos/include/ddk/obtypes.h +++ b/reactos/include/ddk/obtypes.h @@ -1,5 +1,7 @@ struct _DIRECTORY_OBJECT; +typedef ULONG ACCESS_STATE, *PACCESS_STATE; + typedef struct _OBJECT_HANDLE_INFORMATION { ULONG HandleAttributes; ACCESS_MASK GrantedAccess; @@ -113,6 +115,8 @@ typedef struct _OBJECT */ ULONG HandleCount; + struct _DIRECTORY_OBJECT* Parent; + /* * PURPOSE: Object type * NOTE: This overlaps the first member of the object body @@ -125,6 +129,7 @@ typedef struct _OBJECT */ CSHORT Size; + } OBJECT_HEADER, *POBJECT_HEADER; /* diff --git a/reactos/include/ddk/psfuncs.h b/reactos/include/ddk/psfuncs.h index 5f2eb0b5651..329a8acd234 100644 --- a/reactos/include/ddk/psfuncs.h +++ b/reactos/include/ddk/psfuncs.h @@ -1,6 +1,5 @@ -typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext); /* * FUNCTION: Creates a thread which executes in kernel mode @@ -29,4 +28,4 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus); NTSTATUS PsSuspendThread(VOID); NTSTATUS PsWakeThread(PETHREAD Thread); PETHREAD PsGetCurrentThread(VOID); -PEPROCESS PsGetCurrentProcess(VOID); +struct _EPROCESS* PsGetCurrentProcess(VOID); diff --git a/reactos/include/ddk/pstypes.h b/reactos/include/ddk/pstypes.h index b7aaf1e6cfd..75617ce75db 100644 --- a/reactos/include/ddk/pstypes.h +++ b/reactos/include/ddk/pstypes.h @@ -2,69 +2,93 @@ #define __INCLUDE_DDK_PSTYPES_H #include +#include + +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 void* ATOMTABLE; + +typedef struct _pPebInfo { + WCHAR* WindowTitle; + WCHAR* ImageFile; + WCHAR* CommandLine; + WCHAR* DllPath; +// STARTUPINFOW StartupInfo; +} PEBINFO; + +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; + DWORD dwTlsBits[2]; // tls in use bits + WORD NumberOfProcessors; + WORD NtGlobalFlag; + DWORD HeapReserve; + DWORD HeapCommit; + DWORD HeapDecommitFreeBlockThreshold; + DWORD NumberOfHeaps; + DWORD MaxiumNumberOfHeaps; + PEBINFO* PebInfo; + 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 void* HEAP; -typedef void* HANDLE_TABLE; -typedef void* ATOMTABLE; - -typedef struct _pPebInfo { - LPWSTR lpCommandLine; - DWORD cb; - HANDLE hStdInput; //18 - HANDLE hStdput; - HANDLE hStdError; - LPWSTR lpEnvironment; - DWORD dwX; - DWORD dwY; - DWORD dwXSize; - DWORD dwYSize; - DWORD dwXCountChars; - DWORD dwYCountChars; - DWORD dwFillAttribute; - DWORD dwFlags; - DWORD wShowWindow; - LPTSTR lpTitle; - LPTSTR lpDesktop; - LPTSTR reserved; - DWORD cbReserved2; - LPTSTR lpReserved1; -} PEBINFO; - -typedef struct _NT_PEB -{ - - LONG ImageBaseAddress; - DWORD nActiveStdHandle; - void *HeapIndex; - DWORD dwTlsBits[2]; // tls in use bits - WORD NumberOfProcessors; - WORD NtGlobalFlag; - DWORD dwCriticalSectionTime; - DWORD dwHeapReserve; - DWORD dwHeapCommit; - DWORD dwHeapDecommitFreeBlockThreshold; - DWORD dwNumberOfHeaps; - DWORD dwMaxiumNumberOfHeaps; - PEBINFO *pPebInfo; - HEAP *pProcessHeap; - HANDLE_TABLE htGDISharedHandleTable; - ATOMTABLE LocalAtomTable; - CRITICAL_SECTION *pCriticalSection; - WORD wMajorVersion; - WORD wMinorVersion; - WORD wBuildNumber; - WORD wPlatformId; -} NT_PEB, *PPEB; - - typedef struct _NT_TIB { struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; PVOID StackBase; @@ -73,7 +97,7 @@ typedef struct _NT_TIB { union { PVOID FiberData; ULONG Version; - } s; + } Fib; PVOID ArbitraryUserPointer; struct _NT_TIB *Self; } NT_TIB, *PNT_TIB; @@ -82,79 +106,180 @@ typedef struct _NT_TEB { NT_TIB Tib; - DWORD dwProcessId; - DWORD dwThreadId; - HANDLE hRPC; + CLIENT_ID Cid; + HANDLE RPCHandle; + PVOID TlsData; NT_PEB *pPeb; - DWORD dwErrCode; - WORD nMutexCount; - LCID Locale; - //HQUEUE MessageQueue - DWORD dwTlsIndex ; - LPVOID TlsData[512]; - + 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; + ULONG 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; +} KTHREAD, *PKTHREAD; -typedef NT_TEB *PINITIAL_TEB; + +// According to documentation the stack should have a commited [ 1 page ] and +// a reserved part [ 1 M ]. + +typedef struct _INITIAL_TEB { + PVOID StackCommit; + PVOID StackReserved; +} INITIAL_TEB, *PINITIAL_TEB; + + + + +//ThreadState defines the current state of a thread +//FIXME I am allready defined in psmgr.h as a enum +/* +enum +{ + THREAD_STATE_INITIALIZED = 0, + THREAD_STATE_READY, + THREAD_STATE_RUNNING, + THREAD_STATE_STANDBY, + THREAD_STATE_TERMINATED, + THREAD_STATE_WAIT, + THREAD_STATE_TRANSITION, + THREAD_STATE_RESERVED +}; +*/ + +// wait reason only applies for threads in a wait state +// part of this enum is double ???? + +/* +typedef _KWAIT_REASON +{ + WAIT_EXCECUTIVE1 = 0, + WAIT_FREE_PAGE1, + WAIT_PAGE_IN1, + WAIT_POOL_ALLOCATION1, + WAIT_EXECUTION_DELAY1, + WAIT_SUSPENDED_CONDITION1, + WAIT_USER_REQUEST1, + WAIT_EXCECUTIVE2, + WAIT_FREE_PAGE2, + WAIT_PAGE_IN2, + WAIT_POOL_ALLOCATION2, + WAIT_EXECUTION_DELAY2, + WAIT_SUSPENDED_CONDITION2, + WAIT_USER_REQUEST2, + WAIT_EVENT_PAIR_HIGH, + WAIT_EVENT_PAIR_LOW, + WAIT_LPC_RECEIVE, + WAIT_LPC_REPLY, + WAIT_VIRTUAL_MEMORY, + WAIT_PAGE_OUT +} KWAIT_REASON; + +*/ + + +// 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 InOutSwap; // ?? + 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; +} KPROCESS, *PKPROCESS; typedef struct _EPROCESS { + KPROCESS Pcb; } EPROCESS, *PEPROCESS; -//typedef KTHREAD ETHREAD, *PETHREAD; - -#if ETHREAD_NOT_THE_SAME_AS_KTHREAD -typedef struct _ETHREAD -{ - EPROCESS* Process; -} ETHREAD, *PETHREAD; - -/* - * PURPOSE: Thread object - */ -typedef struct -{ - CSHORT Type; - CSHORT Size; - - /* - * PURPOSE: Entry in the linked list of threads - */ - LIST_ENTRY Entry; - - /* - * PURPOSE: Current state of the thread - */ - ULONG State; - - /* - * PURPOSE: Priority modifier of the thread - */ - ULONG Priority; - - /* - * PURPOSE: Pointer to our parent process - */ -// PEPROCESS Parent; - - /* - * PURPOSE: Handle of our parent process - */ - HANDLE ParentHandle; - - /* - * PURPOSE: Not currently used - */ - ULONG AffinityMask; - - /* - * PURPOSE: Saved thread context - */ - hal_thread_state context; - -} THREAD_OBJECT, *PTHREAD_OBJECT; -#endif - #endif /* __INCLUDE_DDK_PSTYPES_H */ diff --git a/reactos/include/ddk/setypes.h b/reactos/include/ddk/setypes.h index d9e8b433ff1..299ded32b61 100644 --- a/reactos/include/ddk/setypes.h +++ b/reactos/include/ddk/setypes.h @@ -1,3 +1,12 @@ +/* + * COPYRIGHT: See COPYING in the top level directory for details + * PROJECT: ReactOS kernel + * FILE: include/ddk/setypes.h + * PURPOSE: Security manager types + * REVISION HISTORY: + * ??/??/??: Created with empty stubs by David Welch + * 29/08/98: ACCESS_TOKEN definition from Boudewijn Dekker + */ typedef ULONG ACCESS_MODE, *PACCESS_MODE; @@ -8,3 +17,25 @@ typedef struct _SECURITY_SUBJECT_CONTEXT typedef struct _SECURITY_DESCRIPTOR_CONTEXT { } SECURITY_DESCRIPTOR_CONTEXT, *PSECURITY_DESCRIPTOR_CONTEXT; + +typedef struct _ACCESS_TOKEN { + TOKEN_SOURCE TokenSource; + LUID AuthenticationId; + LARGE_INTEGER ExpirationTime; + LUID ModifiedId; + ULONG UserAndGroupCount; + ULONG PrivilegeCount; + ULONG VariableLength; + ULONG DynamicCharged; + ULONG DynamicAvailable; + ULONG DefaultOwnerIndex; + PACL DefaultDacl; + TOKEN_TYPE TokenType; + SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; + UCHAR TokenFlags; + UCHAR TokenInUse; + UCHAR Unused[2]; + PVOID ProxyData; + PVOID AuditData; + UCHAR VariablePart[0]; +} ACCESS_TOKEN, *PACCESS_TOKEN; diff --git a/reactos/include/ddk/types.h b/reactos/include/ddk/types.h index d4d69e1c5f9..d9b4161bd6c 100644 --- a/reactos/include/ddk/types.h +++ b/reactos/include/ddk/types.h @@ -58,10 +58,16 @@ typedef ULONG LOCK_OPERATION; typedef ULONG KEY_INFORMATION_CLASS; typedef ULONG FILE_INFORMATION_CLASS; typedef ULONG KEY_VALUE_INFORMATION_CLASS; -typedef ULONG PHYSICAL_ADDRESS; +typedef LARGE_INTEGER PHYSICAL_ADDRESS; typedef PHYSICAL_ADDRESS* PPHYSICAL_ADDRESS; typedef ULONG WAIT_TYPE; //typedef ULONG KINTERRUPT_MODE; typedef USHORT CSHORT; + +typedef struct _TIME { + DWORD LowPart; + LONG HighPart; +} TIME; + #endif diff --git a/reactos/include/ddk/zw.h b/reactos/include/ddk/zw.h index 1ab26a6a7f2..9f96d90d49f 100644 --- a/reactos/include/ddk/zw.h +++ b/reactos/include/ddk/zw.h @@ -1,4 +1,3 @@ - /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -9,6 +8,7 @@ * ??/??/??: Complete implementation by Boudewijn Dekker * 13/07/98: Reorganised things a bit (David Welch) * 04/08/98: Added some documentation (Boudewijn Dekker) + * 14/08/98: Added type TIME and change variable type from [1] to [0] */ #ifndef __DDK_ZW_H @@ -207,18 +207,17 @@ typedef struct _OBJECT_ATTRIBUTES { SECURITY_QUALITY_OF_SERVICE *SecurityQualityOfService; } OBJECT_ATTRIBUTES, *POBJECT_ATTRIBUTES; #endif - + + + +/* #if IOTYPES_DIDNT_DECLARE_THIS typedef struct _IO_STATUS_BLOCK { NTSTATUS Status; ULONG Information; } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK; #endif - - -//typedef LARGE_INTEGER *PLARGE_INTEGER; - -// +*/ #define NtCurrentProcess() ( (HANDLE) 0xFFFFFFFF ) #define NtCurrentThread() ( (HANDLE) 0xFFFFFFFE ) @@ -231,6 +230,52 @@ typedef struct _IO_STATUS_BLOCK { #define EVENT_WRITE_ACCESS 2 +// file creation flags + +#define FILE_DIRECTORY_FILE 0x00000001 +#define FILE_WRITE_THROUGH 0x00000002 +#define FILE_SEQUENTIAL_ONLY 0x00000004 +#define FILE_NO_INTERMEDIATE_BUFFERING 0x00000008 + +#define FILE_SYNCHRONOUS_IO_ALERT 0x00000010 +#define FILE_SYNCHRONOUS_IO_NONALERT 0x00000020 +#define FILE_NON_DIRECTORY_FILE 0x00000040 +#define FILE_CREATE_TREE_CONNECTION 0x00000080 + +#define FILE_COMPLETE_IF_OPLOCKED 0x00000100 +#define FILE_NO_EA_KNOWLEDGE 0x00000200 + +#define FILE_RANDOM_ACCESS 0x00000800 + +#define FILE_DELETE_ON_CLOSE 0x00001000 +#define FILE_OPEN_BY_FILE_ID 0x00002000 +#define FILE_OPEN_FOR_BACKUP_INTENT 0x00004000 +#define FILE_NO_COMPRESSION 0x00008000 + +#define FILE_RESERVE_OPFILTER 0x00100000 +#define FILE_TRANSACTED_MODE 0x00200000 +#define FILE_OPEN_OFFLINE_FILE 0x00400000 + +#define FILE_VALID_OPTION_FLAGS 0x007fffff +#define FILE_VALID_PIPE_OPTION_FLAGS 0x00000032 +#define FILE_VALID_MAILSLOT_OPTION_FLAGS 0x00000032 +#define FILE_VALID_SET_FLAGS 0x00001036 + + +// file disposition values + + +#define FILE_SUPERSEDE 0x0000 +#define FILE_OPEN 0x0001 +#define FILE_CREATE 0x0002 +#define FILE_OPEN_IF 0x0003 +#define FILE_OVERWRITE 0x0004 +#define FILE_OVERWRITE_IF 0x0005 +#define FILE_MAXIMUM_DISPOSITION 0x0005 + + + + //process query / set information class #define ProcessBasicInformation 0 @@ -258,7 +303,6 @@ typedef struct _IO_STATUS_BLOCK { #define MaxProcessInfoClass 22 // thread query / set information class - #define ThreadBasicInformation 0 #define ThreadTimes 1 #define ThreadPriority 2 @@ -277,6 +321,7 @@ typedef struct _IO_STATUS_BLOCK { #define MaxThreadInfoClass 15 + // key query information class #define KeyBasicInformation 0 @@ -296,13 +341,23 @@ typedef struct _IO_STATUS_BLOCK { // object handle information -#define HandleInformation 0 -#define HandleName 1 -#define HandleTypeInformation 2 -#define HandleAllInformation 3 -#define HandleBasicInformation 4 +#define ObjectBasicInformation 0 +#define ObjectNameInformation 1 +#define ObjectTypeInformation 2 +#define ObjectAllInformation 3 +#define ObjectDataInformation 4 + +// semaphore information + +#define SemaphoreBasicInformation 0 + +// event information + +#define EventBasicInformation 0 + // system information + #define SystemPerformanceInformation 5 #define SystemCacheInformation 21 #define SystemTimeAdjustmentInformation 28 @@ -372,7 +427,7 @@ typedef struct _IO_STATUS_BLOCK { // shutdown action -typedef enum _SHUTDOWN_ACTION_ { +typedef enum SHUTDOWN_ACTION_TAG { ShutdownNoReboot, ShutdownReboot, ShutdownPowerOff @@ -394,7 +449,7 @@ typedef enum _SHUTDOWN_ACTION_ { // object type access rights -#define OBJECT_TYPE_CREATE 0x00000001 +#define OBJECT_TYPE_CREATE 0x0001 #define OBJECT_TYPE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1) @@ -412,33 +467,33 @@ typedef enum _SHUTDOWN_ACTION_ { #define SYMBOLIC_LINK_QUERY 0x0001 #define SYMBOLIC_LINK_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1) -typedef struct _PROCESS_WS_WATCH_INFORMATION_ +typedef struct _PROCESS_WS_WATCH_INFORMATION { PVOID FaultingPc; PVOID FaultingVa; } PROCESS_WS_WATCH_INFORMATION, *PPROCESS_WS_WATCH_INFORMATION; -typedef struct _PROCESS_BASIC_INFORMATION_ +typedef struct _PROCESS_BASIC_INFORMATION { NTSTATUS ExitStatus; - PPEB PebBaseAddress; + PNT_PEB PebBaseAddress; KAFFINITY AffinityMask; KPRIORITY BasePriority; ULONG UniqueProcessId; ULONG InheritedFromUniqueProcessId; } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION; -typedef struct _QUOTA_LIMITS_ +typedef struct _QUOTA_LIMITS { ULONG PagedPoolLimit; ULONG NonPagedPoolLimit; ULONG MinimumWorkingSetSize; ULONG MaximumWorkingSetSize; ULONG PagefileLimit; - LARGE_INTEGER TimeLimit; + TIME TimeLimit; } QUOTA_LIMITS, *PQUOTA_LIMITS; -typedef struct _IO_COUNTERS_ +typedef struct _IO_COUNTERS { ULONG ReadOperationCount; ULONG WriteOperationCount; @@ -479,76 +534,87 @@ typedef struct _POOLED_USAGE_AND_LIMITS_ } POOLED_USAGE_AND_LIMITS, *PPOOLED_USAGE_AND_LIMITS; -typedef struct _PROCESS_ACCESS_TOKEN_ +typedef struct _PROCESS_ACCESS_TOKEN { HANDLE Token; HANDLE Thread; } PROCESS_ACCESS_TOKEN, *PPROCESS_ACCESS_TOKEN; -typedef struct _KERNEL_USER_TIMES_ +typedef struct _KERNEL_USER_TIMES { - LARGE_INTEGER CreateTime; - LARGE_INTEGER ExitTime; - LARGE_INTEGER KernelTime; - LARGE_INTEGER UserTime; + TIME CreateTime; + TIME ExitTime; + TIME KernelTime; + TIME UserTime; } KERNEL_USER_TIMES; typedef KERNEL_USER_TIMES *PKERNEL_USER_TIMES; +// thread information + +// incompatible with MS NT + +typedef struct _THREAD_BASIC_INFORMATION +{ + NTSTATUS ExitStatus; + PVOID TebBaseAddress; + KAFFINITY AffinityMask; + KPRIORITY BasePriority; + ULONG UniqueThreadId; +} THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION; + +// object information -typedef struct _OBJECT_NAME_INFORMATION_ +typedef struct _OBJECT_NAME_INFORMATION { UNICODE_STRING Name; } OBJECT_NAME_INFORMATION, *POBJECT_NAME_INFORMATION; -// section information - -// handle information - -//HandleBasicInformation HANDLE_BASIC_INFORMATION -typedef struct _HANDLE_BASIC_INFORMATION_ +typedef struct _OBJECT_DATA_INFORMATION { BOOL bInheritHanlde; BOOL bProtectFromClose; -} HANDLE_BASIC_INFORMATION, *PHANDLE_BASIC_INFORMATION; +} OBJECT_DATA_INFORMATION, *POBJECT_DATA_INFORMATION; -//HandleTypeInormation HANDLE_TYPE_INFORMATION -typedef struct _HANDLE_TYPE_INFORMATION_ { + +typedef struct _OBJECT_TYPE_INFORMATION +{ UNICODE_STRING Name; UNICODE_STRING Type; ULONG TotalHandles; ULONG ReferenceCount; -} HANDLE_TYPE_INFORMATION, *PHANDLE_TYPE_INFORMATION; +} OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION; -typedef struct _SYSTEM_TIME_ADJUSTMENT_ +// system information + +typedef struct _SYSTEM_TIME_ADJUSTMENT { ULONG TimeAdjustment; BOOL TimeAdjustmentDisabled; } SYSTEM_TIME_ADJUSTMENT, *PSYSTEM_TIME_ADJUSTMENT; - -#ifdef __STRUCTS_H_DIDNT_DEFINE_THIS_ALREADY -typedef struct _SYSTEM_INFO_ { + +typedef struct _SYSTEM_CONFIGURATION_INFO { union { - DWORD dwOemId; + ULONG OemId; struct { - WORD wProcessorArchitecture; - WORD wReserved; - }; - }; - DWORD dwPageSize; - LPVOID lpMinimumApplicationAddress; - LPVOID lpMaximumApplicationAddress; - DWORD dwActiveProcessorMask; - DWORD dwNumberOfProcessors; - DWORD dwProcessorType; - DWORD dwAllocationGranularity; - WORD wProcessorLevel; - WORD wProcessorRevision; -} SYSTEM_INFO; -#endif + WORD ProcessorArchitecture; + WORD Reserved; + } tag1; + } tag2; + ULONG PageSize; + PVOID MinimumApplicationAddress; + PVOID MaximumApplicationAddress; + ULONG ActiveProcessorMask; + ULONG NumberOfProcessors; + ULONG ProcessorType; + ULONG AllocationGranularity; + WORD ProcessorLevel; + WORD ProcessorRevision; +} SYSTEM_CONFIGURATION_INFO, *PSYSTEM_CONFIGURATION_INFO; -typedef struct _SYSTEM_CACHE_INFORMATION_ { + +typedef struct _SYSTEM_CACHE_INFORMATION { ULONG CurrentSize; ULONG PeakSize; ULONG PageFaultCount; @@ -561,16 +627,16 @@ typedef struct _SYSTEM_CACHE_INFORMATION_ { // file information -typedef struct _FILE_BASIC_INFORMATION_ +typedef struct _FILE_BASIC_INFORMATION { - LARGE_INTEGER CreationTime; - LARGE_INTEGER LastAccessTime; - LARGE_INTEGER LastWriteTime; - LARGE_INTEGER ChangeTime; + TIME CreationTime; + TIME LastAccessTime; + TIME LastWriteTime; + TIME ChangeTime; ULONG FileAttributes; } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION; -typedef struct _FILE_STANDARD_INFORMATION_ +typedef struct _FILE_STANDARD_INFORMATION { LARGE_INTEGER AllocationSize; LARGE_INTEGER EndOfFile; @@ -579,118 +645,111 @@ typedef struct _FILE_STANDARD_INFORMATION_ BOOLEAN Directory; } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION; -typedef struct _FILE_POSITION_INFORMATION_ +typedef struct _FILE_POSITION_INFORMATION { LARGE_INTEGER CurrentByteOffset; } FILE_POSITION_INFORMATION, *PFILE_POSITION_INFORMATION; -typedef struct _FILE_ALIGNMENT_INFORMATION_ +typedef struct _FILE_ALIGNMENT_INFORMATION { ULONG AlignmentRequirement; } FILE_ALIGNMENT_INFORMATION, *PFILE_ALIGNMENT_INFORMATION; -typedef struct _FILE_DISPOSITION_INFORMATION_ +typedef struct _FILE_DISPOSITION_INFORMATION { BOOLEAN DeleteFile; } FILE_DISPOSITION_INFORMATION, *PFILE_DISPOSITION_INFORMATION; -typedef struct _FILE_END_OF_FILE_INFORMATION_ +typedef struct _FILE_END_OF_FILE_INFORMATION { LARGE_INTEGER EndOfFile; } FILE_END_OF_FILE_INFORMATION, *PFILE_END_OF_FILE_INFORMATION; -typedef struct _FILE_NETWORK_OPEN_INFORMATION_ { - LARGE_INTEGER CreationTime; - LARGE_INTEGER LastAccessTime; - LARGE_INTEGER LastWriteTime; - LARGE_INTEGER ChangeTime; +typedef struct _FILE_NETWORK_OPEN_INFORMATION { + TIME CreationTime; + TIME LastAccessTime; + TIME LastWriteTime; + TIME ChangeTime; LARGE_INTEGER AllocationSize; LARGE_INTEGER EndOfFile; ULONG FileAttributes; } FILE_NETWORK_OPEN_INFORMATION, *PFILE_NETWORK_OPEN_INFORMATION; -typedef struct _FILE_FULL_EA_INFORMATION_ +typedef struct _FILE_FULL_EA_INFORMATION { ULONG NextEntryOffset; UCHAR Flags; UCHAR EaNameLength; USHORT EaValueLength; CHAR *EaName; -} FILE_FULL_EA_INFORMATION; -typedef FILE_FULL_EA_INFORMATION *PFILE_FULL_EA_INFORMATION; +} FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION; -typedef struct _FILE_EA_INFORMATION_ { +typedef struct _FILE_EA_INFORMATION { ULONG EaSize; -} FILE_EA_INFORMATION; +} FILE_EA_INFORMATION, *PFILE_EA_INFORMATION; -typedef struct _FILE_STREAM_INFORMATION_ -{ + +typedef struct _FILE_GET_EA_INFORMATION { + ULONG NextEntryOffset; + UCHAR EaNameLength; + CHAR EaName[0]; +} FILE_GET_EA_INFORMATION, *PFILE_GET_EA_INFORMATION; + +typedef struct _FILE_STREAM_INFORMATION { ULONG NextEntryOffset; ULONG StreamNameLength; LARGE_INTEGER StreamSize; LARGE_INTEGER StreamAllocationSize; - WCHAR StreamName[1]; + WCHAR StreamName[0]; } FILE_STREAM_INFORMATION, *PFILE_STREAM_INFORMATION; +typedef struct _FILE_ALLOCATION_INFORMATION { + LARGE_INTEGER AllocationSize; +} FILE_ALLOCATION_INFORMATION, *PFILE_ALLOCATION_INFORMATION; -#ifdef __IO_TYPE_DIDNT_DEFINE_THIS_ALREADY -typedef struct _IO_COMPLETION_CONTEXT -{ - PVOID Port; - ULONG Key; -} IO_COMPLETION_CONTEXT, *PIO_COMPLETION_CONTEXT; -#endif - -typedef struct _FILE_ALLOCATION_INFORMATION_ { - LARGE_INTEGER AllocationSize; -} FILE_ALLOCATION_INFORMATION; - -typedef struct _FILE_NAME_INFORMATION_ { +typedef struct _FILE_NAME_INFORMATION { ULONG FileNameLength; - WCHAR FileName[1]; -} FILE_NAME_INFORMATION; + WCHAR FileName[0]; +} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION; -typedef struct _FILE_RENAME_INFORMATION_ { +typedef struct _FILE_NAMES_INFORMATION { + ULONG NextEntryOffset; + ULONG FileIndex; + ULONG FileNameLength; + WCHAR FileName[0]; +} FILE_NAMES_INFORMATION, *PFILE_NAMES_INFORMATION; + + +typedef struct _FILE_RENAME_INFORMATION { BOOLEAN Replace; HANDLE RootDir; ULONG FileNameLength; - WCHAR FileName[1]; + WCHAR FileName[0]; } FILE_RENAME_INFORMATION, *PFILE_RENAME_INFORMATION; -typedef struct _FILE_INTERNAL_INFORMATION_ { +typedef struct _FILE_INTERNAL_INFORMATION { LARGE_INTEGER IndexNumber; -} FILE_INTERNAL_INFORMATION; +} FILE_INTERNAL_INFORMATION, *PFILE_INTERNAL_INFORMATION; -typedef struct _FILE_ACCESS_INFORMATION_ { +typedef struct _FILE_ACCESS_INFORMATION { ACCESS_MASK AccessFlags; -} FILE_ACCESS_INFORMATION; +} FILE_ACCESS_INFORMATION, *PFILE_ACCESS_INFORMATION; -#ifdef __DEFINED_ABOVE -typedef struct _FILE_POSITION_INFORMATION_ { - LARGE_INTEGER CurrentByteOffset; -} FILE_POSITION_INFORMATION; -#endif -typedef struct _FILE_MODE_INFORMATION_ { +typedef struct _FILE_MODE_INFORMATION { ULONG Mode; -} FILE_MODE_INFORMATION; +} FILE_MODE_INFORMATION, *PFILE_MODE_INFORMATION; -#ifdef __DEFINED_ABOVE -typedef struct _FILE_ALIGNMENT_INFORMATION_ { - ULONG AlignmentRequirement; -} FILE_ALIGNMENT_INFORMATION; -#endif - -typedef struct _FILE_COMPRESSION_INFORMATION_ { +typedef struct _FILE_COMPRESSION_INFORMATION { LARGE_INTEGER CompressedFileSize; USHORT CompressionFormat; UCHAR CompressionUnitShift; UCHAR ChunkShift; UCHAR ClusterShift; UCHAR Reserved[3]; -} FILE_COMPRESSION_INFORMATION; +} FILE_COMPRESSION_INFORMATION, *PFILE_COMPRESSION_INFORMATION; typedef struct _FILE_ALL_INFORMATION { FILE_BASIC_INFORMATION BasicInformation; @@ -702,15 +761,63 @@ typedef struct _FILE_ALL_INFORMATION { FILE_MODE_INFORMATION ModeInformation; FILE_ALIGNMENT_INFORMATION AlignmentInformation; FILE_NAME_INFORMATION NameInformation; -} FILE_ALL_INFORMATION; +} FILE_ALL_INFORMATION, *PFILE_ALL_INFORMATION; // file system information structures -typedef struct _FILE_FS_DEVICE_INFORMATION_ { +typedef struct _FILE_FS_DEVICE_INFORMATION { DEVICE_TYPE DeviceType; ULONG Characteristics; -} FILE_FS_DEVICE_INFORMATION; -typedef FILE_FS_DEVICE_INFORMATION *PFILE_FS_DEVICE_INFORMATION; +} FILE_FS_DEVICE_INFORMATION, *PFILE_FS_DEVICE_INFORMATION; + + +/* device type can be one of the following values: + + FILE_DEVICE_BEEP 0x00000001 + FILE_DEVICE_CD_ROM 0x00000002 + FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003 + FILE_DEVICE_CONTROLLER 0x00000004 + FILE_DEVICE_DATALINK 0x00000005 + FILE_DEVICE_DFS 0x00000006 + FILE_DEVICE_DISK 0x00000007 + FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008 + FILE_DEVICE_FILE_SYSTEM 0x00000009 + FILE_DEVICE_INPORT_PORT 0x0000000a + FILE_DEVICE_KEYBOARD 0x0000000b + FILE_DEVICE_MAILSLOT 0x0000000c + FILE_DEVICE_MIDI_IN 0x0000000d + FILE_DEVICE_MIDI_OUT 0x0000000e + FILE_DEVICE_MOUSE 0x0000000f + FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010 + FILE_DEVICE_NAMED_PIPE 0x00000011 + FILE_DEVICE_NETWORK 0x00000012 + FILE_DEVICE_NETWORK_BROWSER 0x00000013 + FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014 + FILE_DEVICE_NULL 0x00000015 + FILE_DEVICE_PARALLEL_PORT 0x00000016 + FILE_DEVICE_PHYSICAL_NETCARD 0x00000017 + FILE_DEVICE_PRINTER 0x00000018 + FILE_DEVICE_SCANNER 0x00000019 + FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a + FILE_DEVICE_SERIAL_PORT 0x0000001b + FILE_DEVICE_SCREEN 0x0000001c + FILE_DEVICE_SOUND 0x0000001d + FILE_DEVICE_STREAMS 0x0000001e + FILE_DEVICE_TAPE 0x0000001f + FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020 + FILE_DEVICE_TRANSPORT 0x00000021 + FILE_DEVICE_UNKNOWN 0x00000022 + FILE_DEVICE_VIDEO 0x00000023 + FILE_DEVICE_VIRTUAL_DISK 0x00000024 + FILE_DEVICE_WAVE_IN 0x00000025 + FILE_DEVICE_WAVE_OUT 0x00000026 + FILE_DEVICE_8042_PORT 0x00000027 + FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028 + FILE_DEVICE_BATTERY 0x00000029 + FILE_DEVICE_BUS_EXTENDER 0x0000002a + FILE_DEVICE_MODEM 0x0000002b + FILE_DEVICE_VDM 0x0000002c + */ /* characteristics is one of the following values: @@ -724,26 +831,26 @@ typedef FILE_FS_DEVICE_INFORMATION *PFILE_FS_DEVICE_INFORMATION; FILE_VIRTUAL_VOLUME 0x00000040 */ -typedef struct _FILE_FS_VOLUME_INFORMATION_ { - LARGE_INTEGER VolumeCreationTime; +typedef struct _FILE_FS_VOLUME_INFORMATION { + TIME VolumeCreationTime; ULONG VolumeSerialNumber; ULONG VolumeLabelLength; BOOLEAN SupportsObjects; - WCHAR VolumeLabel[1]; + WCHAR VolumeLabel[0]; } FILE_FS_VOLUME_INFORMATION; -typedef struct _FILE_FS_SIZE_INFORMATION_ { +typedef struct _FILE_FS_SIZE_INFORMATION { LARGE_INTEGER TotalAllocationUnits; LARGE_INTEGER AvailableAllocationUnits; ULONG SectorsPerAllocationUnit; ULONG BytesPerSector; -} FILE_FS_SIZE_INFORMATION; +} FILE_FS_SIZE_INFORMATION, *PFILE_FS_SIZE_INFORMATION; -typedef struct _FILE_FS_ATTRIBUTE_INFORMATION_ { +typedef struct _FILE_FS_ATTRIBUTE_INFORMATION { ULONG FileSystemAttributes; LONG MaximumComponentNameLength; ULONG FileSystemNameLength; - WCHAR FileSystemName[1]; + WCHAR FileSystemName[0]; } FILE_FS_ATTRIBUTE_INFORMATION; /* @@ -757,17 +864,76 @@ typedef struct _FILE_FS_ATTRIBUTE_INFORMATION_ { FILE_VOLUME_QUOTAS 0x00000020 FILE_VOLUME_IS_COMPRESSED 0x00008000 */ +typedef struct _FILE_FS_LABEL_INFORMATION { + ULONG VolumeLabelLength; + WCHAR VolumeLabel[0]; +} FILE_FS_LABEL_INFORMATION, *PFILE_FS_LABEL_INFORMATION; +// read file scatter / write file scatter +//FIXME I am a win32 struct aswell + +typedef union _FILE_SEGMENT_ELEMENT { + PVOID Buffer; + ULONG Alignment; +}FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT; // directory information -typedef struct _OBJDIR_INFORMATION_ { +typedef struct _OBJDIR_INFORMATION { UNICODE_STRING ObjectName; UNICODE_STRING ObjectTypeName; // Directory, Device ... - UCHAR Data[1]; // variable size + UCHAR Data[0]; } OBJDIR_INFORMATION, *POBJDIR_INFORMATION; +typedef struct _FILE_DIRECTORY_INFORMATION { + ULONG NextEntryOffset; + ULONG FileIndex; + TIME CreationTime; + TIME LastAccessTime; + TIME LastWriteTime; + TIME ChangeTime; + LARGE_INTEGER EndOfFile; + LARGE_INTEGER AllocationSize; + ULONG FileAttributes; + ULONG FileNameLength; + WCHAR FileName[0]; +} FILE_DIRECTORY_INFORMATION, *PFILE_DIRECTORY_INFORMATION; + +typedef struct _FILE_FULL_DIRECTORY_INFORMATION { + ULONG NextEntryOffset; + ULONG FileIndex; + TIME CreationTime; + TIME LastAccessTime; + TIME LastWriteTime; + TIME ChangeTime; + LARGE_INTEGER EndOfFile; + LARGE_INTEGER AllocationSize; + ULONG FileAttributes; + ULONG FileNameLength; + ULONG EaSize; + WCHAR FileName[0]; +} FILE_FULL_DIRECTORY_INFORMATION, *PFILE_FULL_DIRECTORY_INFORMATION; + + +typedef struct _FILE_BOTH_DIRECTORY_INFORMATION { + ULONG NextEntryOffset; + ULONG FileIndex; + TIME CreationTime; + TIME LastAccessTime; + TIME LastWriteTime; + TIME ChangeTime; + LARGE_INTEGER EndOfFile; + LARGE_INTEGER AllocationSize; + ULONG FileAttributes; + ULONG FileNameLength; + ULONG EaSize; + CHAR ShortNameLength; + WCHAR ShortName[12]; // 8.3 name + WCHAR FileName[0]; +} FILE_BOTH_DIRECTORY_INFORMATION, *PFILE_BOTH_DIRECTORY_INFORMATION; + + /* NotifyFilter / CompletionFilter: @@ -786,11 +952,11 @@ typedef struct _OBJDIR_INFORMATION_ { FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 */ -typedef struct _FILE_NOTIFY_INFORMATION_ { +typedef struct _FILE_NOTIFY_INFORMATION { ULONG NextEntryOffset; ULONG Action; ULONG FileNameLength; - WCHAR FileName[1]; // variable size + WCHAR FileName[0]; } FILE_NOTIFY_INFORMATION; @@ -809,7 +975,7 @@ typedef struct _FILE_NOTIFY_INFORMATION_ { */ -//FIXME: I belong somewhere in windows.h +//FIXME: I am a win32 object typedef VOID (*PTIMERAPCROUTINE)( @@ -820,14 +986,14 @@ VOID // NtProcessStartup parameters -typedef struct _ENVIRONMENT_INFORMATION_ { +typedef struct _ENVIRONMENT_INFORMATION { ULONG Unknown[21]; UNICODE_STRING CommandLine; UNICODE_STRING ImageFile; } ENVIRONMENT_INFORMATION, *PENVIRONMENT_INFORMATION; -typedef struct _STARTUP_ARGUMENT_ { +typedef struct _STARTUP_ARGUMENT { ULONG Unknown[3]; PENVIRONMENT_INFORMATION Environment; } STARTUP_ARGUMENT, *PSTARTUP_ARGUMENT; @@ -840,24 +1006,28 @@ typedef struct _STARTUP_ARGUMENT_ { #define FSCTL_GET_RETRIEVAL_POINTERS 0x90073 #define FSCTL_MOVE_FILE 0x90074 -typedef struct _MAPPING_PAIR_ { +typedef struct _MAPPING_PAIR +{ ULONGLONG Vcn; ULONGLONG Lcn; } MAPPING_PAIR, *PMAPPING_PAIR; -typedef struct _GET_RETRIEVAL_DESCRIPTOR_ { +typedef struct _GET_RETRIEVAL_DESCRIPTOR +{ ULONG NumberOfPairs; ULONGLONG StartVcn; - MAPPING_PAIR Pair[1]; + MAPPING_PAIR Pair[0]; } GET_RETRIEVAL_DESCRIPTOR, *PGET_RETRIEVAL_DESCRIPTOR; -typedef struct _BITMAP_DESCRIPTOR_ { +typedef struct _BITMAP_DESCRIPTOR +{ ULONGLONG StartLcn; ULONGLONG ClustersToEndOfVol; - BYTE Map[1]; + BYTE Map[0]; } BITMAP_DESCRIPTOR, *PBITMAP_DESCRIPTOR; -typedef struct _MOVEFILE_DESCRIPTOR_ { +typedef struct _MOVEFILE_DESCRIPTOR +{ HANDLE FileHandle; ULONG Reserved; LARGE_INTEGER StartVcn; @@ -867,12 +1037,29 @@ typedef struct _MOVEFILE_DESCRIPTOR_ { } MOVEFILE_DESCRIPTOR, *PMOVEFILE_DESCRIPTOR; +// semaphore information + +typedef struct _SEMAPHORE_BASIC_INFORMATION +{ + ULONG CurrentCount; + ULONG MaximumCount; +} SEMAPHORE_BASIC_INFORMATION, *PSEMAPHORE_BASIC_INFORMATION; + +// event information + +typedef struct _EVENT_BASIC_INFORMATION +{ + BOOL AutomaticReset; + BOOL Signaled; +} EVENT_BASIC_INFORMATION, *PEVENT_INFORMATION; + /* * FUNCTION: Adds an atom to the global atom table * ARGUMENTS: + Atom (OUT) = Caller supplies storage for the resulting atom. * AtomString = The string to add to the atom table. * REMARKS: The arguments map to the win32 add GlobalAddAtom. * RETURNS: Status @@ -881,15 +1068,16 @@ NTSTATUS STDCALL NtAddAtom( OUT ATOM *Atom, - IN PUNICODE_STRING pString + IN PUNICODE_STRING AtomString ); /* - * FUNCTION: Decrements a thread's resume count and places it in an alerted state. + * FUNCTION: Decrements a thread's suspend count and places it in an alerted + * state. * ARGUMENTS: * ThreadHandle = Handle to the thread that should be resumed - * SuspendCount = The resulting resume count. + * SuspendCount = The resulting suspend count. * REMARK: - A thread is resumed if its resume count is 0 + * A thread is resumed if its suspend count is 0 * RETURNS: Status */ NTSTATUS @@ -898,6 +1086,7 @@ NtAlertResumeThread( IN HANDLE ThreadHandle, OUT PULONG SuspendCount ); + /* * FUNCTION: Puts the thread in a alerted state * ARGUMENTS: @@ -909,6 +1098,7 @@ STDCALL NtAlertThread( IN HANDLE ThreadHandle ); + /* * FUNCTION: Allocates a locally unique id * ARGUMENTS: @@ -925,12 +1115,15 @@ NtAllocateLocallyUniqueId( * FUNCTION: Allocates a block of virtual memory in the process address space * ARGUMENTS: * ProcessHandle = The handle of the process which owns the virtual memory - * BaseAddress = A pointer to the virtual memory allocated - * StartAddress = (OPTIONAL) The requested start address - * NumberOfBytesAllocated = The number of bytes to allocate + * BaseAddress = A pointer to the virtual memory allocated. If you supply a non zero + * value the system will try to allocate the memory at the address supplied. It rounds + * it down to a multiple if the page size. + * ZeroBits = (OPTIONAL) You can specify the number of high order bits that must be zero, ensuring that + * the memory will be allocated at a address below a certain value. + * RegionSize = The number of bytes to allocate * AllocationType = Indicates the type of virtual memory you like to allocated, * can be one of the values : MEM_COMMIT, MEM_RESERVE, MEM_RESET, MEM_TOP_DOWN - * ProtectionType = Indicates the protection type of the pages allocated, can be a combination of + * Protect = Indicates the protection type of the pages allocated, can be a combination of * PAGE_READONLY, PAGE_READWRITE, PAGE_EXECUTE_READ, * PAGE_EXECUTE_READWRITE, PAGE_GUARD, PAGE_NOACCESS, PAGE_NOACCESS * REMARKS: @@ -943,19 +1136,20 @@ NtAllocateLocallyUniqueId( NTSTATUS STDCALL NtAllocateVirtualMemory( - IN HANDLE hProcess, - OUT PVOID BaseAddress, - IN ULONG StartAddress, - IN ULONG NumberOfBytesAllocated, + IN HANDLE ProcessHandle, + OUT PVOID *BaseAddress, + IN ULONG ZeroBits, + IN ULONG RegionSize, IN ULONG AllocationType, - IN ULONG ProtectionType + IN ULONG Protect ); /* * FUNCTION: Cancels a IO request * ARGUMENTS: * FileHandle = Handle to the file - * IoStatusBlock = Specifies the status of the io request when it was cancelled + * IoStatusBlock = + * REMARKS: * This function maps to the win32 CancelIo. * RETURNS: Status @@ -1001,7 +1195,7 @@ NtClearEvent( * ARGUMENTS: * Handle = Handle to the object * REMARKS: - This function maps to the win32 function CloseHandle. + * This function maps to the win32 function CloseHandle. * RETURNS: Status */ @@ -1017,7 +1211,7 @@ NtClose( * ARGUMENTS: * Context = Specifies the processor context * REMARKS - NtContinue can be used to continue after a exception. + * NtContinue can be used to continue after a exception. * RETURNS: Status */ //FIXME This function might need another parameter @@ -1068,6 +1262,24 @@ NtCreateEvent( IN BOOL ManualReset, IN BOOL InitialState ); + +/* + * FUNCTION: Creates an eventpair object + * ARGUMENTS: + * EventPairHandle (OUT) = Caller supplied storage for the resulting handle + * DesiredAccess = Specifies access to the event + * ObjectAttribute = Initialized attributes for the object + */ + +NTSTATUS +STDCALL +NtCreateEventPair( + OUT PHANDLE FileHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ); + + /* * FUNCTION: Creates or opens a file, directory or device object. * ARGUMENTS: @@ -1201,7 +1413,7 @@ NtCreatePagingFile( IN PUNICODE_STRING PageFileName, IN ULONG MiniumSize, IN ULONG MaxiumSize, - OUT PULONG ActualSize + OUT PULONG ActualSize ); /* * FUNCTION: Creates a process. @@ -1305,7 +1517,7 @@ NtCreateSymbolicLinkObject( * DesiredAccess = Specifies the allowed or desired access to the thread. * ObjectAttributes = Initialized attributes for the object. * ProcessHandle = Handle to the threads parent process. - * ClientId = Caller supplies storage for process id and thread id. + * ClientId (OUT) = Caller supplies storage for returned process id and thread id. * ThreadContext = Initial processor context for the thread. * InitialTeb = Initial Thread Environment Block for the Thread. * CreateSuspended = Specifies if the thread is ready for scheduling @@ -1320,7 +1532,7 @@ NtCreateThread( IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN HANDLE ProcessHandle, - IN PCLIENT_ID ClientId, + OUT PCLIENT_ID ClientId, IN PCONTEXT ThreadContext, IN PINITIAL_TEB InitialTeb, IN BOOLEAN CreateSuspended @@ -1389,15 +1601,17 @@ NtDeleteAtom( /* * FUNCTION: Deletes a file * ARGUMENTS: - * FileHandle = Handle to the file which should be deleted + * ObjectAttributes = Handle to the file which should be deleted * REMARKS: - * The function maps to the win32 DeleteFile + This system call is functionally equivalent to NtSetInformationFile + setting the disposition information. + * The function maps to the win32 DeleteFile. * RETURNS: Status */ NTSTATUS STDCALL NtDeleteFile( - IN HANDLE FileHandle + IN POBJECT_ATTRIBUTES ObjectAttributes ); /* @@ -1572,6 +1786,9 @@ NtFindAtom( * FUNCTION: Flushes chached file data to disk * ARGUMENTS: * FileHandle = Points to the file + IoStatusBlock = Caller must supply storage to receive the result of the flush + buffers operation. The information field is set to number of bytes + flushed to disk. * RETURNS: Status * REMARKS: This funciton maps to the win32 FlushFileBuffers @@ -1579,7 +1796,8 @@ NtFindAtom( NTSTATUS STDCALL NtFlushBuffersFile( - IN HANDLE FileHandle + IN HANDLE FileHandle, + OUT PIO_STATUS_BLOCK IoStatusBlock ); /* * FUNCTION: Flushes a the processors instruction cache @@ -1651,9 +1869,9 @@ NtFlushWriteBuffer ( * FUNCTION: Frees a range of virtual memory * ARGUMENTS: * ProcessHandle = Points to the process that allocated the virtual memory - * BaseAddress = Points to the memory address - * NumberOfBytesToFree = Limits the range to free, - * NumberOfBytesFreed = Actual number of bytes freed + * BaseAddress = Points to the memory address, rounded down to a multiple of the pagesize + * RegionSize = Limits the range to free, rounded up to a multiple of the paging size + * FreeType = Can be one of the values: MEM_DECOMMIT, or MEM_RELEASE * RETURNS: Status */ @@ -1661,9 +1879,9 @@ NTSTATUS STDCALL NtFreeVirtualMemory( IN PHANDLE ProcessHandle, - IN PVOID BaseAddress, - IN ULONG NumberOfBytesToFree, - OUT PULONG NumberOfBytesFreeed OPTIONAL + IN PVOID *BaseAddress, + IN ULONG RegionSize, + IN ULONG FreeType ); /* @@ -1758,9 +1976,9 @@ NtLoadDriver( * FUNCTION: Loads a registry key. * ARGUMENTS: * KeyHandle = Handle to the registry key - * ObjectAttributes = ??? + ObjectAttributes = ??? * REMARK: - * This procedure maps to the win32 procedure RegLoadKey + This procedure maps to the win32 procedure RegLoadKey * RETURNS: Status */ NTSTATUS @@ -1778,13 +1996,13 @@ NtLoadKey( * ApcContext = Argument to the callback * IoStatusBlock (OUT) = Caller should supply storage for a structure containing * the completion status and information about the requested lock operation. - * ByteOffsetOfLock = Offset - * LengthOfLock = Number of bytes to lock. - * KeyOfLock = - * DoNotWaitIfHeld = - * IsExclusiveLock = + * ByteOffset = Offset + * Length = Number of bytes to lock. + * Key = + * FailImmediatedly = + * ExclusiveLock = * REMARK: - * This procedure maps to the win32 procedure LockFileEx + This procedure maps to the win32 procedure LockFileEx * RETURNS: Status */ NTSTATUS @@ -1795,11 +2013,11 @@ NtLockFile( IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN PLARGE_INTEGER ByteOffsetOfLock, - IN PLARGE_INTEGER LengthOfLock, - IN ULONG KeyOfLock, - IN BOOLEAN DoNotWaitIfHeld, - IN BOOLEAN IsExclusiveLock + IN PLARGE_INTEGER ByteOffset, + IN PLARGE_INTEGER Length, + IN ULONG Key, + IN BOOLEAN FailImmediatedly, + IN BOOLEAN ExclusiveLock ); /* * FUNCTION: Locks a range of virtual memory. @@ -1809,7 +2027,7 @@ NtLockFile( * NumberOfBytesLock = Offset to the upper boundary. * NumberOfBytesLocked (OUT) = Number of bytes actually locked. * REMARK: - * This procedure maps to the win32 procedure VirtualLock + This procedure maps to the win32 procedure VirtualLock * RETURNS: Status */ NTSTATUS @@ -1832,8 +2050,6 @@ STDCALL NtMakeTemporaryObject( IN HANDLE Handle ); - - /* * FUNCTION: Maps a view of a section into the virtual address space of a * process @@ -1873,15 +2089,28 @@ NtMapViewOfSection( * FUNCTION: Installs a notify for the change of a directory's contents * ARGUMENTS: * FileHandle = Handle to the directory - * Event = - * UserApcRoutine = Start address - * UserApcContext = Delimits the range of virtual memory + Event = + * ApcRoutine = Start address + * ApcContext = Delimits the range of virtual memory * for which the new access protection holds * IoStatusBlock = The new access proctection for the pages * Buffer = Caller supplies storage for resulting information --> FILE_NOTIFY_INFORMATION * BufferSize = Size of the buffer - * NotifyFilter = // might be completionfileter - * WatchSubtree = + CompletionFilter = Can be one of the following values: + FILE_NOTIFY_CHANGE_FILE_NAME + FILE_NOTIFY_CHANGE_DIR_NAME + FILE_NOTIFY_CHANGE_NAME ( FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME ) + FILE_NOTIFY_CHANGE_ATTRIBUTES + FILE_NOTIFY_CHANGE_SIZE + FILE_NOTIFY_CHANGE_LAST_WRITE + FILE_NOTIFY_CHANGE_LAST_ACCESS + FILE_NOTIFY_CHANGE_CREATION ( change of creation timestamp ) + FILE_NOTIFY_CHANGE_EA + FILE_NOTIFY_CHANGE_SECURITY + FILE_NOTIFY_CHANGE_STREAM_NAME + FILE_NOTIFY_CHANGE_STREAM_SIZE + FILE_NOTIFY_CHANGE_STREAM_WRITE + WatchTree = If true the notify will be installed recursively on the targetdirectory and all subdirectories. * * REMARKS: * The function maps to the win32 FindFirstChangeNotification, FindNextChangeNotification @@ -1892,16 +2121,29 @@ STDCALL NtNotifyChangeDirectoryFile( IN HANDLE FileHandle, IN HANDLE Event OPTIONAL, - IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, - IN PVOID UserApcContext OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, OUT PVOID Buffer, IN ULONG BufferSize, - IN ULONG NotifyFilter, - IN BOOL WatchSubtree + IN ULONG CompletionFilter, + IN BOOL WatchTree + ); +NTSTATUS +STDCALL +NtNotifyChangeKey( + IN HANDLE KeyHandle, + IN HANDLE Event, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + IN ULONG CompletionFilter, + IN BOOLEAN Asynchroneous, + OUT PVOID ChangeBuffer, + IN ULONG Length, + IN BOOLEAN WatchSubtree ); -//NtNotifyChangeKey /* * FUNCTION: Opens an existing directory object * ARGUMENTS: @@ -1941,7 +2183,7 @@ NtOpenEvent( * ObjectAttributes = Initialized attributes for the object * IoStatusBlock = * ShareAccess = - * FileAttributes = + * OpenOptions = * RETURNS: Status */ NTSTATUS @@ -1952,15 +2194,32 @@ NtOpenFile( IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG ShareAccess, - IN ULONG FileAttributes + IN ULONG OpenOptions ); -//--> NtOpenIoCompletion + +/* + * FUNCTION: Opens an existing io completion object + * ARGUMENTS: + * CompletionPort (OUT) = Caller supplied storage for the resulting handle + * DesiredAccess = Requested access to the io completion object + * ObjectAttributes = Initialized attributes for the object + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtOpenIoCompletion( + OUT PHANDLE CompetionPort, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes + ); + /* * FUNCTION: Opens an existing key in the registry * ARGUMENTS: * KeyHandle (OUT) = Caller supplied storage for the resulting handle * DesiredAccess = Requested access to the key - * ObjectAttribute = Initialized attributes for the object + * ObjectAttributes = Initialized attributes for the object * RETURNS: Status */ NTSTATUS @@ -1992,7 +2251,7 @@ NtOpenMutant( * ProcessHandle (OUT) = Caller supplied storage for the resulting handle * DesiredAccess = Requested access to the process * ObjectAttribute = Initialized attributes for the object - * ClientId = storage for the process id and the thread id + * ClientId = Identifies the process id to open * RETURNS: Status */ NTSTATUS @@ -2054,6 +2313,7 @@ NtOpenSymbolicLinkObject( * ThreadHandle (OUT) = Caller supplied storage for the resulting handle * DesiredAccess = Requested access to the thread * ObjectAttribute = Initialized attributes for the object + * ClientId = Identifies the thread to open. * RETURNS: Status */ NTSTATUS @@ -2061,7 +2321,8 @@ STDCALL NtOpenThread( OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, - IN POBJECT_ATTRIBUTES ObjectAttributes + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN PCLIENT_ID ClientId ); /* * FUNCTION: Opens an existing timer @@ -2130,7 +2391,25 @@ NtPulseEvent( ); //-- NtQueryAttributesFile -//-- NtQueryDirectoryFile + +// FileNameInformation - FILE_NAMES_INFORMATION + +NTSTATUS +STDCALL +NtQueryDirectoryFile( + IN HANDLE FileHandle, + IN HANDLE Event OPTIONAL, + IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, + IN PVOID ApcContext OPTIONAL, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID FileInformation, + IN ULONG Length, + IN FILE_INFORMATION_CLASS FileInformationClass, + IN BOOLEAN ReturnSingleEntry, + IN PUNICODE_STRING FileName OPTIONAL, + IN BOOLEAN RestartScan + ); + /* * FUNCTION: Query information about the content of a directory object * ARGUMENTS: @@ -2155,13 +2434,27 @@ NtQueryDirectoryObject( OUT PULONG DataWritten OPTIONAL ); - -//-- NtQueryEaFile +NTSTATUS +STDCALL +NtQueryEaFile( + IN HANDLE FileHandle, + OUT PIO_STATUS_BLOCK IoStatusBlock, + OUT PVOID Buffer, + IN ULONG Length, + IN BOOLEAN ReturnSingleEntry, + IN PVOID EaList OPTIONAL, + IN ULONG EaListLength, + IN PULONG EaIndex OPTIONAL, + IN BOOLEAN RestartScan + ); /* * FUNCTION: Queries an event * ARGUMENTS: * EventHandle = Handle to the event * EventInformationClass = Index of the information structure + + EventBasicInformation EVENT_BASIC_INFORMATION + * EventInformation = Caller supplies storage for the information structure * EventInformationLength = Size of the information structure * ReturnLength = Data written @@ -2193,9 +2486,9 @@ NtQueryEvent( * Lenght = Size of the storage for the file information. * FileInformationClass = Indicates which file information is queried - FileDirectoryInformation - FileFullDirectoryInformation - FileBothDirectoryInformation + FileDirectoryInformation FILE_DIRECTORY_INFORMATION + FileFullDirectoryInformation FILE_FULL_DIRECTORY_INFORMATION + FileBothDirectoryInformation FILE_BOTH_DIRECTORY_INFORMATION FileBasicInformation FILE_BASIC_INFORMATION FileStandardInformation FILE_STANDARD_INFORMATION FileInternalInformation FILE_INTERNAL_INFORMATION @@ -2204,7 +2497,7 @@ NtQueryEvent( FileNameInformation FILE_NAME_INFORMATION FileRenameInformation FILE_RENAME_INFORMATION FileLinkInformation - FileNamesInformation + FileNamesInformation FILE_NAMES_INFORMATION FileDispositionInformation FILE_DISPOSITION_INFORMATION FilePositionInformation FILE_POSITION_INFORMATION FileFullEaInformation FILE_FULL_EA_INFORMATION @@ -2262,7 +2555,6 @@ NtQueryInformationFile( ProcessVmCounters VM_COUNTERS ProcessTimes KERNEL_USER_TIMES ProcessBasePriority KPRIORITY - ProcessBasePriority KPRIORITY ProcessRaisePriority KPRIORITY ProcessDebugPort HANDLE ProcessExceptionPort HANDLE @@ -2276,7 +2568,7 @@ NtQueryInformationFile( ProcessUserModeIOPL (I/O Privilege Level) ProcessEnableAlignmentFaultFixup BOOLEAN ProcessPriorityClass ULONG - ProcessWx86Information + ProcessWx86Information ULONG ProcessHandleCount ULONG ProcessAffinityMask ULONG ProcessPooledQuotaLimits QUOTA_LIMITS @@ -2295,6 +2587,7 @@ NtQueryInformationFile( + NTSTATUS STDCALL NtQueryInformationProcess( @@ -2305,13 +2598,15 @@ NtQueryInformationProcess( OUT PULONG ReturnLength ); + + /* * FUNCTION: Queries the information of a thread object. * ARGUMENTS: * ThreadHandle = Handle to the thread object * ThreadInformationClass = Index to a certain information structure - ThreadBasicInformation + ThreadBasicInformation THREAD_BASIC_INFORMATION ThreadTimes KERNEL_USER_TIMES ThreadPriority KPRIORITY ThreadBasePriority KPRIORITY @@ -2323,9 +2618,9 @@ NtQueryInformationProcess( ThreadQuerySetWin32StartAddress ThreadZeroTlsCell ThreadPerformanceCount - ThreadAmILastThread - ThreadIdealProcessor - ThreadPriorityBoost + ThreadAmILastThread BOOLEAN + ThreadIdealProcessor ULONG + ThreadPriorityBoost ULONG MaxThreadInfoClass @@ -2349,8 +2644,18 @@ NtQueryInformationThread( IN ULONG ThreadInformationLength, OUT PULONG ReturnLength ); -// NtQueryInformationToken -//-- NtQueryIoCompletion + +NTSTATUS +STDCALL +NtQueryIoCompletion( + IN HANDLE CompletionPort, + IN CINT CompletionInformationClass, + OUT PVOID CompletionInformation, + IN ULONG Length, + OUT PULONG ReturnLength + ); + + /* * FUNCTION: Queries the information of a registry key object. * ARGUMENTS: @@ -2369,20 +2674,53 @@ NtQueryKey( IN ULONG Length, OUT PULONG ResultLength ); -//-- NtQueryMultipleValueKey -//-- NtQueryMutant + +// preliminary guess + +NTSTATUS +STDCALL +NtQueryMultipleValueKey( + HANDLE KeyHandle, + PVALENT ListOfValuesToQuery, + ULONG NumberOfItems, + PVOID MultipleValueInformation, + ULONG Length, + PULONG ReturnLength +); + +/* + * FUNCTION: Queries the information of a mutant object. + * ARGUMENTS: + MutantHandle = Handle to a mutant + MutantInformationClass = Index to a certain information structure + MutantInformation = Caller supplies storage for resulting information + Length = Size of the supplied storage + ResultLength = Bytes written + */ +NTSTATUS +STDCALL +NtQueryMutant( + IN HANDLE MutantHandle, + IN CINT MutantInformationClass, + OUT PVOID MutantInformation, + IN ULONG Length, + OUT PULONG ResultLength + ); + /* * FUNCTION: Queries the information of a object. * ARGUMENTS: ObjectHandle = Handle to a object - HandleInformationClass = Index to a certain information structure + ObjectInformationClass = Index to a certain information structure - HandleBasicInformation HANDLE_BASIC_INFORMATION - HandleTypeInormation HANDLE_TYPE_INFORMATION + ObjectBasicInformation + ObjectTypeInformation OBJECT_TYPE_INFORMATION + ObjectNameInformation OBJECT_NAME_INFORMATION + ObjectDataInformation OBJECT_DATA_INFORMATION - HandleInformation = Caller supplies storage for resulting information + ObjectInformation = Caller supplies storage for resulting information Length = Size of the supplied storage ResultLength = Bytes written */ @@ -2391,8 +2729,8 @@ NTSTATUS STDCALL NtQueryObject( IN HANDLE ObjectHandle, - IN CINT HandleInformationClass, - OUT PVOID HandleInformationPtr, + IN CINT ObjectInformationClass, + OUT PVOID ObjectInformation, IN ULONG Length, OUT PULONG ResultLength ); @@ -2436,7 +2774,28 @@ NtQuerySection( ); -//-- NtQuerySemaphore +/* + * FUNCTION: Queries the information of a semaphore. + * ARGUMENTS: + * SemaphoreHandle = Handle to the semaphore object + * SemaphoreInformationClass = Index to a certain information structure + + SemaphoreBasicInformation SEMAPHORE_BASIC_INFORMATION + + * SemaphoreInformation = Caller supplies storage for the semaphore information structure + * Length = Size of the infomation structure + */ + +NTSTATUS +STDCALL +NtQuerySemaphore( + HANDLE SemaphoreHandle, + CINT SemaphoreInformationClass, + OUT PVOID SemaphoreInformation, + ULONG Length, + PULONG ReturnLength + ); + /* * FUNCTION: Queries the information of a symbolic link object. * ARGUMENTS: @@ -2497,21 +2856,18 @@ NtQuerySystemTime ( /* * FUNCTION: Queries the timer resolution * ARGUMENTS: - * MinimumResolution (OUT) = Caller should supply storage for the - * resulting time. - * Maximum Resolution (OUT) = Caller should supply storage for the - * resulting time. - * ActualResolution (OUT) = Caller should supply storage for the - * resulting time. + * MinimumResolution (OUT) = Caller should supply storage for the resulting time. + Maximum Resolution (OUT) = Caller should supply storage for the resulting time. + ActualResolution (OUT) = Caller should supply storage for the resulting time. * RETURNS: Status * - */ +*/ NTSTATUS NtQueryTimerResolution ( OUT PULONG MinimumResolution, - OUT PULONG MaximumResolution, + OUT PULONG MaximumResolution, OUT PULONG ActualResolution ); @@ -2581,13 +2937,13 @@ NtQueryVirtualMemory( FSInformationClass = Index to a information structure FileFsVolumeInformation FILE_FS_VOLUME_INFORMATION - FileFsLabelInformation + FileFsLabelInformation FILE_FS_LABEL_INFORMATION FileFsSizeInformation FILE_FS_SIZE_INFORMATION FileFsDeviceInformation FILE_FS_DEVICE_INFORMATION FileFsAttributeInformation FILE_FS_ATTRIBUTE_INFORMATION FileFsControlInformation - FileFsQuotaQueryInformation - FileFsQuotaSetInformation + FileFsQuotaQueryInformation -- + FileFsQuotaSetInformation -- FileFsMaximumInformation * RETURNS: Status @@ -2676,7 +3032,7 @@ NtReadFileScatter( IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK UserIoStatusBlock, - IN LARGE_INTEGER BufferDescription[], + IN FILE_SEGMENT_ELEMENT BufferDescription[], IN ULONG BufferLength, IN PLARGE_INTEGER ByteOffset, IN PULONG Key OPTIONAL @@ -2730,7 +3086,7 @@ NtReleaseMutant( /* * FUNCTION: Releases a semaphore * ARGUMENTS: - * SemaphoreHandle = + * SemaphoreHandle = Handle to the semaphore object * ReleaseCount = * PreviousCount = * RETURNS: Status @@ -2790,7 +3146,14 @@ NtResetEvent( HANDLE EventHandle, PULONG NumberOfWaitingThreads OPTIONAL ); - //NtRestoreKey +//Preliminary guess +NTSTATUS +STDCALL +NtRestoreKey( + HANDLE KeyHandle, + HANDLE FileHandle, + ULONG RestoreFlags + ); /* * FUNCTION: Decrements a thread's resume count * ARGUMENTS: @@ -2807,7 +3170,22 @@ NtResumeThread( IN HANDLE ThreadHandle, IN PULONG SuspendCount ); - //NtSaveKey +/* + * FUNCTION: Writes the content of a registry key to ascii file + * ARGUMENTS: + * KeyHandle = Handle to the key + * FileHandle = Handle of the file + * REMARKS: + This function maps to the Win32 RegSaveKey. + * RETURNS: Status + */ + +NTSTATUS +STDCALL +NtSaveKey( + IN HANDLE KeyHandle, + IN HANDLE FileHandle + ); /* * FUNCTION: Sets the context of a specified thread. * ARGUMENTS: @@ -2841,8 +3219,10 @@ NtSetEaFile( ULONG EaBufferSize ); +//FIXME Shoud I have input EVENT_BASIC_INFORMATION ?? + /* - * FUNCTION: Set an event to a signalled state. + * FUNCTION: Sets the attributes of an event. * ARGUMENTS: * EventHandle = Handle to the event * Count = The resulting count. @@ -2854,10 +3234,35 @@ NtSetEaFile( NTSTATUS STDCALL NtSetEvent( - HANDLE EventHandle, + IN HANDLE EventHandle, PULONG Count ); +/* + * FUNCTION: Sets the high part of an event pair + * ARGUMENTS: + EventPair = Handle to the event pair + * RETURNS: Status +*/ + +NTSTATUS +STDCALL +NtSetHighEventPair( + IN HANDLE EventPair + ); + +/* + * FUNCTION: Sets the high part of an event pair and wait for the low part + * ARGUMENTS: + EventPair = Handle to the event pair + * RETURNS: Status +*/ +NTSTATUS +STDCALL +NtSetHighWaitLowEventPair( + IN HANDLE EventPair + ); + /* * FUNCTION: Sets the information of a file object. * ARGUMENTS: @@ -2865,10 +3270,10 @@ NtSetEvent( * IoStatusBlock = Caller supplies storage for extended information * on the current operation. * FileInformation = Storage for the new file information - * Lenght = Size of the storage for the file information. - * FileInformationClass = Indicates which file information is set + * Lenght = Size of the new file information. + * FileInformationClass = Indicates to a certain information structure - FileNameInformation PUNICODE_STRING + FileNameInformation FILE_NAME_INFORMATION FileRenameInformation FILE_RENAME_INFORMATION FileStreamInformation FILE_STREAM_INFORMATION * FileCompletionInformation IO_COMPLETION_CONTEXT @@ -2879,6 +3284,7 @@ NtSetEvent( * RETURNS: Status */ + NTSTATUS STDCALL NtSetInformationFile( @@ -2894,13 +3300,13 @@ NtSetInformationFile( * FUNCTION: Sets the information of a registry key. * ARGUMENTS: * KeyHandle = Handle to the registry key - * KeyInformationClass = Index to the a certain set of parameter to set. + * KeyInformationClass = Index to the a certain information structure. Can be one of the following values: * KeyWriteTimeInformation KEY_WRITE_TIME_INFORMATION - KeyInformation = Storage for the new key information - * KeyInformationLength = Size of the storage allocated for the key information + KeyInformation = Storage for the new information + * KeyInformationLength = Size of the information strucure * RETURNS: Status */ @@ -2916,16 +3322,17 @@ NtSetInformationKey( * FUNCTION: Changes a set of object specific parameters * ARGUMENTS: * ObjectHandle = - * HandleInformationClass = Index to the set of parameters to change. + * ObjectInformationClass = Index to the set of parameters to change. - HandleInformation - HandleName - HandleTypeInformation - HandleAllInformation - HandleBasicInformation + + ObjectBasicInformation + ObjectTypeInformation OBJECT_TYPE_INFORMATION + ObjectAllInformation + ObjectDataInformation OBJECT_DATA_INFORMATION + ObjectNameInformation OBJECT_NAME_INFORMATION - * HandleInformation = Caller supplies storage for parameters to set. + * ObjectInformation = Caller supplies storage for parameters to set. * Length = Size of the storage supplied * RETURNS: Status */ @@ -2933,8 +3340,8 @@ NTSTATUS STDCALL NtSetInformationObject( IN HANDLE ObjectHandle, - IN CINT HandleInformationClass, - IN PVOID HandleInformationPtr, + IN CINT ObjectInformationClass, + IN PVOID ObjectInformation, IN ULONG Length ); @@ -2947,13 +3354,13 @@ NtSetInformationObject( * ProcessBasicInformation PROCESS_BASIC_INFORMATION * ProcessQuotaLimits QUOTA_LIMITS * ProcessBasePriority KPRIORITY - * ProcessRaisePriority KPRIORITY + * ProcessRaisePriority KPRIORITY * ProcessDebugPort HANDLE * ProcessExceptionPort HANDLE * ProcessAccessToken PROCESS_ACCESS_TOKEN * ProcessDefaultHardErrorMode ULONG * ProcessPriorityClass ULONG - * ProcessAffinityMask KAFFINITY + * ProcessAffinityMask KAFFINITY //?? * * ProcessInformation = Caller supplies storage for information to set. * ProcessInformationLength = Size of the information structure @@ -2975,9 +3382,10 @@ NtSetInformationProcess( * Can be one of the following values: * * ThreadBasicInformation THREAD_BASIC_INFORMATION - * ThreadPriority KPRIORITY + * ThreadPriority KPRIORITY //??? * ThreadBasePriority KPRIORITY - * ThreadAffinityMask KAFFINITY + * ThreadAffinityMask KAFFINITY //?? + * ThreadImpersonationToken ACCESS_TOKEN * ThreadIdealProcessor ULONG * ThreadPriorityBoost ULONG * @@ -2994,8 +3402,9 @@ NtSetInformationThread( IN ULONG ThreadInformationLength ); //FIXME: Are the arguments correct +// Might be a ordinary set function /* - * FUNCTION: Sets a io completion + * FUNCTION: Sets an io completion * ARGUMENTS: * CompletionPort = * CompletionKey = @@ -3014,23 +3423,43 @@ NtSetIoCompletion( OUT PULONG NumberOfBytesTransferred ); //FIXME: Should I have more parameters ? - -typedef struct - { - } LDT_ENTR, *PLDT_ENTR; - /* * FUNCTION: Initializes the Local Descriptor Table * ARGUMENTS: - * ProcessHandle = - * LdtEntry = + ProcessHandle = + LdtEntry = * RETURNS: Status - */ +*/ NTSTATUS STDCALL NtSetLdtEntries( HANDLE ProcessHandle, - PLDT_ENTR LdtEntry + PVOID LdtEntry // LDT_ENTR + ); + +/* + * FUNCTION: Sets the low part of an event pair + * ARGUMENTS: + EventPair = Handle to the event pair + * RETURNS: Status +*/ + +NTSTATUS +STDCALL +NtSetLowEventPair( + HANDLE EventPair + ); + +/* + * FUNCTION: Sets the low part of an event pair and wait for the high part + * ARGUMENTS: + EventPair = Handle to the event pair + * RETURNS: Status +*/ +NTSTATUS +STDCALL +NtSetLowWaitHighEventPair( + HANDLE EventPair ); //FIXME: Should Value be a void pointer or a pointer to a unicode string ? @@ -3200,7 +3629,7 @@ NtSignalAndWaitForSingleObject( * FUNCTION: Increments a thread's resume count * ARGUMENTS: * ThreadHandle = Handle to the thread that should be resumed - * SuspendCount = The resulting suspend count. + * PreviousSuspendCount = The resulting/previous suspend count. * REMARK: * A thread will be suspended if its suspend count is greater than 0. This procedure maps to * the win32 SuspendThread function. ( documentation about the the suspend count can be found here aswell ) @@ -3285,9 +3714,10 @@ NtUnloadKey( * FileHandle = Handle to the file * IoStatusBlock = Caller should supply storage for a structure containing * the completion status and information about the requested unlock operation. - * StartAddress = StartAddress of the range of bytes to unlock - * NumberOfBytesToUnlock = Number of bytes to unlock. - * NumberOfBytesUnlocked (OUT) = Number of bytes actually unlocked. + The information field is set to the number of bytes unlocked. + * ByteOffset = Offset to start the range of bytes to unlock + * Length = Number of bytes to unlock. + * Key = * REMARK: This procedure maps to the win32 procedure UnlockFileEx * RETURNS: Status @@ -3297,9 +3727,9 @@ STDCALL NtUnlockFile( IN HANDLE FileHandle, OUT IO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER StartAddress, - IN LARGE_INTEGER NumberOfBytesToUnlock, - OUT PLARGE_INTEGER NumberOfBytesUnlocked OPTIONAL + IN LARGE_INTEGER ByteOffset, + IN LARGE_INTEGER Lenght, + OUT PULONG Key OPTIONAL ); /* @@ -3352,7 +3782,7 @@ NTSTATUS STDCALL NtWaitForMultipleObjects ( IN ULONG Count, - IN PHANDLE Object[], + IN PHANDLE Object[0], IN CINT WaitType, IN BOOLEAN Alertable, IN PLARGE_INTEGER Time @@ -3436,7 +3866,7 @@ STDCALL NtWriteFileScatter( IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, IN PVOID ApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, - IN LARGE_INTEGER BufferDescription[], + IN FILE_SEGMENT_ELEMENT BufferDescription[], IN ULONG BufferLength, IN PLARGE_INTEGER ByteOffset, IN PULONG Key OPTIONAL diff --git a/reactos/include/internal/debug.h b/reactos/include/internal/debug.h index 6c8a05f9c30..f770eb2f7fe 100644 --- a/reactos/include/internal/debug.h +++ b/reactos/include/internal/debug.h @@ -16,13 +16,13 @@ #ifndef __INTERNAL_DEBUG #define __INTERNAL_DEBUG -#define UNIMPLEMENTED do {printk("%s at %s:%d is umimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;); } while(0); +#define UNIMPLEMENTED do {DbgPrint("%s at %s:%d is umimplemented, have a nice day\n",__FUNCTION__,__FILE__,__LINE__); for(;;); } while(0); #ifndef NDEBUG -#define DPRINT(fmt,args...) do { printk("(%s:%d) ",__FILE__,__LINE__); printk(fmt,args); } while(0); -//#define assert(x) if (!(x)) {printk("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); (*((unsigned int *)0))=1; for (;;); } -#define assert(x) if (!(x)) {printk("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); for (;;); } -#define CHECKPOINT printk("%s:%d\n",__FILE__,__LINE__) +#define DPRINT(fmt,args...) do { DbgPrint("(%s:%d) ",__FILE__,__LINE__); DbgPrint(fmt,args); } while(0); +//#define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); (*((unsigned int *)0))=1; for (;;); } +#define assert(x) if (!(x)) {DbgPrint("Assertion "#x" failed at %s:%d\n", __FILE__,__LINE__); for (;;); } +#define CHECKPOINT DbgPrint("%s:%d\n",__FILE__,__LINE__) #else #define DPRINT(fmt,args...) #define assert(x) diff --git a/reactos/include/internal/hal/page.h b/reactos/include/internal/hal/page.h index b185bb5b131..2976b47434a 100644 --- a/reactos/include/internal/hal/page.h +++ b/reactos/include/internal/hal/page.h @@ -5,7 +5,7 @@ #ifndef __INTERNAL_HAL_PAGE_H #define __INTERNAL_HAL_PAGE_H -#include +#include #define PAGESIZE (4096) @@ -27,6 +27,8 @@ void set_page(unsigned int vaddr, unsigned int attributes, #define PA_READ (1<<0) #define PA_WRITE ((1<<0)+(1<<1)) #define PA_EXECUTE PA_READ +#define PA_PCD (1<<4) +#define PA_PWT (1<<3) /* * Page attributes @@ -60,7 +62,6 @@ extern inline unsigned int* get_page_directory(void) unsigned int page_dir=0; __asm__("movl %%cr3,%0\n\t" : "=r" (page_dir)); -// printk("page_dir %x %x\n",page_dir,physical_to_linear(page_dir)); return((unsigned int *)physical_to_linear(page_dir)); } diff --git a/reactos/include/internal/kernel.h b/reactos/include/internal/kernel.h index 28d17060a7d..a5979a292fb 100644 --- a/reactos/include/internal/kernel.h +++ b/reactos/include/internal/kernel.h @@ -1,109 +1 @@ -/* - * Various useful prototypes - */ - -#ifndef __KERNEL_H -#define __KERNEL_H - -#include -#include - -#include -#include - -/* - * Use these to place a function in a specific section of the executable - */ -#define PLACE_IN_SECTION(s) __attribute__((section (s))) -#define INIT_FUNCTION (PLACE_IN_SECTION("init")) -#define PAGE_LOCKED_FUNCTION (PLACE_IN_SECTION("pagelk")) -#define PAGE_UNLOCKED_FUNCTION (PLACE_IN_SECTION("pagepo")) - -/* - * Maximum size of the kmalloc area (this is totally arbitary) - */ -#define NONPAGED_POOL_SIZE (4*1024*1024) - -VOID KiInterruptDispatch(unsigned int irq); -VOID KiDispatchInterrupt(unsigned int irq); -VOID KeTimerInterrupt(VOID); - -/* - * Defines a descriptor as it appears in the processor tables - */ -typedef struct -{ - unsigned int a; - unsigned int b; -} descriptor; - -extern descriptor idt[256]; -extern descriptor gdt[256]; - -/* - * printf style functions - */ -asmlinkage void printk(const char* fmt, ...); -int vsprintf(char *buf, const char *fmt, va_list args); -int sprintf(char* buf, const char* fmt, ...); - -typedef struct -{ - /* - * Magic value (useless really) - */ - unsigned int magic; - - /* - * Cursor position - */ - unsigned int cursorx; - unsigned int cursory; - - /* - * Number of files (including the kernel) loaded - */ - unsigned int nr_files; - - /* - * Range of physical memory being used by the system - */ - unsigned int start_mem; - unsigned int end_mem; - - /* - * List of module lengths (terminated by a 0) - */ - unsigned int module_length[64]; -} boot_param; - - -/* - * Initalization functions (called once by main()) - */ -void MmInitalize(boot_param* bp); -void InitalizeExceptions(void); -void InitalizeIRQ(void); -void InitializeTimer(void); -void InitConsole(boot_param* bp); -void KeInitDpc(void); -void HalInit(boot_param* bp); -void IoInit(void); -void ObjNamespcInit(void); -void PsMgrInit(void); -void KeInitializeBugCheck(void); -VOID KeInitializeDispatcher(VOID); -void TstBegin(void); -void KeCalibrateTimerLoop(void); - -/* - * FUNCTION: Called to execute queued dpcs - */ -void KeDrainDpcQueue(void); - -void KeExpireTimers(void); - -typedef unsigned int (exception_hook)(CONTEXT* c, unsigned int exp); -asmlinkage unsigned int ExHookException(exception_hook fn, UINT exp); - -#endif +#include diff --git a/reactos/include/internal/mm.h b/reactos/include/internal/mm.h index 8d9581ce095..189ba82b8e9 100644 --- a/reactos/include/internal/mm.h +++ b/reactos/include/internal/mm.h @@ -2,81 +2,60 @@ * Higher level memory managment definitions */ -#ifndef __MM_H -#define __MM_H +#ifndef __INCLUDE_INTERNAL_MM_H +#define __INCLUDE_INTERNAL_MM_H #define PAGE_SYSTEM (0x80000000) #include -#include +#include #include -typedef struct _memory_area -/* - * PURPOSE: Describes an area of virtual memory - */ +/* TYPES *********************************************************************/ + +enum { - /* - * Access protection - */ - unsigned int access; - - /* - * Memory region base - */ - unsigned int base; - - /* - * Memory region length - */ - unsigned int length; - - /* - * Memory type (Mapped file, mapped from an executable or private) - */ - unsigned int type; + MEMORY_AREA_INVALID, + MEMORY_AREA_SECTION_VIEW, + MEMORY_AREA_CONTINUOUS_MEMORY, + MEMORY_AREA_NO_CACHE, + MEMORY_AREA_IO_MAPPING, + MEMORY_AREA_SYSTEM, + MEMORY_AREA_MDL_MAPPING, +}; - /* - * Memory region state (committed, reserved or free) - */ - unsigned int state; - - /* - * Original access protection - */ - unsigned int initial_access; - - /* - * Used to maintain the linked list of memory areas - */ - struct _memory_area* previous; - struct _memory_area* next; - - /* - * True the region is locked - */ - BOOL lock; - - /* - * FUNCTION: Decommits all the pages in the regions - */ - void (*free)(struct _memory_area* marea); - - /* - * FUNCTION: Handles a page fault by loading the required page - * RECEIVES: - * marea = the memory area - * address = the relative address of the page to load - * RETURNS: - * TRUE = the access should be restarted - * FALSE = the access was illegal and an exception should - * be generated - * NOTES: This function is guarrented to be called within the context - * of the thread which required a page to be loaded - */ - BOOL (*load_page)(struct _memory_area* marea, unsigned int address); -} memory_area; +typedef struct +{ + FILE_OBJECT* File; +} SECTION_OBJECT; +typedef struct +{ + ULONG Type; + ULONG BaseAddress; + ULONG Length; + ULONG Attributes; + LIST_ENTRY Entry; + union + { + SECTION_OBJECT* Section; + } d; +} MEMORY_AREA; + + +NTSTATUS MmCreateMemoryArea(KPROCESSOR_MODE Mode, + ULONG Type, + PULONG BaseAddress, + ULONG Length, + ULONG Attributes, + MEMORY_AREA** Result); +MEMORY_AREA* MmOpenMemoryAreaByAddress(ULONG Address); +NTSTATUS MmInitMemoryAreas(VOID); +VOID ExInitNonPagedPool(ULONG BaseAddress); +NTSTATUS MmFreeMemoryArea(PVOID BaseAddress, + ULONG Length, + BOOLEAN FreePages); +VOID MmDumpMemoryAreas(VOID); /* * FUNCTION: Gets a page with a restricted max physical address (i.e. @@ -120,27 +99,4 @@ void mark_page_not_writable(unsigned int vaddr); void VirtualInit(boot_param* bp); -/* - * FUNCTION: Returns the first memory area starting in the region or the last - * one before the start of the region - * ARGUMENTS: - * list_head = Head of the list of memory areas to search - * base = base address of the region - * length = length of the region - * RETURNS: A pointer to the area found or - * NULL if the region was before the first region on the list - */ -memory_area* find_first_marea(memory_area* list_head, unsigned int base, - unsigned int length); - -/* - * Head of the list of system memory areas - */ -extern memory_area* system_memory_area_list_head; - -/* - * Head of the list of user memory areas (this should be per process) - */ -extern memory_area* memory_area_list_head; - #endif diff --git a/reactos/include/internal/objmgr.h b/reactos/include/internal/objmgr.h index 0c621aea0da..1cf462240d1 100644 --- a/reactos/include/internal/objmgr.h +++ b/reactos/include/internal/objmgr.h @@ -26,6 +26,7 @@ typedef struct _DIRECTORY_OBJECT * PURPOSE: Head of the list of our subdirectories */ LIST_ENTRY head; + KSPIN_LOCK Lock; } DIRECTORY_OBJECT, *PDIRECTORY_OBJECT; diff --git a/reactos/include/internal/psmgr.h b/reactos/include/internal/psmgr.h index 75b9cc4099b..cfa531ee4da 100644 --- a/reactos/include/internal/psmgr.h +++ b/reactos/include/internal/psmgr.h @@ -1,9 +1,13 @@ #ifndef __INCLUDE_INTERNAL_PSMGR_H #define __INCLUDE_INTERNAL_PSMGR_H -#include +#include + +extern EPROCESS SystemProcess; +extern HANDLE SystemProcessHandle; void PsInitThreadManagment(void); +VOID PsInitIdleThread(VOID); /* * PURPOSE: Thread states diff --git a/reactos/include/internal/version.h b/reactos/include/internal/version.h index a7510460baf..f219e8bce63 100644 --- a/reactos/include/internal/version.h +++ b/reactos/include/internal/version.h @@ -9,9 +9,9 @@ #ifndef __VERSION_H #define __VERSION_H -#define KERNEL_VERSION "0.0.9" +#define KERNEL_VERSION "0.0.10" #define KERNEL_MAJOR_VERSION 0 #define KERNEL_MINOR_VERSION 0 -#define KERNEL_PATCH_LEVEL 9 +#define KERNEL_PATCH_LEVEL 10 #endif diff --git a/reactos/include/kernel32/heap.h b/reactos/include/kernel32/heap.h index 9b0ea12deeb..35c83985f41 100644 --- a/reactos/include/kernel32/heap.h +++ b/reactos/include/kernel32/heap.h @@ -105,6 +105,6 @@ typedef struct __HEAP HEAP_BLOCK Start __attribute__((aligned (8))); } HEAP, *PHEAP; -PHEAP __ProcessHeap; +//PHEAP __ProcessHeap; #endif /* __INCLUDE_KERNEL32_HEAP_H */ diff --git a/reactos/include/wstring.h b/reactos/include/wstring.h index 578ed7851e2..7652dd3d0b1 100644 --- a/reactos/include/wstring.h +++ b/reactos/include/wstring.h @@ -20,7 +20,7 @@ typedef unsigned short wchar_t; extern "C" { #endif -wchar_t * ___wcstok; +//wchar_t * ___wcstok = NULL; 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 *); diff --git a/reactos/loaders/dos/loadros.asm b/reactos/loaders/dos/loadros.asm index 7c8e14de00d..7844ce94cd4 100644 --- a/reactos/loaders/dos/loadros.asm +++ b/reactos/loaders/dos/loadros.asm @@ -267,13 +267,12 @@ _load_file: ; Move onto the next position in prepartion for a future read ; movzx eax,word [size_div_4k] - inc eax mov bx,[size_mod_4k] cmp bx,0 - je l20 - inc eax + je l20 + inc eax l20: - shl eax,12 + shl eax,0ch add [next_load_base],eax push fs diff --git a/reactos/makefile.dos b/reactos/makefile.dos index 5f14aeffcfd..91b86dc6358 100644 --- a/reactos/makefile.dos +++ b/reactos/makefile.dos @@ -32,6 +32,8 @@ all: $(COMPONENTS) $(LOADERS) $(MODULES) # # Device driver rules # +ide: dummy + make -C services/ide parallel: dummy make -C services/parallel diff --git a/reactos/ntoskrnl/dbg/brkpoint.c b/reactos/ntoskrnl/dbg/brkpoint.c index 369fa3b7d22..643a658b8fb 100644 --- a/reactos/ntoskrnl/dbg/brkpoint.c +++ b/reactos/ntoskrnl/dbg/brkpoint.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/callback.c b/reactos/ntoskrnl/ex/callback.c index 0ae6efd54dd..3bd3d788bd8 100644 --- a/reactos/ntoskrnl/ex/callback.c +++ b/reactos/ntoskrnl/ex/callback.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/fmutex.c b/reactos/ntoskrnl/ex/fmutex.c index 52301362fee..2aaa60011de 100644 --- a/reactos/ntoskrnl/ex/fmutex.c +++ b/reactos/ntoskrnl/ex/fmutex.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/interlck.c b/reactos/ntoskrnl/ex/interlck.c index 46ede4042fd..25287e6ebd4 100644 --- a/reactos/ntoskrnl/ex/interlck.c +++ b/reactos/ntoskrnl/ex/interlck.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/resource.c b/reactos/ntoskrnl/ex/resource.c index e02046c2b4e..a27b8c0ea48 100644 --- a/reactos/ntoskrnl/ex/resource.c +++ b/reactos/ntoskrnl/ex/resource.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/time.c b/reactos/ntoskrnl/ex/time.c index 4c6b9194bcc..ac2969fbf7b 100644 --- a/reactos/ntoskrnl/ex/time.c +++ b/reactos/ntoskrnl/ex/time.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ex/work.c b/reactos/ntoskrnl/ex/work.c index 83a7a7afc5f..405e39caf68 100644 --- a/reactos/ntoskrnl/ex/work.c +++ b/reactos/ntoskrnl/ex/work.c @@ -12,7 +12,6 @@ #include #include -#include #include @@ -46,7 +45,7 @@ typedef struct /* * PURPOSE: Queue of items waiting to be processed at normal priority */ -WORK_QUEUE normal_work_queue; +WORK_QUEUE normal_work_queue = {0,}; #define WAIT_INTERVAL (0) diff --git a/reactos/ntoskrnl/hal/x86/bios32.c b/reactos/ntoskrnl/hal/x86/bios32.c index 34e967ca2f6..bbb7f78f391 100644 --- a/reactos/ntoskrnl/hal/x86/bios32.c +++ b/reactos/ntoskrnl/hal/x86/bios32.c @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -133,7 +132,7 @@ VOID Hal_bios32_probe() { continue; } - printk("BIOS32 detected at %x\n",i); + DbgPrint("BIOS32 detected at %x\n",i); bios32_indirect.address = service_entry->entry; bios32_detected=TRUE; } diff --git a/reactos/ntoskrnl/hal/x86/bus.c b/reactos/ntoskrnl/hal/x86/bus.c index 73ecce9e507..18112832f3e 100644 --- a/reactos/ntoskrnl/hal/x86/bus.c +++ b/reactos/ntoskrnl/hal/x86/bus.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/hal/x86/bus.c + * PURPOSE: Bus functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/hal/x86/dma.c b/reactos/ntoskrnl/hal/x86/dma.c index f87d5971e7b..e819b561b5d 100644 --- a/reactos/ntoskrnl/hal/x86/dma.c +++ b/reactos/ntoskrnl/hal/x86/dma.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/hal/x86/dma.c + * FILE: ntoskrnl/hal/x86/dma.c * PURPOSE: DMA functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/hal/x86/exp.c b/reactos/ntoskrnl/hal/x86/exp.c index 54b4f9ec8fe..10dcfae1515 100644 --- a/reactos/ntoskrnl/hal/x86/exp.c +++ b/reactos/ntoskrnl/hal/x86/exp.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/hal/x86/exp.c + * FILE: ntoskrnl/hal/x86/exp.c * PURPOSE: Handling exceptions * PROGRAMMER: David Welch (welch@mcmail.com) * REVISION HISTORY: @@ -11,13 +11,19 @@ /* INCLUDES *****************************************************************/ #include - -#include +#include +#include #include #include +#define NDEBUG +#include + /* GLOBALS *****************************************************************/ +typedef unsigned int (exception_hook)(CONTEXT* c, unsigned int exp); +asmlinkage unsigned int ExHookException(exception_hook fn, UINT exp); + extern descriptor idt[256]; static exception_hook* exception_hooks[256]={NULL,}; @@ -116,6 +122,8 @@ asmlinkage void exception_handler(unsigned int edi, unsigned int i; unsigned int* stack; + __asm__("cli\n\t"); + /* * Activate any hook for the exception */ @@ -129,6 +137,7 @@ asmlinkage void exception_handler(unsigned int edi, */ printk("Exception: %d(%x)\n",type,error_code&0xffff); printk("CS:EIP %x:%x\n",cs&0xffff,eip); + for(;;); printk("EAX: %.8x EBX: %.8x ECX: %.8x\n",eax,ebx,ecx); printk("EDX: %.8x EBP: %.8x ESI: %.8x\n",edx,ebp,esi); printk("EDI: %.8x EFLAGS: %.8x ",edi,eflags); @@ -192,13 +201,15 @@ asmlinkage unsigned int ExHookException(exception_hook fn, unsigned int exp) return(0); } -asmlinkage void InitalizeExceptions(void) +asmlinkage void KeInitExceptions(void) /* * FUNCTION: Initalize CPU exception handling */ { int i; + DPRINT("KeInitExceptions()\n",0); + set_interrupt_gate(0,(int)exception_handler0); set_interrupt_gate(1,(int)exception_handler1); set_interrupt_gate(2,(int)exception_handler2); diff --git a/reactos/ntoskrnl/hal/x86/halinit.c b/reactos/ntoskrnl/hal/x86/halinit.c index a578df6b728..1b90afba403 100644 --- a/reactos/ntoskrnl/hal/x86/halinit.c +++ b/reactos/ntoskrnl/hal/x86/halinit.c @@ -10,16 +10,18 @@ /* INCLUDES *****************************************************************/ -#include -#include +#include +#include +#include /* FUNCTIONS ***************************************************************/ VOID HalInit(boot_param* bp) { - InitalizeExceptions(); - InitalizeIRQ(); + KeInitExceptions(); + KeInitIRQ(); + KeLowerIrql(DISPATCH_LEVEL); /* * Probe for a BIOS32 extension diff --git a/reactos/ntoskrnl/hal/x86/irq.c b/reactos/ntoskrnl/hal/x86/irq.c index 232ad8f0d87..9b0feaee656 100644 --- a/reactos/ntoskrnl/hal/x86/irq.c +++ b/reactos/ntoskrnl/hal/x86/irq.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/hal/x86/irq.c + * FILE: ntoskrnl/hal/x86/irq.c * PURPOSE: IRQ handling * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -20,7 +20,8 @@ #include #include -#include +#include +#include #include #include #include @@ -79,8 +80,8 @@ static unsigned int irq_handler[NR_IRQS]= * be accessed at any irq level. */ static LIST_ENTRY isr_table[NR_IRQS]={{NULL,NULL},}; -static PKSPIN_LOCK isr_lock[NR_IRQS]; -static KSPIN_LOCK isr_table_lock; +static PKSPIN_LOCK isr_lock[NR_IRQS] = {NULL,}; +static KSPIN_LOCK isr_table_lock = {0,}; /* FUNCTIONS ****************************************************************/ @@ -88,7 +89,7 @@ static KSPIN_LOCK isr_table_lock; #define PRESENT (0x8000) #define I486_INTERRUPT_GATE (0xe00) -asmlinkage void KiInterruptDispatch(unsigned int irq) +asmlinkage VOID KiInterruptDispatch(ULONG irq) /* * FUNCTION: Calls the irq specific handler for an irq * ARGUMENTS: @@ -103,7 +104,7 @@ asmlinkage void KiInterruptDispatch(unsigned int irq) * Notify the rest of the kernel of the raised irq level */ old_level = KeGetCurrentIrql(); - DPRINT("old_level %d\n",old_level); +// DPRINT("old_level %d\n",old_level); KeSetCurrentIrql(HIGH_LEVEL - irq); /* @@ -114,23 +115,24 @@ asmlinkage void KiInterruptDispatch(unsigned int irq) if (irq==0) { - KeTimerInterrupt(); + KiTimerInterrupt(); } else { - DPRINT("KiInterruptDispatch(irq %x)\n",irq); - /* - * Iterate the list until one of the isr tells us its device interrupted - */ - current = isr_table[irq].Flink; - isr = CONTAINING_RECORD(current,KINTERRUPT,Entry); - DPRINT("current %x isr %x\n",current,isr); - while (current!=NULL && !isr->ServiceRoutine(isr,isr->ServiceContext)) - { - current = current->Flink; - isr = CONTAINING_RECORD(current,KINTERRUPT,Entry); - DPRINT("current %x isr %x\n",current,isr); - } + DPRINT("KiInterruptDispatch(irq %x)\n",irq); + /* + * Iterate the list until one of the isr tells us its device interrupted + */ + current = isr_table[irq].Flink; + isr = CONTAINING_RECORD(current,KINTERRUPT,Entry); + DPRINT("current %x isr %x\n",current,isr); + while (current!=(&isr_table[irq]) && + !isr->ServiceRoutine(isr,isr->ServiceContext)) + { + current = current->Flink; + isr = CONTAINING_RECORD(current,KINTERRUPT,Entry); + DPRINT("current %x isr %x\n",current,isr); + } } /* @@ -172,10 +174,12 @@ asmlinkage void KiInterruptDispatch(unsigned int irq) KeSetCurrentIrql(old_level); } -void InitalizeIRQ(void) +void KeInitIRQ(void) { int i; + DPRINT("KeInitIrq()\n",0); + /* * First mask off all interrupts from pic */ @@ -195,6 +199,27 @@ void InitalizeIRQ(void) } } +static VOID KeDumpIrqList(VOID) +{ + PKINTERRUPT current; + PLIST_ENTRY current_entry; + unsigned int i; + + for (i=0;iFlink; + current = CONTAINING_RECORD(current_entry,KINTERRUPT,Entry); + } + DPRINT("\n",0); + } +} + NTSTATUS IoConnectInterrupt(PKINTERRUPT* InterruptObject, PKSERVICE_ROUTINE ServiceRoutine, PVOID ServiceContext, @@ -240,6 +265,8 @@ NTSTATUS IoConnectInterrupt(PKINTERRUPT* InterruptObject, ASSERT_IRQL(PASSIVE_LEVEL); + DPRINT("IoConnectInterrupt(Vector %x)\n",Vector); + /* * Check the parameters */ @@ -305,6 +332,8 @@ NTSTATUS IoConnectInterrupt(PKINTERRUPT* InterruptObject, */ KeReleaseSpinLock(&isr_table_lock,oldlvl); + KeDumpIrqList(); + return(STATUS_SUCCESS); } @@ -320,8 +349,7 @@ VOID IoDisconnectInterrupt(PKINTERRUPT InterruptObject) KeRaiseIrql(InterruptObject->SynchLevel,&oldlvl); KeAcquireSpinLockAtDpcLevel(InterruptObject->IrqLock); - RemoveEntryFromList(&isr_table[InterruptObject->Vector], - &InterruptObject->Entry); + RemoveEntryList(&InterruptObject->Entry); KeReleaseSpinLockFromDpcLevel(InterruptObject->IrqLock); KeLowerIrql(oldlvl); } diff --git a/reactos/ntoskrnl/hal/x86/irql.c b/reactos/ntoskrnl/hal/x86/irql.c index 878d3f5fc52..1c6e662eeb1 100644 --- a/reactos/ntoskrnl/hal/x86/irql.c +++ b/reactos/ntoskrnl/hal/x86/irql.c @@ -122,7 +122,7 @@ VOID KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql) // OldIrql); if (NewIrql < CurrentIrql) { - printk("%s:%d\n",__FILE__,__LINE__); + DbgPrint("%s:%d\n",__FILE__,__LINE__); for(;;); } diff --git a/reactos/ntoskrnl/hal/x86/isa.c b/reactos/ntoskrnl/hal/x86/isa.c index bba10b97ea6..bbf5127a3a7 100644 --- a/reactos/ntoskrnl/hal/x86/isa.c +++ b/reactos/ntoskrnl/hal/x86/isa.c @@ -12,10 +12,6 @@ #include #include -#include -#include -#include -#include /* FUNCTIONS *****************************************************************/ @@ -27,7 +23,7 @@ BOOL HalIsaProbe() * true */ { - printk("Assuming ISA bus\n"); + DbgPrint("Assuming ISA bus\n"); /* * Probe for plug and play support diff --git a/reactos/ntoskrnl/hal/x86/mbr.c b/reactos/ntoskrnl/hal/x86/mbr.c index 991b3ac4382..27fa2ee3c63 100644 --- a/reactos/ntoskrnl/hal/x86/mbr.c +++ b/reactos/ntoskrnl/hal/x86/mbr.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/hal/x86/mp.c b/reactos/ntoskrnl/hal/x86/mp.c index 1633dcc5fe6..2efc20575b6 100644 --- a/reactos/ntoskrnl/hal/x86/mp.c +++ b/reactos/ntoskrnl/hal/x86/mp.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/hal/x86/page.c b/reactos/ntoskrnl/hal/x86/page.c index 9ff4805aaca..8ff96d94510 100644 --- a/reactos/ntoskrnl/hal/x86/page.c +++ b/reactos/ntoskrnl/hal/x86/page.c @@ -10,7 +10,6 @@ /* INCLUDES ***************************************************************/ -#include #include #include #include @@ -127,8 +126,11 @@ PHYSICAL_ADDRESS MmGetPhysicalAddress(PVOID vaddr) * FUNCTION: Returns the physical address corresponding to a virtual address */ { + PHYSICAL_ADDRESS p; DPRINT("get_page_physical_address(vaddr %x)\n",vaddr); - return(PAGE_MASK(*get_page_entry((unsigned int)vaddr))); + p.HighPart = 0; + p.LowPart = PAGE_MASK(*get_page_entry((unsigned int)vaddr)); + return(p); } BOOL is_page_present(unsigned int vaddr) diff --git a/reactos/ntoskrnl/hal/x86/pci.c b/reactos/ntoskrnl/hal/x86/pci.c index d1692dd34be..d5db1a36e4b 100644 --- a/reactos/ntoskrnl/hal/x86/pci.c +++ b/reactos/ntoskrnl/hal/x86/pci.c @@ -16,10 +16,6 @@ #include #include -#include -#include -#include -#include /* FUNCTIONS **************************************************************/ @@ -33,7 +29,7 @@ BOOL HalPciProbe() { if (Hal_bios32_is_service_present(PCI_SERVICE)) { - printk("Detected PCI service\n"); + DbgPrint("Detected PCI service\n"); return(TRUE); } return(FALSE); diff --git a/reactos/ntoskrnl/hal/x86/printk.c b/reactos/ntoskrnl/hal/x86/printk.c index 70a1964fe31..f5be4dec169 100644 --- a/reactos/ntoskrnl/hal/x86/printk.c +++ b/reactos/ntoskrnl/hal/x86/printk.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/hal/x86/printk.c + * FILE: ntoskrnl/hal/x86/printk.c * PURPOSE: Writing to the console * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -11,7 +11,7 @@ /* INCLUDES *****************************************************************/ -#include +#include #include #include #include diff --git a/reactos/ntoskrnl/hal/x86/sysinfo.c b/reactos/ntoskrnl/hal/x86/sysinfo.c index 2a1904082f7..5d04be8449c 100644 --- a/reactos/ntoskrnl/hal/x86/sysinfo.c +++ b/reactos/ntoskrnl/hal/x86/sysinfo.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/hal/x86/sysinfo.c + * PURPOSE: Getting system information * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/hal/x86/thread.c b/reactos/ntoskrnl/hal/x86/thread.c index b5729e22f5c..5f7bd4e3db6 100644 --- a/reactos/ntoskrnl/hal/x86/thread.c +++ b/reactos/ntoskrnl/hal/x86/thread.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/hal/x86/thread.c + * FILE: ntoskrnl/hal/x86/thread.c * PURPOSE: HAL multitasking functions * PROGRAMMER: David Welch (welch@mcmail.com) * REVISION HISTORY: @@ -12,10 +12,10 @@ #include #include -#include +#include #include #include -#include +#include #include #include @@ -27,6 +27,10 @@ #define FIRST_TSS_SELECTOR (KERNEL_DS + 0x8) #define FIRST_TSS_OFFSET (FIRST_TSS_SELECTOR / 8) +static char null_ldt[8]={0,}; +static unsigned int null_ldt_sel=0; +static PKTHREAD FirstThread=NULL; + /* FUNCTIONS **************************************************************/ void HalTaskSwitch(PKTHREAD thread) @@ -38,13 +42,40 @@ void HalTaskSwitch(PKTHREAD thread) * again */ { + DPRINT("Scheduling thread %x\n",thread->Context.nr); + DPRINT("previous task %x reserved1 %x esp0 %x ss0 %x\n", + thread->Context.previous_task,thread->Context.reserved1, + thread->Context.esp0,thread->Context.ss0); + DPRINT("reserved2 %x esp1 %x ss1 %x reserved3 %x esp2 %x ss2 %x\n", + thread->Context.reserved2,thread->Context.esp1,thread->Context.ss1, + thread->Context.reserved3,thread->Context.esp2,thread->Context.ss2); + DPRINT("reserved4 %x cr3 %x eip %x eflags %x eax %x\n", + thread->Context.reserved4,thread->Context.cr3,thread->Context.eip, + thread->Context.eflags,thread->Context.eax); + DPRINT("ecx %x edx %x ebx %x esp %x ebp %x esi %x\n", + thread->Context.ecx,thread->Context.edx,thread->Context.ebx, + thread->Context.esp,thread->Context.ebp,thread->Context.esi); + DPRINT("edi %x es %x reserved5 %x cs %x reserved6 %x\n", + thread->Context.edi,thread->Context.es,thread->Context.reserved5, + thread->Context.cs,thread->Context.reserved6); + DPRINT("ss %x reserved7 %x ds %x reserved8 %x fs %x\n", + thread->Context.ss,thread->Context.reserved7,thread->Context.ds, + thread->Context.reserved8,thread->Context.fs); + DPRINT("reserved9 %x gs %x reserved10 %x ldt %x reserved11 %x\n", + thread->Context.reserved9,thread->Context.gs, + thread->Context.reserved10,thread->Context.ldt, + thread->Context.reserved11); + DPRINT("trap %x iomap_base %x nr %x io_bitmap[0] %x\n", + thread->Context.trap,thread->Context.iomap_base, + thread->Context.nr,thread->Context.io_bitmap[0]); __asm__("pushfl\n\t" "cli\n\t" "ljmp %0\n\t" "popfl\n\t" : /* No outputs */ - : "m" (*(((unsigned char *)(&(thread->context.nr)))-4) ) + : "m" (*(((unsigned char *)(&(thread->Context.nr)))-4) ) : "ax","dx"); +// set_breakpoint(0,&(FirstThread->Context.gs),HBP_READWRITE,HBP_DWORD); } static unsigned int allocate_tss_descriptor(void) @@ -76,7 +107,7 @@ static void begin_thread(PKSTART_ROUTINE fn, PVOID start_context) */ { NTSTATUS ret; - DPRINT("begin_thread %x %x\n",fn,start_context); +// DPRINT("begin_thread %x %x\n",fn,start_context); KeLowerIrql(PASSIVE_LEVEL); ret = fn(start_context); PsTerminateSystemThread(ret); @@ -96,9 +127,12 @@ BOOLEAN HalInitTask(PKTHREAD thread, PKSTART_ROUTINE fn, { unsigned int desc = allocate_tss_descriptor(); unsigned int length = sizeof(hal_thread_state) - 1; - unsigned int base = (unsigned int)(&(thread->context)); + unsigned int base = (unsigned int)(&(thread->Context)); unsigned int* kernel_stack = ExAllocatePool(NonPagedPool,4096); + DPRINT("HalInitTask(Thread %x, fn %x, StartContext %x)\n", + thread,fn,StartContext); + /* * Make sure */ @@ -122,24 +156,26 @@ BOOLEAN HalInitTask(PKTHREAD thread, PKSTART_ROUTINE fn, /* * Initialize the thread context */ - memset(&thread->context,0,sizeof(hal_thread_state)); - thread->context.ldt = 0; - thread->context.eflags = (1<<1)+(1<<9); - thread->context.iomap_base = FIELD_OFFSET(hal_thread_state,io_bitmap); - thread->context.esp0 = &kernel_stack[1021]; - thread->context.ss0 = KERNEL_DS; - thread->context.esp = &kernel_stack[1021]; - thread->context.ss = KERNEL_DS; - thread->context.cs = KERNEL_CS; - thread->context.eip = (unsigned long)begin_thread; - thread->context.io_bitmap[0] = 0xff; - thread->context.cr3 = ((unsigned int)get_page_directory()) - IDMAP_BASE; - thread->context.ds = KERNEL_DS; - thread->context.es = KERNEL_DS; - thread->context.fs = KERNEL_DS; - thread->context.gs = KERNEL_DS; - thread->context.nr = desc * 8; + memset(&thread->Context,0,sizeof(hal_thread_state)); + thread->Context.ldt = null_ldt_sel; + thread->Context.eflags = (1<<1)+(1<<9); + thread->Context.iomap_base = FIELD_OFFSET(hal_thread_state,io_bitmap); + thread->Context.esp0 = &kernel_stack[1021]; + thread->Context.ss0 = KERNEL_DS; + thread->Context.esp = &kernel_stack[1021]; + thread->Context.ss = KERNEL_DS; + thread->Context.cs = KERNEL_CS; + thread->Context.eip = (unsigned long)begin_thread; + thread->Context.io_bitmap[0] = 0xff; + thread->Context.cr3 = ((unsigned int)get_page_directory()) - IDMAP_BASE; + thread->Context.ds = KERNEL_DS; + thread->Context.es = KERNEL_DS; + thread->Context.fs = KERNEL_DS; + thread->Context.gs = KERNEL_DS; + thread->Context.nr = desc * 8; + DPRINT("Allocated %x\n",desc*8); + return(TRUE); } @@ -149,15 +185,29 @@ void HalInitFirstTask(PKTHREAD thread) * initial thread */ { + unsigned int base; + unsigned int length; + unsigned int desc; + + memset(null_ldt,0,sizeof(null_ldt)); + desc = allocate_tss_descriptor(); + base = (unsigned int)&null_ldt; + length = sizeof(null_ldt) - 1; + gdt[desc].a = (length & 0xffff) | ((base & 0xffff) << 16); + gdt[desc].b = ((base & 0xff0000)>>16) | 0x8200 | (length & 0xf0000) + | (base & 0xff000000); + null_ldt_sel = desc*8; + /* * Initialize the thread context */ HalInitTask(thread,NULL,NULL); - + /* * Load the task register */ __asm__("ltr %%ax" : /* no output */ - : "a" (FIRST_TSS_OFFSET*8)); + : "a" (thread->Context.nr)); + FirstThread = thread; } diff --git a/reactos/ntoskrnl/io/adapter.c b/reactos/ntoskrnl/io/adapter.c index 4c2d2da114f..ae08a5c521b 100644 --- a/reactos/ntoskrnl/io/adapter.c +++ b/reactos/ntoskrnl/io/adapter.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/arc.c b/reactos/ntoskrnl/io/arc.c index fe89d6be8e9..8ed720ca24a 100644 --- a/reactos/ntoskrnl/io/arc.c +++ b/reactos/ntoskrnl/io/arc.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/io/arc.c + * PURPOSE: arc names * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/cancel.c b/reactos/ntoskrnl/io/cancel.c index 6501387afc9..d68d9b67fb0 100644 --- a/reactos/ntoskrnl/io/cancel.c +++ b/reactos/ntoskrnl/io/cancel.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #define NDEBUG @@ -19,7 +17,7 @@ /* GLOBALS *******************************************************************/ -static KSPIN_LOCK CancelSpinLock; +static KSPIN_LOCK CancelSpinLock = {0,}; /* FUNCTIONS *****************************************************************/ diff --git a/reactos/ntoskrnl/io/cntrller.c b/reactos/ntoskrnl/io/cntrller.c index 07f7e00432e..0f798083881 100644 --- a/reactos/ntoskrnl/io/cntrller.c +++ b/reactos/ntoskrnl/io/cntrller.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/create.c b/reactos/ntoskrnl/io/create.c index 830e9cb2589..ef3a8ae848a 100644 --- a/reactos/ntoskrnl/io/create.c +++ b/reactos/ntoskrnl/io/create.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -33,6 +32,28 @@ NTSTATUS ZwCreateFile(PHANDLE FileHandle, ULONG CreateOptions, PVOID EaBuffer, ULONG EaLength) +/* + * FUNCTION: Either causes a new file or directory to be created, or it opens + * an existing file, device, directory or volume, giving the caller a handle + * for the file object. This handle can be used by subsequent calls to + * manipulate data within the file or the file object's state of attributes. + * ARGUMENTS: + * FileHandle (OUT) = Points to a variable which receives the file + * handle on return + * DesiredAccess = Desired access to the file + * ObjectAttributes = Structure describing the file + * IoStatusBlock (OUT) = Receives information about the operation on + * return + * AllocationSize = Initial size of the file in bytes + * FileAttributes = Attributes to create the file with + * ShareAccess = Type of shared access the caller would like to the file + * CreateDisposition = Specifies what to do, depending on whether the + * file already existings + * CreateOptions = Options for creating a new file + * EaBuffer = Undocumented + * EaLength = Undocumented + * RETURNS: Status + */ { UNIMPLEMENTED; } @@ -43,6 +64,19 @@ NTSTATUS ZwOpenFile(PHANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, ULONG ShareAccess, ULONG OpenOptions) +/* + * FUNCTION: Opens a file (simpler than ZwCreateFile) + * ARGUMENTS: + * FileHandle (OUT) = Variable that receives the file handle on return + * DesiredAccess = Access desired by the caller to the file + * ObjectAttributes = Structue describing the file to be opened + * IoStatusBlock (OUT) = Receives details about the result of the + * operation + * ShareAccess = Type of shared access the caller requires + * OpenOptions = Options for the file open + * RETURNS: Status + * NOTE: Undocumented + */ { PVOID Object; NTSTATUS Status; diff --git a/reactos/ntoskrnl/io/device.c b/reactos/ntoskrnl/io/device.c index 7830583ed7e..6af10578162 100644 --- a/reactos/ntoskrnl/io/device.c +++ b/reactos/ntoskrnl/io/device.c @@ -12,12 +12,11 @@ #include -#include #include #include #include -//#define NDEBUG +#define NDEBUG #include /* FUNCTIONS ***************************************************************/ @@ -92,7 +91,7 @@ NTSTATUS InitalizeLoadedDriver(PDRIVER_INITIALIZE entry) DriverObject=ExAllocatePool(NonPagedPool,sizeof(DRIVER_OBJECT)); if (DriverObject==NULL) { - printk("%s:%d\n",__FILE__,__LINE__); + DbgPrint("%s:%d\n",__FILE__,__LINE__); return(STATUS_INSUFFICIENT_RESOURCES); } memset(DriverObject,sizeof(DRIVER_OBJECT),0); @@ -195,6 +194,7 @@ NTSTATUS IoCreateDevice(PDRIVER_OBJECT DriverObject, dev->DeviceType=DeviceType; dev->StackSize=1; dev->AlignmentRequirement=1; + KeInitializeDeviceQueue(&dev->DeviceQueue); *DeviceObject=dev; DPRINT("dev->DriverObject %x\n",dev->DriverObject); diff --git a/reactos/ntoskrnl/io/dpc.c b/reactos/ntoskrnl/io/dpc.c index 93d7f45b6d9..f5889bfc01a 100644 --- a/reactos/ntoskrnl/io/dpc.c +++ b/reactos/ntoskrnl/io/dpc.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/io/dpc.c + * PURPOSE: io manager dpc functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/drvlck.c b/reactos/ntoskrnl/io/drvlck.c index 01ea765ddbc..92ee41795d8 100644 --- a/reactos/ntoskrnl/io/drvlck.c +++ b/reactos/ntoskrnl/io/drvlck.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/iomgr/drvlck.c + * FILE: ntoskrnl/io/drvlck.c * PURPOSE: Managing driver managing * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/errlog.c b/reactos/ntoskrnl/io/errlog.c index 25b30760f64..920bf278607 100644 --- a/reactos/ntoskrnl/io/errlog.c +++ b/reactos/ntoskrnl/io/errlog.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/io/errlog.c + * PURPOSE: Error logging * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/error.c b/reactos/ntoskrnl/io/error.c index 64d0f624821..9d302b52f13 100644 --- a/reactos/ntoskrnl/io/error.c +++ b/reactos/ntoskrnl/io/error.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/event.c b/reactos/ntoskrnl/io/event.c index 5e3e25a442e..cf158970e58 100644 --- a/reactos/ntoskrnl/io/event.c +++ b/reactos/ntoskrnl/io/event.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/fdisk.c b/reactos/ntoskrnl/io/fdisk.c index 678dc8c645f..323fe6411c8 100644 --- a/reactos/ntoskrnl/io/fdisk.c +++ b/reactos/ntoskrnl/io/fdisk.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/file.c b/reactos/ntoskrnl/io/file.c index 127793741d1..810047542b5 100644 --- a/reactos/ntoskrnl/io/file.c +++ b/reactos/ntoskrnl/io/file.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/io/file.c + * FILE: ntoskrnl/io/file.c * PURPOSE: Graceful system shutdown if a bug is detected * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/fs.c b/reactos/ntoskrnl/io/fs.c index b5e944a015d..32ccec730cb 100644 --- a/reactos/ntoskrnl/io/fs.c +++ b/reactos/ntoskrnl/io/fs.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include @@ -26,8 +24,8 @@ typedef struct /* GLOBALS ******************************************************************/ -static KSPIN_LOCK FileSystemListLock; -static LIST_ENTRY FileSystemListHead; +static KSPIN_LOCK FileSystemListLock = {0,}; +static LIST_ENTRY FileSystemListHead = {NULL,NULL}; /* FUNCTIONS *****************************************************************/ @@ -113,7 +111,7 @@ VOID IoUnregisterFileSystem(PDEVICE_OBJECT DeviceObject) current = CONTAINING_RECORD(current_entry,FILE_SYSTEM_OBJECT,Entry); if (current->DeviceObject == DeviceObject) { - RemoveEntryFromList(&FileSystemListHead,current_entry); + RemoveEntryList(current_entry); KeReleaseSpinLock(&FileSystemListLock,oldlvl); return; } diff --git a/reactos/ntoskrnl/io/ioctrl.c b/reactos/ntoskrnl/io/ioctrl.c index 1e4cd3af73c..308a3e11516 100644 --- a/reactos/ntoskrnl/io/ioctrl.c +++ b/reactos/ntoskrnl/io/ioctrl.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/iomgr.c b/reactos/ntoskrnl/io/iomgr.c index ea15e165cb0..46bca6fffbb 100644 --- a/reactos/ntoskrnl/io/iomgr.c +++ b/reactos/ntoskrnl/io/iomgr.c @@ -12,9 +12,11 @@ #include #include -#include #include +#define NDEBUG +#include + /* GLOBALS *******************************************************************/ OBJECT_TYPE DeviceObjectType = {{0,0,NULL}, @@ -64,22 +66,28 @@ VOID IoInit(VOID) /* * Register iomgr types */ + CHECKPOINT; RtlInitAnsiString(&astring,"Device"); + CHECKPOINT; RtlAnsiStringToUnicodeString(&DeviceObjectType.TypeName,&astring,TRUE); + CHECKPOINT; ObRegisterType(OBJTYP_DEVICE,&DeviceObjectType); - + CHECKPOINT; RtlInitAnsiString(&astring,"File"); RtlAnsiStringToUnicodeString(&FileObjectType.TypeName,&astring,TRUE); ObRegisterType(OBJTYP_FILE,&FileObjectType); - + CHECKPOINT; /* * Create the device directory */ RtlInitAnsiString(&astring,"\\Device"); + CHECKPOINT; RtlAnsiStringToUnicodeString(&string,&astring,TRUE); + CHECKPOINT; InitializeObjectAttributes(&attr,&string,0,NULL,NULL); + CHECKPOINT; ZwCreateDirectoryObject(&handle,0,&attr); - + CHECKPOINT; IoInitCancelHandling(); IoInitSymbolicLinkImplementation(); } diff --git a/reactos/ntoskrnl/io/irp.c b/reactos/ntoskrnl/io/irp.c index b7feaeb016d..ba31f968016 100644 --- a/reactos/ntoskrnl/io/irp.c +++ b/reactos/ntoskrnl/io/irp.c @@ -30,7 +30,6 @@ /* INCLUDES ****************************************************************/ #include -#include #include #define NDEBUG diff --git a/reactos/ntoskrnl/io/mdl.c b/reactos/ntoskrnl/io/mdl.c index f4d1e519948..f3a7c2f93c0 100644 --- a/reactos/ntoskrnl/io/mdl.c +++ b/reactos/ntoskrnl/io/mdl.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/process.c b/reactos/ntoskrnl/io/process.c index 5be918882ae..d4915ab388a 100644 --- a/reactos/ntoskrnl/io/process.c +++ b/reactos/ntoskrnl/io/process.c @@ -10,15 +10,13 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include /* FUNCTIONS *****************************************************************/ -PEPROCESS IoGetCurrentProcess() +struct _EPROCESS* IoGetCurrentProcess() { return(PsGetCurrentProcess()); } diff --git a/reactos/ntoskrnl/io/queue.c b/reactos/ntoskrnl/io/queue.c index 4bd30e4a84e..2c38ce700ce 100644 --- a/reactos/ntoskrnl/io/queue.c +++ b/reactos/ntoskrnl/io/queue.c @@ -10,7 +10,8 @@ #include #include -#include + +#define NDEBUG #include /* FUNCTIONS *****************************************************************/ @@ -54,6 +55,9 @@ VOID IoStartNextPacket(PDEVICE_OBJECT DeviceObject, BOOLEAN Cancelable) PIRP Irp; KIRQL oldirql; + DPRINT("IoStartNextPacket(DeviceObject %x, Cancelable %d)\n", + DeviceObject,Cancelable); + entry = KeRemoveDeviceQueue(&DeviceObject->DeviceQueue); if (entry!=NULL) diff --git a/reactos/ntoskrnl/io/resource.c b/reactos/ntoskrnl/io/resource.c index c7dad78b4ae..76d24dc37f5 100644 --- a/reactos/ntoskrnl/io/resource.c +++ b/reactos/ntoskrnl/io/resource.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/rw.c b/reactos/ntoskrnl/io/rw.c index 96011371cdc..a221e4dd0db 100644 --- a/reactos/ntoskrnl/io/rw.c +++ b/reactos/ntoskrnl/io/rw.c @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -29,7 +28,7 @@ /* FUNCTIONS ***************************************************************/ NTSTATUS ZwReadFile(HANDLE FileHandle, - HANDLE Event, + HANDLE EventHandle, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, @@ -42,7 +41,8 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr; PIRP Irp; PIO_STACK_LOCATION StackPtr; - + KEVENT Event; + if (hdr==NULL) { return(STATUS_INVALID_HANDLE); @@ -75,6 +75,8 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, Irp->UserBuffer = NULL; Irp->AssociatedIrp.SystemBuffer = NULL; } + KeInitializeEvent(&Event,NotificationEvent,FALSE); + Irp->UserEvent=&Event; StackPtr = IoGetNextIrpStackLocation(Irp); DPRINT("StackPtr %x\n",StackPtr); @@ -106,7 +108,11 @@ NTSTATUS ZwReadFile(HANDLE FileHandle, DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject); IoCallDriver(FileObject->DeviceObject,Irp); - memcpy(Buffer,Irp->AssociatedIrp.SystemBuffer,Length); + KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL); + if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO) + { + memcpy(Buffer,Irp->AssociatedIrp.SystemBuffer,Length); + } return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/io/share.c b/reactos/ntoskrnl/io/share.c index cb4ba94730b..951669d7c82 100644 --- a/reactos/ntoskrnl/io/share.c +++ b/reactos/ntoskrnl/io/share.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/shutdown.c b/reactos/ntoskrnl/io/shutdown.c index 3214df76b83..f2828cf77a1 100644 --- a/reactos/ntoskrnl/io/shutdown.c +++ b/reactos/ntoskrnl/io/shutdown.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/symlink.c b/reactos/ntoskrnl/io/symlink.c index 8b99e477ed7..7c94df45116 100644 --- a/reactos/ntoskrnl/io/symlink.c +++ b/reactos/ntoskrnl/io/symlink.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/io/timer.c b/reactos/ntoskrnl/io/timer.c index d5dd74b67c0..d9ada2fc7f7 100644 --- a/reactos/ntoskrnl/io/timer.c +++ b/reactos/ntoskrnl/io/timer.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ke/apc.c b/reactos/ntoskrnl/ke/apc.c index 5d8951158db..cc730674075 100644 --- a/reactos/ntoskrnl/ke/apc.c +++ b/reactos/ntoskrnl/ke/apc.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include @@ -23,9 +21,9 @@ VOID KeDrainApcQueue(VOID) { PLIST_ENTRY current_entry; PKAPC current; + PKTHREAD CurrentThread=KeGetCurrentThread(); - current_entry = KeGetCurrentThread()->ApcQueueHead.Flink; - while (current_entry!=NULL) + while ((current_entry=RemoveHeadList(CurrentThread->ApcList))!=NULL) { current = CONTAINING_RECORD(current_entry,KAPC,ApcListEntry); current->NormalRoutine(current->NormalContext, @@ -35,25 +33,40 @@ VOID KeDrainApcQueue(VOID) } } -VOID KeInitializeApc(PKAPC Apc, PKNORMAL_ROUTINE NormalRoutine, - PVOID NormalContext, - PKTHREAD TargetThread) +VOID KeInitializeApc(PKAPC Apc, + PKTHREAD Thread, + UCHAR StateIndex, + PKKERNEL_ROUTINE KernelRoutine, + PKRUNDOWN_ROUTINE RundownRoutine, + PKNORMAL_ROUTINE NormalRoutine, + UCHAR Mode, + PVOID Context) { memset(Apc,0,sizeof(KAPC)); - Apc->Thread = TargetThread; + Apc->Thread = Thread; + Apc->ApcListEntry.Flink=NULL; + Apc->ApcListEntry.Blink=NULL; + Apc->KernelRoutine=KernelRoutine; + Apc->RundownRoutine=RundownRoutine; Apc->NormalRoutine=NormalRoutine; - Apc->NormalContext=NormalContext; + Apc->NormalContext=Context; Apc->Inserted=FALSE; + Apc->ApcStateIndex=StateIndex; + Apc->ApcMode=Mode; } -BOOLEAN KeInsertQueueApc(PKAPC Apc) +void KeInsertQueueApc(PKAPC Apc, PVOID SystemArgument1, + PVOID SystemArgument2, UCHAR Mode) { + Apc->SystemArgument1=SystemArgument1; + Apc->SystemArgument2=SystemArgument2; + Apc->ApcMode=Mode; if (Apc->Inserted) { - return(FALSE); + return; } Apc->Inserted=TRUE; - InsertTailList(&Apc->Thread->ApcQueueHead,&Apc->ApcListEntry); - return(TRUE); + InsertTailList(Apc->Thread->ApcList,&Apc->ApcListEntry); + return; } diff --git a/reactos/ntoskrnl/ke/bug.c b/reactos/ntoskrnl/ke/bug.c index 84a95d5dbc8..1549e6ebd1d 100644 --- a/reactos/ntoskrnl/ke/bug.c +++ b/reactos/ntoskrnl/ke/bug.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include @@ -49,11 +47,11 @@ BOOLEAN KeRegisterBugCheckCallback(PKBUGCHECK_CALLBACK_RECORD CallbackRecord, CallbackRecord->CallbackRoutine=CallbackRoutine; } -asmlinkage VOID KeBugCheckEx(ULONG BugCheckCode, - ULONG BugCheckParameter1, - ULONG BugCheckParameter2, - ULONG BugCheckParameter3, - ULONG BugCheckParameter4) +VOID KeBugCheckEx(ULONG BugCheckCode, + ULONG BugCheckParameter1, + ULONG BugCheckParameter2, + ULONG BugCheckParameter3, + ULONG BugCheckParameter4) /* * FUNCTION: Brings the system down in a controlled manner when an * inconsistency that might otherwise cause corruption has been detected @@ -63,13 +61,13 @@ asmlinkage VOID KeBugCheckEx(ULONG BugCheckCode, * RETURNS: Doesn't */ { - printk("Bug detected (code %x param %x %x %x %x)\n",BugCheckCode, + DbgPrint("Bug detected (code %x param %x %x %x %x)\n",BugCheckCode, BugCheckParameter1,BugCheckParameter2,BugCheckParameter3, BugCheckParameter4); for(;;); } -asmlinkage VOID KeBugCheck(ULONG BugCheckCode) +VOID KeBugCheck(ULONG BugCheckCode) /* * FUNCTION: Brings the system down in a controlled manner when an * inconsistency that might otherwise cause corruption has been detected diff --git a/reactos/ntoskrnl/ke/catch.c b/reactos/ntoskrnl/ke/catch.c index 2e1d6950811..3b6bc5ce67e 100644 --- a/reactos/ntoskrnl/ke/catch.c +++ b/reactos/ntoskrnl/ke/catch.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/kernel/catch.c + * FILE: ntoskrnl/ke/catch.c * PURPOSE: Exception handling * PROGRAMMER: David Welch (welch@mcmail.com) */ @@ -10,12 +10,11 @@ #include #include -#include /* FUNCTIONS ****************************************************************/ VOID ExRaiseStatus(NTSTATUS Status) { - printk("ExRaiseStatus(%d)\n",Status); + DbgPrint("ExRaiseStatus(%d)\n",Status); for(;;); } diff --git a/reactos/ntoskrnl/ke/critical.c b/reactos/ntoskrnl/ke/critical.c index 4916b8e8d97..c4b66dbd725 100644 --- a/reactos/ntoskrnl/ke/critical.c +++ b/reactos/ntoskrnl/ke/critical.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/critical.c + * FILE: ntoskrnl/ke/critical.c * PURPOSE: Implement critical regions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ke/dispatch.c b/reactos/ntoskrnl/ke/dispatch.c index d061f100d8b..ff90e538336 100644 --- a/reactos/ntoskrnl/ke/dispatch.c +++ b/reactos/ntoskrnl/ke/dispatch.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/kernel/dispatch.c + * FILE: ntoskrnl/ke/dispatch.c * PURPOSE: Handles a dispatch interrupt * PROGRAMMER: David Welch (welch@mcmail.com) */ @@ -10,11 +10,11 @@ #include #include -#include +#include /* FUNCTIONS ****************************************************************/ -void KiDispatchInterrupt(unsigned int irq) +VOID KiDispatchInterrupt(ULONG irq) /* * FUNCTION: Called after an irq when the interrupted processor was at a lower * level than DISPATCH_LEVEL diff --git a/reactos/ntoskrnl/ke/dpc.c b/reactos/ntoskrnl/ke/dpc.c index 81485b8f0d7..7c8ffc44c6f 100644 --- a/reactos/ntoskrnl/ke/dpc.c +++ b/reactos/ntoskrnl/ke/dpc.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/kernel/dpc.cc + * FILE: ntoskrnl/ke/dpc.c * PURPOSE: Handle DPCs (Delayed Procedure Calls) * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -9,20 +9,22 @@ */ /* - * NOTE: See also the higher level support routines in mkernel/iomgr/iodpc.cc + * NOTE: See also the higher level support routines in ntoskrnl/io/dpc.c */ /* INCLUDES ***************************************************************/ #include -#include +#define NDEBUG +#include /* TYPES *******************************************************************/ /* GLOBALS ******************************************************************/ -LIST_ENTRY DpcQueueHead; +static LIST_ENTRY DpcQueueHead={NULL,NULL}; +static KSPIN_LOCK DpcQueueLock={0,}; /* FUNCTIONS ****************************************************************/ @@ -48,17 +50,25 @@ void KeDrainDpcQueue(void) * FUNCTION: Called to execute queued dpcs */ { - PLIST_ENTRY current_entry = ExInterlockedRemoveHeadList(&DpcQueueHead,NULL); - PKDPC current = CONTAINING_RECORD(¤t_entry,KDPC,DpcListEntry); + PLIST_ENTRY current_entry; + PKDPC current; - while (current_entry!=NULL) + + KeAcquireSpinLockAtDpcLevel(&DpcQueueLock); + current_entry = RemoveHeadList(&DpcQueueHead); + current = CONTAINING_RECORD(current_entry,KDPC,DpcListEntry); + while (current_entry!=(&DpcQueueHead)) { + CHECKPOINT; current->DeferredRoutine(current,current->DeferredContext, current->SystemArgument1, current->SystemArgument2); - current_entry = ExInterlockedRemoveHeadList(&DpcQueueHead,NULL); + current->Lock=FALSE; + current_entry = RemoveHeadList(&DpcQueueHead); current = CONTAINING_RECORD(¤t_entry,KDPC,DpcListEntry); } + KeReleaseSpinLockFromDpcLevel(&DpcQueueLock); +// DPRINT("Finished KeDrainDpcQueue()\n",0); } BOOLEAN KeRemoveQueueDpc(PKDPC Dpc) @@ -74,8 +84,9 @@ BOOLEAN KeRemoveQueueDpc(PKDPC Dpc) { return(FALSE); } - ExInterlockedRemoveEntryList(&DpcQueueHead,&Dpc->DpcListEntry,NULL); + RemoveEntryList(&Dpc->DpcListEntry); Dpc->Lock=0; + return(TRUE); } BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1, @@ -90,6 +101,9 @@ BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1, * FALSE otherwise */ { + DPRINT("KeInsertQueueDpc()\n",0); + assert(KeGetCurrentIrql()==DISPATCH_LEVEL); + dpc->Number=0; dpc->Importance=Medium; dpc->SystemArgument1=SystemArgument1; @@ -98,8 +112,12 @@ BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1, { return(FALSE); } - ExInterlockedInsertHeadList(&DpcQueueHead,&dpc->DpcListEntry,NULL); + KeAcquireSpinLockAtDpcLevel(&DpcQueueLock); + InsertHeadList(&DpcQueueHead,&dpc->DpcListEntry); + KeReleaseSpinLockFromDpcLevel(&DpcQueueLock); dpc->Lock=1; + DPRINT("DpcQueueHead.Flink %x\n",DpcQueueHead.Flink); + DPRINT("Leaving KeInsertQueueDpc()\n",0); return(TRUE); } diff --git a/reactos/ntoskrnl/ke/error.c b/reactos/ntoskrnl/ke/error.c index c6d698f3ca1..d9a8344114d 100644 --- a/reactos/ntoskrnl/ke/error.c +++ b/reactos/ntoskrnl/ke/error.c @@ -17,7 +17,7 @@ /* * Last error code (this should be per process) */ -DWORD error_code; +DWORD error_code = 0; /* FUNCTIONS ***************************************************************/ diff --git a/reactos/ntoskrnl/ke/event.c b/reactos/ntoskrnl/ke/event.c index 9bd1f98b5d0..9cb787fe940 100644 --- a/reactos/ntoskrnl/ke/event.c +++ b/reactos/ntoskrnl/ke/event.c @@ -2,7 +2,7 @@ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/event.c - * PURPOSE: Implements event + * PURPOSE: Implements events * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,27 +10,22 @@ /* INCLUDES *****************************************************************/ -#include -#include - #include +#define NDEBUG #include /* FUNCTIONS ****************************************************************/ VOID KeClearEvent(PKEVENT Event) { - Event->Header.SignalState=FALSE; // (??) Is this atomic + Event->Header.SignalState=FALSE; } VOID KeInitializeEvent(PKEVENT Event, EVENT_TYPE Type, BOOLEAN State) { - Event->Header.Type = Type; - Event->Header.Absolute = 0; - Event->Header.Inserted = 0; - Event->Header.Size = sizeof(KEVENT) / sizeof(ULONG); - Event->Header.SignalState = State; + KeInitializeDispatcherHeader(&(Event->Header),Type, + sizeof(Event)/sizeof(ULONG),State); InitializeListHead(&(Event->Header.WaitListHead)); } @@ -47,10 +42,11 @@ LONG KeResetEvent(PKEVENT Event) LONG KeSetEvent(PKEVENT Event, KPRIORITY Increment, BOOLEAN Wait) { int ret; - KIRQL oldlvl; - - KeAcquireSpinLock(&DispatcherDatabaseLock,&oldlvl); - ret = InterlockedExchange(&(Event->Header.SignalState),1); + + DPRINT("KeSetEvent(Event %x, Wait %x)\n",Event,Wait); + KeAcquireDispatcherDatabaseLock(Wait); +// ret = InterlockedExchange(&(Event->Header.SignalState),1); + Event->Header.SignalState=1; KeDispatcherObjectWake((DISPATCHER_HEADER *)Event); - KeReleaseSpinLock(&DispatcherDatabaseLock,oldlvl); + KeReleaseDispatcherDatabaseLock(Wait); } diff --git a/reactos/ntoskrnl/ke/kqueue.c b/reactos/ntoskrnl/ke/kqueue.c index 2b372af0bd0..b0fe05b77a2 100644 --- a/reactos/ntoskrnl/ke/kqueue.c +++ b/reactos/ntoskrnl/ke/kqueue.c @@ -12,8 +12,8 @@ #include #include -#include +#define NDEBUG #include /* FUNCTIONS *****************************************************************/ @@ -54,7 +54,7 @@ BOOLEAN KeInsertByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue, } current=DeviceQueue->ListHead.Flink; - while (current!=NULL) + while (current!=(&DeviceQueue->ListHead)) { entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry); if (entry->Key < SortKey) @@ -98,7 +98,7 @@ PKDEVICE_QUEUE_ENTRY KeRemoveByKeyDeviceQueue(PKDEVICE_QUEUE DeviceQueue, entry = CONTAINING_RECORD(current,KDEVICE_QUEUE_ENTRY,Entry); if (entry->Key < SortKey || current->Flink == NULL) { - RemoveEntryFromList(&DeviceQueue->ListHead,current); + RemoveEntryList(current); KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl); return(entry); } @@ -118,6 +118,8 @@ PKDEVICE_QUEUE_ENTRY KeRemoveDeviceQueue(PKDEVICE_QUEUE DeviceQueue) PLIST_ENTRY list_entry; PKDEVICE_QUEUE_ENTRY entry; + DPRINT("KeRemoveDeviceQueue(DeviceQueue %x)\n",DeviceQueue); + assert_irql(DISPATCH_LEVEL); assert(DeviceQueue!=NULL); assert(DeviceQueue->Busy); @@ -125,7 +127,7 @@ PKDEVICE_QUEUE_ENTRY KeRemoveDeviceQueue(PKDEVICE_QUEUE DeviceQueue) KeAcquireSpinLock(&DeviceQueue->Lock,&oldlvl); list_entry = RemoveHeadList(&DeviceQueue->ListHead); - if (list_entry==NULL) + if (list_entry==(&DeviceQueue->ListHead)) { DeviceQueue->Busy=FALSE; KeReleaseSpinLock(&DeviceQueue->Lock,oldlvl); diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 201fa386a8f..3a0a245ba3a 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -11,9 +11,8 @@ /* INCLUDES *****************************************************************/ #include -#include -#include +#include #include #include #include @@ -101,6 +100,9 @@ void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type, : "ax"); } +extern int edata; +extern int end; + asmlinkage void _main(boot_param* _bp) /* * FUNCTION: Called by the boot loader to start the kernel @@ -112,11 +114,14 @@ asmlinkage void _main(boot_param* _bp) { unsigned int i; unsigned int start; + unsigned int start1; + boot_param bp; + +// memset((void *)&edata,0,((int)&end)-((int)&edata)); /* * Copy the parameters to a local buffer because lowmem will go away */ - boot_param bp; memcpy(&bp,_bp,sizeof(bp)); /* @@ -126,44 +131,51 @@ asmlinkage void _main(boot_param* _bp) printk("Starting ReactOS "KERNEL_VERSION"\n"); + start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]); + DPRINT("MmGetPhysicalAddress(start) = %x\n",MmGetPhysicalAddress(start)); + DPRINT("bp.module_length[0] %x PAGE_ROUND_UP(bp.module_length[0]) %x\n", + bp.module_length[0],PAGE_ROUND_UP(bp.module_length[0])); + start1 = start+PAGE_ROUND_UP(bp.module_length[1]); + DPRINT("bp.module_length[1] %x PAGE_ROUND_UP(bp.module_length[1]) %x\n", + bp.module_length[1],PAGE_ROUND_UP(bp.module_length[1])); + + DPRINT("start %x *start %x\n",start,*((unsigned int *)start)); + DPRINT("start1 %x *start1 %x\n",start1,*((unsigned int *)start1)); + + /* * Initalize various critical subsystems */ HalInit(&bp); +// set_breakpoint(0,start,HBP_READWRITE,HBP_DWORD); MmInitalize(&bp); - KeInitDpc(); - KeInitializeBugCheck(); - KeInitializeDispatcher(); - InitializeTimer(); - - /* - * Allow interrupts - */ - KeLowerIrql(PASSIVE_LEVEL); - - KeCalibrateTimerLoop(); - ObjNamespcInit(); - PsMgrInit(); - IoInit(); + CHECKPOINT; + KeInit(); + CHECKPOINT; + ObInit(); + CHECKPOINT; + PsInit(); + CHECKPOINT; + IoInit(); + CHECKPOINT; /* - * Initalize loaded modules + * Initalize services loaded at boot time */ DPRINT("%d files loaded\n",bp.nr_files); - - start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]) + - PAGESIZE; + start = KERNEL_BASE + PAGE_ROUND_UP(bp.module_length[0]); for (i=1;i #include -#include #include #include #include @@ -120,7 +119,7 @@ static int do_reloc32_reloc(module* mod, SCNHDR* scn, RELOC* reloc) val = get_kernel_symbol_addr(name); if (val==0) { - printk("Undefined symbol %s in module\n",name); + DbgPrint("Undefined symbol %s in module\n",name); return(0); } // DPRINT("REL32 value %x name %s\n",val,name); @@ -204,7 +203,7 @@ static BOOLEAN do_reloc(module* mod, unsigned int scn_idx) break; default: - printk("Unknown relocation type %x at %d in module\n", + DbgPrint("Unknown relocation type %x at %d in module\n", reloc->r_type,j); return(0); } @@ -234,8 +233,8 @@ BOOLEAN process_boot_module(unsigned int start) PDRIVER_INITIALIZE func; int i; + DPRINT("process_boot_module(start %x)\n",start); DPRINT("n = %x\n",*((unsigned int *)start)); - mod=(module *)ExAllocatePool(NonPagedPool,sizeof(module)); DPRINT("magic %x\n",((FILHDR *)start)->f_magic); @@ -244,7 +243,7 @@ BOOLEAN process_boot_module(unsigned int start) if (I386BADMAG(hdr)) { - printk("(%s:%d) Module has bad magic value (%x)\n",__FILE__, + DbgPrint("(%s:%d) Module has bad magic value (%x)\n",__FILE__, __LINE__,hdr.f_magic); return(0); } @@ -288,14 +287,14 @@ BOOLEAN process_boot_module(unsigned int start) } } - mod->base = (unsigned int)VirtualAlloc((LPVOID)0,mod->size,MEM_COMMIT, - PAGE_SYSTEM + PAGE_EXECUTE_READWRITE); + CHECKPOINT; + mod->base = (unsigned int)MmAllocateSection(mod->size); if (mod->base == 0) { - printk("Failed to allocated section for module\n"); + DbgPrint("Failed to alloc section for module\n"); return(0); } - + CHECKPOINT; /* * Adjust section vaddrs for allocated area @@ -349,7 +348,7 @@ BOOLEAN process_boot_module(unsigned int start) if (!found_entry) { - printk("No module entry point defined\n"); + DbgPrint("No module entry point defined\n"); return(0); } diff --git a/reactos/ntoskrnl/ke/mutex.c b/reactos/ntoskrnl/ke/mutex.c index dbc9250c413..ec8a4da1f84 100644 --- a/reactos/ntoskrnl/ke/mutex.c +++ b/reactos/ntoskrnl/ke/mutex.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/mutex.c + * FILE: ntoskrnl/ke/mutex.c * PURPOSE: Implements mutex * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/ke/sem.c b/reactos/ntoskrnl/ke/sem.c index ac76acbce4c..902a58a90e9 100644 --- a/reactos/ntoskrnl/ke/sem.c +++ b/reactos/ntoskrnl/ke/sem.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/sem.c + * FILE: ntoskrnl/ke/sem.c * PURPOSE: Implements kernel semaphores * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,9 +10,8 @@ /* INCLUDES *****************************************************************/ -#include -#include #include +#include #include @@ -22,12 +21,15 @@ VOID KeInitializeSemaphore(PKSEMAPHORE Semaphore, LONG Count, LONG Limit) { - UNIMPLEMENTED; + KeInitializeDispatcherHeader(&Semaphore->Header,SemaphoreType, + sizeof(KSEMAPHORE)/sizeof(ULONG), + Count); + Semaphore->Limit=Limit; } LONG KeReadStateSemaphore(PKSEMAPHORE Semaphore) { - UNIMPLEMENTED; + return(Semaphore->Header.SignalState); } LONG KeReleaseSemaphore(PKSEMAPHORE Semaphore, @@ -35,6 +37,5 @@ LONG KeReleaseSemaphore(PKSEMAPHORE Semaphore, LONG Adjustment, BOOLEAN Wait) { - UNIMPLEMENTED; } diff --git a/reactos/ntoskrnl/ke/timer.c b/reactos/ntoskrnl/ke/timer.c index 4f887c54bfd..56464a35282 100644 --- a/reactos/ntoskrnl/ke/timer.c +++ b/reactos/ntoskrnl/ke/timer.c @@ -16,14 +16,9 @@ /* INCLUDES ***************************************************************/ #include - -#include -#include -#include -#include -#include #include +#define NDEBUG #include /* TYPES *****************************************************************/ @@ -55,7 +50,7 @@ static volatile unsigned long long ticks=0; * PURPOSE: List of timers */ static LIST_ENTRY timer_list_head = {NULL,NULL}; -static KSPIN_LOCK timer_list_lock; +static KSPIN_LOCK timer_list_lock = {0,}; #define MICROSECONDS_TO_CALIBRATE (1000000) @@ -89,27 +84,45 @@ void KeCalibrateTimerLoop() loops_per_microsecond = (loops_per_microsecond * MICROSECONDS_TO_CALIBRATE) / (nr_ticks*MICROSECONDS_PER_TICK); - printk("nr_ticks %d\n",nr_ticks); - printk("loops_per_microsecond %d\n",loops_per_microsecond); - printk("Processor speed (approx) %d\n", - (6*loops_per_microsecond)/1000); + DbgPrint("nr_ticks %d\n",nr_ticks); + DbgPrint("loops_per_microsecond %d\n",loops_per_microsecond); + DbgPrint("Processor speed (approx) %d\n", + (6*loops_per_microsecond)/1000); if (nr_ticks == (TICKS_PER_SECOND_APPROX * MICROSECONDS_TO_CALIBRATE) / MICROSECONDS_IN_A_SECOND) { - printk("Testing loop\n"); + DbgPrint("Testing loop\n"); KeStallExecutionProcessor(10000); - printk("Finished loop\n"); + DbgPrint("Finished loop\n"); return; } } } +NTSTATUS KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval) +{ + KeInitializeTimer(&(Thread->TimerBlock)); + KeSetTimer(&(Thread->TimerBlock),*Interval,NULL); +} + NTSTATUS KeDelayExecutionThread(KPROCESSOR_MODE WaitMode, BOOLEAN Alertable, PLARGE_INTEGER Interval) +/* + * FUNCTION: Puts the current thread into an alertable or nonalertable + * wait state for a given internal + * ARGUMENTS: + * WaitMode = Processor mode in which the caller is waiting + * Altertable = Specifies if the wait is alertable + * Interval = Specifies the interval to wait + * RETURNS: Status + */ { - UNIMPLEMENTED; + PKTHREAD CurrentThread = KeGetCurrentThread(); + KeAddThreadTimeout(CurrentThread,Interval); + return(KeWaitForSingleObject(&(CurrentThread->TimerBlock),Executive, + KernelMode,Alertable,NULL)); } VOID KeStallExecutionProcessor(ULONG MicroSeconds) @@ -241,8 +254,8 @@ BOOLEAN KeSetTimerEx(PKTIMER Timer, LARGE_INTEGER DueTime, LONG Period, if (Timer->expire_time < 0) { Timer->expire_time = system_time - Timer->expire_time; - Timer->signaled = FALSE; } + Timer->signaled = FALSE; if (Timer->running) { KeReleaseSpinLock(&timer_list_lock,oldlvl); @@ -270,7 +283,7 @@ BOOLEAN KeCancelTimer(PKTIMER Timer) { return(FALSE); } - RemoveEntryFromList(&timer_list_head,&Timer->entry); + RemoveEntryList(&Timer->entry); KeReleaseSpinLock(&timer_list_lock,oldlvl); return(TRUE); } @@ -334,7 +347,7 @@ static void HandleExpiredTimer(PKTIMER current) } else { - RemoveEntryFromList(&timer_list_head,¤t->entry); + RemoveEntryList(¤t->entry); current->running=FALSE; } } @@ -347,7 +360,7 @@ void KeExpireTimers(void) KeAcquireSpinLock(&timer_list_lock,&oldlvl); - while (current_entry!=NULL) + while (current_entry!=(&timer_list_head)) { if (system_time == current->expire_time) { @@ -360,7 +373,7 @@ void KeExpireTimers(void) KeReleaseSpinLock(&timer_list_lock,oldlvl); } -VOID KeTimerInterrupt(VOID) +VOID KiTimerInterrupt(VOID) /* * FUNCTION: Handles a timer interrupt */ diff --git a/reactos/ntoskrnl/ke/wait.c b/reactos/ntoskrnl/ke/wait.c index 917af040ce8..dcc57af989b 100644 --- a/reactos/ntoskrnl/ke/wait.c +++ b/reactos/ntoskrnl/ke/wait.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS project - * FILE: ntoskrnl/ps/wait.c + * FILE: ntoskrnl/ke/wait.c * PURPOSE: Manages non-busy waiting * PROGRAMMER: David Welch (welch@mcmail.com) * REVISION HISTORY: @@ -16,35 +16,113 @@ #include #include -#include -#include +#include #define NDEBUG #include /* GLOBALS ******************************************************************/ -KSPIN_LOCK DispatcherDatabaseLock; -BOOLEAN WaitSet; +static KSPIN_LOCK DispatcherDatabaseLock = {0,}; +static BOOLEAN WaitSet = FALSE; +static KIRQL oldlvl = PASSIVE_LEVEL; +static PKTHREAD Owner = NULL; /* FUNCTIONS *****************************************************************/ -VOID KeDispatcherObjectWake(DISPATCHER_HEADER* hdr) +VOID KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, + ULONG Type, + ULONG Size, + ULONG SignalState) +{ + Header->Type = Type; + Header->Absolute = 0; + Header->Inserted = 0; + Header->Size = Size; + Header->SignalState = SignalState; + InitializeListHead(&(Header->WaitListHead)); +} + +VOID KeAcquireDispatcherDatabaseLock(BOOLEAN Wait) +/* + * PURPOSE: Acquires the dispatcher database lock for the caller + */ +{ + DPRINT("KeAcquireDispatcherDatabaseLock(Wait %x)\n",Wait); + if (WaitSet && Owner == KeGetCurrentThread()) + { + return; + } + KeAcquireSpinLock(&DispatcherDatabaseLock,&oldlvl); + WaitSet = Wait; + Owner = KeGetCurrentThread(); +} + +VOID KeReleaseDispatcherDatabaseLock(BOOLEAN Wait) +{ + DPRINT("KeReleaseDispatcherDatabaseLock(Wait %x)\n",Wait); + assert(Wait==WaitSet); + if (!Wait) + { + Owner = NULL; + KeReleaseSpinLock(&DispatcherDatabaseLock,oldlvl); + } +} + +VOID KeDispatcherObjectWakeAll(DISPATCHER_HEADER* hdr) { PKWAIT_BLOCK current; PLIST_ENTRY current_entry; - DPRINT("Entering KeDispatcherObjectWake(hdr %x)\n",hdr); - DPRINT("hdr->WaitListHead %x hdr->WaitListHead.Flink %x\n", - &hdr->WaitListHead,hdr->WaitListHead.Flink); - while ((current_entry=RemoveHeadList(&hdr->WaitListHead))!=NULL) + while (!IsListEmpty(&(hdr->WaitListHead))) { + current_entry = RemoveHeadList(&hdr->WaitListHead); current = CONTAINING_RECORD(current_entry,KWAIT_BLOCK, WaitListEntry); DPRINT("Waking %x\n",current->Thread); - PsWakeThread(current->Thread); + PsWakeThread((PETHREAD)current->Thread); }; } + +BOOLEAN KeDispatcherObjectWakeOne(DISPATCHER_HEADER* hdr) +{ + PKWAIT_BLOCK current; + PLIST_ENTRY current_entry; + + DPRINT("KeDispatcherObjectWakeOn(hdr %x)\n",hdr); + DPRINT("hdr->WaitListHead.Flink %x hdr->WaitListHead.Blink %x\n", + hdr->WaitListHead.Flink,hdr->WaitListHead.Blink); + if (IsListEmpty(&(hdr->WaitListHead))) + { + return(FALSE); + } + current_entry=RemoveHeadList(&(hdr->WaitListHead)); + current = CONTAINING_RECORD(current_entry,KWAIT_BLOCK, + WaitListEntry); + DPRINT("current_entry %x current %x\n",current_entry,current); + DPRINT("Waking %x\n",current->Thread); + PsWakeThread((PETHREAD)current->Thread); + return(TRUE); +} + +VOID KeDispatcherObjectWake(DISPATCHER_HEADER* hdr) +{ + + DPRINT("Entering KeDispatcherObjectWake(hdr %x)\n",hdr); +// DPRINT("hdr->WaitListHead %x hdr->WaitListHead.Flink %x\n", +// &hdr->WaitListHead,hdr->WaitListHead.Flink); + if (hdr->Type==NotificationEvent) + { + KeDispatcherObjectWakeAll(hdr); + } + if (hdr->Type==SynchronizationEvent) + { + if (KeDispatcherObjectWakeOne(hdr)) + { + hdr->SignalState=FALSE; + } + } +} NTSTATUS KeWaitForSingleObject(PVOID Object, @@ -52,16 +130,51 @@ NTSTATUS KeWaitForSingleObject(PVOID Object, KPROCESSOR_MODE WaitMode, BOOLEAN Alertable, PLARGE_INTEGER Timeout) +/* + * FUNCTION: Puts the current thread into a wait state until the + * given dispatcher object is set to signalled + * ARGUMENTS: + * Object = Object to wait on + * WaitReason = Reason for the wait (debugging aid) + * WaitMode = Can be KernelMode or UserMode, if UserMode then + * user-mode APCs can be delivered and the thread's + * stack can be paged out + * Altertable = Specifies if the wait is a alertable + * Timeout = Optional timeout value + * RETURNS: Status + */ { DISPATCHER_HEADER* hdr = (DISPATCHER_HEADER *)Object; KWAIT_BLOCK blk; + KIRQL oldlvl; DPRINT("Entering KeWaitForSingleObject(Object %x)\n",Object); + + KeAcquireDispatcherDatabaseLock(FALSE); + + if (hdr->SignalState) + { + hdr->SignalState=FALSE; + KeReleaseDispatcherDatabaseLock(FALSE); + return(STATUS_SUCCESS); + } + + if (Timeout!=NULL) + { + KeAddThreadTimeout(KeGetCurrentThread(),Timeout); + } blk.Object=Object; blk.Thread=KeGetCurrentThread(); - InsertTailList(&hdr->WaitListHead,&blk.WaitListEntry); + blk.WaitKey = WaitReason; // Assumed + blk.WaitType = WaitMode; // Assumed + blk.NextWaitBlock = NULL; + InsertTailList(&(hdr->WaitListHead),&(blk.WaitListEntry)); +// DPRINT("hdr->WaitListHead.Flink %x hdr->WaitListHead.Blink %x\n", +// hdr->WaitListHead.Flink,hdr->WaitListHead.Blink); + KeReleaseDispatcherDatabaseLock(FALSE); PsSuspendThread(); + return(STATUS_SUCCESS); } NTSTATUS KeWaitForMultipleObjects(ULONG Count, diff --git a/reactos/ntoskrnl/ldr/loader.c b/reactos/ntoskrnl/ldr/loader.c index b76bf190a06..56fb2ad849c 100644 --- a/reactos/ntoskrnl/ldr/loader.c +++ b/reactos/ntoskrnl/ldr/loader.c @@ -34,7 +34,7 @@ NTSTATUS LdrProcessImage(HANDLE SectionHandle, PVOID BaseAddress) NTSTATUS LdrLoadDriver(PUNICODE_STRING FileName) /* - * FUNCTION: Loads a PE executable into the current process + * FUNCTION: Loads a PE executable into the kernel * ARGUMENTS: * FileName = Driver to load * RETURNS: Status diff --git a/reactos/ntoskrnl/mm/freelist.c b/reactos/ntoskrnl/mm/freelist.c index b6aa6910141..f5249015f0e 100644 --- a/reactos/ntoskrnl/mm/freelist.c +++ b/reactos/ntoskrnl/mm/freelist.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/mm/freelist.cc + * FILE: ntoskrnl/mm/freelist.c * PURPOSE: Handle the list of free physical pages * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include diff --git a/reactos/ntoskrnl/mm/iospace.c b/reactos/ntoskrnl/mm/iospace.c index 243212ed101..b75e24f9925 100644 --- a/reactos/ntoskrnl/mm/iospace.c +++ b/reactos/ntoskrnl/mm/iospace.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/mm/iospace.c + * PURPOSE: Mapping io space * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/mm/mdl.c b/reactos/ntoskrnl/mm/mdl.c index 7dab6306113..68237bcc2dd 100644 --- a/reactos/ntoskrnl/mm/mdl.c +++ b/reactos/ntoskrnl/mm/mdl.c @@ -26,23 +26,39 @@ VOID MmUnlockPages(PMDL MemoryDescriptorList) * FUNCTION: Unlocks the physical pages described by a given MDL * ARGUMENTS: * MemoryDescriptorList = MDL describing the buffer to be unlocked + * NOTES: The memory described by the specified MDL must have been locked + * previously by a call to MmProbeAndLockPages. As the pages unlocked, the + * MDL is updated */ { UNIMPLEMENTED; } PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode) +/* + * FUNCTION: Maps the physical pages described by a given MDL + * ARGUMENTS: + * Mdl = Points to an MDL updated by MmProbeAndLockPages + * AccessMode = Specifies the access mode in which to map the MDL + * RETURNS: The base virtual address that maps the locked pages for the + * range described by the MDL + */ { PVOID base; unsigned int i; ULONG* mdl_pages=NULL; + MEMORY_AREA* Result; DPRINT("Mdl->ByteCount %x\n",Mdl->ByteCount); DPRINT("PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE) %x\n", PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE); - base = VirtualAlloc((LPVOID)0,Mdl->ByteCount,MEM_COMMIT, - PAGE_SYSTEM + PAGE_EXECUTE_READWRITE); + MmCreateMemoryArea(KernelMode, + MEMORY_AREA_MDL_MAPPING, + &base, + Mdl->ByteCount, + 0, + &Result); mdl_pages = (ULONG *)(Mdl + 1); for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE); i++) { @@ -57,8 +73,14 @@ PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode) } VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList) +/* + * FUNCTION: Releases a mapping set up by a preceding call to MmMapLockedPages + * ARGUMENTS: + * BaseAddress = Base virtual address to which the pages were mapped + * MemoryDescriptorList = MDL describing the mapped pages + */ { - UNIMPLEMENTED; + (void)MmFreeMemoryArea(BaseAddress,MemoryDescriptorList->ByteCount,FALSE); } VOID MmPrepareMdlForReuse(PMDL Mdl) @@ -84,24 +106,12 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, { ULONG* mdl_pages=NULL; int i; - memory_area* marea; + MEMORY_AREA* marea; DPRINT("MmProbeAndLockPages(Mdl %x)\n",Mdl); DPRINT("StartVa %x\n",Mdl->StartVa); - if (Mdl->StartVa > KERNEL_BASE) - { - marea=find_first_marea(system_memory_area_list_head, - (ULONG)Mdl->StartVa, - Mdl->ByteCount); - } - else - { - marea=find_first_marea(memory_area_list_head, - (ULONG)Mdl->StartVa, - Mdl->ByteCount); - } - + marea = MmOpenMemoryAreaByAddress((ULONG)Mdl->StartVa); DPRINT("marea %x\n",marea); @@ -109,7 +119,7 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, /* * Check the area is valid */ - if (marea==NULL || (marea->base+marea->length) < ((ULONG)Mdl->StartVa)) + if (marea==NULL ) { printk("Area is invalid\n"); ExRaiseStatus(STATUS_INVALID_PARAMETER); @@ -118,6 +128,7 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, /* * Check the permissions */ + #if 0 switch(Operation) { case IoReadAccess: @@ -141,6 +152,7 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, __FUNCTION__); KeBugCheck(UNEXPECTED_KERNEL_MODE_TRAP); } + #endif /* * Lock the memory area @@ -155,13 +167,8 @@ VOID MmProbeAndLockPages(PMDL Mdl, KPROCESSOR_MODE AccessMode, for (i=0;i<(PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE);i++) { - if (!is_page_present(PAGE_ROUND_DOWN(Mdl->StartVa) + (i*PAGESIZE))) - { - marea->load_page(marea,PAGE_ROUND_DOWN(Mdl->StartVa) + (i*PAGESIZE) - - marea->base); - } mdl_pages[i]=MmGetPhysicalAddress((PVOID)(PAGE_ROUND_DOWN(Mdl->StartVa) - +(i*PAGESIZE))); + +(i*PAGESIZE))).LowPart; DPRINT("mdl_pages[i] %x\n",mdl_pages[i]); DPRINT("&mdl_pages[i] %x\n",&mdl_pages[i]); } @@ -239,7 +246,7 @@ VOID MmBuildMdlForNonPagedPool(PMDL Mdl) for (va=0; vaSize; va++) { ((PULONG)(Mdl + 1))[va] = MmGetPhysicalAddress( - Mdl->StartVa+ (va * PAGESIZE)); + Mdl->StartVa+ (va * PAGESIZE)).LowPart; } Mdl->MappedSystemVa = Mdl->StartVa; } diff --git a/reactos/ntoskrnl/mm/mm.c b/reactos/ntoskrnl/mm/mm.c index ea6914580b8..76ef94b9d13 100644 --- a/reactos/ntoskrnl/mm/mm.c +++ b/reactos/ntoskrnl/mm/mm.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top directory * PROJECT: ReactOS kernel - * FILE: mm/mm.c + * FILE: ntoskrnl/mm/mm.c * PURPOSE: kernel memory managment functions * PROGRAMMER: David Welch * UPDATE HISTORY: @@ -13,8 +13,7 @@ #include #include #include -#include -#include +#include #include #include diff --git a/reactos/ntoskrnl/mm/pool.c b/reactos/ntoskrnl/mm/pool.c index f8f211416f0..a9ac669e848 100644 --- a/reactos/ntoskrnl/mm/pool.c +++ b/reactos/ntoskrnl/mm/pool.c @@ -15,12 +15,13 @@ /* INCLUDES ****************************************************************/ +#include #include #include #include #include #include -#include +#include #define NDEBUG #include @@ -44,7 +45,7 @@ typedef struct _block_hdr /* * Memory managment initalized symbol for the base of the pool */ -extern unsigned int kernel_pool_base; +unsigned int kernel_pool_base = 0; /* * Pointer to the first block in the free list @@ -64,6 +65,11 @@ static unsigned int alloc_map[ALLOC_MAP_SIZE/32]={0,}; /* FUNCTIONS ***************************************************************/ +VOID ExInitNonPagedPool(ULONG BaseAddress) +{ + kernel_pool_base=BaseAddress; +} + static void validate_free_list(void) /* * FUNCTION: Validate the integrity of the list of free blocks @@ -572,6 +578,7 @@ static PVOID ExAllocatePagedPool(ULONG type, ULONG size) static PVOID ExAllocateNonPagedPool(ULONG type, ULONG size) { block_hdr* current=NULL; + void* block; DPRINT("kmalloc(size %d)\n",size); validate_kernel_pool(); @@ -596,7 +603,9 @@ static PVOID ExAllocateNonPagedPool(ULONG type, ULONG size) if (current->size>=size) { DPRINT("found block %x of size %d\n",current,size); - return(take_block(current,size)); + block=take_block(current,size); + memset(block,0,size); + return(block); } current=current->next; } @@ -604,7 +613,9 @@ static PVOID ExAllocateNonPagedPool(ULONG type, ULONG size) /* * Otherwise create a new block */ - return(block_to_address(grow_kernel_pool(size))); + block=block_to_address(grow_kernel_pool(size)); + memset(block,0,size); + return(block); } PVOID ExAllocatePoolWithQuota(POOL_TYPE PoolType, ULONG NumberOfBytes) diff --git a/reactos/ntoskrnl/mm/section.c b/reactos/ntoskrnl/mm/section.c index a6059707913..e4914c0dc6e 100644 --- a/reactos/ntoskrnl/mm/section.c +++ b/reactos/ntoskrnl/mm/section.c @@ -10,14 +10,47 @@ /* INCLUDES *****************************************************************/ -#include -#include #include +#include #include /* FUNCTIONS *****************************************************************/ +NTSTATUS STDCALL ZwCreateSection(OUT PHANDLE SectionHandle, + IN ACCESS_MASK DesiredAccess, + IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, + IN PLARGE_INTEGER MaximumSize OPTIONAL, + IN ULONG SectionPageProtection OPTIONAL, + IN ULONG AllocationAttributes, + IN HANDLE FileHandle OPTIONAL) +/* + * FUNCTION: Creates a section object. + * ARGUMENTS: + * SectionHandle (OUT) = Caller supplied storage for the resulting + * handle + * DesiredAccess = Specifies the desired access to the section can be a + * combination of STANDARD_RIGHTS_REQUIRED | + * SECTION_QUERY | SECTION_MAP_WRITE | + * SECTION_MAP_READ | SECTION_MAP_EXECUTE. + * ObjectAttribute = Initialized attributes for the object can be used + * to create a named section + * MaxiumSize = Maximizes the size of the memory section. Must be + * non-NULL for a page-file backed section. + * If value specified for a mapped file and the file is + * not large enough, file will be extended. + * SectionPageProtection = Can be a combination of PAGE_READONLY | + * PAGE_READWRITE | PAGE_WRITEONLY | + * PAGE_WRITECOPY. + * AllocationAttributes = can be a combination of SEC_IMAGE | + * SEC_RESERVE + * FileHandle = Handle to a file to create a section mapped to a file + * instead of a memory backed section. + * RETURNS: Status + */ +{ +} + NTSTATUS ZwOpenSection(PHANDLE SectionHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes) diff --git a/reactos/ntoskrnl/mm/virtual.c b/reactos/ntoskrnl/mm/virtual.c index e4fd6dc8eca..ae8fa0e3789 100644 --- a/reactos/ntoskrnl/mm/virtual.c +++ b/reactos/ntoskrnl/mm/virtual.c @@ -29,26 +29,10 @@ extern unsigned int end; * These two are statically declared because mm is initalized before the * memory pool */ -static memory_area kernel_text_desc; -static memory_area kernel_data_desc; -static memory_area kernel_param_desc; -static memory_area kernel_pool_desc; - -/* - * Head of the list of system memory areas - */ -memory_area* system_memory_area_list_head=&kernel_text_desc; - -/* - * Head of the list of user memory areas (this should be per process) - */ -memory_area* memory_area_list_head=NULL; - -/* - * The base address of the kmalloc region - */ -unsigned int kernel_pool_base = 0; - +static MEMORY_AREA* kernel_text_desc = NULL; +static MEMORY_AREA* kernel_data_desc = NULL; +static MEMORY_AREA* kernel_param_desc = NULL; +static MEMORY_AREA* kernel_pool_desc = NULL; /* FUNCTIONS ****************************************************************/ @@ -61,92 +45,55 @@ void VirtualInit(boot_param* bp) */ { unsigned int kernel_len = bp->end_mem - bp->start_mem; + ULONG BaseAddress; + ULONG Length; + ULONG ParamLength = kernel_len; DPRINT("VirtualInit() %x\n",bp); + MmInitMemoryAreas(); + ExInitNonPagedPool(KERNEL_BASE+ PAGE_ROUND_UP(kernel_len) + PAGESIZE); + + /* * Setup the system area descriptor list */ - kernel_text_desc.base = KERNEL_BASE; - kernel_text_desc.length = ((ULONG)&etext) - KERNEL_BASE; - kernel_text_desc.previous = NULL; - kernel_text_desc.next = &kernel_data_desc; - kernel_text_desc.load_page=NULL; - kernel_text_desc.access = PAGE_EXECUTE_READ; + BaseAddress = KERNEL_BASE; + Length = ((ULONG)&etext) - KERNEL_BASE; + ParamLength = ParamLength - Length; + MmCreateMemoryArea(KernelMode,MEMORY_AREA_SYSTEM,&BaseAddress, + Length,0,&kernel_text_desc); - kernel_data_desc.base = PAGE_ROUND_UP(((ULONG)&etext)); - kernel_data_desc.length = ((ULONG)&end) - kernel_text_desc.base; - kernel_data_desc.previous = &kernel_text_desc; - kernel_data_desc.next = &kernel_param_desc; - kernel_data_desc.load_page=NULL; - kernel_data_desc.access = PAGE_READWRITE; + Length = ((ULONG)&end) - ((ULONG)&etext); + ParamLength = ParamLength - Length; + DPRINT("Length %x\n",Length); + BaseAddress = PAGE_ROUND_UP(((ULONG)&etext)); + MmCreateMemoryArea(KernelMode, + MEMORY_AREA_SYSTEM, + &BaseAddress, + Length, + 0, + &kernel_data_desc); - kernel_param_desc.base = PAGE_ROUND_UP(((ULONG)&end)); - kernel_param_desc.length = kernel_len - (kernel_data_desc.length + - kernel_text_desc.length); - kernel_param_desc.previous = &kernel_data_desc; - kernel_param_desc.next = &kernel_pool_desc; - kernel_param_desc.load_page=NULL; - /* - * The kmalloc area starts one page after the kernel area - */ - kernel_pool_desc.base = KERNEL_BASE+ PAGE_ROUND_UP(kernel_len) + PAGESIZE; - kernel_pool_desc.length = NONPAGED_POOL_SIZE; - kernel_pool_desc.previous = &kernel_param_desc; - kernel_pool_desc.next = NULL; - kernel_pool_desc.load_page=NULL; - - kernel_pool_base = kernel_pool_desc.base; - DPRINT("kmalloc_region_base %x\n",kernel_pool_base); + BaseAddress = PAGE_ROUND_UP(((ULONG)&end)); + Length = ParamLength; + MmCreateMemoryArea(KernelMode,MEMORY_AREA_SYSTEM,&BaseAddress, + Length,0,&kernel_param_desc); + + BaseAddress = KERNEL_BASE+ PAGE_ROUND_UP(kernel_len) + PAGESIZE; + Length = NONPAGED_POOL_SIZE; + MmCreateMemoryArea(KernelMode,MEMORY_AREA_SYSTEM,&BaseAddress, + Length,0,&kernel_pool_desc); + + MmDumpMemoryAreas(); + CHECKPOINT; } - -memory_area* find_first_marea(memory_area* list_head, unsigned int base, - unsigned int length) -/* - * FUNCTION: Returns the first memory area starting in the region or the last - * one before the start of the region - * ARGUMENTS: - * list_head = Head of the list of memory areas to search - * base = base address of the region - * length = length of the region - * RETURNS: A pointer to the area found or - * NULL if the region was before the first region on the list - */ +NTSTATUS MmSectionHandleFault(MEMORY_AREA* MemoryArea, ULONG Address) { - memory_area* current=list_head; - for (;;) - { - if (current==NULL) - { -// printk("current is null\n"); - return(NULL); - } -// printk("current %x current->base %x\n",current,current->base); - if (current->base == base && length==0) - { - return(current); - } - - if (current->base >= base) - { - if (current->base < (base+length)) - { - return(current); - } - else - { - return(current->previous); - } - } - if (current->next==NULL) - { - return(current); - } - current=current->next; - } - return(NULL); + set_page(Address,0x7,get_free_page()); + return(STATUS_SUCCESS); } asmlinkage int page_fault_handler(unsigned int edi, @@ -164,17 +111,21 @@ asmlinkage int page_fault_handler(unsigned int edi, * FUNCTION: Handle a page fault */ { - memory_area* marea=NULL; - + KPROCESSOR_MODE FaultMode; + MEMORY_AREA* MemoryArea; + /* * Get the address for the page fault */ unsigned int cr2; __asm__("movl %%cr2,%0\n\t" : "=d" (cr2)); DPRINT("Page fault at address %x with eip %x\n",cr2,eip); + for(;;); cr2 = PAGE_ROUND_DOWN(cr2); + assert_irql(DISPATCH_LEVEL); + /* * Find the memory area for the faulting address */ @@ -188,298 +139,31 @@ asmlinkage int page_fault_handler(unsigned int edi, printk("%s:%d\n",__FILE__,__LINE__); return(0); } - marea=find_first_marea(system_memory_area_list_head,cr2, - PAGESIZE); + FaultMode = UserMode; } else { - marea=find_first_marea(memory_area_list_head,cr2, - PAGESIZE); + FaultMode = KernelMode; } - /* - * If the access was to an invalid area of memory raise an exception - */ - if (marea==NULL || marea->load_page==NULL) + MemoryArea = MmOpenMemoryAreaByAddress(cr2); + if (MemoryArea==NULL) { printk("%s:%d\n",__FILE__,__LINE__); return(0); } - /* - * Check the access was within the area - */ - if (cr2 > (marea->base + marea->length) || cr2 < marea->base) + switch (MemoryArea->Type) { - DPRINT("base was %x length %x\n",marea->base,marea->length); - DPRINT("%s:%d\n",__FILE__,__LINE__); + case MEMORY_AREA_SYSTEM: return(0); - } - - /* - * Call the region specific page fault handler - */ - return(marea->load_page(marea,cr2 - marea->base)); -} - - - -static LPVOID allocate_marea(DWORD dwSize, DWORD flAllocationType, - DWORD flProtect, memory_area** list_head, - unsigned int last_addr, - BOOL (*fn)(memory_area* marea, - unsigned int address)) -/* - * FUNCTION: - */ -{ - memory_area* current=*list_head; - memory_area* previous; - memory_area* ndesc=NULL; - - previous=current; - while (current!=NULL) - { - last_addr = PAGE_ROUND_UP(current->base + current->length); - previous=current; - current=current->next; - } - ndesc = ExAllocatePool(NonPagedPool,sizeof(memory_area)); - ndesc->access=flProtect; - ndesc->state=flAllocationType; - ndesc->lock=FALSE; - ndesc->base=last_addr+PAGESIZE; - ndesc->length=dwSize; - ndesc->previous=previous; - if (previous!=NULL) - { - ndesc->next=previous->next; - previous->next=ndesc; - if (previous->next!=NULL) - { - previous->next->previous=ndesc; - } - } - else - { - *list_head=ndesc; - ndesc->next=NULL; - ndesc->previous=NULL; - } - ndesc->load_page=fn; - DPRINT("VirtualAlloc() returning %x\n",ndesc->base); - return((LPVOID)ndesc->base); -} - -void commit_region_free(memory_area* marea) -/* - * FUNCTION: Decommits the region - */ -{ - int i; - for (i=0;ilength;i=i+PAGESIZE) - { - if (is_page_present(marea->base+marea->length)) - { - free_page(MmGetPhysicalAddress(marea->base+marea->length),1); - } - } -} - -BOOL commit_region_load_page(memory_area* marea, unsigned int address) -/* - * FUNCTION: Handles a page fault on a committed region of memory - * ARGUMENTS: - * marea = memory area - * address = address of faulting access - * RETURNS: TRUE if the page was loaded - * FALSE if an exception should be generated - */ -{ - set_page(marea->base+address,0x7,get_free_page()); - return(TRUE); -} - -asmlinkage LPVOID STDCALL VirtualAlloc(LPVOID lpAddress, DWORD dwSize, - DWORD flAllocationType, - DWORD flProtect) -{ -/* - * FUNCTION: Create a memory area - * ARGUMENTS: - * lpAddress = the base address of the area or NULL if the system - * decides the base - * dwSize = the size of the area - * flAllocationType = the type of allocation - * MEM_COMMIT = accessible - * MEM_RESERVE = not accessible but can't be allocated - * flProtect = what protection to give the area - * RETURNS: The base address of the block - */ - DPRINT("VirtualAlloc() lpAddress %x dwSize %x flAllocationType %x ", - lpAddress,dwSize,flAllocationType); - DPRINT("flProtect %x\n",flProtect); - - if (lpAddress==NULL) - { - /* - * We decide the address - */ - if (flProtect & PAGE_SYSTEM) - { - return(allocate_marea(dwSize,flAllocationType, - flProtect,&system_memory_area_list_head, - KERNEL_BASE,commit_region_load_page)); - } - else - { - return(allocate_marea(dwSize,flAllocationType, - flProtect,&memory_area_list_head,PAGESIZE, - commit_region_load_page)); - } - } - else - { - memory_area* marea=NULL; - if (lpAddress < ((PVOID)KERNEL_BASE)) - { - marea=find_first_marea(memory_area_list_head, - (unsigned int)lpAddress,dwSize); - } - else - { - marea=find_first_marea(system_memory_area_list_head, - (unsigned int)lpAddress,dwSize); - } - - /* - * Check someone hasn't already allocated that area - */ - if (marea!=NULL && marea->base <= (unsigned int)lpAddress && - (marea->base + marea->length) > (unsigned int)lpAddress) - { - SetLastError(ERROR_INVALID_DATA); - return(0); - } - - /* - * Grab the area - */ - } -} - -BOOL WINAPI VirtualFreeEx(HANDLE hProcess, LPVOID lpAddress, DWORD dwSize, - DWORD dwFreeType) -/* - * FUNCTION: Releases, decommits or both a region of memory within the - * virtual address of a specified process - * ARGUMENTS: - * hProcess = Process to act on - * lpAddress = starting virtual address to free - * dwSize = Size in bytes of the memory region to free - * dwFreeType = Type of free operation - * RETURNS: On success non-zero - * On failure zero - * NOTE: This tries to optimize for the most common case which is for - * regions to be decommitted in large chunks. If a process alternatedly - * decommitted every other page in a region this function would be extremely - * inefficent. - */ -{ - memory_area* marea = NULL; - - /* - * Check our permissions for hProcess here - */ - - /* - * Get the list of memory areas corresponding to hProcess here - */ - - /* - * Do the business - */ - if (dwFreeType==MEM_RELEASE) - { - if (dwSize!=0) - { - SetLastError(ERROR_INVALID_BLOCK_LENGTH); - return(0); - } - marea = find_first_marea(memory_area_list_head,(unsigned int)lpAddress, - 1); - - if (marea==NULL || marea->base!=((int)lpAddress)) - { - SetLastError(ERROR_INVALID_BLOCK); - return(0); - } - - /* - * Ask the memory area to destroy itself - */ - marea->free(marea); - - /* - * Change the area attributes - */ - marea->access=PAGE_NOACCESS; - marea->state=MEM_FREE; - marea->type=MEM_PRIVATE; - } - else - { + case MEMORY_AREA_SECTION_VIEW: + return(MmSectionHandleFault(MemoryArea,cr2)); } + return(0); } -BOOL WINAPI VirtualProtectEx(HANDLE hProcess, LPVOID lpAddress, - DWORD dwSize, DWORD flNewProtect, PDWORD lpflOldProtect) -/* - * FUNCTION: - */ -{ -} - -DWORD WINAPI VirtualQueryEx(HANDLE hProcess, LPCVOID lpAddress, - PMEMORY_BASIC_INFORMATION lpBuffer, DWORD dwLength) -/* - * FUNCTION: Provides information about a range of pages within the virtual - * address space of a specified process. - * ARGUMENTS: - * hProcess = Handle of process - * lpAddress = Address of region - * lpBuffer = Buffer to store information - * dwLength = length of region - * RETURNS: The number of bytes transferred into the buffer - */ -{ - /* - * Find the memory area - */ - memory_area* marea = find_first_marea(memory_area_list_head, - (unsigned int) lpAddress, - dwLength); - - /* - * Check it exists - */ - if (marea==NULL || marea->base!=((int)lpAddress)) - { - SetLastError(0); - return(0); - } - - lpBuffer->BaseAddress = (void *)lpAddress; - lpBuffer->AllocationBase = (void *)marea->base; - lpBuffer->AllocationProtect = marea->initial_access; - lpBuffer->RegionSize = marea->length; - lpBuffer->State = marea->state; - lpBuffer->Protect = marea->access; - lpBuffer->Type = marea->type; - - return(sizeof(MEMORY_BASIC_INFORMATION)); -} BOOLEAN MmIsNonPagedSystemAddressValid(PVOID VirtualAddress) { @@ -498,30 +182,6 @@ BOOLEAN MmIsAddressValid(PVOID VirtualAddress) * allow byte granular access? */ { - memory_area* marea; - - if (VirtualAddress >= (PVOID)KERNEL_BASE) - { - marea = find_first_marea(system_memory_area_list_head, - (unsigned int)VirtualAddress,1); - } - else - { - marea = find_first_marea(memory_area_list_head, - (unsigned int)VirtualAddress,1); - } - - if (marea==NULL) - { - return(FALSE); - } - - if (marea->access == PAGE_NOACCESS || marea->access & PAGE_GUARD || - marea->state == MEM_FREE || marea->state == MEM_RESERVE) - { - return(FALSE); - } - - return(TRUE); + UNIMPLEMENTED; } diff --git a/reactos/ntoskrnl/mm/zone.c b/reactos/ntoskrnl/mm/zone.c index 7ee536a1c5e..55a27b616fd 100644 --- a/reactos/ntoskrnl/mm/zone.c +++ b/reactos/ntoskrnl/mm/zone.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: mkernel/mm/zone.c + * FILE: ntoskrnl/mm/zone.c * PURPOSE: Implements zone buffers * PROGRAMMER: David Welch (welch@mcmail.com) */ @@ -9,8 +9,6 @@ /* INCLUDES ****************************************************************/ #include -#include -#include /* FUNCTIONS ***************************************************************/ diff --git a/reactos/ntoskrnl/ob/handle.c b/reactos/ntoskrnl/ob/handle.c index 533014d3d12..ffd4950e0fa 100644 --- a/reactos/ntoskrnl/ob/handle.c +++ b/reactos/ntoskrnl/ob/handle.c @@ -14,7 +14,6 @@ #include #include #include -#include #define NDEBUG #include @@ -46,7 +45,7 @@ typedef struct * PURPOSE: Head of the list of handle blocks */ LIST_ENTRY handle_list_head = {NULL,NULL}; -KSPIN_LOCK handle_list_lock; +KSPIN_LOCK handle_list_lock = {0}; /* FUNCTIONS ***************************************************************/ diff --git a/reactos/ntoskrnl/ob/namespc.c b/reactos/ntoskrnl/ob/namespc.c index 9b6ac7cd969..636814fc437 100644 --- a/reactos/ntoskrnl/ob/namespc.c +++ b/reactos/ntoskrnl/ob/namespc.c @@ -15,7 +15,6 @@ #include #include #include -#include #define NDEBUG #include @@ -27,7 +26,7 @@ OBJECT_TYPE DirectoryObjectType = {{0,0,NULL}, 0, ULONG_MAX, ULONG_MAX, - sizeof(DEVICE_OBJECT), + sizeof(DIRECTORY_OBJECT), 0, NULL, NULL, @@ -39,18 +38,29 @@ OBJECT_TYPE DirectoryObjectType = {{0,0,NULL}, NULL, }; + static struct { OBJECT_HEADER hdr; // DIRECTORY_OBJECT directory; LIST_ENTRY head; -} namespc_root; + KSPIN_LOCK Lock; +} namespc_root = {{0,},}; /* FUNCTIONS **************************************************************/ NTSTATUS ZwOpenDirectoryObject(PHANDLE DirectoryHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes) +/* + * FUNCTION: Opens a namespace directory object + * ARGUMENTS: + * DirectoryHandle (OUT) = Variable which receives the directory handle + * DesiredAccess = Desired access to the directory + * ObjectAttributes = Structure describing the directory + * RETURNS: Status + * NOTES: Undocumented + */ { PVOID Object; NTSTATUS Status; @@ -77,30 +87,97 @@ NTSTATUS ZwQueryDirectoryObject(IN HANDLE DirObjHandle, IN BOOLEAN IgnoreInputIndex, IN OUT PULONG ObjectIndex, OUT PULONG DataWritten OPTIONAL) +/* + * FUNCTION: Reads information from a namespace directory + * ARGUMENTS: + * DirObjInformation (OUT) = Buffer to hold the data read + * BufferLength = Size of the buffer in bytes + * GetNextIndex = If TRUE then set ObjectIndex to the index of the + * next object + * If FALSE then set ObjectIndex to the number of + * objects in the directory + * IgnoreInputIndex = If TRUE start reading at index 0 + * If FALSE start reading at the index specified + * by object index + * ObjectIndex = Zero based index into the directory, interpretation + * depends on IgnoreInputIndex and GetNextIndex + * DataWritten (OUT) = Caller supplied storage for the number of bytes + * written (or NULL) + * RETURNS: Status + */ { POBJECT_HEADER hdr = ObGetObjectByHandle(DirObjHandle); PDIRECTORY_OBJECT dir = (PDIRECTORY_OBJECT)(HEADER_TO_BODY(hdr)); + ULONG EntriesToRead; PLIST_ENTRY current_entry; POBJECT_HEADER current; - PWSTR outbuffer = (PWSTR)(ObjectIndex); + ULONG i=0; + ULONG EntriesToSkip; + + assert_irql(PASSIVE_LEVEL); + + EntriesToRead = BufferLength / sizeof(OBJDIR_INFORMATION); + *DataWritten = 0; current_entry = dir->head.Flink; - while (current_entry!=NULL) + + /* + * Optionally, skip over some entries at the start of the directory + */ + if (!IgnoreInputIndex) + { + EntriesToSkip = *ObjectIndex; + while ( iFlink; + } + } + + /* + * Read the maximum entries possible into the buffer + */ + while ( iname.Buffer)) - { - return(STATUS_SUCCESS); - } - BufferLength = BufferLength - wstrlen(current->name.Buffer); -// wcscpy(outbuffer,current->name.Buffer); - outbuffer = outbuffer + wstrlen(current->name.Buffer); + RtlCopyUnicodeString(&DirObjInformation[i].ObjectName, + &(current->name)); + i++; current_entry = current_entry->Flink; + (*DataWritten) = (*DataWritten) + sizeof(OBJDIR_INFORMATION); + } + + /* + * Optionally, count the number of entries in the directory + */ + if (!GetNextIndex) + { + *ObjectIndex=i; + } + else + { + while ( current_entry!=NULL ) + { + current_entry=current_entry->Flink; + i++; + } + *ObjectIndex=i; } return(STATUS_SUCCESS); } +NTSTATUS ObReferenceObjectByName(PUNICODE_STRING ObjectPath, + ULONG Attributes, + PACCESS_STATE PassedAccessState, + ACCESS_MASK DesiredAccess, + POBJECT_TYPE ObjectType, + KPROCESSOR_MODE Accessmode, + PVOID ParseContext, + PVOID* ObjectPtr) +{ + UNIMPLEMENTED; +} + NTSTATUS ObOpenObjectByName(POBJECT_ATTRIBUTES ObjectAttributes, PVOID* Object) { @@ -120,7 +197,7 @@ NTSTATUS ObOpenObjectByName(POBJECT_ATTRIBUTES ObjectAttributes, return(STATUS_SUCCESS); } -void ObjNamespcInit(void) +void ObInit(void) /* * FUNCTION: Initialize the object manager namespace */ @@ -160,7 +237,8 @@ NTSTATUS ZwCreateDirectoryObject(PHANDLE DirectoryHandle, * Initialize the object body */ InitializeListHead(&dir->head); - + KeInitializeSpinLock(&(dir->Lock)); + return(STATUS_SUCCESS); } @@ -219,10 +297,9 @@ static PVOID ObDirLookup(PDIRECTORY_OBJECT dir, PWSTR name) } if (name[0]=='.'&&name[1]=='.'&&name[2]==0) { - UNIMPLEMENTED; - return(NULL); + return(BODY_TO_HEADER(BODY_TO_HEADER(dir)->Parent)); } - while (current!=NULL) + while (current!=(&((PDIRECTORY_OBJECT)dir)->head)) { current_obj = CONTAINING_RECORD(current,OBJECT_HEADER,entry); if ( wcscmp(current_obj->name.Buffer, name)==0) @@ -300,7 +377,7 @@ PVOID ObLookupObject(HANDLE rooth, PWSTR string) if (string[0]!='\\') { - printk("(%s:%d) Non absolute pathname passed to %s\n",__FILE__, + DbgPrint("(%s:%d) Non absolute pathname passed to %s\n",__FILE__, __LINE__,__FUNCTION__); return(NULL); } @@ -324,7 +401,7 @@ PVOID ObLookupObject(HANDLE rooth, PWSTR string) */ if (current_dir->Type!=OBJTYP_DIRECTORY) { - printk("(%s:%d) Bad path component\n",__FILE__, + DbgPrint("(%s:%d) Bad path component\n",__FILE__, __LINE__); ExFreePool(string); return(NULL); @@ -336,7 +413,7 @@ PVOID ObLookupObject(HANDLE rooth, PWSTR string) current_hdr=(PDIRECTORY_OBJECT)ObDirLookup(current_dir,current); if (current_hdr==NULL) { - printk("(%s:%d) Path component not found\n",__FILE__, + DbgPrint("(%s:%d) Path component not found\n",__FILE__, __LINE__); ExFreePool(string); return(NULL); diff --git a/reactos/ntoskrnl/ob/object.c b/reactos/ntoskrnl/ob/object.c index 4b6492ccd4e..10011ca197b 100644 --- a/reactos/ntoskrnl/ob/object.c +++ b/reactos/ntoskrnl/ob/object.c @@ -12,7 +12,6 @@ #include #include -#include #include #define NDEBUG @@ -97,13 +96,13 @@ PVOID ObGenericCreateObject(PHANDLE Handle, name=name+1; } - parent = ObLookupObject(ObjectAttributes->RootDirectory,path); + hdr->Parent = ObLookupObject(ObjectAttributes->RootDirectory,path); /* * Initialize the object header */ ObInitializeObjectHeader(Type,name,hdr); - ObCreateEntry(parent,hdr); + ObCreateEntry(hdr->Parent,hdr); DPRINT("Handle %x\n",Handle); *Handle = ObAddHandle(HEADER_TO_BODY(hdr)); @@ -188,7 +187,7 @@ NTSTATUS ObReferenceObjectByPointer(PVOID ObjectBody, { POBJECT_HEADER Object; - DPRINT("ObReferenceObjectByPointer(%x %x)\n",ObjectBody,Object); + DPRINT("ObReferenceObjectByPointer(%x)\n",ObjectBody); Object = BODY_TO_HEADER(ObjectBody); Object->RefCount++; @@ -253,7 +252,7 @@ NTSTATUS ObReferenceObjectByHandle(HANDLE Handle, PVOID ObjectBody; ASSERT_IRQL(PASSIVE_LEVEL); - assert(HandleInformation==NULL); + assert(HandleInformationPtr==NULL); assert(Object!=NULL); assert(Handle!=NULL); diff --git a/reactos/ntoskrnl/ps/process.c b/reactos/ntoskrnl/ps/process.c index 0db1a4953a4..043508483d6 100644 --- a/reactos/ntoskrnl/ps/process.c +++ b/reactos/ntoskrnl/ps/process.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/psmgr/process.c + * FILE: ntoskrnl/ps/process.c * PURPOSE: Process managment * PROGRAMMER: David Welch (welch@mcmail.com) * REVISION HISTORY: @@ -10,18 +10,28 @@ /* INCLUDES ******************************************************************/ -#include #include #include +/* GLOBALS ******************************************************************/ + +EPROCESS SystemProcess = {{0},}; +HANDLE SystemProcessHandle = NULL; + /* FUNCTIONS *****************************************************************/ -PEPROCESS PsGetCurrentProcess(VOID) +PKPROCESS KeGetCurrentProcess(VOID) +{ + return(NULL); +// return(&(PsGetCurrentProcess()->Pcb)); +} + +struct _EPROCESS* PsGetCurrentProcess(VOID) /* * FUNCTION: Returns a pointer to the current process */ { - return(PsGetCurrentThread()->Process); + return(PsGetCurrentThread()->ThreadsProcess); } diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index e4ecc2200b3..f90f4a7ffe8 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -14,8 +14,9 @@ /* FUNCTIONS ***************************************************************/ -VOID PsMgrInit(VOID) +VOID PsInit(VOID) { ObjInitializeHandleTable(NULL); PsInitThreadManagment(); + PsInitIdleThread(); } diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index b06eedd7feb..017ab56f6a5 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -20,10 +20,10 @@ #include #include -#include +#include #include #include -#include +#include #include #define NDEBUG @@ -38,7 +38,7 @@ OBJECT_TYPE ThreadObjectType = {{NULL,0,0}, 0, ULONG_MAX, ULONG_MAX, - sizeof(KTHREAD), + sizeof(ETHREAD), 0, NULL, NULL, @@ -50,23 +50,22 @@ OBJECT_TYPE ThreadObjectType = {{NULL,0,0}, NULL, }; - #define NR_THREAD_PRIORITY_LEVELS (32) -static KSPIN_LOCK ThreadListLock; +static KSPIN_LOCK ThreadListLock = {0,}; /* * PURPOSE: List of all threads currently active */ -static LIST_ENTRY ThreadListHead; +static LIST_ENTRY ThreadListHead = {NULL,NULL}; /* * PURPOSE: List of threads associated with each priority level */ -static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]; +static LIST_ENTRY PriorityListHead[NR_THREAD_PRIORITY_LEVELS]={{NULL,NULL},}; static BOOLEAN DoneInitYet = FALSE; -static PKTHREAD CurrentThread; +static PETHREAD CurrentThread = NULL; static ULONG NextThreadUniqueId = 0; @@ -82,7 +81,7 @@ NTSTATUS ZwSetInformationThread(HANDLE ThreadHandle, PKTHREAD KeGetCurrentThread(VOID) { - return(CurrentThread); + return((PKTHREAD)CurrentThread); } PETHREAD PsGetCurrentThread(VOID) @@ -131,9 +130,9 @@ void PsDispatchThread(void) * If this was an involuntary reschedule then the current thread will still * be eligible to run later */ - if (CurrentThread->State==THREAD_STATE_RUNNING) + if (CurrentThread->Tcb.ThreadState==THREAD_STATE_RUNNING) { - CurrentThread->State=THREAD_STATE_RUNNABLE; + CurrentThread->Tcb.ThreadState=THREAD_STATE_RUNNABLE; } /* @@ -143,16 +142,17 @@ void PsDispatchThread(void) current = CONTAINING_RECORD(ThreadListHead.Flink,KTHREAD,Entry); current_entry = ThreadListHead.Flink; - while (current_entry!=NULL) + while (current_entry!=(&ThreadListHead)) { - DPRINT("Scanning %x\n",current); - DPRINT("State %x Runnable %x\n",current->State,THREAD_STATE_RUNNABLE); - if (current->State == THREAD_STATE_RUNNABLE && - current !=CurrentThread) + DPRINT("Scanning %x ",current); + DPRINT("State %x Runnable %x\n",current->ThreadState, + THREAD_STATE_RUNNABLE); + if (current->ThreadState == THREAD_STATE_RUNNABLE && + current != (PKTHREAD)CurrentThread) { DPRINT("Scheduling this one %x\n",current); CurrentThread = current; - CurrentThread->State = THREAD_STATE_RUNNING; + CurrentThread->Tcb.ThreadState = THREAD_STATE_RUNNING; KeReleaseSpinLock(&ThreadListLock,irql); HalTaskSwitch(current); return; @@ -165,7 +165,7 @@ void PsDispatchThread(void) * If there are no other threads then continue with the current one if * possible */ - if (CurrentThread->State == THREAD_STATE_RUNNABLE) + if (CurrentThread->Tcb.ThreadState == THREAD_STATE_RUNNABLE) { return; } @@ -182,26 +182,27 @@ void PsInitThreadManagment(void) * FUNCTION: Initialize thread managment */ { - PKTHREAD first_thread; + PETHREAD first_thread; InitializeListHead(&ThreadListHead); KeInitializeSpinLock(&ThreadListLock); ObRegisterType(OBJTYP_THREAD,&ThreadObjectType); - first_thread = ExAllocatePool(NonPagedPool,sizeof(KTHREAD)); - first_thread->State = THREAD_STATE_RUNNING; - HalInitFirstTask(first_thread); - ExInterlockedInsertHeadList(&ThreadListHead,&first_thread->Entry, + first_thread = ExAllocatePool(NonPagedPool,sizeof(ETHREAD)); + first_thread->Tcb.ThreadState = THREAD_STATE_RUNNING; + HalInitFirstTask((PKTHREAD)first_thread); + ExInterlockedInsertHeadList(&ThreadListHead,&first_thread->Tcb.Entry, &ThreadListLock); CurrentThread = first_thread; DoneInitYet = TRUE; } -NTSTATUS PsWakeThread(PKTHREAD Thread) +NTSTATUS PsWakeThread(PETHREAD Thread) { - Thread->State = THREAD_STATE_RUNNABLE; + Thread->Tcb.ThreadState = THREAD_STATE_RUNNABLE; + return(STATUS_SUCCESS); } NTSTATUS PsSuspendThread(VOID) @@ -217,34 +218,12 @@ NTSTATUS PsSuspendThread(VOID) * NOTE: When we return from PsDispatchThread the spinlock will be * released */ - CurrentThread->State = THREAD_STATE_SUSPENDED; + CurrentThread->Tcb.ThreadState = THREAD_STATE_SUSPENDED; PsDispatchThread(); + return(STATUS_SUCCESS); } -NTSTATUS PsCreateThread(HANDLE Parent, - LPSECURITY_ATTRIBUTES lpThreadAttributes, - PVOID Stack, - LPTHREAD_START_ROUTINE lpStartAddress, - LPVOID Parameter, - DWORD dwCreationFlags, - LPDWORD lpThreadId, - PHANDLE ThreadHandle) -/* - * FUNCTION: Creates a thread - * ARGUMENTS: - * Parent = Parent process (or NULL for current) - * lpThreadAttributes = Security descriptor for the new thread - * Stack = Caller allocated stack - * lpStartAddress = Entry point for the thread - * Parameter = Parameter to be passed to the entrypoint - * dwCreationFlags = Flags for creation - * lpThreadId = Pointer which receives thread identifier - * ThreadHandle = Variable which receives handle - * RETURNS: Status - */ -{ - -} + NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) /* @@ -258,13 +237,23 @@ NTSTATUS PsTerminateSystemThread(NTSTATUS ExitStatus) DPRINT("terminating %x\n",CurrentThread); KeRaiseIrql(DISPATCH_LEVEL,&oldlvl); - CurrentThread->State = THREAD_STATE_TERMINATED; - ExInterlockedRemoveEntryList(&ThreadListHead,&CurrentThread->Entry, - &ThreadListLock); + CurrentThread->Tcb.ThreadState = THREAD_STATE_TERMINATED; + RemoveEntryList(&CurrentThread->Tcb.Entry); PsDispatchThread(); for(;;); } +NTSTATUS NtCreateThread(PHANDLE ThreadHandle, + ACCESS_MASK DesiredAccess, + POBJECT_ATTRIBUTES ObjectAttributes, + HANDLE ProcessHandle, + PCLIENT_ID Client, + PCONTEXT ThreadContext, + PINITIAL_TEB InitialTeb, + BOOLEAN CreateSuspended) +{ +} + NTSTATUS PsCreateSystemThread(PHANDLE ThreadHandle, ACCESS_MASK DesiredAccess, POBJECT_ATTRIBUTES ObjectAttributes, @@ -289,28 +278,40 @@ NTSTATUS PsCreateSystemThread(PHANDLE ThreadHandle, * RETURNS: Success or failure status */ { - PKTHREAD thread; + PETHREAD thread; ULONG ThreadId; ULONG ProcessId; thread = ObGenericCreateObject(ThreadHandle,0,NULL,OBJTYP_THREAD); - + DPRINT("Allocating thread %x\n",thread); - thread->State=THREAD_STATE_RUNNABLE; - thread->Priority=0; -// thread->Process=ObjGetObjectByHandle(ProcessHandle); - thread->ProcessHandle=ProcessHandle; - HalInitTask(thread,StartRoutine,StartContext); - -// ThreadId = InterlockedIncrement(&NextThreadUniqueId); - if (ClientId != NULL) + thread->Tcb.ThreadState=THREAD_STATE_RUNNABLE; + thread->Tcb.BasePriority=0; + thread->Tcb.CurrentPriority=0; + thread->Tcb.ApcList=ExAllocatePool(NonPagedPool,sizeof(LIST_ENTRY)); + InitializeListHead(thread->Tcb.ApcList); + HalInitTask(&(thread->Tcb),StartRoutine,StartContext); + InitializeListHead(&(thread->IrpList)); + thread->Cid.UniqueThread=NextThreadUniqueId++; +// thread->Cid.ThreadId=InterlockedIncrement(&NextThreadUniqueId); + if (ClientId!=NULL) { - ClientId->UniqueThread = ThreadId; + *ClientId=thread->Cid; } - ExInterlockedInsertHeadList(&ThreadListHead,&thread->Entry, + if (ProcessHandle!=NULL) + { + thread->ThreadsProcess=ObGetObjectByHandle(ProcessHandle); + } + else + { + thread->ThreadsProcess=&SystemProcess; + } + thread->StartAddress=StartRoutine; + + + ExInterlockedInsertHeadList(&ThreadListHead,&thread->Tcb.Entry, &ThreadListLock); - InitializeListHead(&thread->ApcQueueHead); return(STATUS_SUCCESS); } diff --git a/reactos/ntoskrnl/rtl/list.c b/reactos/ntoskrnl/rtl/list.c index a090636e0de..1018f6ee451 100644 --- a/reactos/ntoskrnl/rtl/list.c +++ b/reactos/ntoskrnl/rtl/list.c @@ -10,29 +10,33 @@ #include #include -#include #define NDEBUG #include /* FUNCTIONS *************************************************************/ -VOID RemoveEntryList(PLIST_ENTRY Entry) +BOOLEAN IsListEmpty(PLIST_ENTRY ListHead) /* - * FUNCTION: Resets the links for an entry from a double linked list + * FUNCTION: Determines if a list is empty * ARGUMENTS: - * Entry = Entry to reset - * NOTE: This isn't the same as ExInterlockedRemoveEntryList + * ListHead = Head of the list + * RETURNS: True if there are no entries in the list */ { - if (Entry->Blink!=NULL) - { - Entry->Blink->Flink=Entry->Flink; - } - if (Entry->Flink!=NULL) - { - Entry->Flink->Blink=Entry->Blink; - } + return(ListHead->Flink==ListHead); +} + +VOID RemoveEntryList(PLIST_ENTRY ListEntry) +{ + PLIST_ENTRY OldFlink; + PLIST_ENTRY OldBlink; + DPRINT("RemoveEntryList(ListEntry %x)\n",ListEntry); + OldFlink=ListEntry->Flink; + OldBlink=ListEntry->Blink; + DPRINT("OldFlink %x OldBlink %x\n",OldFlink,OldBlink); + OldFlink->Blink=OldBlink; + OldBlink->Flink=OldFlink; } PLIST_ENTRY RemoveTailList(PLIST_ENTRY ListHead) @@ -43,102 +47,19 @@ PLIST_ENTRY RemoveTailList(PLIST_ENTRY ListHead) * RETURNS: The removed entry */ { - PLIST_ENTRY entry = ListHead->Blink; - if (ListHead->Blink == ListHead->Flink) - { - ListHead->Flink = NULL; - } - if (entry!=NULL) - { - ListHead->Blink = entry->Blink; - } - return(entry); -} - -VOID ExInterlockedRemoveEntryList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry, - PKSPIN_LOCK Lock) -{ - KIRQL oldlvl; - KeAcquireSpinLock(Lock,&oldlvl); - if (ListHead->Flink == Entry && ListHead->Blink == Entry) - { - ListHead->Flink = ListHead->Blink = NULL; - Entry->Flink = Entry->Blink = NULL; - KeReleaseSpinLock(Lock,oldlvl); - return; - } - if (ListHead->Flink == Entry) - { - ListHead->Flink=Entry->Flink; - Entry->Flink = Entry->Blink = NULL; - KeReleaseSpinLock(Lock,oldlvl); - return; - } - if (ListHead->Blink == Entry) - { - ListHead->Blink = Entry->Blink; - Entry->Flink = Entry->Blink = NULL; - KeReleaseSpinLock(Lock,oldlvl); - return; - } - Entry->Flink->Blink = Entry->Blink; - Entry->Blink->Flink = Entry->Flink; - Entry->Flink = Entry->Blink = NULL; - KeReleaseSpinLock(Lock,oldlvl); -} - -PLIST_ENTRY RemoveHeadList(PLIST_ENTRY ListHead) -{ - PLIST_ENTRY Old; - - DPRINT("RemoveHeadList(ListHead %x)\n",ListHead); - DPRINT("Flink %x Blink %x\n",ListHead->Flink,ListHead->Blink); - - Old = ListHead->Flink; - - if (ListHead->Flink==NULL) - { - return(NULL); - } - - DPRINT("ListHead->Flink->Flink %x\n",ListHead->Flink->Flink); - ListHead->Flink=ListHead->Flink->Flink; - if (ListHead->Flink!=NULL) - { - DPRINT("ListHead->Flink->Blink %x\n",ListHead->Flink->Blink); - ListHead->Flink->Blink=NULL; - } + PLIST_ENTRY Old = ListHead->Blink; + RemoveEntryList(ListHead->Blink); return(Old); } -VOID RemoveEntryFromList(PLIST_ENTRY ListHead, PLIST_ENTRY Entry) -{ - if (ListHead->Flink == Entry && ListHead->Blink == Entry) - { - ListHead->Flink = ListHead->Blink = NULL; - Entry->Flink = Entry->Blink = NULL; - return; - } - if (ListHead->Flink == Entry) - { - ListHead->Flink=Entry->Flink; - Entry->Flink = Entry->Blink = NULL; - return; - } - if (ListHead->Blink == Entry) - { - ListHead->Blink = Entry->Blink; - Entry->Flink = Entry->Blink = NULL; - return; - } - Entry->Flink->Blink = Entry->Blink; - Entry->Blink->Flink = Entry->Flink; - Entry->Flink = Entry->Blink = NULL; +PLIST_ENTRY RemoveHeadList(PLIST_ENTRY ListHead) +{ + PLIST_ENTRY Old = ListHead->Flink; + DPRINT("RemoveHeadList(ListHead %x)\n",ListHead); + RemoveEntryList(ListHead->Flink); + return(Old); } - - - VOID InitializeListHead(PLIST_ENTRY ListHead) /* * FUNCTION: Initializes a double linked list @@ -146,8 +67,7 @@ VOID InitializeListHead(PLIST_ENTRY ListHead) * ListHead = Caller supplied storage for the head of the list */ { - ListHead->Blink=NULL; - ListHead->Flink=NULL; + ListHead->Flink = ListHead->Blink = ListHead; } VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry) @@ -158,63 +78,43 @@ VOID InsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry) * Entry = Entry to insert */ { - assert(ListHead!=NULL); - assert(ListEntry!=NULL); - if (ListHead->Blink==NULL) - { - ListEntry->Blink = ListEntry->Flink = NULL; - ListHead->Blink = ListHead->Flink = ListEntry; - } - else - { - ListEntry->Blink = ListHead->Blink; - ListEntry->Flink = NULL; - ListHead->Blink->Flink = ListEntry; - ListHead->Blink = ListEntry; - } + PLIST_ENTRY Blink; + + Blink = ListHead->Blink; + ListEntry->Flink=ListHead; + ListEntry->Blink=Blink; + Blink->Flink=ListEntry; + ListHead->Blink=ListEntry; } VOID InsertHeadList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry) { - /* - * Insert the entry - */ - ListEntry->Blink=NULL; - ListEntry->Flink=ListHead->Flink; + PLIST_ENTRY OldFlink; - if (ListHead->Flink==NULL) - { - assert(ListHead->Blink==NULL); - ListHead->Blink = ListHead->Flink = ListEntry; - } - else - { - ListHead->Flink->Blink = ListEntry; - ListHead->Flink = ListEntry; - } + OldFlink = ListHead->Flink; + ListEntry->Flink = OldFlink; + ListEntry->Blink = ListHead; + OldFlink->Blink = ListEntry; + ListHead->Flink = ListEntry; } PLIST_ENTRY ExInterlockedInsertTailList(PLIST_ENTRY ListHead, PLIST_ENTRY ListEntry, PKSPIN_LOCK Lock) { - PLIST_ENTRY Old = NULL; + PLIST_ENTRY Old; KIRQL oldlvl; - /* - * Lock the spinlock - */ KeAcquireSpinLock(Lock,&oldlvl); - DPRINT("oldlvl %x\n",oldlvl); - /* - * Insert the entry - */ - Old = ListHead->Flink; - InsertTailList(ListHead,ListEntry); - - /* - * Unlock the spinlock - */ + if (IsListEmpty(ListHead)) + { + Old = NULL; + } + else + { + Old = ListHead->Blink; + } + InsertTailList(ListHead,ListEntry); KeReleaseSpinLock(Lock,oldlvl); return(Old); @@ -232,38 +132,24 @@ PLIST_ENTRY ExInterlockedInsertHeadList(PLIST_ENTRY ListHead, * RETURNS: The previous head of the list */ { - PLIST_ENTRY old = NULL; + PLIST_ENTRY Old; KIRQL oldlvl; - - /* - * Block on the spinlock here - */ + KeAcquireSpinLock(Lock,&oldlvl); - - /* - * Insert the entry - */ - old=ListHead->Flink; - InsertHeadList(ListHead,ListEntry); - - /* - * Release spin lock - */ + if (IsListEmpty(ListHead)) + { + Old = NULL; + } + else + { + Old = ListHead->Flink; + } + InsertHeadList(ListHead,ListEntry); KeReleaseSpinLock(Lock,oldlvl); - return(old); + return(Old); } -BOOLEAN IsListEmpty(PLIST_ENTRY ListHead) -/* - * FUNCTION: Determines if a list is emptry - * ARGUMENTS: - * ListHead = Head of the list - * RETURNS: True if there are no entries in the list - */ -{ - return(ListHead->Flink==NULL); -} PLIST_ENTRY ExInterlockedRemoveHeadList(PLIST_ENTRY Head, PKSPIN_LOCK Lock) @@ -277,9 +163,42 @@ PLIST_ENTRY ExInterlockedRemoveHeadList(PLIST_ENTRY Head, { PLIST_ENTRY ret; KIRQL oldlvl; - + KeAcquireSpinLock(Lock,&oldlvl); - ret = RemoveHeadList(Head); + if (IsListEmpty(Head)) + { + ret = NULL; + } + else + { + ret = RemoveHeadList(Head); + } + KeReleaseSpinLock(Lock,oldlvl); + return(ret); +} + +PLIST_ENTRY ExInterlockedRemoveTailList(PLIST_ENTRY Head, + PKSPIN_LOCK Lock) +/* + * FUNCTION: Removes the tail of a double linked list + * ARGUMENTS: + * Head = List head + * Lock = Lock for synchronizing access to the list + * RETURNS: The removed entry + */ +{ + PLIST_ENTRY ret; + KIRQL oldlvl; + + KeAcquireSpinLock(Lock,&oldlvl); + if (IsListEmpty(Head)) + { + ret = NULL; + } + else + { + ret = RemoveTailList(Head); + } KeReleaseSpinLock(Lock,oldlvl); return(ret); } diff --git a/reactos/ntoskrnl/rtl/lookas.c b/reactos/ntoskrnl/rtl/lookas.c index e6e2799d311..50b81d947c4 100644 --- a/reactos/ntoskrnl/rtl/lookas.c +++ b/reactos/ntoskrnl/rtl/lookas.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.cc - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/rtl/lookas.c + * PURPOSE: Lookaside lists * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/rtl/mem.c b/reactos/ntoskrnl/rtl/mem.c index fd0e90acbc5..23c312154ee 100644 --- a/reactos/ntoskrnl/rtl/mem.c +++ b/reactos/ntoskrnl/rtl/mem.c @@ -2,7 +2,7 @@ * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: kernel/rtl/mem.c - * PURPOSE: Graceful system shutdown if a bug is detected + * PURPOSE: Memory functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/rtl/return.c b/reactos/ntoskrnl/rtl/return.c index c84f6fb6e35..3a8e77e80a1 100644 --- a/reactos/ntoskrnl/rtl/return.c +++ b/reactos/ntoskrnl/rtl/return.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/rtl/slist.c b/reactos/ntoskrnl/rtl/slist.c index 42cbf1bf6cc..f0ee9d3b990 100644 --- a/reactos/ntoskrnl/rtl/slist.c +++ b/reactos/ntoskrnl/rtl/slist.c @@ -12,7 +12,6 @@ #include #include -#include #include @@ -49,13 +48,12 @@ PSINGLE_LIST_ENTRY PopEntryList(PSINGLE_LIST_ENTRY ListHead) * RETURNS: The removed entry */ { - PSINGLE_LIST_ENTRY entry = ListHead->Next; - if (entry==NULL) + PSINGLE_LIST_ENTRY ListEntry = ListHead->Next; + if (ListEntry!=NULL) { - return(NULL); + ListHead->Next = ListEntry->Next; } - ListHead->Next = ListHead->Next->Next; - return(entry); + return(ListEntry); } PSINGLE_LIST_ENTRY ExInterlockedPopEntryList(PSINGLE_LIST_ENTRY ListHead, diff --git a/reactos/ntoskrnl/rtl/strtok.c b/reactos/ntoskrnl/rtl/strtok.c index af8d44a1756..69c8abf520d 100644 --- a/reactos/ntoskrnl/rtl/strtok.c +++ b/reactos/ntoskrnl/rtl/strtok.c @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/rtl/unalign.c b/reactos/ntoskrnl/rtl/unalign.c index 143e6db2cb1..8f391ed3f1b 100644 --- a/reactos/ntoskrnl/rtl/unalign.c +++ b/reactos/ntoskrnl/rtl/unalign.c @@ -1,8 +1,8 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: kernel/base/bug.c - * PURPOSE: Graceful system shutdown if a bug is detected + * FILE: ntoskrnl/rtl/unalign.c + * PURPOSE: Unaligned stores and loads * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: * Created 22/05/98 @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/rtl/unicode.c b/reactos/ntoskrnl/rtl/unicode.c index 62d7141d869..fb0fc276ebf 100644 --- a/reactos/ntoskrnl/rtl/unicode.c +++ b/reactos/ntoskrnl/rtl/unicode.c @@ -14,7 +14,7 @@ #include #include -#include +#include #include #define NDEBUG diff --git a/reactos/ntoskrnl/rtl/vsprintf.c b/reactos/ntoskrnl/rtl/vsprintf.c index e35f71e3817..35e2d5caf0b 100644 --- a/reactos/ntoskrnl/rtl/vsprintf.c +++ b/reactos/ntoskrnl/rtl/vsprintf.c @@ -15,7 +15,6 @@ #include -#include #include #include #include diff --git a/reactos/ntoskrnl/rtl/wstring.c b/reactos/ntoskrnl/rtl/wstring.c index 5aa2929bbeb..5065abf8570 100644 --- a/reactos/ntoskrnl/rtl/wstring.c +++ b/reactos/ntoskrnl/rtl/wstring.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ke/wstring.c + * FILE: ntoskrnl/rtl/wstring.c * PURPOSE: Wide string functions * PROGRAMMER: David Welch (welch@mcmail.com) * UPDATE HISTORY: @@ -10,8 +10,6 @@ /* INCLUDES *****************************************************************/ -#include -#include #include #include diff --git a/reactos/ntoskrnl/se/semgr.c b/reactos/ntoskrnl/se/semgr.c index ae75b4bd926..619e244eb4c 100644 --- a/reactos/ntoskrnl/se/semgr.c +++ b/reactos/ntoskrnl/se/semgr.c @@ -12,8 +12,6 @@ #include -#include - #include /* FUNCTIONS ***************************************************************/ diff --git a/reactos/ntoskrnl/tst/test.c b/reactos/ntoskrnl/tst/test.c index ae67188dfb5..1f950d25c19 100644 --- a/reactos/ntoskrnl/tst/test.c +++ b/reactos/ntoskrnl/tst/test.c @@ -12,7 +12,6 @@ #include #include -#include #include #define NDEBUG @@ -22,7 +21,8 @@ /* GLOBALS ******************************************************************/ -static KEVENT event; +static KEVENT event = {}; +//static KEVENT event2; /* FUNCTIONS ****************************************************************/ @@ -48,15 +48,23 @@ NTSTATUS TstPlaySound(void) NTSTATUS TstFirstThread(PVOID start) { printk("Beginning Thread A\n"); - KeClearEvent(&event); - KeSetEvent(&event,IO_NO_INCREMENT,TRUE); + for (;;) + { + KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); + printk("AAA "); + KeSetEvent(&event,IO_NO_INCREMENT,FALSE); + } } NTSTATUS TstSecondThread(PVOID start) { - printk("Beginning Thread B\n"); - KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); - printk("Ending Thread B\n"); + printk("Beginning Thread B\n"); + for (;;) + { + KeSetEvent(&event,IO_NO_INCREMENT,FALSE); + KeWaitForSingleObject(&event,Executive,KernelMode,FALSE,NULL); + printk("BBB "); + } } NTSTATUS TstThreadSupport() @@ -64,9 +72,9 @@ NTSTATUS TstThreadSupport() HANDLE th1, th2; KeInitializeEvent(&event,SynchronizationEvent,FALSE); -// PsCreateSystemThread(&th1,0,NULL,NULL,NULL,TstFirstThread,NULL); - KeClearEvent(&event); + PsCreateSystemThread(&th1,0,NULL,NULL,NULL,TstFirstThread,NULL); PsCreateSystemThread(&th2,0,NULL,NULL,NULL,TstSecondThread,NULL); + printk("Ending main thread\n"); for(;;); } @@ -115,25 +123,44 @@ void TstParallelPortWrite() void TstKeyboardRead() { - KEY_EVENT_RECORD key; + OBJECT_ATTRIBUTES attr; HANDLE hfile; + ANSI_STRING afilename; + UNICODE_STRING ufilename; + KEY_EVENT_RECORD key[2]; -// hfile = CreateFile("\\Device\\Keyboard",0,0,0,0,0,0); - if (hfile == NULL) + DbgPrint("Opening keyboard\n"); + RtlInitAnsiString(&afilename,"\\Device\\Keyboard"); + RtlAnsiStringToUnicodeString(&ufilename,&afilename,TRUE); + InitializeObjectAttributes(&attr,&ufilename,0,NULL,NULL); + ZwOpenFile(&hfile,0,&attr,NULL,0,0); + if (hfile==NULL) { - printk("Failed to open keyboard\n"); - return; + DbgPrint("Failed to open keyboard\n"); + return; } - for (;;) + for(;;) { -// ReadFile(hfile,&key,sizeof(KEY_EVENT_RECORD),NULL,NULL); - printk("%c",key.AsciiChar); - for(;;); + ZwReadFile(hfile, + NULL, + NULL, + NULL, + NULL, + &key[0], + sizeof(KEY_EVENT_RECORD)*2, + 0, + 0); + DbgPrint("%c",key[0].AsciiChar); +// DbgPrint("%c",key[1].AsciiChar); } -} + } + + void TstBegin() { - TstGeneralWrite(); +// TstGeneralWrite(); +// TstThreadSupport(); + TstKeyboardRead(); }