ReactOS 0.4.16-dev-109-gf4cb10f
stubs.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for stubs.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PVOID KiSwitchKernelStackHelper (LONG_PTR StackOffset, PVOID OldStackBase)
 
PVOID NTAPI KiSwitchKernelStack (PVOID StackBase, PVOID StackLimit)
 
DECLSPEC_NORETURN VOID KiIdleLoop (VOID)
 
VOID NTAPI KiSwapProcess (IN PKPROCESS NewProcess, IN PKPROCESS OldProcess)
 
NTSTATUS NTAPI NtSetLdtEntries (ULONG Selector1, LDT_ENTRY LdtEntry1, ULONG Selector2, LDT_ENTRY LdtEntry2)
 
NTSTATUS NTAPI NtVdmControl (IN ULONG ControlCode, IN PVOID ControlData)
 

Variables

ULONG ProcessCount
 
SIZE_T KeXStateLength = sizeof(XSAVE_FORMAT)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file stubs.c.

Function Documentation

◆ KiIdleLoop()

DECLSPEC_NORETURN VOID KiIdleLoop ( VOID  )

Definition at line 99 of file stubs.c.

100{
101 PKPRCB Prcb = KeGetCurrentPrcb();
102 PKTHREAD OldThread, NewThread;
103
104 /* Now loop forever */
105 while (TRUE)
106 {
107 /* Start of the idle loop: disable interrupts */
108 _enable();
111 _disable();
112
113 /* Check for pending timers, pending DPCs, or pending ready threads */
114 if ((Prcb->DpcData[0].DpcQueueDepth) ||
115 (Prcb->TimerRequest) ||
117 {
118 /* Quiesce the DPC software interrupt */
120
121 /* Handle it */
122 KiRetireDpcList(Prcb);
123 }
124
125 /* Check if a new thread is scheduled for execution */
126 if (Prcb->NextThread)
127 {
128 /* Enable interrupts */
129 _enable();
130
131 /* Capture current thread data */
132 OldThread = Prcb->CurrentThread;
133 NewThread = Prcb->NextThread;
134
135 /* Set new thread data */
136 Prcb->NextThread = NULL;
137 Prcb->CurrentThread = NewThread;
138
139 /* The thread is now running */
140 NewThread->State = Running;
141
142#ifdef CONFIG_SMP
143 /* Do the swap at SYNCH_LEVEL */
145#endif
146
147 /* Switch away from the idle thread */
148 KiSwapContext(APC_LEVEL, OldThread);
149
150#ifdef CONFIG_SMP
151 /* Go back to DISPATCH_LEVEL */
153#endif
154 }
155 else
156 {
157 /* Continue staying idle. Note the HAL returns with interrupts on */
158 Prcb->PowerState.IdleFunction(&Prcb->PowerState);
159 }
160 }
161}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define SYNCH_LEVEL
Definition: env_spec_w32.h:704
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
VOID FASTCALL HalClearSoftwareInterrupt(IN KIRQL Irql)
Definition: pic.c:282
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void __cdecl _enable(void)
Definition: intrin_arm.h:373
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
@ Running
Definition: ketypes.h:390
BOOLEAN FASTCALL KiSwapContext(IN KIRQL WaitIrql, IN PKTHREAD CurrentThread)
VOID FASTCALL KiRetireDpcList(IN PKPRCB Prcb)
Definition: dpc.c:562
#define YieldProcessor
Definition: ke.h:48
volatile ULONG DpcQueueDepth
Definition: ketypes.h:858
UINT64 TimerRequest
Definition: ketypes.h:775
PROCESSOR_POWER_STATE PowerState
Definition: ketypes.h:879
KDPC_DATA DpcData[2]
Definition: ketypes.h:760
struct _KTHREAD * CurrentThread
Definition: ketypes.h:650
struct _KTHREAD * NextThread
Definition: ketypes.h:651
SINGLE_LIST_ENTRY DeferredReadyListHead
Definition: ketypes.h:712
volatile UCHAR State
Definition: ketypes.h:1789
PPROCESSOR_IDLE_FUNCTION IdleFunction
Definition: potypes.h:68
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:629

◆ KiSwapProcess()

VOID NTAPI KiSwapProcess ( IN PKPROCESS  NewProcess,
IN PKPROCESS  OldProcess 
)

Definition at line 165 of file stubs.c.

167{
168 PKIPCR Pcr = (PKIPCR)KeGetPcr();
169
170#ifdef CONFIG_SMP
171 /* Update active processor mask */
172 InterlockedXor64((PLONG64)&NewProcess->ActiveProcessors, Pcr->Prcb.SetMember);
173 InterlockedXor64((PLONG64)&OldProcess->ActiveProcessors, Pcr->Prcb.SetMember);
174#endif
175
176 /* Update CR3 */
177 __writecr3(NewProcess->DirectoryTableBase[0]);
178
179 /* Update IOPM offset */
180 Pcr->TssBase->IoMapBase = NewProcess->IopmOffset;
181}
__int64 * PLONG64
Definition: basetsd.h:183
#define InterlockedXor64
Definition: interlocked.h:291
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1794
struct _KIPCR * PKIPCR
#define KeGetPcr()
Definition: ketypes.h:81
KPRCB Prcb
Definition: ketypes.h:976
struct _KTSS64 * TssBase
Definition: ketypes.h:948
UINT64 SetMember
Definition: ketypes.h:662

◆ KiSwitchKernelStack()

PVOID NTAPI KiSwitchKernelStack ( PVOID  StackBase,
PVOID  StackLimit 
)

Definition at line 40 of file stubs.c.

41{
42 PKTHREAD CurrentThread;
43 PVOID OldStackBase;
44 LONG_PTR StackOffset;
46 PKIPCR Pcr;
47 ULONG Eflags;
48
49 /* Get the current thread */
50 CurrentThread = KeGetCurrentThread();
51
52 /* Save the old stack base */
53 OldStackBase = CurrentThread->StackBase;
54
55 /* Get the size of the current stack */
56 StackSize = (ULONG_PTR)CurrentThread->StackBase - CurrentThread->StackLimit;
57 ASSERT(StackSize <= (ULONG_PTR)StackBase - (ULONG_PTR)StackLimit);
58
59 /* Copy the current stack contents to the new stack */
60 RtlCopyMemory((PUCHAR)StackBase - StackSize,
61 (PVOID)CurrentThread->StackLimit,
62 StackSize);
63
64 /* Calculate the offset between the old and the new stack */
65 StackOffset = (PUCHAR)StackBase - (PUCHAR)CurrentThread->StackBase;
66
67 /* Disable interrupts while messing with the stack */
68 Eflags = __readeflags();
69 _disable();
70
71 /* Set the new trap frame */
72 CurrentThread->TrapFrame = (PKTRAP_FRAME)Add2Ptr(CurrentThread->TrapFrame,
73 StackOffset);
74
75 /* Set the new initial stack */
76 CurrentThread->InitialStack = Add2Ptr(CurrentThread->InitialStack,
77 StackOffset);
78
79 /* Set the new stack limits */
80 CurrentThread->StackBase = StackBase;
81 CurrentThread->StackLimit = (ULONG_PTR)StackLimit;
82 CurrentThread->LargeStack = TRUE;
83
84 /* Adjust RspBase in the PCR */
85 Pcr = (PKIPCR)KeGetPcr();
86 Pcr->Prcb.RspBase += StackOffset;
87
88 /* Adjust Rsp0 in the TSS */
89 Pcr->TssBase->Rsp0 += StackOffset;
90
91 /* Restore interrupts */
92 __writeeflags(Eflags);
93
94 return OldStackBase;
95}
static ULONG StackSize
Definition: StackOverflow.c:19
#define ULONG_PTR
Definition: config.h:101
#define KeGetCurrentThread
Definition: hal.h:55
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1669
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1674
#define Add2Ptr(PTR, INC)
#define ASSERT(a)
Definition: mode.c:44
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
struct _KTRAP_FRAME * PKTRAP_FRAME
UINT64 RspBase
Definition: ketypes.h:660
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1774
PVOID InitialStack
Definition: ketypes.h:1664
PVOID StackBase
Definition: ketypes.h:1666
volatile VOID * StackLimit
Definition: ketypes.h:1665
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59

◆ KiSwitchKernelStackHelper()

PVOID KiSwitchKernelStackHelper ( LONG_PTR  StackOffset,
PVOID  OldStackBase 
)

◆ NtSetLdtEntries()

NTSTATUS NTAPI NtSetLdtEntries ( ULONG  Selector1,
LDT_ENTRY  LdtEntry1,
ULONG  Selector2,
LDT_ENTRY  LdtEntry2 
)

Definition at line 185 of file stubs.c.

186{
188 __debugbreak();
189 return STATUS_UNSUCCESSFUL;
190}
#define UNIMPLEMENTED
Definition: stubs.c:6
void __cdecl __debugbreak(void)
Definition: intrin_ppc.h:698
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by init_funcs().

◆ NtVdmControl()

NTSTATUS NTAPI NtVdmControl ( IN ULONG  ControlCode,
IN PVOID  ControlData 
)

Definition at line 194 of file stubs.c.

196{
197 /* Not supported */
199}
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

Referenced by KiEnterV86Mode().

Variable Documentation

◆ KeXStateLength

SIZE_T KeXStateLength = sizeof(XSAVE_FORMAT)

Definition at line 18 of file stubs.c.

◆ ProcessCount

ULONG ProcessCount

Definition at line 17 of file stubs.c.