From 4d9e3a1cae700bf881154727b01204d54112e73b Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Sun, 3 Oct 2004 03:03:54 +0000 Subject: [PATCH] Corrected KPCR structure, removed IKPCR, set up CurrentThread in proper structure (implemented KPRCB), added some types needed by KPRCB. svn path=/trunk/; revision=11162 --- reactos/include/ddk/extypes.h | 7 +- reactos/include/ddk/ketypes.h | 6 + reactos/include/ddk/potypes.h | 67 +++++++ reactos/ntoskrnl/include/internal/i386/ps.h | 196 ++++++++++++++++---- reactos/ntoskrnl/include/internal/mm.h | 12 ++ reactos/ntoskrnl/ke/main.c | 6 +- reactos/ntoskrnl/ps/thread.c | 16 +- reactos/subsys/win32k/misc/error.c | 4 +- 8 files changed, 263 insertions(+), 51 deletions(-) diff --git a/reactos/include/ddk/extypes.h b/reactos/include/ddk/extypes.h index c641cffd18d..c801c111af8 100644 --- a/reactos/include/ddk/extypes.h +++ b/reactos/include/ddk/extypes.h @@ -1,4 +1,4 @@ -/* $Id: extypes.h,v 1.23 2004/08/09 01:26:10 ion Exp $ */ +/* $Id: extypes.h,v 1.24 2004/10/03 03:03:53 ion Exp $ */ #ifndef __INCLUDE_DDK_EXTYPES_H #define __INCLUDE_DDK_EXTYPES_H @@ -150,6 +150,11 @@ typedef struct _PAGED_LOOKASIDE_LIST FAST_MUTEX Obsoleted; } PAGED_LOOKASIDE_LIST, *PPAGED_LOOKASIDE_LIST; +typedef struct _PP_LOOKASIDE_LIST { + struct _GENERAL_LOOKASIDE *P; + struct _GENERAL_LOOKASIDE *L; +} PP_LOOKASIDE_LIST, *PPP_LOOKASIDE_LIST; + typedef enum _EX_POOL_PRIORITY { LowPoolPriority, LowPoolPrioritySpecialPoolOverrun = 8, diff --git a/reactos/include/ddk/ketypes.h b/reactos/include/ddk/ketypes.h index 3d584aa5167..d559ff5da2d 100644 --- a/reactos/include/ddk/ketypes.h +++ b/reactos/include/ddk/ketypes.h @@ -209,6 +209,12 @@ typedef struct _KDPC #include +typedef struct _KDPC_DATA { + LIST_ENTRY DpcListHead; + ULONG DpcLock; + ULONG DpcQueueDepth; + ULONG DpcCount; +} KDPC_DATA, *PKDPC_DATA; typedef struct _KDEVICE_QUEUE_ENTRY { diff --git a/reactos/include/ddk/potypes.h b/reactos/include/ddk/potypes.h index 0b02bc3b689..0a42d564a95 100644 --- a/reactos/include/ddk/potypes.h +++ b/reactos/include/ddk/potypes.h @@ -98,4 +98,71 @@ typedef enum { DeviceTextLocationInformation = 1 } DEVICE_TEXT_TYPE, *PDEVICE_TEXT_TYPE; +typedef struct _PROCESSOR_IDLE_TIMES { + ULONGLONG StartTime; + ULONGLONG EndTime; + ULONG IdleHandlerReserved[4]; +} PROCESSOR_IDLE_TIMES, *PPROCESSOR_IDLE_TIMES; + +typedef struct _PROCESSOR_PERF_STATE { + UCHAR PercentFrequency; + UCHAR MinCapacity; + USHORT Power; + UCHAR IncreaseLevel; + UCHAR DecreaseLevel; + USHORT Flags; + ULONG IncreaseTime; + ULONG DecreaseTime; + ULONG IncreaseCount; + ULONG DecreaseCount; + ULONGLONG PerformanceTime; +} PROCESSOR_PERF_STATE, *PPROCESSOR_PERF_STATE; + +typedef struct _PROCESSOR_POWER_STATE { + PVOID IdleFunction; + ULONG Idle0KernelTimeLimit; + ULONG Idle0LastTime; + PVOID IdleHandlers; + PVOID IdleState; + ULONG IdleHandlersCount; + ULONGLONG LastCheck; + PROCESSOR_IDLE_TIMES IdleTimes; + ULONG IdleTime1; + ULONG PromotionCheck; + ULONG IdleTime2; + UCHAR CurrentThrottle; + UCHAR ThermalThrottleLimit; + UCHAR CurrentThrottleIndex; + UCHAR ThermalThrottleIndex; + ULONG LastKernelUserTime; + ULONG PerfIdleTime; + ULONG DebugDelta; + ULONG DebugCount; + ULONG LastSysTime; + ULONG TotalIdleStateTime[3]; + ULONG TotalIdleTransitions[3]; + ULONGLONG PreviousC3StateTime; + UCHAR KneeThrottleIndex; + UCHAR ThrottleLimitIndex; + UCHAR PerfStatesCount; + UCHAR ProcessorMinThrottle; + UCHAR ProcessorMaxThrottle; + UCHAR LastBusyPercentage; + UCHAR LastC3Percentage; + UCHAR LastAdjustedBusyPercentage; + ULONG PromotionCount; + ULONG DemotionCount; + ULONG ErrorCount; + ULONG RetryCount; + ULONG Flags; + LARGE_INTEGER PerfCounterFrequency; + ULONG PerfTickCount; + KTIMER PerfTimer; + KDPC PerfDpc; + PROCESSOR_PERF_STATE *PerfStates; + PVOID PerfSetThrottle; + ULONG LastC3KernelUserTime; + ULONG Spare1[1]; +} PROCESSOR_POWER_STATE, *PPROCESSOR_POWER_STATE; + #endif /* __INCLUDE_DDK_POTYPES_H */ diff --git a/reactos/ntoskrnl/include/internal/i386/ps.h b/reactos/ntoskrnl/include/internal/i386/ps.h index 16c6eda465d..019f284a1e5 100644 --- a/reactos/ntoskrnl/include/internal/i386/ps.h +++ b/reactos/ntoskrnl/include/internal/i386/ps.h @@ -47,10 +47,156 @@ #ifndef __ASM__ +#pragma pack(push,4) + +// Fixme: Use correct types? +typedef struct _KPROCESSOR_STATE { + PCONTEXT ContextFrame; + PVOID SpecialRegisters; +} KPROCESSOR_STATE; + +// Fixme: Use correct union for Fn/Fx Save Area? +typedef struct _FX_SAVE_AREA { + UCHAR FnFxSaveArea[0x208]; + ULONG NpxSavedCpu; + ULONG Cr0NpxState; +} FX_SAVE_AREA, *PFX_SAVE_AREA; + +/* ProcessoR Control Block */ +typedef struct _KPRCB { + USHORT MinorVersion; + USHORT MajorVersion; + struct _KTHREAD *CurrentThread; + struct _KTHREAD *NextThread; + struct _KTHREAD *IdleThread; + UCHAR Number; + UCHAR Reserved; + USHORT BuildType; + ULONG SetMember; + UCHAR CpuType; + UCHAR CpuID; + USHORT CpuStep; + KPROCESSOR_STATE ProcessorState; + ULONG KernelReserved[16]; + ULONG HalReserved[16]; + UCHAR PrcbPad0[92]; + PVOID LockQueue[33]; // Used for Queued Spinlocks + struct _KTHREAD *NpxThread; + ULONG InterruptCount; + ULONG KernelTime; + ULONG UserTime; + ULONG DpcTime; + ULONG DebugDpcTime; + ULONG InterruptTime; + ULONG AdjustDpcThreshold; + ULONG PageColor; + UCHAR SkipTick; + UCHAR DebuggerSavedIRQL; + UCHAR Spare1[6]; + struct _KNODE *ParentNode; + ULONG MultiThreadProcessorSet; + struct _KPRCB *MultiThreadSetMaster; + ULONG ThreadStartCount[2]; + ULONG CcFastReadNoWait; + ULONG CcFastReadWait; + ULONG CcFastReadNotPossible; + ULONG CcCopyReadNoWait; + ULONG CcCopyReadWait; + ULONG CcCopyReadNoWaitMiss; + ULONG KeAlignmentFixupCount; + ULONG SpareCounter0; + ULONG KeDcacheFlushCount; + ULONG KeExceptionDispatchCount; + ULONG KeFirstLevelTbFills; + ULONG KeFloatingEmulationCount; + ULONG KeIcacheFlushCount; + ULONG KeSecondLevelTbFills; + ULONG KeSystemCalls; + ULONG IoReadOperationCount; + ULONG IoWriteOperationCount; + ULONG IoOtherOperationCount; + LARGE_INTEGER IoReadTransferCount; + LARGE_INTEGER IoWriteTransferCount; + LARGE_INTEGER IoOtherTransferCount; + ULONG SpareCounter1[8]; + PP_LOOKASIDE_LIST PPLookasideList[16]; + PP_LOOKASIDE_LIST PPNPagedLookasideList[32]; + PP_LOOKASIDE_LIST PPPagedLookasideList[32]; + ULONG PacketBarrier; + ULONG ReverseStall; + PVOID IpiFrame; + UCHAR PrcbPad2[52]; + PVOID CurrentPacket[3]; + ULONG TargetSet; + ULONG_PTR WorkerRoutine; + ULONG IpiFrozen; + UCHAR PrcbPad3[40]; + ULONG RequestSummary; + struct _KPRCB *SignalDone; + UCHAR PrcbPad4[56]; + struct _KDPC_DATA DpcData[2]; + PVOID DpcStack; + ULONG MaximumDpcQueueDepth; + ULONG DpcRequestRate; + ULONG MinimumDpcRate; + UCHAR DpcInterruptRequested; + UCHAR DpcThreadRequested; + UCHAR DpcRoutineActive; + UCHAR DpcThreadActive; + ULONG PrcbLock; + ULONG DpcLastCount; + ULONG TimerHand; + ULONG TimerRequest; + PVOID DpcThread; + struct _KEVENT *DpcEvent; + UCHAR ThreadDpcEnable; + UCHAR QuantumEnd; + UCHAR PrcbPad50; + UCHAR IdleSchedule; + ULONG DpcSetEventRequest; + UCHAR PrcbPad5[18]; + LONG TickOffset; + struct _KDPC* CallDpc; + ULONG PrcbPad7[8]; + LIST_ENTRY WaitListHead; + ULONG ReadySummary; + ULONG SelectNextLast; + LIST_ENTRY DispatcherReadyListHead[32]; + SINGLE_LIST_ENTRY DeferredReadyListHead; + ULONG PrcbPad72[11]; + PVOID ChainedInterruptList; + LONG LookasideIrpFloat; + LONG MmPageFaultCount; + LONG MmCopyOnWriteCount; + LONG MmTransitionCount; + LONG MmCacheTransitionCount; + LONG MmDemandZeroCount; + LONG MmPageReadCount; + LONG MmPageReadIoCount; + LONG MmCacheReadCount; + LONG MmCacheIoCount; + LONG MmDirtyPagesWriteCount; + LONG MmDirtyWriteIoCount; + LONG MmMappedPagesWriteCount; + LONG MmMappedWriteIoCount; + ULONG SpareFields0[1]; + UCHAR VendorString[13]; + UCHAR InitialApicId; + UCHAR LogicalProcessorsPerPhysicalProcessor; + ULONG MHz; + ULONG FeatureBits; + LARGE_INTEGER UpdateSignature; + LARGE_INTEGER IsrTime; + LARGE_INTEGER SpareField1; + FX_SAVE_AREA NpxSaveArea; + PROCESSOR_POWER_STATE PowerState; +} KPRCB, *PKRCB; + +#pragma pack(pop) + #ifndef __USE_W32API #pragma pack(push,4) - /* * Processor Control Region Thread Information Block */ @@ -66,6 +212,9 @@ typedef struct _KPCR_TIB { PVOID ArbitraryUserPointer; /* 14 */ } KPCR_TIB, *PKPCR_TIB; /* 18 */ +/* + * Processor Control Region + */ typedef struct _KPCR { KPCR_TIB Tib; /* 00 */ struct _KPCR *Self; /* 18 */ @@ -84,45 +233,20 @@ typedef struct _KPCR { ULONG StallScaleFactor; /* 48 */ UCHAR DebugActive; /* 4C */ UCHAR ProcessorNumber; /* 4D */ - UCHAR Reserved[2]; /* 4E */ -} KPCR; + UCHAR Reserved; /* 4E */ + UCHAR L2CacheAssociativity; /* 4F */ + ULONG VdmAlert; /* 50 */ + ULONG KernelReserved[14]; /* 54 */ + ULONG L2CacheSize; /* 8C */ + ULONG HalReserved[16]; /* 90 */ + ULONG InterruptMode; /* D0 */ + UCHAR KernelReserved2[0x4C]; /* D4 */ + KPRCB PrcbData; /* 120 */ +} KPCR, *PKPCR; #pragma pack(pop) - -typedef struct _KPCR *PKPCR; - #endif /* __USE_W32API */ -#pragma pack(push,4) - -/* - * Processor Control Region - * The first part of this structure must match the KPCR structure in w32api - */ -typedef struct _IKPCR { - KPCR_TIB Tib; /* 00 */ - struct _KPCR *Self; /* 18 */ - struct _KPRCB *PCRCB; /* 1C */ - KIRQL Irql; /* 20 */ - ULONG IRR; /* 24 */ - ULONG IrrActive; /* 28 */ - ULONG IDR; /* 2C */ - PVOID KdVersionBlock; /* 30 */ - PUSHORT IDT; /* 34 */ - PUSHORT GDT; /* 38 */ - struct _KTSS *TSS; /* 3C */ - USHORT MajorVersion; /* 40 */ - USHORT MinorVersion; /* 42 */ - KAFFINITY SetMember; /* 44 */ - ULONG StallScaleFactor; /* 48 */ - UCHAR DebugActive; /* 4C */ - UCHAR ProcessorNumber; /* 4D */ - UCHAR Reserved[2]; /* 4E */ - UCHAR Reserved2[0xD4]; /* 50 */ - struct _KTHREAD* CurrentThread; /* 124 */ -} IKPCR, *PIKPCR; - -#pragma pack(pop) #ifndef __USE_W32API diff --git a/reactos/ntoskrnl/include/internal/mm.h b/reactos/ntoskrnl/include/internal/mm.h index d691844e946..737679a6f35 100644 --- a/reactos/ntoskrnl/include/internal/mm.h +++ b/reactos/ntoskrnl/include/internal/mm.h @@ -193,6 +193,18 @@ typedef struct _MADDRESS_SPACE ULONG PageTableRefCountTableSize; } MADDRESS_SPACE, *PMADDRESS_SPACE; +typedef struct _KNODE { + ULONG ProcessorMask; + ULONG Color; + ULONG MmShiftedColor; + ULONG FreeCount[2]; + SLIST_HEADER DeadStackList; + SLIST_HEADER PfnDereferenceSListHead; + struct _SINGLE_LIST_ENTRY *PfnDeferredList; + UCHAR Seed; + UCHAR NodeNumber; + ULONG Flags; +} KNODE, *PKNODE; #ifndef __USE_W32API /* VARIABLES */ diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 3f06230ef40..096c9e01e4d 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: main.c,v 1.197 2004/09/26 15:07:43 hbirr Exp $ +/* $Id: main.c,v 1.198 2004/10/03 03:03:54 ion Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/main.c @@ -303,9 +303,7 @@ ExpInitializeExecutive(VOID) assert(FIELD_OFFSET(KPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST); assert(FIELD_OFFSET(KPCR, Self) == KPCR_SELF); - assert(FIELD_OFFSET(IKPCR, Tib.ExceptionList) == KPCR_EXCEPTION_LIST); - assert(FIELD_OFFSET(IKPCR, Self) == KPCR_SELF); - assert(FIELD_OFFSET(IKPCR, CurrentThread) == KPCR_CURRENT_THREAD); + assert(FIELD_OFFSET(KPCR, PrcbData) + FIELD_OFFSET(KPRCB, CurrentThread) == KPCR_CURRENT_THREAD); LdrInit1(); diff --git a/reactos/ntoskrnl/ps/thread.c b/reactos/ntoskrnl/ps/thread.c index 07a79825d90..7a490d81162 100644 --- a/reactos/ntoskrnl/ps/thread.c +++ b/reactos/ntoskrnl/ps/thread.c @@ -1,4 +1,4 @@ -/* $Id: thread.c,v 1.134 2004/09/28 15:02:29 weiden Exp $ +/* $Id: thread.c,v 1.135 2004/10/03 03:03:54 ion Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -57,7 +57,7 @@ static GENERIC_MAPPING PiThreadMapping = {THREAD_READ, */ PKTHREAD STDCALL KeGetCurrentThread(VOID) { - return(((PIKPCR) KeGetCurrentKPCR())->CurrentThread); + return(KeGetCurrentKPCR()->PrcbData.CurrentThread); } /* @@ -372,7 +372,7 @@ VOID PsDispatchThreadNoLock (ULONG NewThreadStatus) KPRIORITY CurrentPriority; PETHREAD Candidate; ULONG Affinity; - PKTHREAD KCurrentThread = ((PIKPCR) KeGetCurrentKPCR())->CurrentThread; + PKTHREAD KCurrentThread = KeGetCurrentThread(); PETHREAD CurrentThread = CONTAINING_RECORD(KCurrentThread, ETHREAD, Tcb); DPRINT("PsDispatchThread() %d/%d/%d/%d\n", KeGetCurrentProcessorNumber(), @@ -437,7 +437,7 @@ PsDispatchThread(ULONG NewThreadStatus) /* * Save wait IRQL */ - ((PIKPCR) KeGetCurrentKPCR())->CurrentThread->WaitIrql = oldIrql; + KeGetCurrentThread()->WaitIrql = oldIrql; PsDispatchThreadNoLock(NewThreadStatus); KeLowerIrql(oldIrql); } @@ -483,7 +483,7 @@ PsBlockThread(PNTSTATUS Status, UCHAR Alertable, ULONG WaitMode, KeAcquireSpinLock(&PiThreadLock, &oldIrql); - KThread = ((PIKPCR) KeGetCurrentKPCR())->CurrentThread; + KThread = KeGetCurrentThread(); Thread = CONTAINING_RECORD (KThread, ETHREAD, Tcb); if (KThread->ApcState.KernelApcPending) { @@ -630,7 +630,7 @@ PsSetThreadWin32Thread( VOID PsApplicationProcessorInit(VOID) { - ((PIKPCR) KeGetCurrentKPCR())->CurrentThread = + KeGetCurrentKPCR()->PrcbData.CurrentThread = (PVOID)IdleThreads[KeGetCurrentProcessorNumber()]; } @@ -704,7 +704,7 @@ PsInitThreadManagment(VOID) THREAD_ALL_ACCESS,NULL, TRUE); FirstThread->Tcb.State = THREAD_STATE_RUNNING; FirstThread->Tcb.FreezeCount = 0; - ((PIKPCR) KeGetCurrentKPCR())->CurrentThread = (PVOID)FirstThread; + KeGetCurrentKPCR()->PrcbData.CurrentThread = (PVOID)FirstThread; NtClose(FirstThreadHandle); DPRINT("FirstThread %x\n",FirstThread); @@ -793,7 +793,7 @@ KeSetPriorityThread (PKTHREAD Thread, KPRIORITY Priority) { PsRemoveFromThreadList((PETHREAD)Thread); PsInsertIntoThreadList(Priority, (PETHREAD)Thread); - CurrentThread = ((PIKPCR) KeGetCurrentKPCR())->CurrentThread; + CurrentThread = KeGetCurrentThread(); if (CurrentThread->Priority < Priority) { PsDispatchThreadNoLock(THREAD_STATE_READY); diff --git a/reactos/subsys/win32k/misc/error.c b/reactos/subsys/win32k/misc/error.c index 315a1f34c63..c6870f12493 100644 --- a/reactos/subsys/win32k/misc/error.c +++ b/reactos/subsys/win32k/misc/error.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: error.c,v 1.7 2004/03/14 11:25:33 gvg Exp $ +/* $Id: error.c,v 1.8 2004/10/03 03:03:54 ion Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -27,6 +27,7 @@ * 06-06-2001 CSH Created */ #include +#include #include #include @@ -51,7 +52,6 @@ SetLastWin32Error(DWORD Status) NTSTATUS FASTCALL GetLastNtError() { - // FIXME - not 100% sure this is correct PTEB Teb = PsGetCurrentThread()->Tcb.Teb; if ( NULL != Teb )