Added working set functions

Seperated memory manager initialization
Seperated trap functions
Removed process/thread definitions from ddk headers
Changed indentation back to sane style (please don't change)

svn path=/trunk/; revision=1224
This commit is contained in:
David Welch 2000-07-04 08:52:47 +00:00
parent 9caffc49ae
commit d351d182ef
61 changed files with 1723 additions and 1955 deletions

View file

@ -1,6 +1,6 @@
#ifndef _INCLUDE_DDK_IOFUNCS_H
#define _INCLUDE_DDK_IOFUNCS_H
/* $Id: iofuncs.h,v 1.16 2000/07/04 01:25:27 ekohl Exp $ */
/* $Id: iofuncs.h,v 1.17 2000/07/04 08:52:34 dwelch Exp $ */
/* --- EXPORTED BY NTOSKRNL --- */
@ -618,7 +618,7 @@ IoGetConfigurationInformation (
#define IoGetCurrentIrpStackLocation(Irp) \
((Irp)->Tail.Overlay.CurrentStackLocation)
*/
PEPROCESS
struct _EPROCESS*
STDCALL
IoGetCurrentProcess (
VOID
@ -634,7 +634,7 @@ IoGetDeviceObjectPointer (
PDEVICE_OBJECT
STDCALL
IoGetDeviceToVerify (
PETHREAD Thread
struct _ETHREAD* Thread
);
PGENERIC_MAPPING
STDCALL
@ -676,8 +676,7 @@ STDCALL
IoGetRelatedDeviceObject (
PFILE_OBJECT FileObject
);
PEPROCESS
struct _EPROCESS*
STDCALL
IoGetRequestorProcess (
IN PIRP Irp
@ -838,7 +837,7 @@ STDCALL
IoRaiseInformationalHardError (
NTSTATUS ErrorStatus,
PUNICODE_STRING String,
PKTHREAD Thread
struct _KTHREAD* Thread
);
VOID
STDCALL
@ -1045,11 +1044,7 @@ IoSynchronousPageWrite (
DWORD Unknown3,
DWORD Unknown4
);
PEPROCESS
STDCALL
IoThreadToProcess (
IN PETHREAD Thread
);
struct _EPROCESS* STDCALL IoThreadToProcess (struct _ETHREAD* Thread);
VOID
STDCALL
IoUnregisterFileSystem (

View file

@ -4,6 +4,11 @@
/* KERNEL FUNCTIONS ********************************************************/
VOID STDCALL KeAttachProcess (struct _EPROCESS* Process);
VOID KeDrainApcQueue(VOID);
struct _KPROCESS* KeGetCurrentProcess(VOID);
/*
* FUNCTION: Acquires a spinlock so the caller can synchronize access to
* data
@ -11,30 +16,10 @@
* SpinLock = Initialized spinlock
* OldIrql (OUT) = Set the previous irql on return
*/
VOID
STDCALL
KeAcquireSpinLock (
IN PKSPIN_LOCK SpinLock,
OUT PKIRQL OldIrql
);
VOID STDCALL KeAcquireSpinLock (PKSPIN_LOCK SpinLock,
PKIRQL OldIrql);
VOID
STDCALL
KeAcquireSpinLockAtDpcLevel (
IN PKSPIN_LOCK SpinLock
);
KIRQL
FASTCALL
KeAcquireSpinLockRaiseToSynch (
IN PKSPIN_LOCK SpinLock
);
VOID
STDCALL
KeAttachProcess (
IN PEPROCESS Process
);
VOID STDCALL KeAcquireSpinLockAtDpcLevel (PKSPIN_LOCK SpinLock);
/*
* FUNCTION: Brings the system down in a controlled manner when an
@ -43,11 +28,8 @@ KeAttachProcess (
* BugCheckCode = Specifies the reason for the bug check
* RETURNS: Doesn't
*/
VOID
STDCALL
KeBugCheck (
IN ULONG BugCheckCode
);
VOID STDCALL KeBugCheck (ULONG BugCheckCode);
/*
* FUNCTION: Brings the system down in a controlled manner when an
@ -57,128 +39,47 @@ KeBugCheck (
* BugCheckParameter[1-4] = Additional information about bug
* RETURNS: Doesn't
*/
VOID
STDCALL
KeBugCheckEx (
IN ULONG BugCheckCode,
IN ULONG BugCheckParameter1,
IN ULONG BugCheckParameter2,
IN ULONG BugCheckParameter3,
IN ULONG BugCheckParameter4
);
VOID STDCALL KeBugCheckEx (ULONG BugCheckCode,
ULONG BugCheckParameter1,
ULONG BugCheckParameter2,
ULONG BugCheckParameter3,
ULONG BugCheckParameter4);
BOOLEAN
STDCALL
KeCancelTimer (
IN PKTIMER Timer
);
BOOLEAN STDCALL KeCancelTimer (PKTIMER Timer);
VOID
STDCALL
KeClearEvent (
IN PKEVENT Event
);
VOID STDCALL KeClearEvent (PKEVENT Event);
NTSTATUS
STDCALL
KeDelayExecutionThread (
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Internal
);
NTSTATUS STDCALL KeDelayExecutionThread (KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Internal);
BOOLEAN
STDCALL
KeDeregisterBugCheckCallback (
IN PKBUGCHECK_CALLBACK_RECORD CallbackRecord
);
BOOLEAN STDCALL KeDeregisterBugCheckCallback (
PKBUGCHECK_CALLBACK_RECORD CallbackRecord);
VOID
STDCALL
KeDetachProcess (
VOID
);
VOID STDCALL KeDetachProcess (VOID);
VOID
STDCALL
KeEnterCriticalRegion (
VOID
);
VOID STDCALL KeEnterCriticalRegion (VOID);
/*
* FUNCTION: Enters the kernel debugger
* ARGUMENTS:
* None
*/
VOID
STDCALL
KeEnterKernelDebugger (
VOID
);
VOID KeFlushIoBuffers(PMDL Mdl, BOOLEAN ReadOperation, BOOLEAN DmaOperation);
/*
* VOID
* KeFlushIoBuffers (
* PMDL Mdl,
* BOOLEAN ReadOperation,
* BOOLEAN DmaOperation
* );
*/
#define KeFlushIoBuffers(Mdl,ReadOperation,DmaOperation)
KIRQL STDCALL KeGetCurrentIrql (VOID);
VOID
STDCALL
KeFlushWriteBuffer (
VOID
);
ULONG KeGetCurrentProcessorNumber(VOID);
KIRQL
STDCALL
KeGetCurrentIrql (
VOID
);
struct _KTHREAD* STDCALL KeGetCurrentThread (VOID);
/*
* ULONG
* KeGetCurrentProcessorNumber(VOID);
*/
/*
* FIXME: This should be an inline function on x86 systems
*/
#define KeGetCurrentProcessorNumber() 0UL
ULONG KeGetDcacheFillSize(VOID);
PKTHREAD
STDCALL
KeGetCurrentThread (
VOID
);
ULONG STDCALL KeGetPreviousMode (VOID);
/*
* ULONG KeGetDcacheFillSize(VOID);
*
* FUNCTION:
* Returns the microprocessor's data cache-line boundary in bytes
*/
#define KeGetDcacheFillSize() 1L
ULONG
STDCALL
KeGetPreviousMode (
VOID
);
VOID
STDCALL
KeInitializeApc (
PKAPC Apc,
PKTHREAD Thread,
UCHAR StateIndex,
PKKERNEL_ROUTINE KernelRoutine,
PKRUNDOWN_ROUTINE RundownRoutine,
PKNORMAL_ROUTINE NormalRoutine,
UCHAR Mode,
PVOID Context
);
VOID STDCALL KeInitializeApc (PKAPC Apc,
struct _KTHREAD* Thread,
UCHAR StateIndex,
PKKERNEL_ROUTINE KernelRoutine,
PKRUNDOWN_ROUTINE RundownRoutine,
PKNORMAL_ROUTINE NormalRoutine,
UCHAR Mode,
PVOID Context);
/*
* VOID
@ -189,118 +90,54 @@ KeInitializeApc (
#define KeInitializeCallbackRecord(CallbackRecord) \
(CallbackRecord)->State = BufferEmpty
VOID
STDCALL
KeInitializeDeviceQueue (
PKDEVICE_QUEUE DeviceQueue
);
VOID STDCALL KeInitializeDeviceQueue (PKDEVICE_QUEUE DeviceQueue);
VOID
STDCALL
KeInitializeDpc (
PKDPC Dpc,
PKDEFERRED_ROUTINE DeferredRoutine,
PVOID DeferredContext
);
VOID STDCALL KeInitializeDpc (PKDPC Dpc,
PKDEFERRED_ROUTINE DeferredRoutine,
PVOID DeferredContext);
VOID
STDCALL
KeInitializeEvent (
PKEVENT Event,
EVENT_TYPE Type,
BOOLEAN State
);
VOID STDCALL KeInitializeEvent (PKEVENT Event,
EVENT_TYPE Type,
BOOLEAN State);
VOID
STDCALL
KeInitializeMutex (
PKMUTEX Mutex,
ULONG Level
);
VOID STDCALL KeInitializeMutex (PKMUTEX Mutex,
ULONG Level);
VOID
STDCALL
KeInitializeSemaphore (
PKSEMAPHORE Semaphore,
LONG Count,
LONG Limit
);
VOID STDCALL KeInitializeSemaphore (PKSEMAPHORE Semaphore,
LONG Count,
LONG Limit);
/*
* FUNCTION: Initializes a spinlock
* ARGUMENTS:
* SpinLock = Spinlock to initialize
*/
VOID
STDCALL
KeInitializeSpinLock (
PKSPIN_LOCK SpinLock
);
VOID STDCALL KeInitializeSpinLock (PKSPIN_LOCK SpinLock);
VOID
STDCALL
KeInitializeTimer (
PKTIMER Timer
);
VOID STDCALL KeInitializeTimer (PKTIMER Timer);
VOID
STDCALL
KeInitializeTimerEx (
PKTIMER Timer,
TIMER_TYPE Type
);
VOID STDCALL KeInitializeTimerEx (PKTIMER Timer,
TIMER_TYPE Type);
BOOLEAN
STDCALL
KeInsertByKeyDeviceQueue (
PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY DeviceQueueEntry,
ULONG SortKey
);
BOOLEAN STDCALL KeInsertByKeyDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY QueueEntry,
ULONG SortKey);
BOOLEAN
STDCALL
KeInsertDeviceQueue (
PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY DeviceQueueEntry
);
BOOLEAN STDCALL KeInsertDeviceQueue (PKDEVICE_QUEUE DeviceQueue,
PKDEVICE_QUEUE_ENTRY DeviceQueueEntry);
VOID
STDCALL
KeInsertQueueApc (
PKAPC Apc,
PVOID SystemArgument1,
PVOID SystemArgument2,
UCHAR Mode
);
VOID STDCALL KeInsertQueueApc (PKAPC Apc,
PVOID SystemArgument1,
PVOID SystemArgument2,
UCHAR Mode);
BOOLEAN
STDCALL
KeInsertQueueDpc (
PKDPC Dpc,
PVOID SystemArgument1,
PVOID SystemArgument2
);
BOOLEAN STDCALL KeInsertQueueDpc (PKDPC Dpc,
PVOID SystemArgument1,
PVOID SystemArgument2);
VOID
STDCALL
KeLeaveCriticalRegion (
VOID
);
VOID STDCALL KeLeaveCriticalRegion (VOID);
VOID
STDCALL
KeLowerIrql (
KIRQL NewIrql
);
NTSTATUS
STDCALL
KePulseEvent (
PKEVENT Event,
KPRIORITY Increment,
BOOLEAN Wait
);
VOID STDCALL KeLowerIrql (KIRQL NewIrql);
LARGE_INTEGER
STDCALL
@ -439,12 +276,8 @@ KeResetEvent (
PKEVENT Event
);
LONG
STDCALL
KeSetBasePriorityThread (
PKTHREAD Thread,
LONG Increment
);
LONG STDCALL KeSetBasePriorityThread (struct _KTHREAD* Thread,
LONG Increment);
LONG
STDCALL
@ -454,76 +287,32 @@ KeSetEvent (
BOOLEAN Wait
);
VOID
STDCALL
KeSetImportanceDpc (
IN PKDPC Dpc,
IN KDPC_IMPORTANCE Importance
);
KPRIORITY STDCALL KeSetPriorityThread (struct _KTHREAD* Thread,
KPRIORITY Priority);
KPRIORITY
STDCALL
KeSetPriorityThread (
PKTHREAD Thread,
KPRIORITY Priority
);
BOOLEAN STDCALL KeSetTimer (PKTIMER Timer,
LARGE_INTEGER DueTime,
PKDPC Dpc);
VOID
STDCALL
KeSetTargetProcessorDpc (
IN PKDPC Dpc,
IN CCHAR Number
);
BOOLEAN STDCALL KeSetTimerEx (PKTIMER Timer,
LARGE_INTEGER DueTime,
LONG Period,
PKDPC Dpc);
BOOLEAN
STDCALL
KeSetTimer (
PKTIMER Timer,
LARGE_INTEGER DueTime,
PKDPC Dpc
);
VOID STDCALL KeStallExecutionProcessor (ULONG MicroSeconds);
BOOLEAN
STDCALL
KeSetTimerEx (
PKTIMER Timer,
LARGE_INTEGER DueTime,
LONG Period,
PKDPC Dpc
);
BOOLEAN STDCALL KeSynchronizeExecution (PKINTERRUPT Interrupt,
PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
PVOID SynchronizeContext);
VOID
STDCALL
KeStallExecutionProcessor (
ULONG MicroSeconds
);
BOOLEAN
STDCALL
KeSynchronizeExecution (
PKINTERRUPT Interrupt,
PKSYNCHRONIZE_ROUTINE SynchronizeRoutine,
PVOID SynchronizeContext
);
VOID
STDCALL
KeUpdateSystemTime (
VOID
);
NTSTATUS
STDCALL
KeWaitForMultipleObjects (
ULONG Count,
PVOID Object[],
WAIT_TYPE WaitType,
KWAIT_REASON WaitReason,
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Timeout,
PKWAIT_BLOCK WaitBlockArray
);
NTSTATUS STDCALL KeWaitForMultipleObjects (ULONG Count,
PVOID Object[],
WAIT_TYPE WaitType,
KWAIT_REASON WaitReason,
KPROCESSOR_MODE WaitMode,
BOOLEAN Alertable,
PLARGE_INTEGER Timeout,
PKWAIT_BLOCK WaitBlockArray);
NTSTATUS
STDCALL
@ -546,6 +335,15 @@ KeWaitForSingleObject (
);
/*
* FUNCTION: Sets the current irql without altering the current processor
* state
* ARGUMENTS:
* newlvl = IRQ level to set
* NOTE: This is for internal use only
*/
VOID KeSetCurrentIrql(KIRQL newlvl);
// io permission map has a 8k size
// Each bit in the IOPM corresponds to an io port byte address. The bitmap
@ -588,7 +386,7 @@ VOID Ke386QueryIoAccessMap(BOOLEAN NewMap, PIOPM *IoPermissionMap);
* Eprocess = Pointer to a executive process object
* EnableIo = Specify TRUE to enable IO and FALSE to disable
*/
NTSTATUS Ke386IoSetAccessProcess(PEPROCESS Eprocess, BOOLEAN EnableIo);
NTSTATUS Ke386IoSetAccessProcess(struct _EPROCESS* Eprocess, BOOLEAN EnableIo);
/*
* FUNCTION: Releases a set of Global Descriptor Table Selectors
@ -608,6 +406,30 @@ NTSTATUS KeI386ReleaseGdtSelectors(OUT PULONG SelArray,
NTSTATUS KeI386AllocateGdtSelectors(OUT PULONG SelArray,
IN ULONG NumOfSelectors);
<<<<<<< kefuncs.h
/*
* FUNCTION: Raises a user mode exception
* ARGUMENTS:
* ExceptionCode = Status code of the exception
*/
VOID KeRaiseUserException(NTSTATUS ExceptionCode);
/*
* FUNCTION: Enters the kernel debugger
* ARGUMENTS:
* None
*/
VOID
STDCALL
KeEnterKernelDebugger (VOID);
VOID
STDCALL
KeFlushWriteBuffer (
VOID
);
KIRQL
FASTCALL

View file

@ -1,4 +1,4 @@
/* $Id: mmtypes.h,v 1.7 2000/06/29 23:35:12 dwelch Exp $ */
/* $Id: mmtypes.h,v 1.8 2000/07/04 08:52:34 dwelch Exp $ */
#ifndef _INCLUDE_DDK_MMTYPES_H
#define _INCLUDE_DDK_MMTYPES_H
@ -11,17 +11,6 @@ extern POBJECT_TYPE EXPORTED MmSectionObjectType;
extern POBJECT_TYPE IMPORTED MmSectionObjectType;
#endif
struct _EPROCESS;
typedef struct _MADDRESS_SPACE
{
LIST_ENTRY MAreaListHead;
KMUTEX Lock;
ULONG LowestAddress;
struct _EPROCESS* Process;
} MADDRESS_SPACE, *PMADDRESS_SPACE;
#define MDL_MAPPED_TO_SYSTEM_VA (0x1)
#define MDL_PAGES_LOCKED (0x2)
#define MDL_SOURCE_IS_NONPAGED_POOL (0x4)
@ -58,24 +47,21 @@ typedef struct _MDL
#define MmSmallSystem (0)
#define MmMediumSystem (1)
#define MmLargeSystem (2)
/* Used in MmFlushImageSection */
typedef
enum _MMFLUSH_TYPE
typedef enum _MMFLUSH_TYPE
{
MmFlushForDelete,
MmFlushForWrite
} MMFLUSH_TYPE;
typedef
enum _MEMORY_CACHING_TYPE
typedef enum _MEMORY_CACHING_TYPE
{
MmNonCached = FALSE,
MmCached = TRUE,
MmFrameBufferCached,
MmHardwareCoherentCached,
MmMaximumCacheType
} MEMORY_CACHING_TYPE;
#endif

View file

@ -1,9 +1,15 @@
/* $Id: psfuncs.h,v 1.8 2000/07/01 22:36:53 ekohl Exp $
/* $Id: psfuncs.h,v 1.9 2000/07/04 08:52:34 dwelch Exp $
*/
#ifndef _INCLUDE_DDK_PSFUNCS_H
#define _INCLUDE_DDK_PSFUNCS_H
PACCESS_TOKEN PsReferenceEffectiveToken(struct _ETHREAD* Thread,
PTOKEN_TYPE TokenType,
PUCHAR b,
PSECURITY_IMPERSONATION_LEVEL Level);
NTSTATUS PsOpenTokenOfProcess(HANDLE ProcessHandle,
PACCESS_TOKEN* Token);
NTSTATUS
STDCALL
PsAssignImpersonationToken (
@ -11,6 +17,9 @@ PsAssignImpersonationToken (
HANDLE TokenHandle
);
HANDLE STDCALL PsGetCurrentProcessId(VOID);
HANDLE STDCALL PsGetCurrentThreadId(VOID);
/*
* FUNCTION: Creates a thread which executes in kernel mode
* ARGUMENTS:
@ -27,102 +36,42 @@ PsAssignImpersonationToken (
* execution
* RETURNS: Success or failure status
*/
NTSTATUS
STDCALL
PsCreateSystemThread (
PHANDLE ThreadHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
HANDLE ProcessHandle,
PCLIENT_ID ClientId,
PKSTART_ROUTINE StartRoutine,
PVOID StartContext
);
NTSTATUS STDCALL PsCreateSystemThread(PHANDLE ThreadHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
HANDLE ProcessHandle,
PCLIENT_ID ClientId,
PKSTART_ROUTINE StartRoutine,
PVOID StartContext);
NTSTATUS STDCALL PsTerminateSystemThread(NTSTATUS ExitStatus);
ULONG PsSuspendThread(struct _ETHREAD* Thread,
PNTSTATUS WaitStatus,
UCHAR Alertable,
ULONG WaitMode);
ULONG PsResumeThread(struct _ETHREAD* Thread,
PNTSTATUS WaitStatus);
struct _ETHREAD* PsGetCurrentThread(VOID);
struct _EPROCESS* PsGetCurrentProcess(VOID);
PACCESS_TOKEN STDCALL PsReferenceImpersonationToken(struct _ETHREAD* Thread,
PULONG Unknown1,
PULONG Unknown2,
SECURITY_IMPERSONATION_LEVEL*
Level);
PACCESS_TOKEN STDCALL PsReferencePrimaryToken(struct _EPROCESS* Process);
NTSTATUS STDCALL PsAssignImpersonationToken(struct _ETHREAD* Thread,
HANDLE TokenHandle);
/*
* PEPROCESS
* PsGetCurrentProcess (
* VOID
* );
*/
#define PsGetCurrentProcess() \
(IoGetCurrentProcess ())
VOID STDCALL PsImpersonateClient(struct _ETHREAD* Thread,
PACCESS_TOKEN Token,
UCHAR b,
UCHAR c,
SECURITY_IMPERSONATION_LEVEL Level);
VOID STDCALL PsRevertToSelf(struct _ETHREAD* Thread);
HANDLE
STDCALL
PsGetCurrentProcessId (
VOID
);
/*
* PETHREAD
* PsGetCurrentThread (
* VOID
* );
*/
#define PsGetCurrentThread() \
((PETHREAD)KeGetCurrentThread ())
HANDLE
STDCALL
PsGetCurrentThreadId (
VOID
);
BOOLEAN
STDCALL
PsGetVersion (
PULONG MajorVersion OPTIONAL,
PULONG MinorVersion OPTIONAL,
PULONG BuildNumber OPTIONAL,
PUNICODE_STRING CSDVersion OPTIONAL
);
VOID
STDCALL
PsImpersonateClient (
PETHREAD Thread,
PACCESS_TOKEN Token,
UCHAR b,
UCHAR c,
SECURITY_IMPERSONATION_LEVEL Level
);
PACCESS_TOKEN
STDCALL
PsReferenceImpersonationToken (
PETHREAD Thread,
PULONG Unknown1,
PULONG Unknown2,
SECURITY_IMPERSONATION_LEVEL * Level
);
PACCESS_TOKEN
STDCALL
PsReferencePrimaryToken (
PEPROCESS Process
);
#if 0
/* FIXME: This is the correct prototype */
VOID
STDCALL
PsRevertToSelf (
VOID
);
#endif
VOID
STDCALL
PsRevertToSelf (
PETHREAD Thread
);
NTSTATUS
STDCALL
PsTerminateSystemThread (
NTSTATUS ExitStatus
);
BOOLEAN STDCALL PsGetVersion (PULONG MajorVersion OPTIONAL,
PULONG MinorVersion OPTIONAL,
PULONG BuildNumber OPTIONAL,
PUNICODE_STRING CSDVersion OPTIONAL);
#endif

View file

@ -13,7 +13,10 @@
#define MAX_PATH (260)
#endif
struct _EPORT;
struct _EPROCESS;
struct _KPROCESS;
struct _ETHREAD;
struct _KTHREAD;
typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext);
@ -23,294 +26,10 @@ typedef struct _STACK_INFORMATION
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;
struct _KPROCESS;
typedef struct _KAPC_STATE
{
LIST_ENTRY ApcListHead[2];
struct _KPROCESS* Process;
ULONG KernelApcInProgress;
ULONG KernelApcPending;
USHORT UserApcPending;
} KAPC_STATE, *PKAPC_STATE;
typedef struct _KTHREAD
{
DISPATCHER_HEADER DispatcherHeader; // For waiting for the thread
LIST_ENTRY MutantListHead;
PVOID InitialStack;
ULONG StackLimit;
NT_TEB* Teb;
PVOID TlsArray;
PVOID KernelStack;
UCHAR DebugActive;
UCHAR State;
UCHAR Alerted[2];
UCHAR Iopl;
UCHAR NpxState;
UCHAR Saturation;
KPRIORITY Priority;
KAPC_STATE ApcState;
ULONG ContextSwitches;
ULONG WaitStatus;
KIRQL WaitIrql;
ULONG WaitMode;
UCHAR WaitNext;
UCHAR WaitReason;
PKWAIT_BLOCK WaitBlockList;
LIST_ENTRY WaitListEntry;
ULONG WaitTime;
KPRIORITY BasePriority;
UCHAR DecrementCount;
UCHAR PriorityDecrement;
UCHAR Quantum;
KWAIT_BLOCK WaitBlock[4];
PVOID LegoData; // ??
LONG KernelApcDisable;
KAFFINITY UserAffinity;
UCHAR SystemAffinityActive;
UCHAR Pad;
PKQUEUE Queue;
KSPIN_LOCK ApcQueueLock;
KTIMER Timer;
LIST_ENTRY QueueListEntry;
KAFFINITY Affinity;
UCHAR Preempted;
UCHAR ProcessReadyQueue;
UCHAR KernelStackResident;
UCHAR NextProcessor;
PVOID CallbackStack;
BOOL Win32Thread;
PVOID TrapFrame;
PVOID ApcStatePointer; // Is actually eight bytes
UCHAR EnableStackSwap;
UCHAR LargeStack;
UCHAR ResourceIndex;
UCHAR PreviousMode;
TIME KernelTime;
TIME UserTime;
KAPC_STATE SavedApcState;
UCHAR Alertable;
UCHAR ApcQueueable;
ULONG AutoAlignment;
PVOID StackBase;
KAPC SuspendApc;
KSEMAPHORE SuspendSemaphore;
LIST_ENTRY ThreadListEntry;
CHAR FreezeCount;
ULONG SuspendCount;
UCHAR IdealProcessor;
UCHAR DisableBoost;
LIST_ENTRY ProcessThreadListEntry; // Added by Phillip Susi for list of threads in a process
/* Provisionally added by David Welch */
hal_thread_state Context;
KDPC TimerDpc; // Added by Phillip Susi for internal KeAddThreadTimeout() impl.
} KTHREAD, *PKTHREAD;
// According to documentation the stack should have a commited [ 1 page ] and
// a reserved part [ 1 M ] but can be specified otherwise in the image file.
typedef struct _INITIAL_TEB
{
PVOID StackBase;
PVOID StackLimit;
PVOID StackCommit;
PVOID StackCommitMax;
PVOID StackReserved;
} INITIAL_TEB, *PINITIAL_TEB;
// TopLevelIrp can be one of the following values:
// FIXME I belong somewhere else
#define FSRTL_FSP_TOP_LEVEL_IRP (0x01)
#define FSRTL_CACHE_TOP_LEVEL_IRP (0x02)
#define FSRTL_MOD_WRITE_TOP_LEVEL_IRP (0x03)
#define FSRTL_FAST_IO_TOP_LEVEL_IRP (0x04)
#define FSRTL_MAX_TOP_LEVEL_IRP_FLAG (0x04)
typedef struct _TOP_LEVEL_IRP
{
PIRP TopLevelIrp;
ULONG TopLevelIrpConst;
} TOP_LEVEL_IRP;
typedef struct
{
PACCESS_TOKEN Token; // 0x0
UCHAR Unknown1; // 0x4
UCHAR Unknown2; // 0x5
UCHAR Pad[2]; // 0x6
SECURITY_IMPERSONATION_LEVEL Level; // 0x8
} PS_IMPERSONATION_INFO, *PPS_IMPERSONATION_INFO;
typedef struct _ETHREAD
{
KTHREAD Tcb;
TIME CreateTime;
TIME ExitTime;
NTSTATUS ExitStatus;
LIST_ENTRY PostBlockList;
LIST_ENTRY TerminationPortList;
KSPIN_LOCK ActiveTimerListLock;
PVOID ActiveTimerListHead;
CLIENT_ID Cid;
PLARGE_INTEGER LpcReplySemaphore;
PVOID LpcReplyMessage;
PLARGE_INTEGER LpcReplyMessageId;
PPS_IMPERSONATION_INFO 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;
UCHAR LpcExitThreadCalled;
UCHAR HardErrorsAreDisabled;
UCHAR LpcReceivedMsgIdValid;
UCHAR ActiveImpersonationInfo;
ULONG PerformanceCountHigh;
/*
* Added by David Welch (welch@cwcom.net)
*/
struct _EPROCESS* OldProcess;
} ETHREAD, *PETHREAD;
typedef struct _KPROCESS
{
DISPATCHER_HEADER DispatcherHeader;
PVOID PageTableDirectory; // FIXME: I should point to a PTD
TIME ElapsedTime;
TIME KernelTime;
TIME UserTime;
LIST_ENTRY InMemoryList;
LIST_ENTRY SwappedOutList;
KSPIN_LOCK SpinLock;
KAFFINITY Affinity;
ULONG StackCount;
KPRIORITY BasePriority;
ULONG DefaultThreadQuantum;
UCHAR ProcessState;
ULONG ThreadSeed;
UCHAR DisableBoost;
/*
* Added by David Welch (welch@mcmail.com)
*/
MADDRESS_SPACE AddressSpace;
HANDLE_TABLE HandleTable;
LIST_ENTRY ProcessListEntry;
LIST_ENTRY ThreadListHead; // Added by Phillip Susi for list of threads in process
} KPROCESS, *PKPROCESS;
typedef struct _EPROCESS
{
KPROCESS Pcb;
NTSTATUS ExitStatus;
KEVENT LockEvent;
ULONG LockCount;
TIME CreateTime;
TIME ExitTime;
PVOID LockOwner;
ULONG UniqueProcessId;
LIST_ENTRY ActiveProcessLinks;
ULONG QuotaPeakPoolUsage[2];
ULONG QuotaPoolUsage[2];
ULONG PagefileUsage;
ULONG CommitCharge;
ULONG PeakPagefileUsage;
ULONG PeakVirtualUsage;
LARGE_INTEGER VirtualSize;
PVOID Vm; // Actually 48 bytes
PVOID LastProtoPteFault;
struct _EPORT* DebugPort;
struct _EPORT* ExceptionPort;
PVOID ObjectTable;
PVOID Token;
KMUTEX WorkingSetLock;
PVOID WorkingSetPage;
UCHAR ProcessOutswapEnabled;
UCHAR ProcessOutswapped;
UCHAR AddressSpaceInitialized;
UCHAR AddressSpaceDeleted;
KMUTEX AddressCreationLock;
PVOID ForkInProgress;
PVOID VmOperation;
PKEVENT VmOperationEvent;
PVOID PageDirectoryPte;
LARGE_INTEGER LastFaultCount;
PVOID VadRoot;
PVOID VadHint;
PVOID CloneRoot;
ULONG NumberOfPrivatePages;
ULONG NumberOfLockedPages;
UCHAR ForkWasSuccessFul;
UCHAR ExitProcessCalled;
UCHAR CreateProcessReported;
HANDLE SectionHandle;
PPEB Peb;
PVOID SectionBaseAddress;
PVOID QuotaBlock;
NTSTATUS LastThreadExitStatus;
LARGE_INTEGER WorkingSetWatch; //
ULONG InheritedFromUniqueProcessId;
ACCESS_MASK GrantedAccess;
ULONG DefaultHardErrorProcessing;
PVOID LdtInformation;
ULONG VadFreeHint;
PVOID VdmObjects;
KMUTANT ProcessMutant;
CHAR ImageFileName[16];
LARGE_INTEGER VmTrimFaultValue;
PVOID Win32Process; // Actually 12 bytes
PVOID Win32WindowStation;
} EPROCESS, *PEPROCESS;
#define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2)
#define LOW_PRIORITY (0)
#define LOW_REALTIME_PRIORITY (16)
#define HIGH_PRIORITY (31)
@ -318,11 +37,11 @@ typedef struct _EPROCESS
#ifdef __NTOSKRNL__
extern PEPROCESS EXPORTED PsInitialSystemProcess;
extern struct _EPROCESS* EXPORTED PsInitialSystemProcess;
extern POBJECT_TYPE EXPORTED PsProcessType;
extern POBJECT_TYPE EXPORTED PsThreadType;
#else
extern PEPROCESS IMPORTED PsInitialSystemProcess;
extern struct _EPROCESS* IMPORTED PsInitialSystemProcess;
extern POBJECT_TYPE IMPORTED PsProcessType;
extern POBJECT_TYPE IMPORTED PsThreadType;
#endif

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.39 2000/07/04 01:25:27 ekohl Exp $
/* $Id: rtl.h,v 1.40 2000/07/04 08:52:34 dwelch Exp $
*
*/
@ -10,6 +10,15 @@
#include <pe.h>
typedef struct _INITIAL_TEB
{
PVOID StackBase;
PVOID StackLimit;
PVOID StackCommit;
PVOID StackCommitMax;
PVOID StackReserved;
} INITIAL_TEB, *PINITIAL_TEB;
typedef struct _CONTROLLER_OBJECT
{
CSHORT Type;

View file

@ -1,6 +1,6 @@
#ifndef _INCLUDE_DDK_SEFUNCS_H
#define _INCLUDE_DDK_SEFUNCS_H
/* $Id: sefuncs.h,v 1.12 2000/06/29 23:35:12 dwelch Exp $ */
/* $Id: sefuncs.h,v 1.13 2000/07/04 08:52:34 dwelch Exp $ */
NTSTATUS STDCALL RtlCreateAcl(PACL Acl, ULONG AclSize, ULONG AclRevision);
NTSTATUS STDCALL RtlQueryInformationAcl (PACL Acl, PVOID Information, ULONG InformationLength, ACL_INFORMATION_CLASS InformationClass);
NTSTATUS STDCALL RtlSetInformationAcl (PACL Acl, PVOID Information, ULONG InformationLength, ACL_INFORMATION_CLASS InformationClass);
@ -89,13 +89,13 @@ NTSTATUS STDCALL SeAssignSecurity (PSECURITY_DESCRIPTOR ParentDescriptor,
NTSTATUS STDCALL SeDeassignSecurity (PSECURITY_DESCRIPTOR* SecurityDescriptor);
BOOLEAN STDCALL SeSinglePrivilegeCheck (LUID PrivilegeValue, KPROCESSOR_MODE PreviousMode);
VOID STDCALL SeImpersonateClient(PSE_SOME_STRUCT2 a,
PETHREAD Thread);
struct _ETHREAD* Thread);
NTSTATUS STDCALL SeCreateClientSecurity(PETHREAD Thread,
NTSTATUS STDCALL SeCreateClientSecurity(struct _ETHREAD* Thread,
PSECURITY_QUALITY_OF_SERVICE Qos,
ULONG e,
PSE_SOME_STRUCT2 f);
NTSTATUS SeExchangePrimaryToken(PEPROCESS Process,
NTSTATUS SeExchangePrimaryToken(struct _EPROCESS* Process,
PACCESS_TOKEN NewToken,
PACCESS_TOKEN* OldTokenP);
VOID STDCALL SeReleaseSubjectContext (PSECURITY_SUBJECT_CONTEXT SubjectContext);

View file

@ -702,6 +702,44 @@
#define STATUS_CONFLICTING_ADDRESS (0xC1000005)
#define STATUS_NO_MEDIA_IN_DRIVE (0xC1000006)
#ifndef __ASM__
enum
{
RPC_NT_INVALID_STRING_BINDING=0xC0020001,
RPC_NT_WRONG_KIND_OF_BINDING,
RPC_NT_INVALID_BINDING,
RPC_NT_PROTSEQ_NOT_SUPPORTED,
RPC_NT_INVALID_RPC_PROTSEQ,
RPC_NT_INVALID_STRING_UUID,
RPC_NT_INVALID_ENDPOINT_FORMAT,
RPC_NT_INVALID_NET_ADDR,
RPC_NT_NO_ENDPOINT_FOUND,
RPC_NT_INVALID_TIMEOUT,
RPC_NT_OBJECT_NOT_FOUND,
RPC_NT_ALREADY_REGISTERED,
RPC_NT_TYPE_ALREADY_REGISTERED,
RPC_NT_ALREADY_LISTENING,
RPC_NT_NO_PROTSEQS_REGISTERED,
RPC_NT_NOT_LISTENING,
RPC_NT_UNKNOWN_MGR_TYPE,
RPC_NT_UNKNOWN_IF,
RPC_NT_NO_BINDINGS,
RPC_NT_NO_PROTSEQS,
RPC_NT_CANT_CREATE_ENDPOINT,
RPC_NT_OUT_OF_RESOURCES,
RPC_NT_SERVER_UNAVAILABLE,
RPC_NT_SERVER_TOO_BUSY,
RPC_NT_INVALID_NETWORK_OPTIONS,
RPC_NT_NO_CALL_ACTIVE,
RPC_NT_CALL_FAILED,
RPC_NT_CALL_FAILED_DNE,
RPC_NT_PROTOCOL_ERROR,
RPC_NT_SS_IN_NULL_CONTEXT=0xC0030004,
};
#endif
#endif /* __INCLUDE_DDK_STATUS_H */

View file

@ -1,5 +1,5 @@
/* $Id: zw.h,v 1.32 2000/06/29 23:35:12 dwelch Exp $
/* $Id: zw.h,v 1.33 2000/07/04 08:52:34 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -5191,7 +5191,7 @@ NtSetContextChannel (
NTSTATUS
STDCALL
NtSetLdtEntries (
PETHREAD Thread,
HANDLE Thread,
ULONG FirstEntry,
PULONG Entries
);

View file

@ -1,4 +1,4 @@
/* $Id: view.c,v 1.8 2000/03/05 19:17:40 ea Exp $
/* $Id: view.c,v 1.9 2000/07/04 08:52:36 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -122,7 +122,7 @@ NTSTATUS STDCALL CcRequestCachePage(PBCB Bcb,
MmSetPage(NULL,
current->BaseAddress,
PAGE_READWRITE,
(ULONG)MmAllocPage());
(ULONG)MmAllocPage(0));
DPRINT("Returning %x (BaseAddress %x)\n", current, *BaseAddress);

View file

@ -1,4 +1,4 @@
/* $Id: irq.c,v 1.14 2000/06/29 23:35:34 dwelch Exp $
/* $Id: irq.c,v 1.15 2000/07/04 08:52:37 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -92,8 +92,7 @@ static KSPIN_LOCK isr_table_lock = {0,};
#define I486_INTERRUPT_GATE (0xe00)
VOID
HalpDispatchInterrupt (ULONG irq)
VOID HalpDispatchInterrupt (ULONG irq)
/*
* FUNCTION: Calls the irq specific handler for an irq
* ARGUMENTS:
@ -124,7 +123,7 @@ HalpDispatchInterrupt (ULONG irq)
if (irq==0)
{
KeUpdateSystemTime ();
KiUpdateSystemTime();
}
else
{

View file

@ -12,6 +12,7 @@
#include <internal/bitops.h>
#include <internal/halio.h>
#include <internal/ke.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -127,11 +128,7 @@ VOID KeSetCurrentIrql(KIRQL newlvl)
}
KIRQL
STDCALL
KeGetCurrentIrql (
VOID
)
KIRQL STDCALL KeGetCurrentIrql (VOID)
/*
* PURPOSE: Returns the current irq level
* RETURNS: The current irq level

View file

@ -0,0 +1,25 @@
%macro DECLARE_EXTERNAL_SYMBOL 1
%ifdef coff
extern _%1
%elifdef win32
extern _%1
%elifdef elf
extern %1
_%1:
call %1
ret
%endif
%endmacro
%macro DECLARE_GLOBAL_SYMBOL 1
%ifdef coff
global _%1
_%1:
%elifdef win32
global _%1
_%1:
%elifdef elf
global %1
%1:
%endif
%endmacro

View file

@ -5,6 +5,8 @@
#ifndef __INTERNAL_HAL_I386_MMHAL_H
#define __INTERNAL_HAL_I386_MMHAL_H
struct _EPROCESS;
#define PAGESIZE (4096)
PULONG MmGetPageEntry(PVOID Address);
@ -47,15 +49,16 @@ extern inline PULONG get_page_directory(void)
#define VADDR_TO_PT_OFFSET(x) (((x/1024)%4096))
#define VADDR_TO_PD_OFFSET(x) ((x)/(4*1024*1024))
VOID MmSetPage(PEPROCESS Process,
VOID MmSetPage(struct _EPROCESS* Process,
PVOID Address,
ULONG flProtect,
ULONG PhysicalAddress);
VOID MmSetPageProtect(PEPROCESS Process,
VOID MmSetPageProtect(struct _EPROCESS* Process,
PVOID Address,
ULONG flProtect);
BOOLEAN MmIsPagePresent(PEPROCESS Process, PVOID Address);
BOOLEAN MmIsPagePresent(struct _EPROCESS* Process,
PVOID Address);
#endif /* __INTERNAL_HAL_I386_MMHAL_H */

View file

@ -1,5 +1,5 @@
#ifndef _ASM_SEGMENT_H
#define _ASM_SEGMENT_H
#ifndef __INCLUDE_INTERNAL_I386_SEGMENT_H
#define __INCLUDE_INTERNAL_i386_SEGMENT_H
#define KERNEL_CS (0x8)
#define KERNEL_DS (0x10)
@ -9,345 +9,4 @@
#define PCR_SELECTOR (0x30)
#define TEB_SELECTOR (0x38 + 0x3)
//#define USER_CS (0x8+0x3)
//#define USER_DS (0x10+0x3)
//#define ZERO_DS 0x18
//#define KERNEL_CS 0x20
//#define KERNEL_DS 0x28
#ifndef __ASSEMBLY__
/*
* Uh, these should become the main single-value transfer routines..
* They automatically use the right size if we just have the right
* pointer type..
*/
#define put_user(x,ptr) __put_user((unsigned long)(x),(ptr),sizeof(*(ptr)))
#define get_user(ptr) ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr))))
/*
* This is a silly but good way to make sure that
* the __put_user function is indeed always optimized,
* and that we use the correct sizes..
*/
extern int bad_user_access_length(void);
/*
* dummy pointer type structure.. gcc won't try to do something strange
* this way..
*/
struct __segment_dummy { unsigned long a[100]; };
#define __sd(x) ((struct __segment_dummy *) (x))
#define __const_sd(x) ((const struct __segment_dummy *) (x))
static inline void __put_user(unsigned long x, void * y, int size)
{
switch (size) {
case 1:
__asm__ ("movb %b1,%%fs:%0"
:"=m" (*__sd(y))
:"iq" ((unsigned char) x), "m" (*__sd(y)));
break;
case 2:
__asm__ ("movw %w1,%%fs:%0"
:"=m" (*__sd(y))
:"ir" ((unsigned short) x), "m" (*__sd(y)));
break;
case 4:
__asm__ ("movl %1,%%fs:%0"
:"=m" (*__sd(y))
:"ir" (x), "m" (*__sd(y)));
break;
default:
bad_user_access_length();
}
}
static inline unsigned long __get_user(const void * y, int size)
{
unsigned long result;
switch (size) {
case 1:
__asm__ ("movb %%fs:%1,%b0"
:"=q" (result)
:"m" (*__const_sd(y)));
return (unsigned char) result;
case 2:
__asm__ ("movw %%fs:%1,%w0"
:"=r" (result)
:"m" (*__const_sd(y)));
return (unsigned short) result;
case 4:
__asm__ ("movl %%fs:%1,%0"
:"=r" (result)
:"m" (*__const_sd(y)));
return result;
default:
return bad_user_access_length();
}
}
static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
{
__asm__ volatile
(" cld
push %%es
push %%fs
cmpl $3,%0
pop %%es
jbe 1f
movl %%edi,%%ecx
negl %%ecx
andl $3,%%ecx
subl %%ecx,%0
rep; movsb
movl %0,%%ecx
shrl $2,%%ecx
rep; movsl
andl $3,%0
1: movl %0,%%ecx
rep; movsb
pop %%es"
:"=abd" (n)
:"0" (n),"D" ((long) to),"S" ((long) from)
:"cx","di","si");
}
static inline void __constant_memcpy_tofs(void * to, const void * from, unsigned long n)
{
switch (n) {
case 0:
return;
case 1:
__put_user(*(const char *) from, (char *) to, 1);
return;
case 2:
__put_user(*(const short *) from, (short *) to, 2);
return;
case 3:
__put_user(*(const short *) from, (short *) to, 2);
__put_user(*(2+(const char *) from), 2+(char *) to, 1);
return;
case 4:
__put_user(*(const int *) from, (int *) to, 4);
return;
case 8:
__put_user(*(const int *) from, (int *) to, 4);
__put_user(*(1+(const int *) from), 1+(int *) to, 4);
return;
case 12:
__put_user(*(const int *) from, (int *) to, 4);
__put_user(*(1+(const int *) from), 1+(int *) to, 4);
__put_user(*(2+(const int *) from), 2+(int *) to, 4);
return;
case 16:
__put_user(*(const int *) from, (int *) to, 4);
__put_user(*(1+(const int *) from), 1+(int *) to, 4);
__put_user(*(2+(const int *) from), 2+(int *) to, 4);
__put_user(*(3+(const int *) from), 3+(int *) to, 4);
return;
}
#define COMMON(x) \
__asm__("cld\n\t" \
"push %%es\n\t" \
"push %%fs\n\t" \
"pop %%es\n\t" \
"rep ; movsl\n\t" \
x \
"pop %%es" \
: /* no outputs */ \
:"c" (n/4),"D" ((long) to),"S" ((long) from) \
:"cx","di","si")
switch (n % 4) {
case 0:
COMMON("");
return;
case 1:
COMMON("movsb\n\t");
return;
case 2:
COMMON("movsw\n\t");
return;
case 3:
COMMON("movsw\n\tmovsb\n\t");
return;
}
#undef COMMON
}
static inline void __generic_memcpy_fromfs(void * to, const void * from, unsigned long n)
{
__asm__ volatile
(" cld
cmpl $3,%0
jbe 1f
movl %%edi,%%ecx
negl %%ecx
andl $3,%%ecx
subl %%ecx,%0
fs; rep; movsb
movl %0,%%ecx
shrl $2,%%ecx
fs; rep; movsl
andl $3,%0
1: movl %0,%%ecx
fs; rep; movsb"
:"=abd" (n)
:"0" (n),"D" ((long) to),"S" ((long) from)
:"cx","di","si", "memory");
}
static inline void __constant_memcpy_fromfs(void * to, const void * from, unsigned long n)
{
switch (n) {
case 0:
return;
case 1:
*(char *)to = __get_user((const char *) from, 1);
return;
case 2:
*(short *)to = __get_user((const short *) from, 2);
return;
case 3:
*(short *) to = __get_user((const short *) from, 2);
*((char *) to + 2) = __get_user(2+(const char *) from, 1);
return;
case 4:
*(int *) to = __get_user((const int *) from, 4);
return;
case 8:
*(int *) to = __get_user((const int *) from, 4);
*(1+(int *) to) = __get_user(1+(const int *) from, 4);
return;
case 12:
*(int *) to = __get_user((const int *) from, 4);
*(1+(int *) to) = __get_user(1+(const int *) from, 4);
*(2+(int *) to) = __get_user(2+(const int *) from, 4);
return;
case 16:
*(int *) to = __get_user((const int *) from, 4);
*(1+(int *) to) = __get_user(1+(const int *) from, 4);
*(2+(int *) to) = __get_user(2+(const int *) from, 4);
*(3+(int *) to) = __get_user(3+(const int *) from, 4);
return;
}
#define COMMON(x) \
__asm__("cld\n\t" \
"rep ; fs ; movsl\n\t" \
x \
: /* no outputs */ \
:"c" (n/4),"D" ((long) to),"S" ((long) from) \
:"cx","di","si","memory")
switch (n % 4) {
case 0:
COMMON("");
return;
case 1:
COMMON("fs ; movsb");
return;
case 2:
COMMON("fs ; movsw");
return;
case 3:
COMMON("fs ; movsw\n\tfs ; movsb");
return;
}
#undef COMMON
}
#define memcpy_fromfs(to, from, n) \
(__builtin_constant_p(n) ? \
__constant_memcpy_fromfs((to),(from),(n)) : \
__generic_memcpy_fromfs((to),(from),(n)))
#define memcpy_tofs(to, from, n) \
(__builtin_constant_p(n) ? \
__constant_memcpy_tofs((to),(from),(n)) : \
__generic_memcpy_tofs((to),(from),(n)))
/*
* These are deprecated..
*
* Use "put_user()" and "get_user()" with the proper pointer types instead.
*/
#define get_fs_byte(addr) __get_user((const unsigned char *)(addr),1)
#define get_fs_word(addr) __get_user((const unsigned short *)(addr),2)
#define get_fs_long(addr) __get_user((const unsigned int *)(addr),4)
#define put_fs_byte(x,addr) __put_user((x),(unsigned char *)(addr),1)
#define put_fs_word(x,addr) __put_user((x),(unsigned short *)(addr),2)
#define put_fs_long(x,addr) __put_user((x),(unsigned int *)(addr),4)
#ifdef WE_REALLY_WANT_TO_USE_A_BROKEN_INTERFACE
static inline unsigned short get_user_word(const short *addr)
{
return __get_user(addr, 2);
}
static inline unsigned char get_user_byte(const char * addr)
{
return __get_user(addr,1);
}
static inline unsigned long get_user_long(const int *addr)
{
return __get_user(addr, 4);
}
static inline void put_user_byte(char val,char *addr)
{
__put_user(val, addr, 1);
}
static inline void put_user_word(short val,short * addr)
{
__put_user(val, addr, 2);
}
static inline void put_user_long(unsigned long val,int * addr)
{
__put_user(val, addr, 4);
}
#endif
/*
* Someone who knows GNU asm better than I should double check the following.
* It seems to work, but I don't know if I'm doing something subtly wrong.
* --- TYT, 11/24/91
* [ nothing wrong here, Linus: I just changed the ax to be any reg ]
*/
static inline unsigned long get_fs(void)
{
unsigned long _v;
__asm__("mov %%fs,%w0":"=r" (_v):"0" (0));
return _v;
}
static inline unsigned long get_ds(void)
{
unsigned long _v;
__asm__("mov %%ds,%w0":"=r" (_v):"0" (0));
return _v;
}
static inline void set_fs(unsigned long val)
{
__asm__ __volatile__("mov %w0,%%fs": /* no output */ :"r" (val));
}
static inline void set_ds(unsigned long val)
{
__asm__ __volatile__("mov %w0,%%ds": /* no output */ :"r" (val));
}
#endif /* __ASSEMBLY__ */
#endif /* _ASM_SEGMENT_H */
#endif /* __INCLUDE_INTERNAL_I386_SEGMENT_H */

View file

@ -0,0 +1,6 @@
;
; Useful prototypes and definitions
;
%define KERNEL_DS 028h
%define KERNEL_CS 020h

View file

@ -13,6 +13,57 @@
/* INTERNAL KERNEL FUNCTIONS ************************************************/
struct _KTHREAD;
typedef struct _KTRAP_FRAME
{
PVOID DebugEbp;
PVOID DebugEip;
PVOID DebugArgMark;
PVOID TempCs;
PVOID TempEip;
PVOID Dr0;
PVOID Dr1;
PVOID Dr2;
PVOID Dr3;
PVOID Dr6;
PVOID Dr7;
USHORT Gs;
USHORT Reserved1;
USHORT Es;
USHORT Reserved2;
USHORT Ds;
USHORT Reserved3;
ULONG Edx;
ULONG Ecx;
ULONG Eax;
ULONG PreviousMode;
PVOID ExceptionList;
USHORT Fs;
USHORT Reserved4;
ULONG Edi;
ULONG Esi;
ULONG Ebx;
ULONG Ebp;
ULONG ErrorCode;
ULONG Eip;
ULONG Cs;
ULONG Eflags;
ULONG Esp;
USHORT Ss;
USHORT Reserved5;
USHORT V86_Es;
USHORT Reserved6;
USHORT V86_Ds;
USHORT Reserved7;
USHORT V86_Fs;
USHORT Reserved8;
USHORT V86_Gs;
USHORT Reserved9;
} KTRAP_FRAME;
VOID KiUpdateSystemTime (VOID);
VOID KeAcquireDispatcherDatabaseLock(BOOLEAN Wait);
VOID KeReleaseDispatcherDatabaseLock(BOOLEAN Wait);
BOOLEAN KeDispatcherObjectWake(DISPATCHER_HEADER* hdr);
@ -22,28 +73,18 @@ VOID KiDispatchInterrupt(ULONG irq);
VOID KeDrainApcQueue(VOID);
VOID KeDrainDpcQueue(VOID);
VOID KeExpireTimers(VOID);
PKPROCESS KeGetCurrentProcess(VOID);
NTSTATUS KeAddThreadTimeout(PKTHREAD Thread, PLARGE_INTEGER Interval);
NTSTATUS KeAddThreadTimeout(struct _KTHREAD* Thread,
PLARGE_INTEGER Interval);
VOID KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
ULONG Size, ULONG SignalState);
VOID KeDumpStackFrames(PVOID Stack, ULONG NrFrames);
ULONG KeAllocateGdtSelector(ULONG Desc[2]);
VOID KeFreeGdtSelector(ULONG Entry);
BOOLEAN KiTestAlert(PKTHREAD Thread, PCONTEXT UserContext);
BOOLEAN KiTestAlert(struct _KTHREAD* Thread, PCONTEXT UserContext);
VOID KeCallApcsThread(VOID);
VOID KeRemoveAllWaitsThread(PETHREAD Thread, NTSTATUS WaitStatus);
PULONG KeGetStackTopThread(PETHREAD Thread);
/*
* FUNCTION: Sets the current irql without altering the current processor
* state
* ARGUMENTS:
* newlvl = IRQ level to set
* NOTE: This is for internal use only
*/
VOID KeSetCurrentIrql(KIRQL newlvl);
VOID KeRemoveAllWaitsThread(struct _ETHREAD* Thread, NTSTATUS WaitStatus);
PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
/* INITIALIZATION FUNCTIONS *************************************************/

View file

@ -10,6 +10,9 @@
/* TYPES *********************************************************************/
struct _EPROCESS;
typedef ULONG SWAPENTRY;
enum
{
MEMORY_AREA_INVALID,
@ -36,6 +39,8 @@ enum
#define SPE_PAGEIN_PENDING (0x1)
#define SPE_MPW_PENDING (0x2)
#define SPE_PAGEOUT_PENDING (0x4)
#define SPE_DIRTY (0x8)
#define SPE_IN_PAGEFILE (0x10)
typedef struct
{
@ -69,7 +74,7 @@ typedef struct
ULONG Attributes;
LIST_ENTRY Entry;
ULONG LockCount;
PEPROCESS Process;
struct _EPROCESS* Process;
union
{
struct
@ -81,6 +86,23 @@ typedef struct
} Data;
} MEMORY_AREA, *PMEMORY_AREA;
typedef struct _MWORKING_SET
{
PVOID Address[1020];
struct _MWORKING_SET* Next;
} MWORKING_SET, *PMWORKING_SET;
typedef struct _MADDRESS_SPACE
{
LIST_ENTRY MAreaListHead;
KMUTEX Lock;
ULONG LowestAddress;
struct _EPROCESS* Process;
ULONG WorkingSetSize;
ULONG WorkingSetLruFirst;
ULONG WorkingSetLruLast;
ULONG WorkingSetPagesAllocated;
} MADDRESS_SPACE, *PMADDRESS_SPACE;
/* FUNCTIONS */
@ -89,11 +111,11 @@ VOID MmUnlockAddressSpace(PMADDRESS_SPACE AddressSpace);
VOID MmInitializeKernelAddressSpace(VOID);
PMADDRESS_SPACE MmGetCurrentAddressSpace(VOID);
PMADDRESS_SPACE MmGetKernelAddressSpace(VOID);
NTSTATUS MmInitializeAddressSpace(PEPROCESS Process,
NTSTATUS MmInitializeAddressSpace(struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace);
NTSTATUS MmDestroyAddressSpace(PMADDRESS_SPACE AddressSpace);
PVOID STDCALL MmAllocateSection (IN ULONG Length);
NTSTATUS MmCreateMemoryArea(PEPROCESS Process,
NTSTATUS MmCreateMemoryArea(struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace,
ULONG Type,
PVOID* BaseAddress,
@ -115,7 +137,7 @@ NTSTATUS MmInitSectionImplementation(VOID);
#define MM_LOWEST_USER_ADDRESS (4096)
PMEMORY_AREA MmSplitMemoryArea(PEPROCESS Process,
PMEMORY_AREA MmSplitMemoryArea(struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace,
PMEMORY_AREA OriginalMemoryArea,
PVOID BaseAddress,
@ -127,24 +149,26 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
ULONG MemorySizeInPages,
ULONG LastKernelBase);
PVOID MmAllocPage(VOID);
PVOID MmAllocPage(SWAPENTRY SavedSwapEntry);
VOID MmDereferencePage(PVOID PhysicalAddress);
VOID MmReferencePage(PVOID PhysicalAddress);
VOID MmDeletePageTable(PEPROCESS Process, PVOID Address);
NTSTATUS MmCopyMmInfo(PEPROCESS Src, PEPROCESS Dest);
NTSTATUS MmReleaseMmInfo(PEPROCESS Process);
NTSTATUS Mmi386ReleaseMmInfo(PEPROCESS Process);
VOID MmDeletePageEntry(PEPROCESS Process, PVOID Address, BOOL FreePage);
VOID MmDeletePageTable(struct _EPROCESS* Process,
PVOID Address);
NTSTATUS MmCopyMmInfo(struct _EPROCESS* Src,
struct _EPROCESS* Dest);
NTSTATUS MmReleaseMmInfo(struct _EPROCESS* Process);
NTSTATUS Mmi386ReleaseMmInfo(struct _EPROCESS* Process);
VOID MmDeletePageEntry(struct _EPROCESS* Process,
PVOID Address,
BOOL FreePage);
VOID MmBuildMdlFromPages(PMDL Mdl);
PVOID MmGetMdlPageAddress(PMDL Mdl, PVOID Offset);
VOID MiShutdownMemoryManager(VOID);
ULONG MmGetPhysicalAddressForProcess(PEPROCESS Process,
ULONG MmGetPhysicalAddressForProcess(struct _EPROCESS* Process,
PVOID Address);
NTSTATUS STDCALL MmUnmapViewOfSection(PEPROCESS Process,
PMEMORY_AREA MemoryArea);
PVOID MiTryToSharePageInSection(PSECTION_OBJECT Section, ULONG Offset);
NTSTATUS STDCALL MmUnmapViewOfSection(struct _EPROCESS* Process,
PMEMORY_AREA MemoryArea);
NTSTATUS MmSafeCopyFromUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
NTSTATUS MmSafeCopyToUser(PVOID Dest, PVOID Src, ULONG NumberOfBytes);
VOID MmInitPagingFile(VOID);
@ -182,7 +206,7 @@ NTSTATUS MmNotPresentFaultSectionView(PMADDRESS_SPACE AddressSpace,
NTSTATUS MmWaitForPage(PVOID Page);
VOID MmClearWaitPage(PVOID Page);
VOID MmSetWaitPage(PVOID Page);
BOOLEAN MmIsPageDirty(PEPROCESS Process, PVOID Address);
BOOLEAN MmIsPageDirty(struct _EPROCESS* Process, PVOID Address);
BOOLEAN MmIsPageTablePresent(PVOID PAddress);
ULONG MmPageOutSectionView(PMADDRESS_SPACE AddressSpace,
MEMORY_AREA* MemoryArea,
@ -197,4 +221,29 @@ MEMORY_AREA* MmOpenMemoryAreaByRegion(PMADDRESS_SPACE AddressSpace,
VOID ExUnmapPage(PVOID Addr);
PVOID ExAllocatePage(VOID);
VOID MmLockWorkingSet(struct _EPROCESS* Process);
VOID MmUnlockWorkingSet(struct _EPROCESS* Process);
VOID MmInitializeWorkingSet(struct _EPROCESS* Process,
PMADDRESS_SPACE AddressSpace);
ULONG MmTrimWorkingSet(struct _EPROCESS* Process,
ULONG ReduceHint);
VOID MmRemovePageFromWorkingSet(struct _EPROCESS* Process,
PVOID Address);
BOOLEAN MmAddPageToWorkingSet(struct _EPROCESS* Process,
PVOID Address);
VOID MmInitPagingFile(VOID);
VOID MmReserveSwapPages(ULONG Nr);
VOID MmDereserveSwapPages(ULONG Nr);
SWAPENTRY MmAllocSwapPage(VOID);
VOID MmFreeSwapPage(SWAPENTRY Entry);
VOID MmInit1(boot_param* bp, ULONG LastKernelAddress);
VOID MmInit2(VOID);
VOID MmInit3(VOID);
NTSTATUS MmInitPagerThread(VOID);
VOID MmInitKernelMap(PVOID BaseAddress);
unsigned int alloc_pool_region(unsigned int nr_pages);
#endif

View file

@ -11,6 +11,8 @@
#include <ddk/types.h>
struct _EPROCESS;
typedef struct
{
CSHORT Type;
@ -88,20 +90,20 @@ typedef struct
BOOLEAN Inherit;
} HANDLE_REP, *PHANDLE_REP;
PHANDLE_REP ObTranslateHandle(PKPROCESS Process, HANDLE h);
PHANDLE_REP ObTranslateHandle(struct _EPROCESS* Process, HANDLE h);
extern PDIRECTORY_OBJECT NameSpaceRoot;
VOID ObAddEntryDirectory(PDIRECTORY_OBJECT Parent,
POBJECT Object,
PWSTR Name);
NTSTATUS ObCreateHandle(PEPROCESS Process,
NTSTATUS ObCreateHandle(struct _EPROCESS* Process,
PVOID ObjectBody,
ACCESS_MASK GrantedAccess,
BOOLEAN Inherit,
PHANDLE Handle);
VOID ObCreateHandleTable(PEPROCESS Parent,
VOID ObCreateHandleTable(struct _EPROCESS* Parent,
BOOLEAN Inherit,
PEPROCESS Process);
struct _EPROCESS* Process);
NTSTATUS ObFindObject(POBJECT_ATTRIBUTES ObjectAttributes,
PVOID* ReturnedObject,
PUNICODE_STRING RemainingPath);
@ -109,8 +111,9 @@ NTSTATUS ObFindObject(POBJECT_ATTRIBUTES ObjectAttributes,
ULONG ObGetReferenceCount(PVOID Object);
ULONG ObGetHandleCount(PVOID Object);
VOID ObCloseAllHandles(PEPROCESS Process);
VOID ObDeleteHandleTable(PEPROCESS Process);
PVOID ObDeleteHandle(PEPROCESS Process, HANDLE Handle);
VOID ObCloseAllHandles(struct _EPROCESS* Process);
VOID ObDeleteHandleTable(struct _EPROCESS* Process);
PVOID ObDeleteHandle(struct _EPROCESS* Process,
HANDLE Handle);
#endif /* __INCLUDE_INTERNAL_OBJMGR_H */

View file

@ -2,11 +2,262 @@
#define __INCLUDE_INTERNAL_PS_H
#include <internal/hal.h>
#include <internal/mm.h>
extern HANDLE SystemProcessHandle;
/* ntoskrnl/ps/thread.c */
extern PETHREAD CurrentThread;
typedef struct _KAPC_STATE
{
LIST_ENTRY ApcListHead[2];
struct _KPROCESS* Process;
ULONG KernelApcInProgress;
ULONG KernelApcPending;
USHORT UserApcPending;
} KAPC_STATE, *PKAPC_STATE;
typedef struct _KTHREAD
{
DISPATCHER_HEADER DispatcherHeader; // For waiting for the thread
LIST_ENTRY MutantListHead;
PVOID InitialStack;
ULONG StackLimit;
NT_TEB* Teb;
PVOID TlsArray;
PVOID KernelStack;
UCHAR DebugActive;
UCHAR State;
UCHAR Alerted[2];
UCHAR Iopl;
UCHAR NpxState;
UCHAR Saturation;
KPRIORITY Priority;
KAPC_STATE ApcState;
ULONG ContextSwitches;
ULONG WaitStatus;
KIRQL WaitIrql;
ULONG WaitMode;
UCHAR WaitNext;
UCHAR WaitReason;
PKWAIT_BLOCK WaitBlockList;
LIST_ENTRY WaitListEntry;
ULONG WaitTime;
KPRIORITY BasePriority;
UCHAR DecrementCount;
UCHAR PriorityDecrement;
UCHAR Quantum;
KWAIT_BLOCK WaitBlock[4];
PVOID LegoData; // ??
LONG KernelApcDisable;
KAFFINITY UserAffinity;
UCHAR SystemAffinityActive;
UCHAR Pad;
PKQUEUE Queue;
KSPIN_LOCK ApcQueueLock;
KTIMER Timer;
LIST_ENTRY QueueListEntry;
KAFFINITY Affinity;
UCHAR Preempted;
UCHAR ProcessReadyQueue;
UCHAR KernelStackResident;
UCHAR NextProcessor;
PVOID CallbackStack;
BOOL Win32Thread;
PVOID TrapFrame;
PVOID ApcStatePointer; // Is actually eight bytes
UCHAR EnableStackSwap;
UCHAR LargeStack;
UCHAR ResourceIndex;
UCHAR PreviousMode;
TIME KernelTime;
TIME UserTime;
KAPC_STATE SavedApcState;
UCHAR Alertable;
UCHAR ApcQueueable;
ULONG AutoAlignment;
PVOID StackBase;
KAPC SuspendApc;
KSEMAPHORE SuspendSemaphore;
LIST_ENTRY ThreadListEntry;
CHAR FreezeCount;
ULONG SuspendCount;
UCHAR IdealProcessor;
UCHAR DisableBoost;
LIST_ENTRY ProcessThreadListEntry; // Added by Phillip Susi for list of threads in a process
/* Provisionally added by David Welch */
hal_thread_state Context;
KDPC TimerDpc; // Added by Phillip Susi for internal KeAddThreadTimeout() impl.
} KTHREAD, *PKTHREAD;
// According to documentation the stack should have a commited [ 1 page ] and
// a reserved part [ 1 M ] but can be specified otherwise in the image file.
// 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
{
PACCESS_TOKEN Token; // 0x0
UCHAR Unknown1; // 0x4
UCHAR Unknown2; // 0x5
UCHAR Pad[2]; // 0x6
SECURITY_IMPERSONATION_LEVEL Level; // 0x8
} PS_IMPERSONATION_INFO, *PPS_IMPERSONATION_INFO;
typedef struct _ETHREAD
{
KTHREAD Tcb;
TIME CreateTime;
TIME ExitTime;
NTSTATUS ExitStatus;
LIST_ENTRY PostBlockList;
LIST_ENTRY TerminationPortList;
KSPIN_LOCK ActiveTimerListLock;
PVOID ActiveTimerListHead;
CLIENT_ID Cid;
PLARGE_INTEGER LpcReplySemaphore;
PVOID LpcReplyMessage;
PLARGE_INTEGER LpcReplyMessageId;
PPS_IMPERSONATION_INFO 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;
UCHAR LpcExitThreadCalled;
UCHAR HardErrorsAreDisabled;
UCHAR LpcReceivedMsgIdValid;
UCHAR ActiveImpersonationInfo;
ULONG PerformanceCountHigh;
/*
* Added by David Welch (welch@cwcom.net)
*/
struct _EPROCESS* OldProcess;
} ETHREAD, *PETHREAD;
typedef struct _KPROCESS
{
DISPATCHER_HEADER DispatcherHeader;
PVOID PageTableDirectory; // FIXME: I should point to a PTD
TIME ElapsedTime;
TIME KernelTime;
TIME UserTime;
LIST_ENTRY InMemoryList;
LIST_ENTRY SwappedOutList;
KSPIN_LOCK SpinLock;
KAFFINITY Affinity;
ULONG StackCount;
KPRIORITY BasePriority;
ULONG DefaultThreadQuantum;
UCHAR ProcessState;
ULONG ThreadSeed;
UCHAR DisableBoost;
} KPROCESS, *PKPROCESS;
typedef struct _EPROCESS
{
KPROCESS Pcb;
NTSTATUS ExitStatus;
KEVENT LockEvent;
ULONG LockCount;
TIME CreateTime;
TIME ExitTime;
PVOID LockOwner;
ULONG UniqueProcessId;
LIST_ENTRY ActiveProcessLinks;
ULONG QuotaPeakPoolUsage[2];
ULONG QuotaPoolUsage[2];
ULONG PagefileUsage;
ULONG CommitCharge;
ULONG PeakPagefileUsage;
ULONG PeakVirtualUsage;
LARGE_INTEGER VirtualSize;
PVOID Vm; // Actually 48 bytes
PVOID LastProtoPteFault;
struct _EPORT* DebugPort;
struct _EPORT* ExceptionPort;
PVOID ObjectTable;
PVOID Token;
KMUTEX WorkingSetLock;
PVOID WorkingSetPage;
UCHAR ProcessOutswapEnabled;
UCHAR ProcessOutswapped;
UCHAR AddressSpaceInitialized;
UCHAR AddressSpaceDeleted;
KMUTEX AddressCreationLock;
PVOID ForkInProgress;
PVOID VmOperation;
PKEVENT VmOperationEvent;
PVOID PageDirectoryPte;
LARGE_INTEGER LastFaultCount;
PVOID VadRoot;
PVOID VadHint;
PVOID CloneRoot;
ULONG NumberOfPrivatePages;
ULONG NumberOfLockedPages;
UCHAR ForkWasSuccessFul;
UCHAR ExitProcessCalled;
UCHAR CreateProcessReported;
HANDLE SectionHandle;
PPEB Peb;
PVOID SectionBaseAddress;
PVOID QuotaBlock;
NTSTATUS LastThreadExitStatus;
LARGE_INTEGER WorkingSetWatch; //
ULONG InheritedFromUniqueProcessId;
ACCESS_MASK GrantedAccess;
ULONG DefaultHardErrorProcessing;
PVOID LdtInformation;
ULONG VadFreeHint;
PVOID VdmObjects;
KMUTANT ProcessMutant;
CHAR ImageFileName[16];
LARGE_INTEGER VmTrimFaultValue;
PVOID Win32Process; // Actually 12 bytes
PVOID Win32WindowStation;
/*
* Added by David Welch (welch@mcmail.com)
*/
MADDRESS_SPACE AddressSpace;
HANDLE_TABLE HandleTable;
LIST_ENTRY ProcessListEntry;
/*
* Added by Philip Susi for list of threads in process
*/
LIST_ENTRY ThreadListHead;
} EPROCESS, *PEPROCESS;
#define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2)
VOID PiInitProcessManager(VOID);
VOID PiShutdownProcessManager(VOID);

View file

@ -15,6 +15,7 @@
#include <string.h>
#include <internal/string.h>
#include <internal/ob.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: error.c,v 1.3 2000/06/12 14:57:10 ekohl Exp $
/* $Id: error.c,v 1.4 2000/07/04 08:52:38 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -12,6 +12,7 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: irp.c,v 1.28 2000/06/12 14:57:10 ekohl Exp $
/* $Id: irp.c,v 1.29 2000/07/04 08:52:38 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -32,8 +32,8 @@
#include <ddk/ntddk.h>
#include <string.h>
#include <internal/string.h>
#include <internal/io.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.8 2000/07/04 01:29:05 ekohl Exp $
/* $Id: process.c,v 1.9 2000/07/04 08:52:38 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -12,6 +12,7 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: critical.c,v 1.4 2000/06/04 19:50:12 ekohl Exp $
/* $Id: critical.c,v 1.5 2000/07/04 08:52:39 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -12,27 +12,20 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID
STDCALL
KeEnterCriticalRegion (
VOID
)
VOID STDCALL KeEnterCriticalRegion (VOID)
{
DPRINT("KeEnterCriticalRegion()\n");
KeGetCurrentThread()->KernelApcDisable -= 1;
}
VOID
STDCALL
KeLeaveCriticalRegion (
VOID
)
VOID STDCALL KeLeaveCriticalRegion (VOID)
{
DPRINT("KeLeaveCriticalRegion()\n");
KeGetCurrentThread()->KernelApcDisable += 1;

View file

@ -1,4 +1,4 @@
/* $Id: dpc.c,v 1.16 2000/07/01 18:26:10 ekohl Exp $
/* $Id: dpc.c,v 1.17 2000/07/04 08:52:39 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -17,6 +17,7 @@
/* INCLUDES ***************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -17,14 +17,13 @@
#include <internal/mmhal.h>
#include <internal/module.h>
#include <internal/mm.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
static exception_hook* exception_hooks[256]={NULL,};
#define _STR(x) #x
#define STR(x) _STR(x)
@ -36,15 +35,15 @@ extern ULONG init_stack_top;
/* FUNCTIONS ****************************************************************/
#define EXCEPTION_HANDLER_WITH_ERROR(x,y) \
#define EXCEPTION_HANDLER_WITH_ERROR(y) \
void exception_handler##y (void); \
void tmp_exception_handler##y (void) { \
__asm__("\n\t_exception_handler"##x":\n\t" \
__asm__("\n\t_exception_handler"STR(y)":\n\t" \
"pushl %gs\n\t" \
"pushl %fs\n\t" \
"pushl %es\n\t" \
"pushl %ds\n\t" \
"pushl $"##x"\n\t" \
"pushl $"STR(y)"\n\t" \
"pusha\n\t" \
"movw $"STR(KERNEL_DS)",%ax\n\t" \
"movw %ax,%ds\n\t" \
@ -61,16 +60,16 @@ extern ULONG init_stack_top;
"addl $4,%esp\n\t" \
"iret\n\t"); }
#define EXCEPTION_HANDLER_WITHOUT_ERROR(x,y) \
#define EXCEPTION_HANDLER_WITHOUT_ERROR(y) \
void exception_handler##y (void); \
void tmp_exception_handler##y (void) { \
__asm__("\n\t_exception_handler"##x":\n\t" \
__asm__("\n\t_exception_handler"STR(y)":\n\t" \
"pushl $0\n\t" \
"pushl %gs\n\t" \
"pushl %fs\n\t" \
"pushl %es\n\t" \
"pushl %ds\n\t" \
"pushl $"##x"\n\t" \
"pushl $"STR(y)"\n\t" \
"pusha\n\t" \
"movw $"STR(KERNEL_DS)",%ax\n\t" \
"movw %ax,%ds\n\t" \
@ -87,8 +86,8 @@ extern ULONG init_stack_top;
"addl $4,%esp\n\t" \
"iret\n\t"); }
void exception_handler_unknown(void);
void tmp_exception_handler_unknown(void)
void exception_handler_unknown(void);
void tmp_exception_handler_unknown(void)
{
__asm__("\n\t_exception_handler_unknown:\n\t"
"pushl $0\n\t"
@ -110,23 +109,23 @@ extern ULONG init_stack_top;
"iret\n\t");
}
EXCEPTION_HANDLER_WITHOUT_ERROR("0",0);
EXCEPTION_HANDLER_WITHOUT_ERROR("1",1);
EXCEPTION_HANDLER_WITHOUT_ERROR("2",2);
EXCEPTION_HANDLER_WITHOUT_ERROR("3",3);
EXCEPTION_HANDLER_WITHOUT_ERROR("4",4);
EXCEPTION_HANDLER_WITHOUT_ERROR("5",5);
EXCEPTION_HANDLER_WITHOUT_ERROR("6",6);
EXCEPTION_HANDLER_WITHOUT_ERROR("7",7);
EXCEPTION_HANDLER_WITH_ERROR("8",8);
EXCEPTION_HANDLER_WITHOUT_ERROR("9",9);
EXCEPTION_HANDLER_WITH_ERROR("10",10);
EXCEPTION_HANDLER_WITH_ERROR("11",11);
EXCEPTION_HANDLER_WITH_ERROR("12",12);
EXCEPTION_HANDLER_WITH_ERROR("13",13);
EXCEPTION_HANDLER_WITH_ERROR("14",14);
EXCEPTION_HANDLER_WITH_ERROR("15",15);
EXCEPTION_HANDLER_WITHOUT_ERROR("16",16);
EXCEPTION_HANDLER_WITHOUT_ERROR(0);
EXCEPTION_HANDLER_WITHOUT_ERROR(1);
EXCEPTION_HANDLER_WITHOUT_ERROR(2);
EXCEPTION_HANDLER_WITHOUT_ERROR(3);
EXCEPTION_HANDLER_WITHOUT_ERROR(4);
EXCEPTION_HANDLER_WITHOUT_ERROR(5);
EXCEPTION_HANDLER_WITHOUT_ERROR(6);
EXCEPTION_HANDLER_WITHOUT_ERROR(7);
EXCEPTION_HANDLER_WITH_ERROR(8);
EXCEPTION_HANDLER_WITHOUT_ERROR(9);
EXCEPTION_HANDLER_WITH_ERROR(10);
EXCEPTION_HANDLER_WITH_ERROR(11);
EXCEPTION_HANDLER_WITH_ERROR(12);
EXCEPTION_HANDLER_WITH_ERROR(13);
EXCEPTION_HANDLER_WITH_ERROR(14);
EXCEPTION_HANDLER_WITH_ERROR(15);
EXCEPTION_HANDLER_WITHOUT_ERROR(16);
extern unsigned int stext, etext;
@ -233,14 +232,6 @@ static void print_address(PVOID address)
return;
}
/*
* Activate any hook for the exception
*/
if (exception_hooks[type]!=NULL)
{
exception_hooks[type](NULL,type);
}
/*
* Print out the CPU registers
*/
@ -420,20 +411,7 @@ static void set_interrupt_gate(unsigned int sel, unsigned int func)
KiIdt[sel].b = 0x8f00 + (((int)func)&0xffff0000);
}
unsigned int ExHookException(exception_hook fn, unsigned int exp)
/*
* FUNCTION: Hook an exception
*/
{
if (exp>=256)
{
return(1);
}
exception_hooks[exp]=fn;
return(0);
}
void KeInitExceptions(void)
void KeInitExceptions(void)
/*
* FUNCTION: Initalize CPU exception handling
*/

View file

@ -0,0 +1,198 @@
/* $Id: trap.s,v 1.1 2000/07/04 08:52:41 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/hal/x86/trap.s
* PURPOSE: 2E trap handler
* PROGRAMMER: David Welch (david.welch@seh.ox.ac.uk)
* UPDATE HISTORY:
* ???
*/
#include <ddk/status.h>
#include <internal/i386/segment.h>
.globl _PsBeginThreadWithContextInternal
_PsBeginThreadWithContextInternal:
call _PiBeforeBeginThread
popl %eax
popl %eax
popl %eax
popl %eax
popl %eax
popl %eax
popl %eax
addl $112,%esp
popl %gs
popl %fs
popl %es
popl %ds
popl %edi
popl %esi
popl %ebx
popl %edx
popl %ecx
popl %eax
popl %ebp
iret
.globl _interrupt_handler2e
_interrupt_handler2e:
/* Save the user context */
pushl %ebp /* Ebp */
pushl %eax /* Eax */
pushl %ecx /* Ecx */
pushl %edx /* Edx */
pushl %ebx /* Ebx */
pushl %esi /* Esi */
pushl %edi /* Edi */
pushl %ds /* SegDs */
pushl %es /* SegEs */
pushl %fs /* SegFs */
pushl %gs /* SegGs */
subl $112,%esp /* FloatSave */
pushl $0 /* Dr7 */
pushl $0 /* Dr6 */
pushl $0 /* Dr3 */
pushl $0 /* Dr2 */
pushl $0 /* Dr1 */
pushl $0 /* Dr0 */
pushl $0 /* ContextFlags */
/* Set ES to kernel segment */
movw $KERNEL_DS,%bx
movw %bx,%es
/* Save pointer to user context as argument to system call */
pushl %esp
/* Allocate new Kernel stack frame */
movl %esp,%ebp
/* Users's current stack frame pointer is source */
movl %edx,%esi
/* Determine system service table to use */
cmpl $0x0fff, %eax
ja useShadowTable
/* Check to see if EAX is valid/inrange */
cmpl %es:_KeServiceDescriptorTable + 8, %eax
jbe serviceInRange
movl $STATUS_INVALID_SYSTEM_SERVICE, %eax
jmp done
serviceInRange:
/* Allocate room for argument list from kernel stack */
movl %es:_KeServiceDescriptorTable + 12, %ecx
movl %es:(%ecx, %eax, 4), %ecx
subl %ecx, %esp
/* Copy the arguments from the user stack to the kernel stack */
movl %esp,%edi
rep movsb
/* DS is now also kernel segment */
movw %bx, %ds
/* Call system call hook */
pushl %eax
call _KiSystemCallHook
popl %eax
/* Make the system service call */
movl %es:_KeServiceDescriptorTable, %ecx
movl %es:(%ecx, %eax, 4), %eax
call *%eax
#if CHECKED
/* Bump Service Counter */
#endif
/* Deallocate the kernel stack frame */
movl %ebp,%esp
/* Call the post system call hook and deliver any pending APCs */
pushl %eax
call _KiAfterSystemCallHook
addl $8,%esp
jmp done
useShadowTable:
subl $0x1000, %eax
/* Check to see if EAX is valid/inrange */
cmpl %es:_KeServiceDescriptorTableShadow + 24, %eax
jbe shadowServiceInRange
movl $STATUS_INVALID_SYSTEM_SERVICE, %eax
jmp done
shadowServiceInRange:
/* Allocate room for argument list from kernel stack */
movl %es:_KeServiceDescriptorTableShadow + 28, %ecx
movl %es:(%ecx, %eax, 4), %ecx
subl %ecx, %esp
/* Copy the arguments from the user stack to the kernel stack */
movl %esp,%edi
rep movsb
/* DS is now also kernel segment */
movw %bx,%ds
/* Call system call hook */
pushl %eax
call _KiSystemCallHook
popl %eax
/* Make the system service call */
movl %es:_KeServiceDescriptorTableShadow + 16, %ecx
movl %es:(%ecx, %eax, 4), %eax
call *%eax
#if CHECKED
/* Bump Service Counter */
#endif
/* Deallocate the kernel stack frame */
movl %ebp,%esp
/* Call the post system call hook and deliver any pending APCs */
pushl %eax
call _KiAfterSystemCallHook
addl $8,%esp
done:
/* Restore the user context */
addl $4,%esp /* UserContext */
addl $24,%esp /* Dr[0-3,6-7] */
addl $112,%esp /* FloatingSave */
popl %gs /* SegGs */
popl %fs /* SegFs */
popl %es /* SegEs */
popl %ds /* SegDs */
popl %edi /* Edi */
popl %esi /* Esi */
popl %ebx /* Ebx */
popl %edx /* Edx */
popl %ecx /* Ecx */
addl $4,%esp /* Eax (Not restored) */
popl %ebp /* Ebp */
iret
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: usercall.c,v 1.13 2000/06/29 23:35:38 dwelch Exp $
/* $Id: usercall.c,v 1.14 2000/07/04 08:52:41 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -26,6 +26,7 @@
#define _STR(x) #x
#define STR(x) _STR(x)
#if 0
void PsBeginThreadWithContextInternal(void);
__asm__(
"\n\t.global _PsBeginThreadWithContextInternal\n\t"
@ -54,6 +55,7 @@ void PsBeginThreadWithContextInternal(void);
"popl %eax\n\t"
"popl %ebp\n\t"
"iret\n\t");
#endif
VOID KiSystemCallHook(ULONG Nr, ...)
{
@ -124,7 +126,7 @@ KeAddSystemServiceTable (
return TRUE;
}
#if 0
void interrupt_handler2e(void);
__asm__("\n\t.global _interrupt_handler2e\n\t"
"_interrupt_handler2e:\n\t"
@ -283,5 +285,6 @@ void interrupt_handler2e(void);
"popl %ebp\n\t" /* Ebp */
"iret\n\t");
#endif
/* EOF */

View file

@ -18,7 +18,7 @@
NTSTATUS STDCALL NtSetLdtEntries(PETHREAD Thread,
NTSTATUS STDCALL NtSetLdtEntries(HANDLE Thread,
ULONG FirstEntry,
PULONG Entries)
{

View file

@ -1,4 +1,4 @@
/* $Id: main.c,v 1.50 2000/07/01 18:26:11 ekohl Exp $
/* $Id: main.c,v 1.51 2000/07/04 08:52:39 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -37,21 +37,7 @@ LOADER_PARAMETER_BLOCK EXPORTED KeLoaderBlock;
/* FUNCTIONS ****************************************************************/
static void
PrintString (char* fmt,...)
{
char buffer[512];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
HalDisplayString (buffer);
}
static void
CreateSystemRootLink (LPWSTR Device)
static VOID CreateSystemRootLink (LPWSTR Device)
{
UNICODE_STRING LinkName;
UNICODE_STRING DeviceName;
@ -66,104 +52,6 @@ CreateSystemRootLink (LPWSTR Device)
&DeviceName);
}
void set_breakpoint(unsigned int i, unsigned int addr, unsigned int type,
unsigned int len)
/*
* FUNCTION: Sets a hardware breakpoint
* ARGUMENTS:
* i = breakpoint to set (0 to 3)
* addr = linear address to break on
* type = Type of access to break on
* len = length of the variable to watch
* NOTES:
* The variable to watch must be aligned to its length (i.e. a dword
* breakpoint must be aligned to a dword boundary)
*
* A fatal exception will be generated on the access to the variable.
* It is (at the moment) only really useful for catching undefined
* pointers if you know the variable effected but not the buggy
* routine.
*
* FIXME: Extend to call out to kernel debugger on breakpoint
* Add support for I/O breakpoints
* REFERENCES: See the i386 programmer manual for more details
*/
{
unsigned int mask;
if (i>3)
{
DbgPrint("Invalid breakpoint index at %s:%d\n",__FILE__,__LINE__);
return;
}
/*
* Load the linear address
*/
switch (i)
{
case 0:
__asm("movl %0,%%db0\n\t"
: /* no outputs */
: "d" (addr));
break;
case 1:
__asm__("movl %0,%%db1\n\t"
: /* no outputs */
: "d" (addr));
break;
case 2:
__asm__("movl %0,%%db2\n\t"
: /* no outputs */
: "d" (addr));
break;
case 3:
__asm__("movl %0,%%db3\n\t"
: /* no outputs */
: "d" (addr));
break;
}
/*
* Setup mask for dr7
*/
mask = (len<<(16 + 2 + i*4)) + (type<<(16 + i*4)) + (1<<(i*2));
__asm__("movl %%db7,%%eax\n\t"
"orl %0,%%eax\n\t"
"movl %%eax,%%db7\n\t"
: /* no outputs */
: "d" (mask)
: "ax");
}
extern int edata;
extern int end;
#if 0
static char * INIData =
"[HKEY_LOCAL_MACHINE\\HARDWARE]\r\n"
"\r\n"
"[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP]\r\n"
"\r\n"
"[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk]\r\n"
"\r\n"
"[HKEY_LOCAL_MACHINE\\HARDWARE\\DEVICEMAP\\AtDisk\\Controller 0]\r\n"
"Controller Address=dword:000001f0\r\n"
"Controller Interrupt=dword:0000000e\r\n"
"\r\n"
"\r\n"
"\r\n"
"";
#endif
unsigned int old_idt[256][2];
//extern unsigned int idt[];
unsigned int old_idt_valid = 1;
void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
/*
* FUNCTION: Called by the boot loader to start the kernel
@ -174,9 +62,8 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
*/
{
unsigned int i;
unsigned int start;
unsigned int start1;
unsigned int last_kernel_address;
ULONG start, start1;
/*
* Copy the parameters to a local buffer because lowmem will go away
@ -200,18 +87,6 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
HalDisplayString("Starting ReactOS "KERNEL_VERSION_STR" (Build "KERNEL_VERSION_BUILD_STR")\n");
start = KERNEL_BASE + PAGE_ROUND_UP(KeLoaderBlock.module_length[0]);
if (start < ((int)&end))
{
PrintString("start %x end %x\n",start,(int)&end);
PrintString("Kernel booted incorrectly, aborting\n");
PrintString("Reduce the amount of uninitialized data\n");
PrintString("\n\n*** The system has halted ***\n");
for(;;)
__asm__("hlt\n\t");
}
start1 = start+PAGE_ROUND_UP(KeLoaderBlock.module_length[1]);
last_kernel_address = KERNEL_BASE;
for (i=0; i<=KeLoaderBlock.nr_files; i++)
{
@ -219,8 +94,7 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
PAGE_ROUND_UP(KeLoaderBlock.module_length[i]);
}
DPRINT("MmInitSystem()\n");
MmInitSystem(0, &KeLoaderBlock, last_kernel_address);
MmInit1(&KeLoaderBlock, last_kernel_address);
/*
* Initialize the kernel debugger
@ -235,34 +109,21 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
* Initialization phase 1
* Initalize various critical subsystems
*/
DPRINT("Kernel Initialization Phase 1\n");
DPRINT("HalInitSystem()\n");
HalInitSystem (1, &KeLoaderBlock);
DPRINT("MmInitSystem()\n");
MmInitSystem(1, &KeLoaderBlock, 0);
DPRINT("KeInit()\n");
MmInit2();
KeInit();
DPRINT("ExInit()\n");
ExInit();
DPRINT("ObInit()\n");
ObInit();
DPRINT("PsInit()\n");
PiInitProcessManager();
DPRINT("IoInit()\n");
IoInit();
DPRINT("LdrInitModuleManagement()\n");
LdrInitModuleManagement();
CmInitializeRegistry();
NtInit();
MmInit3();
/* Report all resources used by hal */
HalReportResourceUsage ();
memcpy(old_idt, KiIdt, sizeof(old_idt));
old_idt_valid = 0;
/*
* Initalize services loaded at boot time
*/
@ -300,7 +161,6 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
/*
* Load Auto configured drivers
*/
CHECKPOINT;
LdrLoadAutoConfigDrivers();
/*
@ -314,12 +174,8 @@ void _main (PLOADER_PARAMETER_BLOCK LoaderBlock)
/*
* Launch initial process
*/
CHECKPOINT;
LdrLoadInitialProcess();
/*
* Enter idle loop
*/
DbgPrint("Finished main()\n");
PsTerminateSystemThread(STATUS_SUCCESS);
}

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.4 2000/06/04 19:50:12 ekohl Exp $
/* $Id: process.c,v 1.5 2000/07/04 08:52:40 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -14,6 +14,7 @@
#include <ddk/ntddk.h>
#include <internal/ke.h>
#include <internal/mm.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: timer.c,v 1.30 2000/06/29 23:35:38 dwelch Exp $
/* $Id: timer.c,v 1.31 2000/07/04 08:52:40 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -24,6 +24,7 @@
#include <stdio.h>
#include <internal/ke.h>
#include <internal/id.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -461,11 +462,7 @@ VOID KeExpireTimers(VOID)
}
VOID
STDCALL
KeUpdateSystemTime (
VOID
)
VOID KiUpdateSystemTime (VOID)
/*
* FUNCTION: Handles a timer interrupt
*/

View file

@ -1,4 +1,4 @@
/* $Id: loader.c,v 1.57 2000/06/29 23:35:39 dwelch Exp $
/* $Id: loader.c,v 1.58 2000/07/04 08:52:41 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -374,16 +374,6 @@ LdrProcessModule(PVOID ModuleLoadBase, PUNICODE_STRING ModuleName)
{
return LdrPEProcessModule(ModuleLoadBase, ModuleName);
}
#if 0
if (PEDosHeader->e_magic == IMAGE_DOS_MAGIC)
{
return 0;
}
else /* Assume COFF format and load */
{
return LdrCOFFProcessModule(ModuleLoadBase, ModuleName);
}
#endif
return 0;
}

View file

@ -1,4 +1,4 @@
# $Id: makefile_rex,v 1.79 2000/07/04 01:27:40 ekohl Exp $
# $Id: makefile_rex,v 1.80 2000/07/04 08:52:35 dwelch Exp $
#
# ReactOS Operating System
#
@ -81,12 +81,14 @@ OBJECTS_KE = \
ke/sem.o \
ke/spinlock.o \
ke/timer.o \
ke/wait.o
ke/wait.o
OBJECTS_KE_I386 = \
ke/i386/exp.o \
ke/i386/thread.o \
ke/i386/usercall.o
ke/i386/usercall.o \
ke/i386/trap.o
# Memory Manager (Mm)
OBJECTS_MM = \
@ -107,7 +109,9 @@ OBJECTS_MM = \
mm/section.o \
mm/virtual.o \
mm/pager.o \
# mm/kmap.o
mm/wset.o \
mm/mminit.o \
mm/kmap.o
OBJECTS_MM_I386 = \
mm/i386/memsafe.o \

View file

@ -1,4 +1,4 @@
/* $Id: aspace.c,v 1.2 2000/04/07 02:24:00 dwelch Exp $
/* $Id: aspace.c,v 1.3 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -13,6 +13,7 @@
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/ps.h>
#include <internal/debug.h>
@ -44,7 +45,7 @@ VOID MmInitializeKernelAddressSpace(VOID)
PMADDRESS_SPACE MmGetCurrentAddressSpace(VOID)
{
return(&PsGetCurrentProcess()->Pcb.AddressSpace);
return(&PsGetCurrentProcess()->AddressSpace);
}
PMADDRESS_SPACE MmGetKernelAddressSpace(VOID)
@ -59,6 +60,10 @@ NTSTATUS MmInitializeAddressSpace(PEPROCESS Process,
KeInitializeMutex(&AddressSpace->Lock, 1);
AddressSpace->LowestAddress = MM_LOWEST_USER_ADDRESS;
AddressSpace->Process = Process;
if (Process != NULL)
{
MmInitializeWorkingSet(Process, AddressSpace);
}
return(STATUS_SUCCESS);
}

View file

@ -32,6 +32,7 @@ typedef struct _PHYSICAL_PAGE
LIST_ENTRY ListEntry;
ULONG ReferenceCount;
KEVENT Event;
SWAPENTRY SavedSwapEntry;
} PHYSICAL_PAGE, *PPHYSICAL_PAGE;
/* GLOBALS ****************************************************************/
@ -215,6 +216,19 @@ PVOID MmInitializePageList(PVOID FirstPhysKernelAddress,
return((PVOID)LastKernelAddress);
}
SWAPENTRY MmGetSavedSwapEntryPage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
SWAPENTRY SavedSwapEntry;
KIRQL oldIrql;
KeAcquireSpinLock(&PageListLock, &oldIrql);
SavedSwapEntry = MmPageArray[Start].SavedSwapEntry;
KeReleaseSpinLock(&PageListLock, oldIrql);
return(SavedSwapEntry);
}
VOID MmReferencePage(PVOID PhysicalAddress)
{
ULONG Start = (ULONG)PhysicalAddress / PAGESIZE;
@ -256,7 +270,7 @@ VOID MmDereferencePage(PVOID PhysicalAddress)
}
PVOID MmAllocPage(VOID)
PVOID MmAllocPage(SWAPENTRY SavedSwapEntry)
{
ULONG offset;
PLIST_ENTRY ListEntry;
@ -276,6 +290,7 @@ PVOID MmAllocPage(VOID)
DPRINT("PageDescriptor %x\n",PageDescriptor);
PageDescriptor->Flags = PHYSICAL_PAGE_INUSE;
PageDescriptor->ReferenceCount = 1;
PageDescriptor->SavedSwapEntry = SavedSwapEntry;
ExInterlockedInsertTailList(&UsedPageListHead, ListEntry,
&PageListLock);

View file

@ -1,4 +1,4 @@
/* $Id: page.c,v 1.9 2000/06/25 03:59:16 dwelch Exp $
/* $Id: page.c,v 1.10 2000/07/04 08:52:46 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -15,9 +15,8 @@
#include <internal/mm.h>
#include <internal/mmhal.h>
#include <string.h>
#include <internal/string.h>
#include <internal/bitops.h>
#include <internal/ex.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -218,7 +217,7 @@ PULONG MmGetPageEntry(PVOID PAddress)
DPRINT("page_dir %x *page_dir %x\n",page_dir,*page_dir);
if ((*page_dir) == 0)
{
(*page_dir) = ((ULONG)MmAllocPage()) | 0x7;
(*page_dir) = ((ULONG)MmAllocPage(0)) | 0x7;
memset((PVOID)PAGE_ROUND_DOWN(ADDR_TO_PTE(Address)), 0, PAGESIZE);
FLUSH_TLB;
}

View file

@ -1,4 +1,4 @@
/* $Id: iospace.c,v 1.4 2000/04/02 13:32:41 ea Exp $
/* $Id: iospace.c,v 1.5 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -13,6 +13,7 @@
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -110,7 +111,7 @@ PVOID STDCALL MmMapIoSpace (IN PHYSICAL_ADDRESS PhysicalAddress,
VOID STDCALL MmUnmapIoSpace (IN PVOID BaseAddress,
IN ULONG NumberOfBytes)
{
(VOID)MmFreeMemoryArea(&PsGetCurrentProcess()->Pcb.AddressSpace,
(VOID)MmFreeMemoryArea(&PsGetCurrentProcess()->AddressSpace,
BaseAddress,
NumberOfBytes,
FALSE);

View file

@ -1,4 +1,4 @@
/* $Id: kmap.c,v 1.1 2000/05/13 13:51:05 dwelch Exp $
/* $Id: kmap.c,v 1.2 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -24,41 +24,23 @@
/* GLOBALS *****************************************************************/
/*
* Memory managment initalized symbol for the base of the pool
*/
static ULONG MmKernelMapBase = 0;
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGESIZE)
/*
* One bit for each page in the kmalloc region
* If set then the page is used by a kmalloc block
*/
static ULONG alloc_map[ALLOC_MAP_SIZE/32]={0,};
static unsigned int alloc_map[ALLOC_MAP_SIZE/32]={0,};
static KSPIN_LOCK AllocMapLock;
static PVOID kernel_pool_base;
/* FUNCTIONS ***************************************************************/
PVOID MmAllocPageFrame(VOID)
{
KIRQL oldIrql;
ULONG i = ((ULONG)Addr - kernel_pool_base) / PAGESIZE;
KeAcquireSpinLock(&AllocMapLock, &oldIrql);
MmSetPage(NULL, (PVOID)Addr, 0, 0);
clear_bit(i%32, &alloc_map[i/32]);
KeReleaseSpinLock(&AllocMapLock, oldIrql);
}
VOID MmFreePageFrame(PVOID Addr)
{
}
VOID ExUnmapPage(PVOID Addr)
{
KIRQL oldIrql;
ULONG i = ((ULONG)Addr - kernel_pool_base) / PAGESIZE;
ULONG i = (Addr - kernel_pool_base) / PAGESIZE;
DPRINT("ExUnmapPage(Addr %x)\n",Addr);
DPRINT("i %x\n",i);
@ -76,7 +58,7 @@ PVOID ExAllocatePage(VOID)
ULONG i;
ULONG PhysPage;
PhysPage = (ULONG)MmAllocPage();
PhysPage = (ULONG)MmAllocPage(0);
DPRINT("Allocated page %x\n",PhysPage);
if (PhysPage == 0)
{
@ -90,7 +72,7 @@ PVOID ExAllocatePage(VOID)
{
DPRINT("i %x\n",i);
set_bit(i%32,&alloc_map[i/32]);
addr = kernel_pool_base + (i*PAGESIZE);
addr = (ULONG)(kernel_pool_base + (i*PAGESIZE));
MmSetPage(NULL, (PVOID)addr, PAGE_READWRITE, PhysPage);
KeReleaseSpinLock(&AllocMapLock, oldlvl);
return((PVOID)addr);
@ -100,9 +82,56 @@ PVOID ExAllocatePage(VOID)
return(NULL);
}
VOID MmKernelMapInit(ULONG BaseAddress)
VOID MmInitKernelMap(PVOID BaseAddress)
{
MmKernelMapBase = BaseAddress;
kernel_pool_base = BaseAddress;
KeInitializeSpinLock(&AllocMapLock);
}
unsigned int alloc_pool_region(unsigned int nr_pages)
/*
* FUNCTION: Allocates a region of pages within the nonpaged pool area
*/
{
unsigned int start = 0;
unsigned int length = 0;
unsigned int i,j;
OLD_DPRINT("alloc_pool_region(nr_pages = %d)\n",nr_pages);
for (i=1; i<ALLOC_MAP_SIZE;i++)
{
if (!test_bit(i%32,&alloc_map[i/32]))
{
if (length == 0)
{
start=i;
length = 1;
}
else
{
length++;
}
if (length==nr_pages)
{
OLD_DPRINT("found region at %d for %d\n",start,
length);
for (j=start;j<(start+length);j++)
{
set_bit(j%32,&alloc_map[j/32]);
}
OLD_DPRINT("returning %x\n",(start*PAGESIZE)
+kernel_pool_base);
return((ULONG)((start*PAGESIZE)+kernel_pool_base));
}
}
else
{
start=0;
length=0;
}
}
DbgPrint("CRITICAL: Out of non-paged pool space\n");
for(;;);
return(0);
}

View file

@ -13,6 +13,7 @@
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/mmhal.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -1,4 +1,4 @@
/* $Id: mdl.c,v 1.20 2000/07/02 17:32:51 ekohl Exp $
/* $Id: mdl.c,v 1.21 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -15,7 +15,7 @@
#include <internal/mm.h>
#include <internal/mmhal.h>
#include <string.h>
#include <internal/string.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -118,7 +118,7 @@ VOID MmBuildMdlFromPages(PMDL Mdl)
for (i=0;i<(PAGE_ROUND_UP(Mdl->ByteOffset+Mdl->ByteCount)/PAGESIZE);i++)
{
mdl_pages[i] = (ULONG)MmAllocPage();
mdl_pages[i] = (ULONG)MmAllocPage(0);
DPRINT("mdl_pages[i] %x\n",mdl_pages[i]);
}
}
@ -154,7 +154,7 @@ MmProbeAndLockPages (
}
else
{
AddressSpace = &Mdl->Process->Pcb.AddressSpace;
AddressSpace = &Mdl->Process->AddressSpace;
}
MmLockAddressSpace(AddressSpace);
marea = MmOpenMemoryAreaByAddress(AddressSpace,

View file

@ -1,4 +1,4 @@
/* $Id: mm.c,v 1.32 2000/07/01 18:27:03 ekohl Exp $
/* $Id: mm.c,v 1.33 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -22,7 +22,7 @@
#include <internal/bitops.h>
#include <internal/string.h>
#include <internal/io.h>
#include <internal/ps.h>
#include <internal/mmhal.h>
#define NDEBUG
@ -30,111 +30,96 @@
/* GLOBALS *****************************************************************/
/*
* Size of extended memory (kb) (fixed for now)
*/
#define EXTENDED_MEMORY_SIZE (3*1024*1024)
/*
* Compiler defined symbol
*/
extern unsigned int stext;
extern unsigned int etext;
extern unsigned int end;
static BOOLEAN IsThisAnNtAsSystem = FALSE;
static MM_SYSTEM_SIZE MmSystemSize = MmSmallSystem;
extern unsigned int etext;
extern unsigned int _bss_end__;
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;
ULONG EXPORTED MmUserProbeAddress [PAGESIZE] = {0,}; /* FIXME */
PVOID EXPORTED MmHighestUserAddress = NULL; /* FIXME */
/* FUNCTIONS ****************************************************************/
VOID MiShutdownMemoryManager(VOID)
NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
{
PVOID i;
DPRINT("MmReleaseMemoryArea(Process %x, Marea %x)\n",Process,Marea);
DPRINT("Releasing %x between %x %x\n",
Marea, Marea->BaseAddress, Marea->BaseAddress + Marea->Length);
if (Marea->Type == MEMORY_AREA_SECTION_VIEW_COMMIT ||
Marea->Type == MEMORY_AREA_SECTION_VIEW_RESERVE)
{
MmUnmapViewOfSection(Process, Marea);
}
for (i = Marea->BaseAddress;
i < (Marea->BaseAddress + Marea->Length);
i = i+PAGESIZE)
{
MmDeletePageEntry(Process, i, TRUE);
}
ExFreePool(Marea);
return(STATUS_SUCCESS);
}
VOID MmInitVirtualMemory(PLOADER_PARAMETER_BLOCK LoaderBlock, ULONG LastKernelAddress)
NTSTATUS MmReleaseMmInfo(PEPROCESS Process)
{
PLIST_ENTRY CurrentEntry;
PMEMORY_AREA Current;
DPRINT("MmReleaseMmInfo(Process %x)\n",Process);
MmLockAddressSpace(&Process->AddressSpace);
while (!IsListEmpty(&Process->AddressSpace.MAreaListHead))
{
CurrentEntry = RemoveHeadList(
&Process->AddressSpace.MAreaListHead);
Current = CONTAINING_RECORD(CurrentEntry, MEMORY_AREA, Entry);
MmReleaseMemoryArea(Process, Current);
}
Mmi386ReleaseMmInfo(Process);
MmUnlockAddressSpace(&Process->AddressSpace);
DPRINT("Finished MmReleaseMmInfo()\n");
return(STATUS_SUCCESS);
}
BOOLEAN STDCALL MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
{
UNIMPLEMENTED;
}
BOOLEAN STDCALL MmIsAddressValid(PVOID VirtualAddress)
/*
* FUNCTION: Intialize the memory areas list
* FUNCTION: Checks whether the given address is valid for a read or write
* ARGUMENTS:
* LoaderBlock = Pointer to the boot parameters
* kernel_len = Length of the kernel
* VirtualAddress = address to check
* RETURNS: True if the access would be valid
* False if the access would cause a page fault
* NOTES: This function checks whether a byte access to the page would
* succeed. Is this realistic for RISC processors which don't
* allow byte granular access?
*/
{
unsigned int kernel_len = LoaderBlock->end_mem - LoaderBlock->start_mem;
PVOID BaseAddress;
ULONG Length;
ULONG ParamLength = kernel_len;
MEMORY_AREA* MemoryArea;
PMADDRESS_SPACE AddressSpace;
DPRINT("MmInitVirtualMemory(%x)\n",LoaderBlock);
AddressSpace = &PsGetCurrentProcess()->AddressSpace;
LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
MmInitMemoryAreas();
// ExInitNonPagedPool(KERNEL_BASE + PAGE_ROUND_UP(kernel_len) + PAGESIZE);
ExInitNonPagedPool(LastKernelAddress + PAGESIZE);
/*
* Setup the system area descriptor list
*/
BaseAddress = (PVOID)KERNEL_BASE;
Length = PAGE_ROUND_UP(((ULONG)&etext)) - KERNEL_BASE;
ParamLength = ParamLength - Length;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_text_desc);
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
PAGE_ROUND_UP(((ULONG)&etext));
ParamLength = ParamLength - Length;
DPRINT("Length %x\n",Length);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&etext));
DPRINT("BaseAddress %x\n",BaseAddress);
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_data_desc);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&end));
// Length = ParamLength;
Length = LastKernelAddress - (ULONG)BaseAddress;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_param_desc);
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
VirtualAddress);
BaseAddress = (PVOID)(LastKernelAddress + PAGESIZE);
Length = NONPAGED_POOL_SIZE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_pool_desc);
// MmDumpMemoryAreas();
DPRINT("MmInitVirtualMemory() done\n");
if (MemoryArea == NULL)
{
MmUnlockAddressSpace(AddressSpace);
return(FALSE);
}
MmUnlockAddressSpace(AddressSpace);
return(TRUE);
}
NTSTATUS MmAccessFault(KPROCESSOR_MODE Mode,
@ -180,7 +165,7 @@ NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
}
else
{
AddressSpace = &PsGetCurrentProcess()->Pcb.AddressSpace;
AddressSpace = &PsGetCurrentProcess()->AddressSpace;
}
MmLockAddressSpace(AddressSpace);
@ -219,107 +204,6 @@ NTSTATUS MmNotPresentFault(KPROCESSOR_MODE Mode,
return(Status);
}
BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
{
return(IsThisAnNtAsSystem);
}
MM_SYSTEM_SIZE STDCALL MmQuerySystemSize(VOID)
{
return(MmSystemSize);
}
void MmInitialize(PLOADER_PARAMETER_BLOCK LoaderBlock, ULONG LastKernelAddress)
/*
* FUNCTION: Initalize memory managment
*/
{
unsigned int first_krnl_phys_addr;
unsigned int last_krnl_phys_addr;
int i;
unsigned int kernel_len;
DPRINT("MmInitialize(LoaderBlock %x, LastKernelAddress %x)\n",
LoaderBlock,
LastKernelAddress);
/*
* Unmap low memory
*/
MmDeletePageTable(NULL, 0);
/*
* Free all pages not used for kernel memory
* (we assume the kernel occupies a continuous range of physical
* memory)
*/
first_krnl_phys_addr = LoaderBlock->start_mem;
last_krnl_phys_addr = LoaderBlock->end_mem;
DPRINT("first krnl %x\nlast krnl %x\n",first_krnl_phys_addr,
last_krnl_phys_addr);
/*
* Free physical memory not used by the kernel
*/
LastKernelAddress = (ULONG)MmInitializePageList(
(PVOID)first_krnl_phys_addr,
(PVOID)last_krnl_phys_addr,
1024,
PAGE_ROUND_UP(LastKernelAddress));
kernel_len = last_krnl_phys_addr - first_krnl_phys_addr;
/*
* Create a trap for null pointer references and protect text
* segment
*/
CHECKPOINT;
DPRINT("stext %x etext %x\n",(int)&stext,(int)&etext);
for (i=PAGE_ROUND_UP(((int)&stext));
i<PAGE_ROUND_DOWN(((int)&etext));i=i+PAGESIZE)
{
MmSetPageProtect(NULL,
(PVOID)i,
PAGE_EXECUTE_READ);
}
DPRINT("Invalidating between %x and %x\n",
LastKernelAddress,
KERNEL_BASE + PAGE_TABLE_SIZE);
for (i=(LastKernelAddress);
i<(KERNEL_BASE + PAGE_TABLE_SIZE);
i=i+PAGESIZE)
{
MmSetPage(NULL, (PVOID)(i), PAGE_NOACCESS, 0);
}
DPRINT("Almost done MmInit()\n");
/*
* Intialize memory areas
*/
MmInitVirtualMemory(LoaderBlock, LastKernelAddress);
}
VOID MmInitSystem (
ULONG Phase,
PLOADER_PARAMETER_BLOCK LoaderBlock,
ULONG LastKernelAddress
)
{
if (Phase == 0)
{
/* Phase 0 Initialization */
MmInitializeKernelAddressSpace();
MmInitialize (LoaderBlock, LastKernelAddress);
}
else
{
/* Phase 1 Initialization */
MmInitSectionImplementation();
MmInitPagingFile();
}
}
/* Miscellanea functions: they may fit somewhere else */
DWORD

View file

@ -0,0 +1,229 @@
/* $Id: mminit.c,v 1.1 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/mminit.c
* PURPOSE: kernel memory managment initialization functions
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 9/4/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/hal/io.h>
#include <internal/i386/segment.h>
#include <internal/stddef.h>
#include <internal/mm.h>
#include <string.h>
#include <internal/string.h>
#include <internal/ntoskrnl.h>
#include <internal/bitops.h>
#include <internal/string.h>
#include <internal/io.h>
#include <internal/ps.h>
#include <internal/mmhal.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *****************************************************************/
/*
* Size of extended memory (kb) (fixed for now)
*/
#define EXTENDED_MEMORY_SIZE (3*1024*1024)
/*
* Compiler defined symbol s
*/
extern unsigned int stext;
extern unsigned int etext;
extern unsigned int end;
static BOOLEAN IsThisAnNtAsSystem = FALSE;
static MM_SYSTEM_SIZE MmSystemSize = MmSmallSystem;
extern unsigned int etext;
extern unsigned int _bss_end__;
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 ****************************************************************/
BOOLEAN STDCALL MmIsThisAnNtAsSystem(VOID)
{
return(IsThisAnNtAsSystem);
}
MM_SYSTEM_SIZE STDCALL MmQuerySystemSize(VOID)
{
return(MmSystemSize);
}
VOID MiShutdownMemoryManager(VOID)
{
}
VOID MmInitVirtualMemory(boot_param* bp, ULONG LastKernelAddress)
/*
* FUNCTION: Intialize the memory areas list
* ARGUMENTS:
* bp = Pointer to the boot parameters
* kernel_len = Length of the kernel
*/
{
unsigned int kernel_len = bp->end_mem - bp->start_mem;
PVOID BaseAddress;
ULONG Length;
ULONG ParamLength = kernel_len;
DPRINT("MmInitVirtualMemory(%x)\n",bp);
LastKernelAddress = PAGE_ROUND_UP(LastKernelAddress);
MmInitMemoryAreas();
// ExInitNonPagedPool(KERNEL_BASE + PAGE_ROUND_UP(kernel_len) + PAGESIZE);
ExInitNonPagedPool(LastKernelAddress + PAGESIZE);
/*
* Setup the system area descriptor list
*/
BaseAddress = (PVOID)KERNEL_BASE;
Length = PAGE_ROUND_UP(((ULONG)&etext)) - KERNEL_BASE;
ParamLength = ParamLength - Length;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_text_desc);
Length = PAGE_ROUND_UP(((ULONG)&_bss_end__)) -
PAGE_ROUND_UP(((ULONG)&etext));
ParamLength = ParamLength - Length;
DPRINT("Length %x\n",Length);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&etext));
DPRINT("BaseAddress %x\n",BaseAddress);
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_data_desc);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG)&end));
// Length = ParamLength;
Length = LastKernelAddress - (ULONG)BaseAddress;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_param_desc);
BaseAddress = (PVOID)(LastKernelAddress + PAGESIZE);
Length = NONPAGED_POOL_SIZE;
MmCreateMemoryArea(NULL,
MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
0,
&kernel_pool_desc);
// MmDumpMemoryAreas();
DPRINT("MmInitVirtualMemory() done\n");
}
VOID MmInit1(PLOADER_PARAMETER_BLOCK bp, ULONG LastKernelAddress)
/*
* FUNCTION: Initalize memory managment
*/
{
ULONG first_krnl_phys_addr;
ULONG last_krnl_phys_addr;
ULONG i;
ULONG kernel_len;
DPRINT("MmInit1(bp %x, LastKernelAddress %x)\n", bp,
LastKernelAddress);
MmInitializeKernelAddressSpace();
/*
* Unmap low memory
*/
MmDeletePageTable(NULL, 0);
/*
* Free all pages not used for kernel memory
* (we assume the kernel occupies a continuous range of physical
* memory)
*/
first_krnl_phys_addr = bp->start_mem;
last_krnl_phys_addr = bp->end_mem;
DPRINT("first krnl %x\nlast krnl %x\n",first_krnl_phys_addr,
last_krnl_phys_addr);
/*
* Free physical memory not used by the kernel
*/
LastKernelAddress = (ULONG)MmInitializePageList(
(PVOID)first_krnl_phys_addr,
(PVOID)last_krnl_phys_addr,
1024,
PAGE_ROUND_UP(LastKernelAddress));
kernel_len = last_krnl_phys_addr - first_krnl_phys_addr;
/*
* Create a trap for null pointer references and protect text
* segment
*/
CHECKPOINT;
DPRINT("stext %x etext %x\n",(int)&stext,(int)&etext);
for (i=PAGE_ROUND_UP(((int)&stext));
i<PAGE_ROUND_DOWN(((int)&etext));i=i+PAGESIZE)
{
MmSetPageProtect(NULL,
(PVOID)i,
PAGE_EXECUTE_READ);
}
DPRINT("Invalidating between %x and %x\n",
LastKernelAddress,
KERNEL_BASE + PAGE_TABLE_SIZE);
for (i=(LastKernelAddress);
i<(KERNEL_BASE + PAGE_TABLE_SIZE);
i=i+PAGESIZE)
{
MmSetPage(NULL, (PVOID)(i), PAGE_NOACCESS, 0);
}
DPRINT("Almost done MmInit()\n");
/*
* Intialize memory areas
*/
MmInitVirtualMemory(bp, LastKernelAddress);
}
VOID MmInit2(VOID)
{
MmInitSectionImplementation();
MmInitPagingFile();
}
VOID MmInit3(VOID)
{
MmInitPagerThread();
/* FIXME: Read parameters from memory */
}

108
reactos/ntoskrnl/mm/mpw.c Normal file
View file

@ -0,0 +1,108 @@
/* $Id: mpw.c,v 1.1 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/pager.c
* PURPOSE: Writes data that has been modified in memory but not on
* the disk
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* 27/05/98: Created
*/
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <internal/mm.h>
#include <internal/mmhal.h>
#include <string.h>
#include <internal/string.h>
#define NDEBUG
#include <internal/debug.h>
/* GLOBALS *******************************************************************/
static HANDLE MpwThreadHandle;
static CLIENT_ID MpwThreadId;
static KEVENT MpwThreadEvent;
static PEPROCESS LastProcess;
static volatile BOOLEAN MpwThreadShouldTerminate;
static KEVENT MpwWroteOne;
static ULONG MmDirtyPagesInMemory;
/* FUNCTIONS *****************************************************************/
BOOLEAN MmShouldIWrite(BOOLEAN Wait)
{
if ((MmDirtyPagesInMemory*3) >
}
VOID MmTryPageOutFromProcess(PEPROCESS Process)
{
MmLockAddressSpace(&Process->Pcb.AddressSpace);
PageCount = PageCout - MmTrimWorkingSet(Process);
MmUnlockAddressSpace(&Process->Pcb.AddressSpace);
}
NTSTATUS MmPagerThreadMain(PVOID Ignored)
{
NTSTATUS Status;
for(;;)
{
Status = KeWaitForSingleObject(&PagerThreadEvent,
0,
KernelMode,
FALSE,
NULL);
if (!NT_SUCCESS(Status))
{
DbgPrint("PagerThread: Wait failed\n");
KeBugCheck(0);
}
if (PagerThreadShouldTerminate)
{
DbgPrint("PagerThread: Terminating\n");
return(STATUS_SUCCESS);
}
while (PageCount > 0)
{
KeAttachProcess(LastProcess);
MmTryPageOutFromProcess(LastProcess);
KeDetachProcess();
if (PageCount != 0)
{
LastProcess = PsGetNextProcess(LastProcess);
}
}
}
}
NTSTATUS MmInitPagerThread(VOID)
{
NTSTATUS Status;
PageCount = 0;
LastProcess = PsInitialSystemProcess;
PagerThreadShouldTerminate = FALSE;
KeInitializeEvent(&PagerThreadEvent,
SynchronizationEvent,
FALSE);
Status = PsCreateSystemThread(&PagerThreadHandle,
THREAD_ALL_ACCESS,
NULL,
NULL,
&PagerThreadId,
MmPagerThreadMain,
NULL);
if (!NT_SUCCESS(Status))
{
return(Status);
}
return(STATUS_SUCCESS);
}

View file

@ -1,4 +1,4 @@
/* $Id: ncache.c,v 1.4 2000/03/29 13:11:54 dwelch Exp $
/* $Id: ncache.c,v 1.5 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -13,6 +13,7 @@
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>
@ -67,7 +68,7 @@ PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
MmSetPage (NULL,
(Result + (i * PAGESIZE)),
PAGE_READWRITE,
(ULONG)MmAllocPage());
(ULONG)MmAllocPage(0));
}
return ((PVOID)Result);
}
@ -102,7 +103,7 @@ PVOID STDCALL MmAllocateNonCachedMemory(IN ULONG NumberOfBytes)
VOID STDCALL MmFreeNonCachedMemory (IN PVOID BaseAddress,
IN ULONG NumberOfBytes)
{
MmFreeMemoryArea (&PsGetCurrentProcess()->Pcb.AddressSpace,
MmFreeMemoryArea (&PsGetCurrentProcess()->AddressSpace,
BaseAddress,
NumberOfBytes,
TRUE);

View file

@ -1,4 +1,4 @@
/* $Id: npool.c,v 1.29 2000/06/25 03:59:15 dwelch Exp $
/* $Id: npool.c,v 1.30 2000/07/04 08:52:42 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -74,15 +74,6 @@ static block_hdr* used_list_head = NULL;
static ULONG nr_free_blocks;
ULONG EiNrUsedBlocks = 0;
#define ALLOC_MAP_SIZE (NONPAGED_POOL_SIZE / PAGESIZE)
/*
* One bit for each page in the kmalloc region
* If set then the page is used by a kmalloc block
*/
static unsigned int alloc_map[ALLOC_MAP_SIZE/32]={0,};
static KSPIN_LOCK AllocMapLock;
static KSPIN_LOCK MmNpoolLock;
unsigned int EiFreeNonPagedPool = 0;
@ -90,56 +81,11 @@ unsigned int EiUsedNonPagedPool = 0;
/* FUNCTIONS ***************************************************************/
VOID ExUnmapPage(PVOID Addr)
{
KIRQL oldIrql;
ULONG i = ((ULONG)Addr - kernel_pool_base) / PAGESIZE;
DPRINT("ExUnmapPage(Addr %x)\n",Addr);
DPRINT("i %x\n",i);
KeAcquireSpinLock(&AllocMapLock, &oldIrql);
MmSetPage(NULL, (PVOID)Addr, 0, 0);
clear_bit(i%32, &alloc_map[i/32]);
KeReleaseSpinLock(&AllocMapLock, oldIrql);
}
PVOID ExAllocatePage(VOID)
{
KIRQL oldlvl;
ULONG addr;
ULONG i;
ULONG PhysPage;
PhysPage = (ULONG)MmAllocPage();
DPRINT("Allocated page %x\n",PhysPage);
if (PhysPage == 0)
{
return(NULL);
}
KeAcquireSpinLock(&AllocMapLock, &oldlvl);
for (i=1; i<ALLOC_MAP_SIZE;i++)
{
if (!test_bit(i%32,&alloc_map[i/32]))
{
DPRINT("i %x\n",i);
set_bit(i%32,&alloc_map[i/32]);
addr = kernel_pool_base + (i*PAGESIZE);
MmSetPage(NULL, (PVOID)addr, PAGE_READWRITE, PhysPage);
KeReleaseSpinLock(&AllocMapLock, oldlvl);
return((PVOID)addr);
}
}
KeReleaseSpinLock(&AllocMapLock, oldlvl);
return(NULL);
}
VOID ExInitNonPagedPool(ULONG BaseAddress)
{
kernel_pool_base = BaseAddress;
KeInitializeSpinLock(&AllocMapLock);
KeInitializeSpinLock(&MmNpoolLock);
MmInitKernelMap((PVOID)BaseAddress);
}
#if 0
@ -416,54 +362,6 @@ inline static block_hdr* address_to_block(void* addr)
( ((int)addr) - sizeof(block_hdr) );
}
static unsigned int alloc_pool_region(unsigned int nr_pages)
/*
* FUNCTION: Allocates a region of pages within the nonpaged pool area
*/
{
unsigned int start = 0;
unsigned int length = 0;
unsigned int i,j;
OLD_DPRINT("alloc_pool_region(nr_pages = %d)\n",nr_pages);
for (i=1; i<ALLOC_MAP_SIZE;i++)
{
if (!test_bit(i%32,&alloc_map[i/32]))
{
if (length == 0)
{
start=i;
length = 1;
}
else
{
length++;
}
if (length==nr_pages)
{
OLD_DPRINT("found region at %d for %d\n",start,
length);
for (j=start;j<(start+length);j++)
{
set_bit(j%32,&alloc_map[j/32]);
}
OLD_DPRINT("returning %x\n",(start*PAGESIZE)
+kernel_pool_base);
return((start*PAGESIZE)+kernel_pool_base);
}
}
else
{
start=0;
length=0;
}
}
DbgPrint("CRITICAL: Out of non-paged pool space\n");
for(;;);
return(0);
}
static block_hdr* grow_kernel_pool(unsigned int size)
/*
* FUNCTION: Grow the executive heap to accomodate a block of at least 'size'
@ -485,7 +383,7 @@ static block_hdr* grow_kernel_pool(unsigned int size)
MmSetPage(NULL,
(PVOID)(start + (i*PAGESIZE)),
PAGE_READWRITE,
(ULONG)MmAllocPage());
(ULONG)MmAllocPage(0));
}

View file

@ -1,4 +1,4 @@
/* $Id: pagefile.c,v 1.4 2000/05/13 13:51:05 dwelch Exp $
/* $Id: pagefile.c,v 1.5 2000/07/04 08:52:45 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -14,14 +14,13 @@
#include <ddk/ntddk.h>
#include <internal/bitops.h>
#include <internal/io.h>
#include <internal/mm.h>
#include <napi/core.h>
#include <internal/debug.h>
/* TYPES *********************************************************************/
typedef ULONG SWAPENTRY;
typedef struct _PPAGINGFILE
{
LIST_ENTRY PagingFileListEntry;
@ -46,6 +45,9 @@ static ULONG MiFreeSwapPages;
static ULONG MiUsedSwapPages;
static ULONG MiReservedSwapPages;
#define MM_PAGEFILE_COMMIT_RATIO (1)
#define MM_PAGEFILE_COMMIT_GRACE (256)
#if 0
static PVOID MmCoreDumpPageFrame;
static BYTE MmCoreDumpHeader[PAGESIZE];
@ -55,11 +57,18 @@ static BYTE MmCoreDumpHeader[PAGESIZE];
VOID MmInitPagingFile(VOID)
{
ULONG i;
KeInitializeSpinLock(&PagingFileListLock);
MiFreeSwapPages = 0;
MiUsedSwapPages = 0;
MiReservedSwapPages = 0;
for (i = 0; i < MAX_PAGING_FILES; i++)
{
PagingFileList[i] = NULL;
}
}
VOID MmReserveSwapPages(ULONG Nr)
@ -68,7 +77,7 @@ VOID MmReserveSwapPages(ULONG Nr)
KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
MiReservedSwapPages = MiReservedSwapPages + Nr;
MiFreeSwapPages = MiFreeSwapPages - Nr;
// MiFreeSwapPages = MiFreeSwapPages - Nr;
KeReleaseSpinLock(&PagingFileListLock, oldIrql);
}
@ -78,7 +87,7 @@ VOID MmDereserveSwapPages(ULONG Nr)
KeAcquireSpinLock(&PagingFileListLock, &oldIrql);
MiReservedSwapPages = MiReservedSwapPages - Nr;
MiFreeSwapPages = MiFreeSwapPages - Nr;
// MiFreeSwapPages = MiFreeSwapPages - Nr;
KeReleaseSpinLock(&PagingFileListLock, oldIrql);
}

View file

@ -1,4 +1,4 @@
/* $Id: pager.c,v 1.1 2000/06/25 03:59:15 dwelch Exp $
/* $Id: pager.c,v 1.2 2000/07/04 08:52:45 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -26,109 +26,23 @@
static HANDLE PagerThreadHandle;
static CLIENT_ID PagerThreadId;
static KEVENT PagerThreadEvent;
static PVOID LastAddress;
static PEPROCESS LastProcess;
static BOOLEAN PagerThreadShouldTerminate;
static volatile BOOLEAN PagerThreadShouldTerminate;
static volatile ULONG PageCount;
/* FUNCTIONS *****************************************************************/
VOID MmPageOutPage(PEPROCESS Process,
PMEMORY_AREA marea,
PVOID Address)
{
ULONG Count;
Count = 0;
switch(marea->Type)
{
case MEMORY_AREA_SYSTEM:
break;
case MEMORY_AREA_SECTION_VIEW_COMMIT:
Count = MmPageOutSectionView(&Process->Pcb.AddressSpace,
marea,
Address);
break;
case MEMORY_AREA_COMMIT:
Count = MmPageOutVirtualMemory(&Process->Pcb.AddressSpace,
marea,
Address);
break;
default:
break;
}
PageCount = PageCount - Count;
}
VOID MmTryPageOutFromArea(PEPROCESS Process,
PMEMORY_AREA marea)
{
ULONG i;
ULONG j;
for (i = 0; i < marea->Length; i = i + 0x400000)
{
if (MmIsPageTablePresent(marea->BaseAddress + i))
{
for (j = 0; j < marea->Length; j = j + 4096)
{
if (MmIsPagePresent(NULL, marea->BaseAddress + i + j))
{
MmPageOutPage(Process,
marea,
marea->BaseAddress + i + j);
if (PageCount == 0)
{
return;
}
}
}
}
}
}
VOID MmTryPageOutFromProcess(PEPROCESS Process)
{
PMEMORY_AREA marea;
MmLockAddressSpace(&Process->Pcb.AddressSpace);
while ((ULONG)LastAddress < 0xc0000000)
{
marea = MmOpenMemoryAreaByRegion(&Process->Pcb.AddressSpace,
LastAddress,
0xc0000000 - (ULONG)LastAddress);
if (marea == NULL)
{
return;
}
MmTryPageOutFromArea(Process,
marea);
LastAddress = LastAddress + marea->Length;
if (PageCount == 0)
{
MmUnlockAddressSpace(&Process->Pcb.AddressSpace);
return;
}
}
MmUnlockAddressSpace(&Process->Pcb.AddressSpace);
MmLockAddressSpace(&Process->AddressSpace);
PageCount = PageCount - MmTrimWorkingSet(Process, PageCount);
MmUnlockAddressSpace(&Process->AddressSpace);
}
NTSTATUS MmPagerThreadMain(PVOID Ignored)
{
NTSTATUS Status;
PageCount = 0;
LastAddress = 0;
LastProcess = PsInitialSystemProcess;
PagerThreadShouldTerminate = FALSE;
KeInitializeEvent(&PagerThreadEvent,
SynchronizationEvent,
FALSE);
for(;;)
{
Status = KeWaitForSingleObject(&PagerThreadEvent,
@ -155,16 +69,22 @@ NTSTATUS MmPagerThreadMain(PVOID Ignored)
if (PageCount != 0)
{
LastProcess = PsGetNextProcess(LastProcess);
LastAddress = 0;
}
}
}
}
NTSTATUS MmInitPager(VOID)
NTSTATUS MmInitPagerThread(VOID)
{
NTSTATUS Status;
PageCount = 0;
LastProcess = PsInitialSystemProcess;
PagerThreadShouldTerminate = FALSE;
KeInitializeEvent(&PagerThreadEvent,
SynchronizationEvent,
FALSE);
Status = PsCreateSystemThread(&PagerThreadHandle,
THREAD_ALL_ACCESS,
NULL,

View file

@ -1,5 +1,6 @@
/* $Id: pagfault.c,v 1.1 2000/04/02 13:32:41 ea Exp $ */
/* $Id: pagfault.c,v 1.2 2000/07/04 08:52:45 dwelch Exp $ */
#include <ddk/ntddk.h>
#include <internal/ps.h>
BOOLEAN
STDCALL

View file

@ -1,4 +1,4 @@
/* $Id: section.c,v 1.34 2000/06/29 23:35:41 dwelch Exp $
/* $Id: section.c,v 1.35 2000/07/04 08:52:45 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -817,7 +817,7 @@ NTSTATUS STDCALL NtMapViewOfSection(HANDLE SectionHandle,
return Status;
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
DPRINT("Process %x\n", Process);
DPRINT("ViewSize %x\n",ViewSize);
@ -839,7 +839,7 @@ NTSTATUS STDCALL NtMapViewOfSection(HANDLE SectionHandle,
DPRINT("Creating memory area\n");
MmLockAddressSpace(AddressSpace);
Status = MmCreateMemoryArea(Process,
&Process->Pcb.AddressSpace,
&Process->AddressSpace,
MEMORY_AREA_SECTION_VIEW_COMMIT,
BaseAddress,
*ViewSize,
@ -939,7 +939,7 @@ NTSTATUS STDCALL NtUnmapViewOfSection (HANDLE ProcessHandle,
return(Status);
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
DPRINT("Opening memory area Process %x BaseAddress %x\n",
Process, BaseAddress);
@ -957,7 +957,7 @@ NTSTATUS STDCALL NtUnmapViewOfSection (HANDLE ProcessHandle,
MemoryArea);
DPRINT("MmFreeMemoryArea()\n");
Status = MmFreeMemoryArea(&Process->Pcb.AddressSpace,
Status = MmFreeMemoryArea(&Process->AddressSpace,
BaseAddress,
0,
TRUE);
@ -1034,17 +1034,17 @@ PVOID STDCALL MmAllocateSection (IN ULONG Length)
Length,
0,
&marea);
if (STATUS_SUCCESS != Status)
if (!NT_SUCCESS(STATUS_SUCCESS))
{
return (NULL);
}
}
DPRINT("Result %p\n",Result);
for (i = 0; (i <= (Length / PAGESIZE)); i++)
{
MmSetPage (NULL,
(Result + (i * PAGESIZE)),
PAGE_READWRITE,
(ULONG) MmAllocPage ());
(ULONG)MmAllocPage(0));
}
MmUnlockAddressSpace(AddressSpace);
return ((PVOID)Result);

View file

@ -1,4 +1,4 @@
/* $Id: virtual.c,v 1.29 2000/06/25 03:59:16 dwelch Exp $
/* $Id: virtual.c,v 1.30 2000/07/04 08:52:45 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top directory
* PROJECT: ReactOS kernel
@ -62,99 +62,11 @@ NTSTATUS MmNotPresentFaultVirtualMemory(PMADDRESS_SPACE AddressSpace,
MmSetPage(PsGetCurrentProcess(),
Address,
MemoryArea->Attributes,
(ULONG)MmAllocPage());
(ULONG)MmAllocPage(0));
return(STATUS_SUCCESS);
}
NTSTATUS MmReleaseMemoryArea(PEPROCESS Process, PMEMORY_AREA Marea)
{
PVOID i;
DPRINT("MmReleaseMemoryArea(Process %x, Marea %x)\n",Process,Marea);
DPRINT("Releasing %x between %x %x\n",
Marea, Marea->BaseAddress, Marea->BaseAddress + Marea->Length);
if (Marea->Type == MEMORY_AREA_SECTION_VIEW_COMMIT ||
Marea->Type == MEMORY_AREA_SECTION_VIEW_RESERVE)
{
MmUnmapViewOfSection(Process, Marea);
}
for (i = Marea->BaseAddress;
i < (Marea->BaseAddress + Marea->Length);
i = i+PAGESIZE)
{
MmDeletePageEntry(Process, i, TRUE);
}
ExFreePool(Marea);
return(STATUS_SUCCESS);
}
NTSTATUS MmReleaseMmInfo(PEPROCESS Process)
{
PLIST_ENTRY CurrentEntry;
PMEMORY_AREA Current;
DPRINT("MmReleaseMmInfo(Process %x)\n",Process);
MmLockAddressSpace(&Process->Pcb.AddressSpace);
while (!IsListEmpty(&Process->Pcb.AddressSpace.MAreaListHead))
{
CurrentEntry = RemoveHeadList(
&Process->Pcb.AddressSpace.MAreaListHead);
Current = CONTAINING_RECORD(CurrentEntry, MEMORY_AREA, Entry);
MmReleaseMemoryArea(Process, Current);
}
Mmi386ReleaseMmInfo(Process);
MmUnlockAddressSpace(&Process->Pcb.AddressSpace);
DPRINT("Finished MmReleaseMmInfo()\n");
return(STATUS_SUCCESS);
}
BOOLEAN STDCALL MmIsNonPagedSystemAddressValid(PVOID VirtualAddress)
{
UNIMPLEMENTED;
}
BOOLEAN STDCALL MmIsAddressValid(PVOID VirtualAddress)
/*
* FUNCTION: Checks whether the given address is valid for a read or write
* ARGUMENTS:
* VirtualAddress = address to check
* RETURNS: True if the access would be valid
* False if the access would cause a page fault
* NOTES: This function checks whether a byte access to the page would
* succeed. Is this realistic for RISC processors which don't
* allow byte granular access?
*/
{
MEMORY_AREA* MemoryArea;
PMADDRESS_SPACE AddressSpace;
AddressSpace = &PsGetCurrentProcess()->Pcb.AddressSpace;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
VirtualAddress);
if (MemoryArea == NULL)
{
MmUnlockAddressSpace(AddressSpace);
return(FALSE);
}
MmUnlockAddressSpace(AddressSpace);
return(TRUE);
}
NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
IN OUT PVOID * BaseAddress,
IN ULONG ZeroBits,
@ -222,12 +134,12 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
Type = MEMORY_AREA_COMMIT;
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace);
if ((*BaseAddress) != 0)
{
MemoryArea = MmOpenMemoryAreaByAddress(&Process->Pcb.AddressSpace,
MemoryArea = MmOpenMemoryAreaByAddress(&Process->AddressSpace,
*BaseAddress);
if (MemoryArea != NULL)
@ -244,24 +156,22 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
}
MemoryArea = MmSplitMemoryArea(Process,
&Process->Pcb.AddressSpace,
&Process->AddressSpace,
MemoryArea,
*BaseAddress,
*RegionSize,
Type,
Protect);
DPRINT("*BaseAddress %x\n",*BaseAddress);
/* FIXME: Reserve/dereserve swap pages */
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);
}
}
// FIXME RegionSize should be passed as pointer
// dwelch: Why?
Status = MmCreateMemoryArea(Process,
&Process->Pcb.AddressSpace,
&Process->AddressSpace,
Type,
BaseAddress,
*RegionSize,
@ -277,6 +187,12 @@ NTSTATUS STDCALL NtAllocateVirtualMemory(IN HANDLE ProcessHandle,
}
DPRINT("*BaseAddress %x\n",*BaseAddress);
if ((AllocationType & MEM_COMMIT) &&
((Protect & PAGE_READWRITE) ||
(Protect & PAGE_EXECUTE_READWRITE)))
{
MmReserveSwapPages(PAGE_ROUND_UP((*RegionSize)));
}
MmUnlockAddressSpace(AddressSpace);
ObDereferenceObject(Process);
return(STATUS_SUCCESS);
@ -340,7 +256,7 @@ NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle,
return(Status);
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
@ -361,7 +277,13 @@ NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle,
ObDereferenceObject(Process);
return(STATUS_UNSUCCESSFUL);
}
MmFreeMemoryArea(&Process->Pcb.AddressSpace,
if ((MemoryArea->Type == MEMORY_AREA_COMMIT) &&
((MemoryArea->Attributes & PAGE_READWRITE) ||
(MemoryArea->Attributes & PAGE_EXECUTE_READWRITE)))
{
MmDereserveSwapPages(PAGE_ROUND_UP(MemoryArea->Length));
}
MmFreeMemoryArea(&Process->AddressSpace,
BaseAddress,
0,
TRUE);
@ -370,8 +292,14 @@ NTSTATUS STDCALL NtFreeVirtualMemory(IN HANDLE ProcessHandle,
return(STATUS_SUCCESS);
case MEM_DECOMMIT:
if ((MemoryArea->Type == MEMORY_AREA_COMMIT) &&
((MemoryArea->Attributes & PAGE_READWRITE) ||
(MemoryArea->Attributes & PAGE_EXECUTE_READWRITE)))
{
MmDereserveSwapPages(PAGE_ROUND_UP((*RegionSize)));
}
MmSplitMemoryArea(Process,
&Process->Pcb.AddressSpace,
&Process->AddressSpace,
MemoryArea,
*BaseAddress,
*RegionSize,
@ -438,7 +366,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
return(Status);
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
@ -461,7 +389,7 @@ NTSTATUS STDCALL NtProtectVirtualMemory(IN HANDLE ProcessHandle,
else
{
MemoryArea = MmSplitMemoryArea(Process,
&Process->Pcb.AddressSpace,
&Process->AddressSpace,
MemoryArea,
BaseAddress,
NumberOfBytesToProtect,
@ -527,7 +455,7 @@ NTSTATUS STDCALL NtQueryVirtualMemory (IN HANDLE ProcessHandle,
return(Status);
}
AddressSpace = &Process->Pcb.AddressSpace;
AddressSpace = &Process->AddressSpace;
MmLockAddressSpace(AddressSpace);
MemoryArea = MmOpenMemoryAreaByAddress(AddressSpace,
Address);

164
reactos/ntoskrnl/mm/wset.c Normal file
View file

@ -0,0 +1,164 @@
/* $Id: wset.c,v 1.1 2000/07/04 08:52:45 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: ntoskrnl/mm/wset.c
* PURPOSE: Manages working sets
* PROGRAMMER: David Welch (welch@cwcom.net)
* UPDATE HISTORY:
* Created 22/05/98
*/
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/mm.h>
#include <internal/ps.h>
#include <internal/debug.h>
/* FUNCTIONS *****************************************************************/
VOID MmLockWorkingSet(PEPROCESS Process)
{
(VOID)KeWaitForMutexObject(&Process->WorkingSetLock,
0,
KernelMode,
FALSE,
NULL);
}
VOID MmUnlockWorkingSet(PEPROCESS Process)
{
KeReleaseMutex(&Process->WorkingSetLock, FALSE);
}
VOID MmInitializeWorkingSet(PEPROCESS Process,
PMADDRESS_SPACE AddressSpace)
{
AddressSpace->WorkingSetSize = 0;
AddressSpace->WorkingSetLruFirst = 0;
AddressSpace->WorkingSetLruLast = 0;
AddressSpace->WorkingSetPagesAllocated = 1;
KeInitializeMutex(&Process->WorkingSetLock, 1);
Process->WorkingSetPage = ExAllocatePage();
}
ULONG MmTrimWorkingSet(PEPROCESS Process,
ULONG ReduceHint)
{
ULONG i;
PMADDRESS_SPACE AddressSpace;
PMWORKING_SET WSet;
ULONG Count;
MmLockWorkingSet(Process);
WSet = (PMWORKING_SET)Process->WorkingSetPage;
AddressSpace = &Process->AddressSpace;
Count = 0;
for (i = 0; i < AddressSpace->WorkingSetSize; i++)
{
PVOID Address;
PMEMORY_AREA MArea;
Address = WSet->Address[AddressSpace->WorkingSetLruFirst];
MArea = MmOpenMemoryAreaByAddress(AddressSpace, Address);
switch(MArea->Type)
{
case MEMORY_AREA_SYSTEM:
break;
case MEMORY_AREA_SECTION_VIEW_COMMIT:
Count = Count + MmPageOutSectionView(AddressSpace,
MArea,
Address);
break;
case MEMORY_AREA_COMMIT:
Count = Count + MmPageOutVirtualMemory(AddressSpace,
MArea,
Address);
break;
default:
break;
}
AddressSpace->WorkingSetLruFirst =
((AddressSpace->WorkingSetLruFirst) + 1) % 1020;
if (Count == ReduceHint)
{
MmUnlockWorkingSet(Process);
return(Count);
}
}
MmUnlockWorkingSet(Process);
return(Count);
}
VOID MmRemovePageFromWorkingSet(PEPROCESS Process,
PVOID Address)
{
ULONG i;
PMADDRESS_SPACE AddressSpace;
PMWORKING_SET WSet;
ULONG j;
WSet = (PMWORKING_SET)Process->WorkingSetPage;
AddressSpace = &Process->AddressSpace;
j = AddressSpace->WorkingSetLruFirst;
for (i = 0; i < AddressSpace->WorkingSetSize; i++)
{
if (WSet->Address[j] == Address)
{
WSet->Address[j] = WSet->Address[AddressSpace->WorkingSetLruLast];
if (AddressSpace->WorkingSetLruLast != 0)
{
AddressSpace->WorkingSetLruLast =
AddressSpace->WorkingSetLruLast --;
}
else
{
AddressSpace->WorkingSetLruLast = 1020;
}
return;
}
j = (j + 1) % 1020;
}
KeBugCheck(0);
}
BOOLEAN MmAddPageToWorkingSet(PEPROCESS Process,
PVOID Address)
{
PMWORKING_SET WSet;
PMADDRESS_SPACE AddressSpace;
AddressSpace = &Process->AddressSpace;
if (((AddressSpace->WorkingSetLruLast + 1) % 1020) ==
AddressSpace->WorkingSetLruFirst)
{
return(FALSE);
}
WSet = (PMWORKING_SET)Process->WorkingSetPage;
WSet->Address[AddressSpace->WorkingSetLruLast] = Address;
AddressSpace->WorkingSetLruLast =
(AddressSpace->WorkingSetLruLast + 1) % 1024;
AddressSpace->WorkingSetSize++;
return(TRUE);
}

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.81 2000/07/04 01:27:40 ekohl Exp $
; $Id: ntoskrnl.def,v 1.82 2000/07/04 08:52:36 dwelch Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -415,7 +415,6 @@ KeSynchronizeExecution@12
;KeTerminateThread
;KeTickCount DATA
;KeUpdateRunTime
KeUpdateSystemTime@0
;KeUserModeCallback
KeWaitForMultipleObjects@32
KeWaitForMutexObject@20

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.68 2000/07/04 01:27:40 ekohl Exp $
; $Id: ntoskrnl.edf,v 1.69 2000/07/04 08:52:36 dwelch Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -415,7 +415,6 @@ KeSynchronizeExecution=KeSynchronizeExecution@12
;KeTerminateThread
;KeTickCount DATA
;KeUpdateRunTime
KeUpdateSystemTime=KeUpdateSystemTime@0
;KeUserModeCallback
KeWaitForMultipleObjects=KeWaitForMultipleObjects@32
KeWaitForMutexObject=KeWaitForMutexObject@20

View file

@ -1,4 +1,4 @@
/* $Id: handle.c,v 1.22 2000/05/27 12:48:59 dwelch Exp $
/* $Id: handle.c,v 1.23 2000/07/04 08:52:46 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -124,12 +124,12 @@ NTSTATUS STDCALL NtDuplicateObject (IN HANDLE SourceProcessHandle,
(PVOID*)&TargetProcess,
NULL);
KeAcquireSpinLock(&SourceProcess->Pcb.HandleTable.ListLock, &oldIrql);
SourceHandleRep = ObpGetObjectByHandle(&SourceProcess->Pcb.HandleTable,
KeAcquireSpinLock(&SourceProcess->HandleTable.ListLock, &oldIrql);
SourceHandleRep = ObpGetObjectByHandle(&SourceProcess->HandleTable,
*SourceHandle);
if (SourceHandleRep == NULL)
{
KeReleaseSpinLock(&SourceProcess->Pcb.HandleTable.ListLock, oldIrql);
KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql);
ObDereferenceObject(SourceProcess);
ObDereferenceObject(TargetProcess);
return(STATUS_INVALID_HANDLE);
@ -145,7 +145,7 @@ NTSTATUS STDCALL NtDuplicateObject (IN HANDLE SourceProcessHandle,
DesiredAccess = SourceHandleRep->GrantedAccess;
}
KeReleaseSpinLock(&SourceProcess->Pcb.HandleTable.ListLock, oldIrql);
KeReleaseSpinLock(&SourceProcess->HandleTable.ListLock, oldIrql);
ObCreateHandle(TargetProcess,
ObjectBody,
@ -176,7 +176,7 @@ VOID ObCloseAllHandles(PEPROCESS Process)
DPRINT("ObCloseAllHandles(Process %x)\n", Process);
HandleTable = &Process->Pcb.HandleTable;
HandleTable = &Process->HandleTable;
KeAcquireSpinLock(&HandleTable->ListLock, &oldIrql);
@ -240,7 +240,7 @@ VOID ObDeleteHandleTable(PEPROCESS Process)
ObCloseAllHandles(Process);
HandleTable = &Process->Pcb.HandleTable;
HandleTable = &Process->HandleTable;
current = RemoveHeadList(&HandleTable->ListHead);
while (current != &HandleTable->ListHead)
@ -275,14 +275,14 @@ VOID ObCreateHandleTable(PEPROCESS Parent,
DPRINT("ObCreateHandleTable(Parent %x, Inherit %d, Process %x)\n",
Parent,Inherit,Process);
InitializeListHead(&(Process->Pcb.HandleTable.ListHead));
KeInitializeSpinLock(&(Process->Pcb.HandleTable.ListLock));
InitializeListHead(&(Process->HandleTable.ListHead));
KeInitializeSpinLock(&(Process->HandleTable.ListLock));
if (Parent != NULL)
{
ParentHandleTable = &Parent->Pcb.HandleTable;
ParentHandleTable = &Parent->HandleTable;
KeAcquireSpinLock(&Parent->Pcb.HandleTable.ListLock, &oldIrql);
KeAcquireSpinLock(&Parent->HandleTable.ListLock, &oldIrql);
parent_current = ParentHandleTable->ListHead.Flink;
@ -316,7 +316,7 @@ VOID ObCreateHandleTable(PEPROCESS Parent,
parent_current = parent_current->Flink;
}
KeReleaseSpinLock(&Parent->Pcb.HandleTable.ListLock, oldIrql);
KeReleaseSpinLock(&Parent->HandleTable.ListLock, oldIrql);
}
}
@ -331,7 +331,7 @@ PVOID ObDeleteHandle(PEPROCESS Process, HANDLE Handle)
DPRINT("ObDeleteHandle(Handle %x)\n",Handle);
HandleTable = &Process->Pcb.HandleTable;
HandleTable = &Process->HandleTable;
KeAcquireSpinLock(&HandleTable->ListLock, &oldIrql);
@ -399,7 +399,7 @@ NTSTATUS ObCreateHandle(PEPROCESS Process,
BODY_TO_HEADER(ObjectBody)->HandleCount++;
}
HandleTable = &Process->Pcb.HandleTable;
HandleTable = &Process->HandleTable;
KeAcquireSpinLock(&HandleTable->ListLock, &oldlvl);
current = HandleTable->ListHead.Flink;
@ -437,7 +437,7 @@ NTSTATUS ObCreateHandle(PEPROCESS Process,
*/
new_blk = (HANDLE_BLOCK *)ExAllocatePool(NonPagedPool,sizeof(HANDLE_BLOCK));
memset(new_blk,0,sizeof(HANDLE_BLOCK));
InsertTailList(&(Process->Pcb.HandleTable.ListHead),
InsertTailList(&(Process->HandleTable.ListHead),
&new_blk->entry);
KeReleaseSpinLock(&HandleTable->ListLock, oldlvl);
new_blk->handles[0].ObjectBody = ObjectBody;
@ -520,13 +520,13 @@ NTSTATUS STDCALL ObReferenceObjectByHandle(HANDLE Handle,
return(STATUS_OBJECT_TYPE_MISMATCH);
}
KeAcquireSpinLock(&PsGetCurrentProcess()->Pcb.HandleTable.ListLock,
KeAcquireSpinLock(&PsGetCurrentProcess()->HandleTable.ListLock,
&oldIrql);
HandleRep = ObpGetObjectByHandle(&PsGetCurrentProcess()->Pcb.HandleTable,
HandleRep = ObpGetObjectByHandle(&PsGetCurrentProcess()->HandleTable,
Handle);
if (HandleRep == NULL || HandleRep->ObjectBody == NULL)
{
KeReleaseSpinLock(&PsGetCurrentProcess()->Pcb.HandleTable.ListLock,
KeReleaseSpinLock(&PsGetCurrentProcess()->HandleTable.ListLock,
oldIrql);
return(STATUS_INVALID_HANDLE);
}
@ -536,7 +536,7 @@ NTSTATUS STDCALL ObReferenceObjectByHandle(HANDLE Handle,
NULL,
UserMode);
GrantedAccess = HandleRep->GrantedAccess;
KeReleaseSpinLock(&PsGetCurrentProcess()->Pcb.HandleTable.ListLock,
KeReleaseSpinLock(&PsGetCurrentProcess()->HandleTable.ListLock,
oldIrql);
ObjectHeader = BODY_TO_HEADER(ObjectBody);

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.18 2000/06/29 23:35:44 dwelch Exp $
/* $Id: create.c,v 1.19 2000/07/04 08:52:46 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -370,7 +370,7 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
Thread->ThreadsProcess = Process;
KeInitializeDpc(&Thread->Tcb.TimerDpc, PiTimeoutThread, Thread);
Thread->Tcb.WaitBlockList = NULL;
InsertTailList(&Thread->ThreadsProcess->Pcb.ThreadListHead,
InsertTailList(&Thread->ThreadsProcess->ThreadListHead,
&Thread->Tcb.ProcessThreadListEntry);
InitializeListHead(&Thread->TerminationPortList);
KeInitializeDispatcherHeader(&Thread->Tcb.DispatcherHeader,

View file

@ -12,6 +12,7 @@
#include <ddk/ntddk.h>
#include <internal/ke.h>
#include <internal/ps.h>
#define NDEBUG
#include <internal/debug.h>

View file

@ -96,7 +96,7 @@ VOID PsReapThreads(VOID)
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
ObDereferenceObject(current);
KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
if (IsListEmpty(&Process->Pcb.ThreadListHead))
if (IsListEmpty(&Process->ThreadListHead))
{
/*
* TODO: Optimize this so it doesnt jerk the IRQL around so
@ -160,7 +160,7 @@ VOID PsTerminateOtherThread(PETHREAD Thread, NTSTATUS ExitStatus)
Thread->Tcb.DispatcherHeader.SignalState = TRUE;
KeDispatcherObjectWake(&Thread->Tcb.DispatcherHeader);
KeReleaseSpinLock(&PiThreadListLock, oldIrql);
if (IsListEmpty(&Thread->ThreadsProcess->Pcb.ThreadListHead))
if (IsListEmpty(&Thread->ThreadsProcess->ThreadListHead))
{
DPRINT("Terminating associated process\n");
PiTerminateProcess(Thread->ThreadsProcess, ExitStatus);

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.47 2000/07/01 22:37:28 ekohl Exp $
/* $Id: process.c,v 1.48 2000/07/04 08:52:47 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -55,9 +55,9 @@ PEPROCESS PsGetNextProcess(PEPROCESS OldProcess)
}
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
NextProcess = CONTAINING_RECORD(OldProcess->Pcb.ProcessListEntry.Flink,
NextProcess = CONTAINING_RECORD(OldProcess->ProcessListEntry.Flink,
EPROCESS,
Pcb.ProcessListEntry);
ProcessListEntry);
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
Status = ObReferenceObjectByPointer(NextProcess,
PROCESS_ALL_ACCESS,
@ -137,7 +137,7 @@ VOID PiKillMostProcesses(VOID)
while (current_entry != &PsProcessListHead)
{
current = CONTAINING_RECORD(current_entry, EPROCESS,
Pcb.ProcessListEntry);
ProcessListEntry);
current_entry = current_entry->Flink;
if (current->UniqueProcessId != PsInitialSystemProcess->UniqueProcessId &&
@ -198,15 +198,16 @@ VOID PsInitProcessManagment(VOID)
KProcess = &PsInitialSystemProcess->Pcb;
MmInitializeAddressSpace(PsInitialSystemProcess,
&PsInitialSystemProcess->Pcb.AddressSpace);
&PsInitialSystemProcess->AddressSpace);
ObCreateHandleTable(NULL,FALSE,PsInitialSystemProcess);
KProcess->PageTableDirectory = get_page_directory();
PsInitialSystemProcess->UniqueProcessId =
InterlockedIncrement(&PiNextProcessUniqueId);
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
InsertHeadList(&PsProcessListHead, &KProcess->ProcessListEntry);
InitializeListHead( &KProcess->ThreadListHead );
InsertHeadList(&PsProcessListHead,
&PsInitialSystemProcess->ProcessListEntry);
InitializeListHead(&PsInitialSystemProcess->ThreadListHead);
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
strcpy(PsInitialSystemProcess->ImageFileName, "SYSTEM");
@ -225,7 +226,7 @@ VOID PiDeleteProcess(PVOID ObjectBody)
DPRINT1("PiDeleteProcess(ObjectBody %x)\n",ObjectBody);
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
RemoveEntryList(&((PEPROCESS)ObjectBody)->Pcb.ProcessListEntry);
RemoveEntryList(&((PEPROCESS)ObjectBody)->ProcessListEntry);
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
(VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
ObDeleteHandleTable((PEPROCESS)ObjectBody);
@ -373,7 +374,7 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
KProcess->BasePriority = PROCESS_PRIO_NORMAL;
MmInitializeAddressSpace(Process,
&KProcess->AddressSpace);
&Process->AddressSpace);
Process->UniqueProcessId = InterlockedIncrement(&PiNextProcessUniqueId);
Process->InheritedFromUniqueProcessId = ParentProcess->UniqueProcessId;
ObCreateHandleTable(ParentProcess,
@ -382,8 +383,8 @@ NTSTATUS STDCALL NtCreateProcess (OUT PHANDLE ProcessHandle,
MmCopyMmInfo(ParentProcess, Process);
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
InsertHeadList(&PsProcessListHead, &KProcess->ProcessListEntry);
InitializeListHead( &KProcess->ThreadListHead );
InsertHeadList(&PsProcessListHead, &Process->ProcessListEntry);
InitializeListHead(&Process->ThreadListHead);
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
Process->Pcb.ProcessState = PROCESS_STATE_ACTIVE;
@ -575,7 +576,7 @@ NTSTATUS STDCALL NtOpenProcess (OUT PHANDLE ProcessHandle,
while (current_entry != &PsProcessListHead)
{
current = CONTAINING_RECORD(current_entry, EPROCESS,
Pcb.ProcessListEntry);
ProcessListEntry);
if (current->UniqueProcessId == (ULONG)ClientId->UniqueProcess)
{
ObReferenceObjectByPointer(current,
@ -854,7 +855,7 @@ PiSnapshotProcessTable (
CurrentP = CONTAINING_RECORD(
CurrentEntryP,
EPROCESS,
Pcb.ProcessListEntry
ProcessListEntry
);
/*
* Write process data in the buffer.
@ -869,9 +870,9 @@ PiSnapshotProcessTable (
);
/* THREAD */
for ( pInfoT = & CurrentP->ThreadSysInfo [0],
CurrentEntryT = CurrentP->Pcb.ThreadListHead.Flink;
CurrentEntryT = CurrentP->ThreadListHead.Flink;
(CurrentEntryT != & CurrentP->Pcb.ThreadListHead);
(CurrentEntryT != & CurrentP->ThreadListHead);
pInfoT = & CurrentP->ThreadSysInfo [pInfoP->ThreadCount],
CurrentEntryT = CurrentEntryT->Flink

View file

@ -1,4 +1,4 @@
/* $Id: semgr.c,v 1.15 2000/01/26 10:07:30 dwelch Exp $
/* $Id: semgr.c,v 1.16 2000/07/04 08:52:47 dwelch Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -12,6 +12,7 @@
/* INCLUDES *****************************************************************/
#include <ddk/ntddk.h>
#include <internal/ps.h>
#include <internal/debug.h>