ReactOS  r75214
krnlinit.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <internal/napi.h>
Include dependency graph for krnlinit.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI INIT_FUNCTION KiInitSystem (VOID)
 
LARGE_INTEGER NTAPI INIT_FUNCTION KiComputeReciprocal (IN LONG Divisor, OUT PUCHAR Shift)
 
VOID NTAPI INIT_FUNCTION KiInitSpinLocks (IN PKPRCB Prcb, IN CCHAR Number)
 
BOOLEAN NTAPI INIT_FUNCTION KeInitSystem (VOID)
 

Variables

USHORT KeProcessorArchitecture
 
USHORT KeProcessorLevel
 
USHORT KeProcessorRevision
 
ULONG KeFeatureBits
 
KAFFINITY KeActiveProcessors = 1
 
ULONG KiServiceLimit = NUMBER_OF_SYSCALLS
 
PLOADER_PARAMETER_BLOCK KeLoaderBlock
 
PKPRCB KiProcessorBlock [MAXIMUM_PROCESSORS]
 
CCHAR KeNumberProcessors = 0
 
KNODE KiNode0
 
PKNODE KeNodeBlock [1]
 
UCHAR KeNumberNodes = 1
 
UCHAR KeProcessNodeSeed
 
ETHREAD KiInitialThread
 
EPROCESS KiInitialProcess
 
KSPIN_LOCK KiDispatcherLock
 
KSPIN_LOCK MmPfnLock
 
KSPIN_LOCK MmSystemSpaceLock
 
KSPIN_LOCK CcBcbSpinLock
 
KSPIN_LOCK CcMasterSpinLock
 
KSPIN_LOCK CcVacbSpinLock
 
KSPIN_LOCK CcWorkQueueSpinLock
 
KSPIN_LOCK NonPagedPoolLock
 
KSPIN_LOCK MmNonPagedPoolLock
 
KSPIN_LOCK IopCancelSpinLock
 
KSPIN_LOCK IopVpbSpinLock
 
KSPIN_LOCK IopDatabaseLock
 
KSPIN_LOCK IopCompletionLock
 
KSPIN_LOCK NtfsStructLock
 
KSPIN_LOCK AfdWorkQueueSpinLock
 
KSPIN_LOCK KiTimerTableLock [16]
 
KSPIN_LOCK KiReverseStallIpiLock
 

Macro Definition Documentation

#define NDEBUG

Definition at line 12 of file krnlinit.c.

Function Documentation

BOOLEAN NTAPI INIT_FUNCTION KeInitSystem ( VOID  )

Definition at line 293 of file krnlinit.c.

Referenced by Phase1InitializationDiscard().

294 {
295  /* Check if Threaded DPCs are enabled */
296  if (KeThreadDpcEnable)
297  {
298  /* FIXME: TODO */
299  DPRINT1("Threaded DPCs not yet supported\n");
300  }
301 
302  /* Initialize non-portable parts of the kernel */
304  return TRUE;
305 }
VOID NTAPI KiInitMachineDependent(VOID)
Definition: kiinit.c:47
#define TRUE
Definition: types.h:120
BOOLEAN KeThreadDpcEnable
Definition: dpc.c:23
#define DPRINT1
Definition: precomp.h:8
LARGE_INTEGER NTAPI INIT_FUNCTION KiComputeReciprocal ( IN LONG  Divisor,
OUT PUCHAR  Shift 
)

Definition at line 123 of file krnlinit.c.

Referenced by KiInitializeKernel().

125 {
126  LARGE_INTEGER Reciprocal = {{0, 0}};
127  LONG BitCount = 0, Remainder = 1;
128 
129  /* Start by calculating the remainder */
130  while (Reciprocal.HighPart >= 0)
131  {
132  /* Increase the loop (bit) count */
133  BitCount++;
134 
135  /* Calculate the current fraction */
136  Reciprocal.HighPart = (Reciprocal.HighPart << 1) |
137  (Reciprocal.LowPart >> 31);
138  Reciprocal.LowPart <<= 1;
139 
140  /* Double the remainder and see if we went past the divisor */
141  Remainder <<= 1;
142  if (Remainder >= Divisor)
143  {
144  /* Set the low-bit and calculate the new remainder */
145  Remainder -= Divisor;
146  Reciprocal.LowPart |= 1;
147  }
148  }
149 
150  /* Check if we have a remainder */
151  if (Remainder)
152  {
153  /* Check if the current fraction value is too large */
154  if ((Reciprocal.LowPart == 0xFFFFFFFF) &&
155  (Reciprocal.HighPart == (LONG)0xFFFFFFFF))
156  {
157  /* Set the high bit and reduce the bit count */
158  Reciprocal.LowPart = 0;
159  Reciprocal.HighPart = 0x80000000;
160  BitCount--;
161  }
162  else
163  {
164  /* Check if only the lowest bits got too large */
165  if (Reciprocal.LowPart == 0xFFFFFFFF)
166  {
167  /* Reset them and increase the high bits instead */
168  Reciprocal.LowPart = 0;
169  Reciprocal.HighPart++;
170  }
171  else
172  {
173  /* All is well, increase the low bits */
174  Reciprocal.LowPart++;
175  }
176  }
177  }
178 
179  /* Now calculate the actual shift and return the reciprocal */
180  *Shift = (UCHAR)BitCount - 64;
181  return Reciprocal;
182 }
long LONG
Definition: pedump.c:60
#define LONG
Definition: msvc.h:36
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG LowPart
Definition: typedefs.h:105
_In_ ULONG Shift
Definition: rtlfuncs.h:2683
_In_ LARGE_INTEGER Divisor
Definition: rtlfuncs.h:3046
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3046
VOID NTAPI INIT_FUNCTION KiInitSpinLocks ( IN PKPRCB  Prcb,
IN CCHAR  Number 
)

Definition at line 187 of file krnlinit.c.

Referenced by KiInitializeKernel(), and KiSystemStartupBootStack().

189 {
190  ULONG i;
191 
192  /* Initialize Dispatcher Fields */
193  Prcb->QueueIndex = 1;
194  Prcb->ReadySummary = 0;
195  Prcb->DeferredReadyListHead.Next = NULL;
196  for (i = 0; i < MAXIMUM_PRIORITY; i++)
197  {
198  /* Initialize the ready list */
199  InitializeListHead(&Prcb->DispatcherReadyListHead[i]);
200  }
201 
202  /* Initialize DPC Fields */
203  InitializeListHead(&Prcb->DpcData[DPC_NORMAL].DpcListHead);
204  KeInitializeSpinLock(&Prcb->DpcData[DPC_NORMAL].DpcLock);
205  Prcb->DpcData[DPC_NORMAL].DpcQueueDepth = 0;
206  Prcb->DpcData[DPC_NORMAL].DpcCount = 0;
207  Prcb->DpcRoutineActive = FALSE;
208  Prcb->MaximumDpcQueueDepth = KiMaximumDpcQueueDepth;
209  Prcb->MinimumDpcRate = KiMinimumDpcRate;
210  Prcb->AdjustDpcThreshold = KiAdjustDpcThreshold;
211  KeInitializeDpc(&Prcb->CallDpc, NULL, NULL);
212  KeSetTargetProcessorDpc(&Prcb->CallDpc, Number);
213  KeSetImportanceDpc(&Prcb->CallDpc, HighImportance);
214 
215  /* Initialize the Wait List Head */
216  InitializeListHead(&Prcb->WaitListHead);
217 
218  /* Initialize Queued Spinlocks */
219  Prcb->LockQueue[LockQueueDispatcherLock].Next = NULL;
220  Prcb->LockQueue[LockQueueDispatcherLock].Lock = &KiDispatcherLock;
221  Prcb->LockQueue[LockQueueExpansionLock].Next = NULL;
222  Prcb->LockQueue[LockQueueExpansionLock].Lock = NULL;
223  Prcb->LockQueue[LockQueuePfnLock].Next = NULL;
224  Prcb->LockQueue[LockQueuePfnLock].Lock = &MmPfnLock;
225  Prcb->LockQueue[LockQueueSystemSpaceLock].Next = NULL;
226  Prcb->LockQueue[LockQueueSystemSpaceLock].Lock = &MmSystemSpaceLock;
227  Prcb->LockQueue[LockQueueBcbLock].Next = NULL;
228  Prcb->LockQueue[LockQueueBcbLock].Lock = &CcBcbSpinLock;
229  Prcb->LockQueue[LockQueueMasterLock].Next = NULL;
230  Prcb->LockQueue[LockQueueMasterLock].Lock = &CcMasterSpinLock;
231  Prcb->LockQueue[LockQueueVacbLock].Next = NULL;
232  Prcb->LockQueue[LockQueueVacbLock].Lock = &CcVacbSpinLock;
233  Prcb->LockQueue[LockQueueWorkQueueLock].Next = NULL;
234  Prcb->LockQueue[LockQueueWorkQueueLock].Lock = &CcWorkQueueSpinLock;
235  Prcb->LockQueue[LockQueueNonPagedPoolLock].Next = NULL;
236  Prcb->LockQueue[LockQueueNonPagedPoolLock].Lock = &NonPagedPoolLock;
237  Prcb->LockQueue[LockQueueMmNonPagedPoolLock].Next = NULL;
238  Prcb->LockQueue[LockQueueMmNonPagedPoolLock].Lock = &MmNonPagedPoolLock;
239  Prcb->LockQueue[LockQueueIoCancelLock].Next = NULL;
240  Prcb->LockQueue[LockQueueIoCancelLock].Lock = &IopCancelSpinLock;
241  Prcb->LockQueue[LockQueueIoVpbLock].Next = NULL;
242  Prcb->LockQueue[LockQueueIoVpbLock].Lock = &IopVpbSpinLock;
243  Prcb->LockQueue[LockQueueIoDatabaseLock].Next = NULL;
244  Prcb->LockQueue[LockQueueIoDatabaseLock].Lock = &IopDatabaseLock;
245  Prcb->LockQueue[LockQueueIoCompletionLock].Next = NULL;
246  Prcb->LockQueue[LockQueueIoCompletionLock].Lock = &IopCompletionLock;
247  Prcb->LockQueue[LockQueueNtfsStructLock].Next = NULL;
248  Prcb->LockQueue[LockQueueNtfsStructLock].Lock = &NtfsStructLock;
249  Prcb->LockQueue[LockQueueAfdWorkQueueLock].Next = NULL;
250  Prcb->LockQueue[LockQueueAfdWorkQueueLock].Lock = &AfdWorkQueueSpinLock;
251  Prcb->LockQueue[LockQueueUnusedSpare16].Next = NULL;
252  Prcb->LockQueue[LockQueueUnusedSpare16].Lock = NULL;
253 
254  /* Loop timer locks */
255  for (i = 0; i < LOCK_QUEUE_TIMER_TABLE_LOCKS; i++)
256  {
257  /* Initialize the lock and setup the Queued Spinlock */
259  Prcb->LockQueue[LockQueueTimerTableLock + i].Next = NULL;
260  Prcb->LockQueue[LockQueueTimerTableLock + i].Lock =
262  }
263 
264  /* Initialize the PRCB lock */
265  KeInitializeSpinLock(&Prcb->PrcbLock);
266 
267  /* Check if this is the boot CPU */
268  if (!Number)
269  {
270  /* Initialize the lock themselves */
287  }
288 }
KSPIN_LOCK CcVacbSpinLock
Definition: krnlinit.c:53
#define DPC_NORMAL
KSPIN_LOCK MmPfnLock
Definition: krnlinit.c:49
VOID NTAPI KeSetImportanceDpc(IN PKDPC Dpc, IN KDPC_IMPORTANCE Importance)
Definition: dpc.c:957
ULONG KiAdjustDpcThreshold
Definition: dpc.c:21
KSPIN_LOCK NtfsStructLock
Definition: krnlinit.c:61
KSPIN_LOCK CcWorkQueueSpinLock
Definition: krnlinit.c:54
KSPIN_LOCK IopCancelSpinLock
Definition: krnlinit.c:57
#define LOCK_QUEUE_TIMER_TABLE_LOCKS
GLenum GLclampf GLint i
Definition: glfuncs.h:14
KSPIN_LOCK IopVpbSpinLock
Definition: krnlinit.c:58
#define FALSE
Definition: types.h:117
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:513
KSPIN_LOCK AfdWorkQueueSpinLock
Definition: krnlinit.c:62
KSPIN_LOCK KiReverseStallIpiLock
Definition: krnlinit.c:64
ULONG KiMinimumDpcRate
Definition: dpc.c:20
KSPIN_LOCK KiTimerTableLock[16]
Definition: krnlinit.c:63
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:204
KSPIN_LOCK KiDispatcherLock
Definition: krnlinit.c:48
ULONG KiMaximumDpcQueueDepth
Definition: dpc.c:19
KSPIN_LOCK MmNonPagedPoolLock
Definition: krnlinit.c:56
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
KSPIN_LOCK CcBcbSpinLock
Definition: krnlinit.c:51
KSPIN_LOCK MmSystemSpaceLock
Definition: krnlinit.c:50
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
KSPIN_LOCK IopCompletionLock
Definition: krnlinit.c:60
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
KSPIN_LOCK CcMasterSpinLock
Definition: krnlinit.c:52
KSPIN_LOCK NonPagedPoolLock
Definition: krnlinit.c:55
KSPIN_LOCK IopDatabaseLock
Definition: krnlinit.c:59
#define MAXIMUM_PRIORITY
VOID NTAPI INIT_FUNCTION KiInitSystem ( VOID  )

Definition at line 71 of file krnlinit.c.

Referenced by KiInitializeKernel().

72 {
73  ULONG i;
74 
75  /* Initialize Bugcheck Callback data */
79 
80  /* Initialize the Timer Expiration DPC */
83 
84  /* Initialize Profiling data */
88 
89  /* Loop the timer table */
90  for (i = 0; i < TIMER_TABLE_SIZE; i++)
91  {
92  /* Initialize the list and entries */
94  KiTimerTableListHead[i].Time.HighPart = 0xFFFFFFFF;
96  }
97 
98  /* Initialize the Swap event and all swap lists */
103 
104  /* Initialize the mutex for generic DPC calls */
106 
107  /* Initialize the syscall table */
113 
114  /* Copy the the current table into the shadow table for win32k */
117  sizeof(KeServiceDescriptorTable));
118 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
KSPIN_LOCK KiProfileLock
Definition: profobj.c:20
KDPC KiTimerExpireDpc
Definition: dpc.c:25
ULONG_PTR MainSSDT[]
Definition: napi.h:9
$ULONG LowPart
Definition: ntbasedef.h:568
FAST_MUTEX KiGenericCallDpcMutex
Definition: dpc.c:24
LIST_ENTRY KiProfileListHead
Definition: profobj.c:18
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
VOID NTAPI KiTimerExpiration(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:79
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[SSDT_MAX_ENTRIES]
Definition: procobj.c:24
smooth NULL
Definition: ftsmooth.c:513
ULARGE_INTEGER Time
Definition: ketypes.h:667
#define TIMER_TABLE_SIZE
Definition: ketypes.h:821
$ULONG HighPart
Definition: ntbasedef.h:569
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
ULONG KiServiceLimit
Definition: krnlinit.c:26
LIST_ENTRY KeBugcheckCallbackListHead
Definition: bug.c:21
KTIMER_TABLE_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
Definition: timerobj.c:17
KEVENT KiSwapEvent
Definition: procobj.c:21
LIST_ENTRY KiProfileSourceListHead
Definition: profobj.c:19
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY KeBugcheckReasonCallbackListHead
Definition: bug.c:22
UCHAR MainSSPT[]
Definition: napi.h:15
VOID NTAPI KeSetTargetProcessorDpc(IN PKDPC Dpc, IN CCHAR Number)
Definition: dpc.c:970
KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[SSDT_MAX_ENTRIES]
Definition: procobj.c:23
unsigned int ULONG
Definition: retypes.h:1
LIST_ENTRY KiStackInSwapListHead
Definition: procobj.c:20
LIST_ENTRY KiProcessInSwapListHead
Definition: procobj.c:19
LIST_ENTRY KiProcessOutSwapListHead
Definition: procobj.c:19
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
base of all file and directory entries
Definition: entries.h:82
KSPIN_LOCK BugCheckCallbackLock
Definition: bug.c:23

Variable Documentation

KSPIN_LOCK AfdWorkQueueSpinLock

Definition at line 62 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK CcBcbSpinLock

Definition at line 51 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK CcMasterSpinLock

Definition at line 52 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK CcVacbSpinLock

Definition at line 53 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK CcWorkQueueSpinLock

Definition at line 54 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK IopCancelSpinLock

Definition at line 57 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK IopCompletionLock

Definition at line 60 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK IopDatabaseLock

Definition at line 59 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK IopVpbSpinLock

Definition at line 58 of file krnlinit.c.

Referenced by KiInitSpinLocks().

PKNODE KeNodeBlock[1]

Definition at line 39 of file krnlinit.c.

Referenced by KeInitializeProcess(), KeStartThread(), KiInitializeKernel(), and QSI_DEF().

UCHAR KeNumberNodes = 1

Definition at line 40 of file krnlinit.c.

Referenced by InitializePool(), KeInitializeProcess(), and QSI_DEF().

UCHAR KeProcessNodeSeed

Definition at line 41 of file krnlinit.c.

Referenced by KeInitializeProcess().

USHORT KeProcessorArchitecture
USHORT KeProcessorRevision

Definition at line 21 of file krnlinit.c.

Referenced by KiInitializeKernel(), KiInitializeKernelMachineDependent(), and QSI_DEF().

KSPIN_LOCK KiDispatcherLock

Definition at line 48 of file krnlinit.c.

Referenced by KiInitSpinLocks().

EPROCESS KiInitialProcess

Definition at line 45 of file krnlinit.c.

Referenced by KiSystemStartup(), KiSystemStartupBootStack(), and KiSystemStartupReal().

ETHREAD KiInitialThread

Definition at line 44 of file krnlinit.c.

Referenced by KiSystemStartup(), and KiSystemStartupReal().

KNODE KiNode0

Definition at line 38 of file krnlinit.c.

Referenced by KiInitializeKernel().

KSPIN_LOCK KiReverseStallIpiLock

Definition at line 64 of file krnlinit.c.

Referenced by KeIpiGenericCall(), and KiInitSpinLocks().

ULONG KiServiceLimit = NUMBER_OF_SYSCALLS

Definition at line 26 of file krnlinit.c.

Referenced by ExpInitializeExecutive(), KiInitializeKernel(), and KiInitSystem().

KSPIN_LOCK KiTimerTableLock[16]

Definition at line 63 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK MmNonPagedPoolLock

Definition at line 56 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK MmPfnLock

Definition at line 49 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK MmSystemSpaceLock

Definition at line 50 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK NonPagedPoolLock

Definition at line 55 of file krnlinit.c.

Referenced by KiInitSpinLocks().

KSPIN_LOCK NtfsStructLock

Definition at line 61 of file krnlinit.c.

Referenced by KiInitSpinLocks().