This commit was generated by cvs2svn to compensate for changes in r30,

which included commits to RCS files with non-trunk default branches.

svn path=/trunk/; revision=31
This commit is contained in:
Rex Jolliff 1998-09-05 17:34:23 +00:00
parent bb9cc48934
commit 809b4b1eab
117 changed files with 2226 additions and 1932 deletions

View file

@ -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,
};
/*

View file

@ -39,7 +39,7 @@ typedef struct _ERESOURCE
typedef struct
{
LONG Count;
PKTHREAD Owner;
struct _KTHREAD* Owner;
ULONG Contention;
KEVENT Event;
ULONG OldIrql;

View file

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

View file

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

View file

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

View file

@ -8,6 +8,7 @@ typedef enum _EVENT_TYPE
{
NotificationEvent,
SynchronizationEvent,
SemaphoreType,
} EVENT_TYPE;
typedef enum _KWAIT_REASON

View file

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

View file

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

View file

@ -294,3 +294,4 @@ VOID MmUnlockPagableImageSection(PVOID ImageSectionHandle);
VOID MmUnmapIoSpace(PVOID BaseAddress, ULONG NumberOfBytes);
VOID MmUnmapLockedPages(PVOID BaseAddress, PMDL MemoryDescriptorList);
PVOID MmAllocateSection(ULONG Length);

View file

@ -20,40 +20,28 @@ extern "C"
#include <windows.h>
#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 <ddk/status.h>
#include <ddk/ntdef.h>
#include <ddk/defines.h>
#include <ddk/types.h>
#include <ddk/structs.h>
#include <ddk/cfgtypes.h>
#include <ddk/ketypes.h>
#include <ddk/obtypes.h>
#include <ddk/mmtypes.h>
#include <ddk/iotypes.h>
#include <ddk/extypes.h>
#include <ddk/pstypes.h>
#include <ddk/setypes.h>
#include <ddk/ioctrl.h>
#include <internal/hal/ddk.h>
#include <ddk/rtl.h>

View file

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

View file

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

View file

@ -2,69 +2,93 @@
#define __INCLUDE_DDK_PSTYPES_H
#include <kernel32/heap.h>
#include <internal/hal.h>
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 */

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

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

View file

@ -5,7 +5,7 @@
#ifndef __INTERNAL_HAL_PAGE_H
#define __INTERNAL_HAL_PAGE_H
#include <internal/kernel.h>
#include <ddk/ntddk.h>
#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));
}

View file

@ -1,109 +1 @@
/*
* Various useful prototypes
*/
#ifndef __KERNEL_H
#define __KERNEL_H
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/linkage.h>
#include <stdarg.h>
/*
* 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 <internal/ntoskrnl.h>

View file

@ -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 <internal/linkage.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <windows.h>
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

View file

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

View file

@ -1,9 +1,13 @@
#ifndef __INCLUDE_INTERNAL_PSMGR_H
#define __INCLUDE_INTERNAL_PSMGR_H
#include <internal/hal/hal.h>
#include <internal/hal.h>
extern EPROCESS SystemProcess;
extern HANDLE SystemProcessHandle;
void PsInitThreadManagment(void);
VOID PsInitIdleThread(VOID);
/*
* PURPOSE: Thread states

View file

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

View file

@ -105,6 +105,6 @@ typedef struct __HEAP
HEAP_BLOCK Start __attribute__((aligned (8)));
} HEAP, *PHEAP;
PHEAP __ProcessHeap;
//PHEAP __ProcessHeap;
#endif /* __INCLUDE_KERNEL32_HEAP_H */

View file

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

View file

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

View file

@ -32,6 +32,8 @@ all: $(COMPONENTS) $(LOADERS) $(MODULES)
#
# Device driver rules
#
ide: dummy
make -C services/ide
parallel: dummy
make -C services/parallel

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -12,7 +12,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/debug.h>
@ -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)

View file

@ -16,7 +16,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
@ -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;
}

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <windows.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/ke.h>
#include <internal/hal/segment.h>
#include <internal/hal/page.h>
#define NDEBUG
#include <internal/debug.h>
/* 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);

View file

@ -10,16 +10,18 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/hal/hal.h>
#include <internal/ntoskrnl.h>
#include <internal/ke.h>
#include <internal/hal.h>
/* FUNCTIONS ***************************************************************/
VOID HalInit(boot_param* bp)
{
InitalizeExceptions();
InitalizeIRQ();
KeInitExceptions();
KeInitIRQ();
KeLowerIrql(DISPATCH_LEVEL);
/*
* Probe for a BIOS32 extension

View file

@ -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 <ddk/ntddk.h>
#include <internal/stddef.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/ke.h>
#include <internal/bitops.h>
#include <internal/linkage.h>
#include <internal/string.h>
@ -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;i<NR_IRQS;i++)
{
DPRINT("For irq %x ",i);
current_entry = isr_table[i].Flink;
current = CONTAINING_RECORD(current,KINTERRUPT,Entry);
while (current_entry!=(&isr_table[i]))
{
DPRINT("Isr %x ",current);
current_entry = current_entry->Flink;
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);
}

View file

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

View file

@ -12,10 +12,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
/* FUNCTIONS *****************************************************************/
@ -27,7 +23,7 @@ BOOL HalIsaProbe()
* true
*/
{
printk("Assuming ISA bus\n");
DbgPrint("Assuming ISA bus\n");
/*
* Probe for plug and play support

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,7 +10,6 @@
/* INCLUDES ***************************************************************/
#include <internal/kernel.h>
#include <internal/hal/page.h>
#include <internal/mm.h>
#include <internal/string.h>
@ -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)

View file

@ -16,10 +16,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/hal/page.h>
/* 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);

View file

@ -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 <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/string.h>
#include <internal/hal/page.h>
#include <internal/hal/io.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/psmgr.h>
#include <internal/string.h>
#include <internal/hal/hal.h>
#include <internal/hal.h>
#include <internal/hal/segment.h>
#include <internal/hal/page.h>
@ -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;
}

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#define NDEBUG
@ -19,7 +17,7 @@
/* GLOBALS *******************************************************************/
static KSPIN_LOCK CancelSpinLock;
static KSPIN_LOCK CancelSpinLock = {0,};
/* FUNCTIONS *****************************************************************/

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -12,7 +12,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/objmgr.h>
#include <internal/iomgr.h>
#include <internal/string.h>
@ -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;

View file

@ -12,12 +12,11 @@
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/iomgr.h>
#include <internal/objmgr.h>
#include <internal/string.h>
//#define NDEBUG
#define NDEBUG
#include <internal/debug.h>
/* 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);

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
@ -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;
}

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -12,9 +12,11 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/objmgr.h>
#define NDEBUG
#include <internal/debug.h>
/* 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();
}

View file

@ -30,7 +30,6 @@
/* INCLUDES ****************************************************************/
#include <internal/string.h>
#include <internal/kernel.h>
#include <ddk/ntddk.h>
#define NDEBUG

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <internal/hal/page.h>
#include <ddk/ntddk.h>

View file

@ -10,15 +10,13 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
PEPROCESS IoGetCurrentProcess()
struct _EPROCESS* IoGetCurrentProcess()
{
return(PsGetCurrentProcess());
}

View file

@ -10,7 +10,8 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#define NDEBUG
#include <internal/debug.h>
/* 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)

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -12,7 +12,6 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/iomgr.h>
#include <internal/string.h>
#include <internal/objmgr.h>
@ -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);
}

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/string.h>
@ -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;
}

View file

@ -10,8 +10,6 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>
@ -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

View file

@ -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 <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
/* FUNCTIONS ****************************************************************/
VOID ExRaiseStatus(NTSTATUS Status)
{
printk("ExRaiseStatus(%d)\n",Status);
DbgPrint("ExRaiseStatus(%d)\n",Status);
for(;;);
}

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/ke.h>
/* 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

View file

@ -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 <ddk/ntddk.h>
#include <internal/kernel.h>
#define NDEBUG
#include <internal/debug.h>
/* 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(&current_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(&current_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);
}

View file

@ -17,7 +17,7 @@
/*
* Last error code (this should be per process)
*/
DWORD error_code;
DWORD error_code = 0;
/* FUNCTIONS ***************************************************************/

View file

@ -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 <internal/kernel.h>
#include <internal/wait.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* 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);
}

View file

@ -12,8 +12,8 @@
#include <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#define NDEBUG
#include <internal/debug.h>
/* 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);

View file

@ -11,9 +11,8 @@
/* INCLUDES *****************************************************************/
#include <windows.h>
#include <coff.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/version.h>
#include <internal/mm.h>
#include <internal/string.h>
@ -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<bp.nr_files;i++)
{
DPRINT("start %x length %d\n",start,bp.module_length[i]);
process_boot_module(start);
start=start+PAGE_ROUND_UP(bp.module_length[i])+PAGESIZE;
DPRINT("start %x *start %x\n",start,*((unsigned int *)start));
CHECKPOINT;
process_boot_module(start);
CHECKPOINT;
start=start+PAGE_ROUND_UP(bp.module_length[i]);
}
/*
* Enter shell
* Test various features of the kernel
*/
TstBegin();

View file

@ -16,7 +16,6 @@
#include <ddk/ntddk.h>
#include <internal/iomgr.h>
#include <internal/kernel.h>
#include <internal/symbol.h>
#include <internal/string.h>
#include <internal/mm.h>
@ -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);
}

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/ke.h>
#include <internal/debug.h>
@ -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;
}

View file

@ -16,14 +16,9 @@
/* INCLUDES ***************************************************************/
#include <limits.h>
#include <internal/stddef.h>
#include <internal/kernel.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#include <internal/string.h>
#include <ddk/ntddk.h>
#define NDEBUG
#include <internal/debug.h>
/* 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,&current->entry);
RemoveEntryList(&current->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
*/

View file

@ -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 <windows.h>
#include <ddk/ntddk.h>
#include <internal/kernel.h>
#include <internal/wait.h>
#include <internal/ke.h>
#define NDEBUG
#include <internal/debug.h>
/* 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,

View file

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

View file

@ -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 <internal/stddef.h>
#include <internal/hal/page.h>
#include <internal/mm.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#include <internal/bitops.h>
#include <ddk/ntddk.h>

View file

@ -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 <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/debug.h>

View file

@ -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; va<Mdl->Size; va++)
{
((PULONG)(Mdl + 1))[va] = MmGetPhysicalAddress(
Mdl->StartVa+ (va * PAGESIZE));
Mdl->StartVa+ (va * PAGESIZE)).LowPart;
}
Mdl->MappedSystemVa = Mdl->StartVa;
}

View file

@ -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 <internal/stddef.h>
#include <internal/mm.h>
#include <internal/string.h>
#include <internal/kernel.h>
#include <internal/pool.h>
#include <internal/ntoskrnl.h>
#include <internal/bitops.h>
#include <internal/string.h>

View file

@ -15,12 +15,13 @@
/* INCLUDES ****************************************************************/
#include <internal/string.h>
#include <internal/stddef.h>
#include <internal/mm.h>
#include <internal/hal/page.h>
#include <internal/pool.h>
#include <internal/bitops.h>
#include <internal/kernel.h>
#include <internal/ntoskrnl.h>
#define NDEBUG
#include <internal/debug.h>
@ -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)

View file

@ -10,14 +10,47 @@
/* INCLUDES *****************************************************************/
#include <internal/kernel.h>
#include <internal/linkage.h>
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/debug.h>
/* 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)

View file

@ -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;i<marea->length;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;
}

View file

@ -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 <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/kernel.h>
/* FUNCTIONS ***************************************************************/

View file

@ -14,7 +14,6 @@
#include <ddk/ntddk.h>
#include <internal/objmgr.h>
#include <internal/string.h>
#include <internal/pool.h>
#define NDEBUG
#include <internal/debug.h>
@ -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 ***************************************************************/

Some files were not shown because too many files have changed in this diff Show more