- Optimized the dispatcher lock. It is now gone on non-SMP systems and IRQL is raised...
[reactos.git] / reactos / ntoskrnl / include / internal / ke.h
index e9e78f6..30bf212 100644 (file)
-/*
- *  ReactOS kernel
- *  Copyright (C) 2000 David Welch <welch@cwcom.net>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_KE_H
 #define __NTOSKRNL_INCLUDE_INTERNAL_KE_H
 
 /* INCLUDES *****************************************************************/
 
-#ifndef __ASM__
-#include <ddk/ntifs.h>
-#include <stdarg.h>
-#endif /* not __ASM__ */
-
 #include "arch/ke.h"
 
-/* INTERNAL KERNEL FUNCTIONS ************************************************/
+/* INTERNAL KERNEL TYPES ****************************************************/
 
-#ifdef __USE_W32API
-struct _KPROCESS* KeGetCurrentProcess(VOID);
-VOID KeSetGdtSelector(ULONG Entry, ULONG Value1, ULONG Value2);
-#endif
+typedef struct _WOW64_PROCESS
+{
+  PVOID Wow64;
+} WOW64_PROCESS, *PWOW64_PROCESS;
 
-#ifndef __ASM__
+typedef struct _KPROFILE_SOURCE_OBJECT
+{
+    KPROFILE_SOURCE Source;
+    LIST_ENTRY ListEntry;
+} KPROFILE_SOURCE_OBJECT, *PKPROFILE_SOURCE_OBJECT;
+
+/* Cached modules from the loader block */
+typedef enum _CACHED_MODULE_TYPE
+{
+    AnsiCodepage,
+    OemCodepage,
+    UnicodeCasemap,
+    SystemRegistry,
+    HardwareRegistry,
+    MaximumCachedModuleType,
+} CACHED_MODULE_TYPE, *PCACHED_MODULE_TYPE;
+extern PLOADER_MODULE CachedModules[MaximumCachedModuleType];
 
-struct _KTHREAD;
 struct _KIRQ_TRAPFRAME;
 struct _KPCR;
+struct _KPRCB;
 struct _KEXCEPTION_FRAME;
 
-#define IPI_REQUEST_FUNCTIONCALL    0
-#define IPI_REQUEST_APC                    1
-#define IPI_REQUEST_DPC                    2
+extern PVOID KeUserApcDispatcher;
+extern PVOID KeUserCallbackDispatcher;
+extern PVOID KeUserExceptionDispatcher;
+extern PVOID KeRaiseUserExceptionDispatcher;
+extern LARGE_INTEGER SystemBootTime;
+extern ULONG_PTR KERNEL_BASE;
 
-/* ipi.c ********************************************************************/
+/* MACROS *************************************************************************/
 
-BOOLEAN STDCALL 
-KiIpiServiceRoutine(IN PKTRAP_FRAME TrapFrame, 
-                   IN struct _KEXCEPTION_FRAME* ExceptionFrame);
+/*
+ * On UP machines, we don't actually have a spinlock, we merely raise
+ * IRQL to DPC level.
+ */
+#ifndef CONFIG_SMP
+#define KeInitializeDispatcher()
+#define KeAcquireDispatcherDatabaseLock() KeRaiseIrqlToDpcLevel();
+#define KeAcquireDispatcherDatabaseLockAtDpcLevel()
+#define KeReleaseDispatcherDatabaseLockFromDpcLevel()
+#else
+#define KeInitializeDispatcher() KeInitializeSpinLock(&DispatcherDatabaseLock);
+#define KeAcquireDispatcherDatabaseLock() KfAcquireSpinLock(&DispatcherDatabaseLock);
+#define KeAcquireDispatcherDatabaseLockAtDpcLevel() \
+    KeAcquireSpinLockAtDpcLevel (&DispatcherDatabaseLock);
+#define KeReleaseDispatcherDatabaseLockFromDpcLevel() \
+    KeReleaseSpinLockFromDpcLevel(&DispatcherDatabaseLock);
+#endif
 
-VOID  
-KiIpiSendRequest(ULONG TargetSet, 
-                ULONG IpiRequest);
+/* The following macro initializes a dispatcher object's header */
+#define KeInitializeDispatcherHeader(Header, t, s, State)                   \
+{                                                                           \
+    (Header)->Type = t;                                                     \
+    (Header)->Absolute = 0;                                                 \
+    (Header)->Inserted = 0;                                                 \
+    (Header)->Size = s;                                                     \
+    (Header)->SignalState = State;                                          \
+    InitializeListHead(&((Header)->WaitListHead));                          \
+}
+
+/* The following macro satisfies the wait of any dispatcher object */
+#define KiSatisfyObjectWait(Object, Thread)                                 \
+{                                                                           \
+    /* Special case for Mutants */                                          \
+    if ((Object)->Header.Type == MutantObject)                              \
+    {                                                                       \
+        /* Decrease the Signal State */                                     \
+        (Object)->Header.SignalState--;                                     \
+                                                                            \
+        /* Check if it's now non-signaled */                                \
+        if (!(Object)->Header.SignalState)                                  \
+        {                                                                   \
+            /* Set the Owner Thread */                                      \
+            (Object)->OwnerThread = Thread;                                 \
+                                                                            \
+            /* Disable APCs if needed */                                    \
+            Thread->KernelApcDisable -= (Object)->ApcDisable;               \
+                                                                            \
+            /* Check if it's abandoned */                                   \
+            if ((Object)->Abandoned)                                        \
+            {                                                               \
+                /* Unabandon it */                                          \
+                (Object)->Abandoned = FALSE;                                \
+                                                                            \
+                /* Return Status */                                         \
+                Thread->WaitStatus = STATUS_ABANDONED;                      \
+            }                                                               \
+                                                                            \
+            /* Insert it into the Mutant List */                            \
+            InsertHeadList(&Thread->MutantListHead,                         \
+                           &(Object)->MutantListEntry);                     \
+        }                                                                   \
+    }                                                                       \
+    else if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) ==               \
+             EventSynchronizationObject)                                    \
+    {                                                                       \
+        /* Synchronization Timers and Events just get un-signaled */        \
+        (Object)->Header.SignalState = 0;                                   \
+    }                                                                       \
+    else if ((Object)->Header.Type == SemaphoreObject)                      \
+    {                                                                       \
+        /* These ones can have multiple states, so we only decrease it */   \
+        (Object)->Header.SignalState--;                                     \
+    }                                                                       \
+}
+
+/* The following macro satisfies the wait of a mutant dispatcher object */
+#define KiSatisfyMutantWait(Object, Thread)                                 \
+{                                                                           \
+    /* Decrease the Signal State */                                         \
+    (Object)->Header.SignalState--;                                         \
+                                                                            \
+    /* Check if it's now non-signaled */                                    \
+    if (!(Object)->Header.SignalState)                                      \
+    {                                                                       \
+        /* Set the Owner Thread */                                          \
+        (Object)->OwnerThread = Thread;                                     \
+                                                                            \
+        /* Disable APCs if needed */                                        \
+        Thread->KernelApcDisable -= (Object)->ApcDisable;                   \
+                                                                            \
+        /* Check if it's abandoned */                                       \
+        if ((Object)->Abandoned)                                            \
+        {                                                                   \
+            /* Unabandon it */                                              \
+            (Object)->Abandoned = FALSE;                                    \
+                                                                            \
+            /* Return Status */                                             \
+            Thread->WaitStatus = STATUS_ABANDONED;                          \
+        }                                                                   \
+                                                                            \
+        /* Insert it into the Mutant List */                                \
+        InsertHeadList(&Thread->MutantListHead,                             \
+                       &(Object)->MutantListEntry);                         \
+    }                                                                       \
+}
+
+/* The following macro satisfies the wait of any nonmutant dispatcher object */
+#define KiSatisfyNonMutantWait(Object, Thread)                              \
+{                                                                           \
+    if (((Object)->Header.Type & TIMER_OR_EVENT_TYPE) ==                    \
+             EventSynchronizationObject)                                    \
+    {                                                                       \
+        /* Synchronization Timers and Events just get un-signaled */        \
+        (Object)->Header.SignalState = 0;                                   \
+    }                                                                       \
+    else if ((Object)->Header.Type == SemaphoreObject)                      \
+    {                                                                       \
+        /* These ones can have multiple states, so we only decrease it */   \
+        (Object)->Header.SignalState--;                                     \
+    }                                                                       \
+}
+
+/* The following macro satisfies multiple objects in a wait state */
+#define KiSatisifyMultipleObjectWaits(FirstBlock)                           \
+{                                                                           \
+    PKWAIT_BLOCK WaitBlock = FirstBlock;                                    \
+    PKTHREAD WaitThread = WaitBlock->Thread;                                \
+                                                                            \
+    /* Loop through all the Wait Blocks, and wake each Object */            \
+    do                                                                      \
+    {                                                                       \
+        /* Make sure it hasn't timed out */                                 \
+        if (WaitBlock->WaitKey != STATUS_TIMEOUT)                           \
+        {                                                                   \
+            /* Wake the Object */                                           \
+            KiSatisfyObjectWait((PKMUTANT)WaitBlock->Object, WaitThread);   \
+        }                                                                   \
+                                                                            \
+        /* Move to the next block */                                        \
+        WaitBlock = WaitBlock->NextWaitBlock;                               \
+    } while (WaitBlock != FirstBlock);                                      \
+}
+
+extern KSPIN_LOCK DispatcherDatabaseLock;
+
+#define KeEnterCriticalRegion()                                             \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    if (_Thread) _Thread->KernelApcDisable--;                               \
+}
+
+#define KeLeaveCriticalRegion()                                             \
+{                                                                           \
+    PKTHREAD _Thread = KeGetCurrentThread();                                \
+    if((_Thread) && (++_Thread->KernelApcDisable == 0))                     \
+    {                                                                       \
+        if (!IsListEmpty(&_Thread->ApcState.ApcListHead[KernelMode]) &&     \
+            (_Thread->SpecialApcDisable == 0))                              \
+        {                                                                   \
+            KiCheckForKernelApcDelivery();                                  \
+        }                                                                   \
+    }                                                                       \
+}
+
+#define KEBUGCHECKWITHTF(a,b,c,d,e,f) \
+    DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), \
+             KeBugCheckWithTf(a,b,c,d,e,f)
 
-VOID  
-KeIpiGenericCall(VOID (STDCALL *WorkerRoutine)(PVOID), 
-                PVOID Argument);
+/* INTERNAL KERNEL FUNCTIONS ************************************************/
 
-/* next file ***************************************************************/
+/* threadsch.c ********************************************************************/
 
-typedef struct _KPROCESS_PROFILE
-/*
- * List of the profile data structures associated with a process.
- */
-{
-  LIST_ENTRY ProfileListHead;
-  LIST_ENTRY ListEntry;
-  HANDLE Pid;
-} KPROCESS_PROFILE, *PKPROCESS_PROFILE;
+/* Thread Scheduler Functions */
 
-typedef struct _KPROFILE
-/*
- * Describes a contiguous region of process memory that is being profiled.
- */
-{
-  CSHORT Type;
-  CSHORT Name;
+/* Readies a Thread for Execution. */
+VOID
+STDCALL
+KiDispatchThreadNoLock(ULONG NewThreadStatus);
 
-  /* Entry in the list of profile data structures for this process. */
-  LIST_ENTRY ListEntry; 
+/* Readies a Thread for Execution. */
+VOID
+STDCALL
+KiDispatchThread(ULONG NewThreadStatus);
 
-  /* Base of the region being profiled. */
-  PVOID Base;
+/* Puts a Thread into a block state. */
+VOID
+STDCALL
+KiBlockThread(
+    PNTSTATUS Status,
+    UCHAR Alertable,
+    ULONG WaitMode,
+    UCHAR WaitReason
+);
 
-  /* Size of the region being profiled. */
-  ULONG Size;
+/* Removes a thread out of a block state. */
+VOID
+STDCALL
+KiUnblockThread(
+    PKTHREAD Thread,
+    PNTSTATUS WaitStatus,
+    KPRIORITY Increment
+);
 
-  /* Shift of offsets from the region to buckets in the profiling buffer. */
-  ULONG BucketShift;
+NTSTATUS
+STDCALL
+KeSuspendThread(PKTHREAD Thread);
 
-  /* MDL which described the buffer that receives profiling data. */
-  struct _MDL *BufferMdl;
+NTSTATUS
+FASTCALL
+KiSwapContext(PKTHREAD NewThread);
 
-  /* System alias for the profiling buffer. */
-  PULONG Buffer;
+VOID
+STDCALL
+KiAdjustQuantumThread(IN PKTHREAD Thread);
 
-  /* Size of the buffer for profiling data. */
-  ULONG BufferSize;
+/* gmutex.c ********************************************************************/
 
-  /* 
-   * Mask of processors for which profiling data should be collected. 
-   * Currently unused.
-   */
-  ULONG ProcessorMask;
+VOID
+FASTCALL
+KiAcquireGuardedMutexContented(PKGUARDED_MUTEX GuardedMutex);
 
-  /* TRUE if profiling has been started for this region. */
-  BOOLEAN Started;
+/* gate.c **********************************************************************/
 
-  /* Pointer (and reference) to the process which is being profiled. */
-  struct _EPROCESS *Process;
-} KPROFILE, *PKPROFILE;
+VOID
+FASTCALL
+KeInitializeGate(PKGATE Gate);
+
+VOID
+FASTCALL
+KeSignalGateBoostPriority(PKGATE Gate);
+
+VOID
+FASTCALL
+KeWaitForGate(
+    PKGATE Gate,
+    KWAIT_REASON WaitReason,
+    KPROCESSOR_MODE WaitMode
+);
+
+/* ipi.c ********************************************************************/
 
-VOID STDCALL 
+BOOLEAN
+STDCALL
+KiIpiServiceRoutine(
+    IN PKTRAP_FRAME TrapFrame,
+    IN struct _KEXCEPTION_FRAME* ExceptionFrame
+);
+
+VOID
+NTAPI
+KiIpiSendRequest(
+    KAFFINITY TargetSet,
+    ULONG IpiRequest
+);
+
+VOID
+NTAPI
+KeIpiGenericCall(
+    VOID (STDCALL *WorkerRoutine)(PVOID),
+    PVOID Argument
+);
+
+/* next file ***************************************************************/
+
+VOID 
+STDCALL
 DbgBreakPointNoBugCheck(VOID);
 
+VOID
+STDCALL
+KeInitializeProfile(
+    struct _KPROFILE* Profile,
+    struct _KPROCESS* Process,
+    PVOID ImageBase,
+    ULONG ImageSize,
+    ULONG BucketSize,
+    KPROFILE_SOURCE ProfileSource,
+    KAFFINITY Affinity
+);
+
+VOID
+STDCALL
+KeStartProfile(
+    struct _KPROFILE* Profile,
+    PVOID Buffer
+);
+
+BOOLEAN
+STDCALL
+KeStopProfile(struct _KPROFILE* Profile);
+
+ULONG
+STDCALL
+KeQueryIntervalProfile(KPROFILE_SOURCE ProfileSource);
+
+VOID
+STDCALL
+KeSetIntervalProfile(
+    KPROFILE_SOURCE ProfileSource,
+    ULONG Interval
+);
+
 VOID
 STDCALL
 KeProfileInterrupt(
@@ -127,128 +355,401 @@ KeProfileInterrupt(
 VOID
 STDCALL
 KeProfileInterruptWithSource(
-       IN PKTRAP_FRAME                 TrapFrame,
-       IN KPROFILE_SOURCE              Source
+    IN PKTRAP_FRAME TrapFrame,
+    IN KPROFILE_SOURCE Source
 );
 
-VOID KiAddProfileEventToProcess(PLIST_ENTRY ListHead, PVOID Eip);
-VOID KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Eip);
-VOID KiInsertProfileIntoProcess(PLIST_ENTRY ListHead, PKPROFILE Profile);
-VOID KiInsertProfile(PKPROFILE Profile);
-VOID KiRemoveProfile(PKPROFILE Profile);
-VOID STDCALL KiDeleteProfile(PVOID ObjectBody);
+BOOLEAN
+STDCALL
+KiRosPrintAddress(PVOID Address);
 
+VOID
+STDCALL
+KeUpdateSystemTime(
+    PKTRAP_FRAME TrapFrame,
+    KIRQL Irql
+);
 
-VOID STDCALL KeUpdateSystemTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
-VOID STDCALL KeUpdateRunTime(PKTRAP_FRAME TrapFrame, KIRQL Irql);
+VOID
+STDCALL
+KeUpdateRunTime(
+    PKTRAP_FRAME TrapFrame,
+    KIRQL Irql
+);
 
-VOID STDCALL KiExpireTimers(PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2);
+VOID
+STDCALL
+KiExpireTimers(
+    PKDPC Dpc,
+    PVOID DeferredContext,
+    PVOID SystemArgument1,
+    PVOID SystemArgument2
+);
 
-KIRQL KeAcquireDispatcherDatabaseLock(VOID);
-VOID KeAcquireDispatcherDatabaseLockAtDpcLevel(VOID);
-VOID KeReleaseDispatcherDatabaseLock(KIRQL Irql);
-VOID KeReleaseDispatcherDatabaseLockFromDpcLevel(VOID);
+VOID
+FASTCALL
+KeReleaseDispatcherDatabaseLock(KIRQL Irql);
 
-BOOLEAN KiDispatcherObjectWake(DISPATCHER_HEADER* hdr, KPRIORITY increment);
-VOID STDCALL KeExpireTimers(PKDPC Apc,
-                           PVOID Arg1,
-                           PVOID Arg2,
-                           PVOID Arg3);
-VOID KeInitializeDispatcherHeader(DISPATCHER_HEADER* Header, ULONG Type,
-                                 ULONG Size, ULONG SignalState);
-VOID KeDumpStackFrames(PULONG Frame);
-BOOLEAN KiTestAlert(VOID);
+VOID
+STDCALL
+KeInitializeThread(
+    struct _KPROCESS* Process,
+    PKTHREAD Thread,
+    PKSYSTEM_ROUTINE SystemRoutine,
+    PKSTART_ROUTINE StartRoutine,
+    PVOID StartContext,
+    PCONTEXT Context,
+    PVOID Teb,
+    PVOID KernelStack
+);
 
-BOOLEAN KiAbortWaitThread(struct _KTHREAD* Thread, NTSTATUS WaitStatus);
+VOID
+STDCALL
+KeRundownThread(VOID);
 
-PULONG KeGetStackTopThread(struct _ETHREAD* Thread);
-VOID KeContextToTrapFrame(PCONTEXT Context, PKTRAP_FRAME TrapFrame);
-VOID STDCALL KiDeliverApc(KPROCESSOR_MODE PreviousMode,
-                  PVOID Reserved,
-                  PKTRAP_FRAME TrapFrame);
-                 
-VOID KiInitializeUserApc(IN PVOID Reserved,
-                        IN PKTRAP_FRAME TrapFrame,
-                        IN PKNORMAL_ROUTINE NormalRoutine,
-                        IN PVOID NormalContext,
-                        IN PVOID SystemArgument1,
-                        IN PVOID SystemArgument2);
+NTSTATUS
+NTAPI
+KeReleaseThread(PKTHREAD Thread);
 
-VOID STDCALL KiAttachProcess(struct _KTHREAD *Thread, struct _KPROCESS *Process, KIRQL ApcLock, struct _KAPC_STATE *SavedApcState);
+LONG
+STDCALL
+KeQueryBasePriorityThread(IN PKTHREAD Thread);
 
-VOID STDCALL KiSwapProcess(struct _KPROCESS *NewProcess, struct _KPROCESS *OldProcess);
+VOID
+STDCALL
+KiSetPriorityThread(
+    PKTHREAD Thread,
+    KPRIORITY Priority,
+    PBOOLEAN Released
+);
+
+BOOLEAN
+NTAPI
+KiDispatcherObjectWake(
+    DISPATCHER_HEADER* hdr,
+    KPRIORITY increment
+);
+
+VOID
+STDCALL
+KeExpireTimers(
+    PKDPC Apc,
+    PVOID Arg1,
+    PVOID Arg2,
+    PVOID Arg3
+);
+
+VOID
+NTAPI
+KeDumpStackFrames(PULONG Frame);
+
+BOOLEAN
+NTAPI
+KiTestAlert(VOID);
+
+VOID
+FASTCALL
+KiAbortWaitThread(
+    PKTHREAD Thread,
+    NTSTATUS WaitStatus,
+    KPRIORITY Increment
+);
+
+VOID
+STDCALL
+KeInitializeProcess(
+    struct _KPROCESS *Process,
+    KPRIORITY Priority,
+    KAFFINITY Affinity,
+    LARGE_INTEGER DirectoryTableBase
+);
+
+ULONG
+STDCALL
+KeForceResumeThread(IN PKTHREAD Thread);
+
+BOOLEAN
+STDCALL
+KeDisableThreadApcQueueing(IN PKTHREAD Thread);
+
+BOOLEAN
+STDCALL
+KiInsertTimer(
+    PKTIMER Timer,
+    LARGE_INTEGER DueTime
+);
+
+BOOLEAN
+__inline
+FASTCALL
+KiIsObjectSignaled(
+    PDISPATCHER_HEADER Object,
+    PKTHREAD Thread
+);
+
+VOID
+FASTCALL
+KiWaitTest(
+    PVOID Object,
+    KPRIORITY Increment
+);
+
+PULONG 
+NTAPI
+KeGetStackTopThread(struct _ETHREAD* Thread);
+
+BOOLEAN
+STDCALL
+KeContextToTrapFrame(
+    PCONTEXT Context,
+    PKEXCEPTION_FRAME ExeptionFrame,
+    PKTRAP_FRAME TrapFrame,
+    KPROCESSOR_MODE PreviousMode
+);
+
+VOID
+STDCALL
+KiDeliverApc(
+    KPROCESSOR_MODE PreviousMode,
+    PVOID Reserved,
+    PKTRAP_FRAME TrapFrame
+);
+
+VOID
+STDCALL
+KiCheckForKernelApcDelivery(VOID);
+
+LONG
+STDCALL
+KiInsertQueue(
+    IN PKQUEUE Queue,
+    IN PLIST_ENTRY Entry,
+    BOOLEAN Head
+);
+
+ULONG
+STDCALL
+KeSetProcess(
+    struct _KPROCESS* Process,
+    KPRIORITY Increment
+);
+
+VOID
+STDCALL
+KeInitializeEventPair(PKEVENT_PAIR EventPair);
+
+VOID
+STDCALL
+KiInitializeUserApc(
+    IN PKEXCEPTION_FRAME Reserved,
+    IN PKTRAP_FRAME TrapFrame,
+    IN PKNORMAL_ROUTINE NormalRoutine,
+    IN PVOID NormalContext,
+    IN PVOID SystemArgument1,
+    IN PVOID SystemArgument2
+);
+
+PLIST_ENTRY
+STDCALL
+KeFlushQueueApc(
+    IN PKTHREAD Thread,
+    IN KPROCESSOR_MODE PreviousMode
+);
+
+VOID
+STDCALL
+KiAttachProcess(
+    struct _KTHREAD *Thread,
+    struct _KPROCESS *Process,
+    KIRQL ApcLock,
+    struct _KAPC_STATE *SavedApcState
+);
+
+VOID
+STDCALL
+KiSwapProcess(
+    struct _KPROCESS *NewProcess,
+    struct _KPROCESS *OldProcess
+);
 
 BOOLEAN
 STDCALL
 KeTestAlertThread(IN KPROCESSOR_MODE AlertMode);
 
-BOOLEAN STDCALL KeRemoveQueueApc (PKAPC Apc);
-PLIST_ENTRY STDCALL KeRundownQueue(IN PKQUEUE Queue);
+BOOLEAN
+STDCALL
+KeRemoveQueueApc(PKAPC Apc);
 
-extern LARGE_INTEGER SystemBootTime;
+VOID
+FASTCALL
+KiWakeQueue(IN PKQUEUE Queue);
+
+PLIST_ENTRY
+STDCALL
+KeRundownQueue(IN PKQUEUE Queue);
 
 /* INITIALIZATION FUNCTIONS *************************************************/
 
-VOID KeInitExceptions(VOID);
-VOID KeInitInterrupts(VOID);
-VOID KeInitTimer(VOID);
-VOID KeInitDpc(struct _KPCR* Pcr);
-VOID KeInitDispatcher(VOID);
-VOID KeInitializeDispatcher(VOID);
-VOID KiInitializeSystemClock(VOID);
-VOID KeInitializeBugCheck(VOID);
-VOID Phase1Initialization(PVOID Context);
+VOID
+NTAPI
+KeInitExceptions(VOID);
 
-VOID KeInit1(PCHAR CommandLine, PULONG LastKernelAddress);
-VOID KeInit2(VOID);
+VOID
+NTAPI
+KeInitInterrupts(VOID);
+
+VOID
+NTAPI
+KeInitTimer(VOID);
+
+VOID
+NTAPI
+KeInitDpc(struct _KPRCB* Prcb);
+
+VOID
+NTAPI
+KeInitDispatcher(VOID);
 
-BOOLEAN KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
+VOID
+NTAPI
+KiInitializeSystemClock(VOID);
+
+VOID
+NTAPI
+KiInitializeBugCheck(VOID);
+
+VOID
+NTAPI
+Phase1Initialization(PVOID Context);
+
+VOID
+NTAPI
+KeInit1(
+    PCHAR CommandLine,
+    PULONG LastKernelAddress
+);
+
+VOID
+NTAPI
+KeInit2(VOID);
+
+BOOLEAN
+NTAPI
+KiDeliverUserApc(PKTRAP_FRAME TrapFrame);
 
 VOID
 STDCALL
-KiMoveApcState (PKAPC_STATE OldState,
-               PKAPC_STATE NewState);
+KiMoveApcState(
+    PKAPC_STATE OldState,
+    PKAPC_STATE NewState
+);
 
 VOID
-KiAddProfileEvent(KPROFILE_SOURCE Source, ULONG Pc);
-VOID 
-KiDispatchException(PEXCEPTION_RECORD ExceptionRecord,
-                   PCONTEXT Context,
-                   PKTRAP_FRAME Tf,
-                   KPROCESSOR_MODE PreviousMode,
-                   BOOLEAN SearchFrames);
-VOID KeTrapFrameToContext(PKTRAP_FRAME TrapFrame,
-                         PCONTEXT Context);
+NTAPI
+KiAddProfileEvent(
+    KPROFILE_SOURCE Source,
+    ULONG Pc
+);
+
+VOID
+NTAPI
+KiDispatchException(
+    PEXCEPTION_RECORD ExceptionRecord,
+    PKEXCEPTION_FRAME ExceptionFrame,
+    PKTRAP_FRAME Tf,
+    KPROCESSOR_MODE PreviousMode,
+    BOOLEAN SearchFrames
+);
+
+VOID
+NTAPI
+KeTrapFrameToContext(
+    IN PKTRAP_FRAME TrapFrame,
+    IN PKEXCEPTION_FRAME ExceptionFrame,
+    IN OUT PCONTEXT Context
+);
+
 VOID
+NTAPI
 KeApplicationProcessorInit(VOID);
+
 VOID
+NTAPI
 KePrepareForApplicationProcessorInit(ULONG id);
+
 ULONG
-KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
-VOID STDCALL
-KePushAndStackSwitchAndSysRet(ULONG Push, PVOID NewStack);
-VOID STDCALL
+NTAPI
+KiUserTrapHandler(
+    PKTRAP_FRAME Tf,
+    ULONG ExceptionNr,
+    PVOID Cr2
+);
+
+VOID
+STDCALL
+KePushAndStackSwitchAndSysRet(
+    ULONG Push,
+    PVOID NewStack
+);
+
+VOID
+STDCALL
 KeStackSwitchAndRet(PVOID NewStack);
-VOID STDCALL
-KeBugCheckWithTf(ULONG BugCheckCode,
-                ULONG BugCheckParameter1,
-                ULONG BugCheckParameter2,
-                ULONG BugCheckParameter3,
-                ULONG BugCheckParameter4,
-                PKTRAP_FRAME Tf);
-#define KEBUGCHECKWITHTF(a,b,c,d,e,f) DbgPrint("KeBugCheckWithTf at %s:%i\n",__FILE__,__LINE__), KeBugCheckWithTf(a,b,c,d,e,f)
+
 VOID
-KiDumpTrapFrame(PKTRAP_FRAME Tf, ULONG ExceptionNr, ULONG cr2);
+STDCALL
+KeBugCheckWithTf(
+    ULONG BugCheckCode,
+    ULONG BugCheckParameter1,
+    ULONG BugCheckParameter2,
+    ULONG BugCheckParameter3,
+    ULONG BugCheckParameter4,
+    PKTRAP_FRAME Tf
+);
+
+VOID
+STDCALL
+KiDumpTrapFrame(
+    PKTRAP_FRAME Tf,
+    ULONG ExceptionNr,
+    ULONG cr2
+);
 
 VOID
 STDCALL
 KeFlushCurrentTb(VOID);
 
 VOID
+STDCALL
+KeRosDumpStackFrames(
+    PULONG Frame,
+    ULONG FrameCount
+);
+
+ULONG
+STDCALL
+KeRosGetStackFrames(
+    PULONG Frames,
+    ULONG FrameCount
+);
+
+VOID
+NTAPI
 KiSetSystemTime(PLARGE_INTEGER NewSystemTime);
 
-#endif /* not __ASM__ */
+NTSTATUS 
+STDCALL
+Ke386CallBios(
+    UCHAR Int,
+    PKV86M_REGISTERS Regs
+);
 
-#define MAXIMUM_PROCESSORS      32
+ULONG
+NTAPI
+KeV86Exception(
+    ULONG ExceptionNr,
+    PKTRAP_FRAME Tf,
+    ULONG address
+);
 
 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_KE_H */