ReactOS  0.4.15-dev-5463-g138eb58
usercall.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for usercall.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KiInitializeUserApc (IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame, IN PKNORMAL_ROUTINE NormalRoutine, IN PVOID NormalContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
NTSTATUS NTAPI KeUserModeCallback (IN ULONG RoutineIndex, IN PVOID Argument, IN ULONG ArgumentLength, OUT PVOID *Result, OUT PULONG ResultLength)
 
NTSTATUS FASTCALL KiUserModeCallout (PKCALLOUT_FRAME CalloutFrame)
 
NTSTATUS NTAPI NtCallbackReturn (_In_ PVOID Result, _In_ ULONG ResultLength, _In_ NTSTATUS CallbackStatus)
 

Variables

PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file usercall.c.

Function Documentation

◆ KeUserModeCallback()

NTSTATUS NTAPI KeUserModeCallback ( IN ULONG  RoutineIndex,
IN PVOID  Argument,
IN ULONG  ArgumentLength,
OUT PVOID Result,
OUT PULONG  ResultLength 
)

Definition at line 131 of file usercall.c.

136 {
137  ULONG_PTR NewStack, OldStack;
138  PULONG UserEsp;
140  PEXCEPTION_REGISTRATION_RECORD ExceptionList;
141  PTEB Teb;
142  ULONG GdiBatchCount = 0;
143  ASSERT(KeGetCurrentThread()->ApcState.KernelApcInProgress == FALSE);
145 
146  /* Get the current user-mode stack */
147  UserEsp = KiGetUserModeStackAddress();
148  OldStack = *UserEsp;
149 
150  /* Enter a SEH Block */
151  _SEH2_TRY
152  {
153  /* Calculate and align the stack size */
154  NewStack = (OldStack - ArgumentLength) & ~3;
155 
156  /* Make sure it's writable */
157  ProbeForWrite((PVOID)(NewStack - 6 * sizeof(ULONG_PTR)),
158  ArgumentLength + 6 * sizeof(ULONG_PTR),
159  sizeof(CHAR));
160 
161  /* Copy the buffer into the stack */
162  RtlCopyMemory((PVOID)NewStack, Argument, ArgumentLength);
163 
164  /* Write the arguments */
165  NewStack -= 24;
166  *(PULONG)NewStack = 0;
167  *(PULONG)(NewStack + 4) = RoutineIndex;
168  *(PULONG)(NewStack + 8) = (NewStack + 24);
169  *(PULONG)(NewStack + 12) = ArgumentLength;
170 
171  /* Save the exception list */
172  Teb = KeGetCurrentThread()->Teb;
173  ExceptionList = Teb->NtTib.ExceptionList;
174 
175  /* Jump to user mode */
176  *UserEsp = NewStack;
179  {
180  /* Only restore the exception list if we didn't crash in ring 3 */
181  Teb->NtTib.ExceptionList = ExceptionList;
182  }
183  else
184  {
185  /* Otherwise, pop the stack */
186  OldStack = *UserEsp;
187  }
188 
189  /* Read the GDI Batch count */
190  GdiBatchCount = Teb->GdiBatchCount;
191  }
193  {
194  /* Get the SEH exception */
196  }
197  _SEH2_END;
198 
199  /* Check if we have GDI Batch operations */
200  if (GdiBatchCount)
201  {
202  *UserEsp -= 256;
204  }
205 
206  /* Restore stack and return */
207  *UserEsp = OldStack;
208  return CallbackStatus;
209 }
_SEH2_TRY
Definition: create.c:4226
#define STATUS_CALLBACK_POP_STACK
Definition: ntstatus.h:961
char CHAR
Definition: xmlstorage.h:175
#define KeGetPreviousMode()
Definition: ketypes.h:1108
LONG NTSTATUS
Definition: precomp.h:26
_SEH2_END
Definition: create.c:4400
FORCEINLINE PULONG_PTR KiGetUserModeStackAddress(void)
Definition: ke.h:465
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch
Definition: win32.c:20
#define ASSERT(a)
Definition: mode.c:44
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:711
_In_ FLT_PREOP_CALLBACK_STATUS CallbackStatus
Definition: fltkernel.h:1020
ULONG GdiBatchCount
Definition: compat.h:887
Definition: compat.h:835
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1727
unsigned int * PULONG
Definition: retypes.h:1
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define KeGetCurrentThread
Definition: hal.h:55
NTSTATUS NTAPI KiCallUserMode(IN PVOID *OutputBuffer, IN PULONG OutputLength)
Definition: usercall.c:321
NT_TIB NtTib
Definition: ntddk_ex.h:332

◆ KiInitializeUserApc()

VOID NTAPI KiInitializeUserApc ( IN PKEXCEPTION_FRAME  ExceptionFrame,
IN PKTRAP_FRAME  TrapFrame,
IN PKNORMAL_ROUTINE  NormalRoutine,
IN PVOID  NormalContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 47 of file usercall.c.

53 {
54  CONTEXT Context = { 0 };
55  ULONG_PTR Stack, AlignedEsp;
56  ULONG ContextLength;
57  EXCEPTION_RECORD SehExceptRecord;
58 
59  /* Don't deliver APCs in V86 mode */
60  if (TrapFrame->EFlags & EFLAGS_V86_MASK) return;
61 
62  /* Save the full context */
64  KeTrapFrameToContext(TrapFrame, ExceptionFrame, &Context);
65 
66  /* Protect with SEH */
67  _SEH2_TRY
68  {
69  /* Sanity check */
70  ASSERT(KiUserTrap(TrapFrame));
71 
72  /* Get the aligned size */
73  AlignedEsp = Context.Esp & ~3;
74  ContextLength = CONTEXT_ALIGNED_SIZE + (4 * sizeof(ULONG_PTR));
75  Stack = ((AlignedEsp - 8) & ~3) - ContextLength;
76 
77  /* Probe the stack */
78  ProbeForWrite((PVOID)Stack, AlignedEsp - Stack, 1);
79  ASSERT(!(Stack & 3));
80 
81  /* Copy data into it */
82  RtlCopyMemory((PVOID)(Stack + (4 * sizeof(ULONG_PTR))),
83  &Context,
84  sizeof(CONTEXT));
85 
86  /* Run at APC dispatcher */
87  TrapFrame->Eip = (ULONG)KeUserApcDispatcher;
88  TrapFrame->HardwareEsp = Stack;
89 
90  /* Setup Ring 3 state */
91  TrapFrame->SegCs = Ke386SanitizeSeg(KGDT_R3_CODE, UserMode);
92  TrapFrame->HardwareSegSs = Ke386SanitizeSeg(KGDT_R3_DATA, UserMode);
93  TrapFrame->SegDs = Ke386SanitizeSeg(KGDT_R3_DATA, UserMode);
94  TrapFrame->SegEs = Ke386SanitizeSeg(KGDT_R3_DATA, UserMode);
95  TrapFrame->SegFs = Ke386SanitizeSeg(KGDT_R3_TEB, UserMode);
96  TrapFrame->SegGs = 0;
97  TrapFrame->ErrCode = 0;
98 
99  /* Sanitize EFLAGS */
100  TrapFrame->EFlags = Ke386SanitizeFlags(Context.EFlags, UserMode);
101 
102  /* Check if thread has IOPL and force it enabled if so */
103  if (KeGetCurrentThread()->Iopl) TrapFrame->EFlags |= EFLAGS_IOPL;
104 
105  /* Setup the stack */
106  *(PULONG_PTR)(Stack + 0 * sizeof(ULONG_PTR)) = (ULONG_PTR)NormalRoutine;
107  *(PULONG_PTR)(Stack + 1 * sizeof(ULONG_PTR)) = (ULONG_PTR)NormalContext;
108  *(PULONG_PTR)(Stack + 2 * sizeof(ULONG_PTR)) = (ULONG_PTR)SystemArgument1;
109  *(PULONG_PTR)(Stack + 3 * sizeof(ULONG_PTR)) = (ULONG_PTR)SystemArgument2;
110  }
112  {
113  /* Dispatch the exception */
114  SehExceptRecord.ExceptionAddress = (PVOID)TrapFrame->Eip;
115  KiDispatchException(&SehExceptRecord,
116  ExceptionFrame,
117  TrapFrame,
118  UserMode,
119  TRUE);
120  }
121  _SEH2_END;
122 }
_SEH2_TRY
Definition: create.c:4226
PVOID KeUserApcDispatcher
Definition: ke.h:142
#define TRUE
Definition: types.h:120
FORCEINLINE ULONG Ke386SanitizeFlags(IN ULONG Eflags, IN KPROCESSOR_MODE Mode)
Definition: ke.h:699
#define CONTEXT_ALIGNED_SIZE
Definition: asm.h:364
_SEH2_END
Definition: create.c:4400
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
PVOID ExceptionAddress
Definition: compat.h:211
#define EFLAGS_V86_MASK
Definition: ketypes.h:132
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
VOID NTAPI KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164
#define KGDT_R3_DATA
Definition: ketypes.h:78
VOID NTAPI KeTrapFrameToContext(IN PKTRAP_FRAME TrapFrame, IN PKEXCEPTION_FRAME ExceptionFrame, IN OUT PCONTEXT Context)
Definition: context.c:169
void * PVOID
Definition: retypes.h:9
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
#define CONTEXT_FULL
Definition: nt_native.h:1375
#define ASSERT(a)
Definition: mode.c:44
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define KGDT_R3_TEB
Definition: ketypes.h:81
#define CONTEXT_DEBUG_REGISTERS
Definition: nt_native.h:1373
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:364
FORCEINLINE ULONG Ke386SanitizeSeg(IN ULONG Cs, IN KPROCESSOR_MODE Mode)
Definition: ke.h:682
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
#define KGDT_R3_CODE
Definition: ketypes.h:77
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define EFLAGS_IOPL
Definition: ketypes.h:128
#define KeGetCurrentThread
Definition: hal.h:55

Referenced by KiDeliverApc(), and PspUserThreadStartup().

◆ KiUserModeCallout()

NTSTATUS FASTCALL KiUserModeCallout ( PKCALLOUT_FRAME  CalloutFrame)

Definition at line 238 of file usercall.c.

239 {
240  PKTHREAD CurrentThread;
241  PKTRAP_FRAME TrapFrame, CallbackTrapFrame;
242  PFX_SAVE_AREA FxSaveArea, OldFxSaveArea;
243  PKPCR Pcr;
244  PKTSS Tss;
245  ULONG_PTR InitialStack;
247 
248  /* Get the current thread */
249  CurrentThread = KeGetCurrentThread();
250 
251 #if DBG
252  /* Check if we are at pasive level */
254  {
255  /* We're not, bugcheck */
256  KeBugCheckEx(IRQL_GT_ZERO_AT_SYSTEM_SERVICE,
257  0,
259  0,
260  0);
261  }
262 
263  /* Check if we are attached or APCs are disabled */
264  if ((CurrentThread->ApcStateIndex != OriginalApcEnvironment) ||
265  (CurrentThread->CombinedApcDisable > 0))
266  {
267  KeBugCheckEx(APC_INDEX_MISMATCH,
268  0,
269  CurrentThread->ApcStateIndex,
270  CurrentThread->CombinedApcDisable,
271  0);
272  }
273 #endif
274 
275  /* Align stack on a 16-byte boundary */
276  InitialStack = ALIGN_DOWN_BY(CalloutFrame, 16);
277 
278  /* Check if we have enough space on the stack */
279  if ((InitialStack - KERNEL_STACK_SIZE) < CurrentThread->StackLimit)
280  {
281  /* We don't, we'll have to grow our stack */
282  Status = MmGrowKernelStack((PVOID)InitialStack);
283 
284  /* Quit if we failed */
285  if (!NT_SUCCESS(Status))
286  {
288  {
289  DPRINT1("Thread wants too much stack\n");
290  }
291 
292  return Status;
293  }
294  }
295 
296  /* Save the current callback stack and initial stack */
297  CalloutFrame->CallbackStack = (ULONG_PTR)CurrentThread->CallbackStack;
298  CalloutFrame->InitialStack = (ULONG_PTR)CurrentThread->InitialStack;
299 
300  /* Get and save the trap frame */
301  TrapFrame = CurrentThread->TrapFrame;
302  CalloutFrame->TrapFrame = (ULONG_PTR)TrapFrame;
303 
304  /* Set the new callback stack */
305  CurrentThread->CallbackStack = CalloutFrame;
306 
307  /* Set destination and origin NPX Areas */
308  OldFxSaveArea = (PVOID)(CalloutFrame->InitialStack - sizeof(FX_SAVE_AREA));
309  FxSaveArea = (PVOID)(InitialStack - sizeof(FX_SAVE_AREA));
310 
311  /* Disable interrupts so we can fill the NPX State */
312  _disable();
313 
314  /* Now copy the NPX State */
315  FxSaveArea->U.FnArea.ControlWord = OldFxSaveArea->U.FnArea.ControlWord;
316  FxSaveArea->U.FnArea.StatusWord = OldFxSaveArea->U.FnArea.StatusWord;
317  FxSaveArea->U.FnArea.TagWord = OldFxSaveArea->U.FnArea.TagWord;
318  FxSaveArea->U.FnArea.DataSelector = OldFxSaveArea->U.FnArea.DataSelector;
319  FxSaveArea->Cr0NpxState = OldFxSaveArea->Cr0NpxState;
320 
321  /* Set the stack address */
322  CurrentThread->InitialStack = (PVOID)InitialStack;
323 
324  /* Locate the trap frame on the callback stack */
325  CallbackTrapFrame = (PVOID)((ULONG_PTR)FxSaveArea - sizeof(KTRAP_FRAME));
326 
327  /* Copy the trap frame to the new location */
328  *CallbackTrapFrame = *TrapFrame;
329 
330  /* Get PCR */
331  Pcr = KeGetPcr();
332 
333  /* Update the exception list */
334  CallbackTrapFrame->ExceptionList = Pcr->NtTib.ExceptionList;
335 
336  /* Get TSS */
337  Tss = Pcr->TSS;
338 
339  /* Check for V86 mode */
340  if (CallbackTrapFrame->EFlags & EFLAGS_V86_MASK)
341  {
342  /* Set new stack address in TSS (full trap frame) */
343  Tss->Esp0 = (ULONG_PTR)(CallbackTrapFrame + 1);
344  }
345  else
346  {
347  /* Set new stack address in TSS (non-V86 trap frame) */
348  Tss->Esp0 = (ULONG_PTR)&CallbackTrapFrame->V86Es;
349  }
350 
351  /* Set user-mode dispatcher address as EIP */
352  CallbackTrapFrame->Eip = (ULONG_PTR)KeUserCallbackDispatcher;
353 
354  /* Bring interrupts back */
355  _enable();
356 
357  /* Exit to user-mode */
358  KiServiceExit(CallbackTrapFrame, 0);
359 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
ULONG DataSelector
Definition: ketypes.h:422
ULONG V86Es
Definition: ketypes.h:273
union _FX_SAVE_AREA::@2412 U
ULONG CombinedApcDisable
Definition: ketypes.h:1823
ULONG TagWord
Definition: ketypes.h:418
void __cdecl _enable(void)
Definition: intrin_arm.h:373
LONG NTSTATUS
Definition: precomp.h:26
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1714
ULONG64 TrapFrame
Definition: ketypes.h:953
Definition: ke.h:289
#define KeGetPcr()
Definition: ke.h:26
#define EFLAGS_V86_MASK
Definition: ketypes.h:132
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _KTRAP_FRAME KTRAP_FRAME
PVOID KeUserCallbackDispatcher
Definition: ke.h:143
Definition: ketypes.h:790
ULONG Cr0NpxState
Definition: ketypes.h:452
void * PVOID
Definition: retypes.h:9
NTSTATUS NTAPI MmGrowKernelStack(IN PVOID StackPointer)
Definition: procsup.c:476
DECLSPEC_NORETURN VOID FASTCALL KiServiceExit(IN PKTRAP_FRAME TrapFrame, IN NTSTATUS Status)
Definition: traphdlr.c:150
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:711
volatile VOID * StackLimit
Definition: ketypes.h:1605
struct _EXCEPTION_REGISTRATION_RECORD FAR * ExceptionList
Definition: ketypes.h:261
#define KERNEL_STACK_SIZE
ULONG ControlWord
Definition: ketypes.h:416
NT_TIB NtTib
Definition: ke.h:293
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
ULONG Eip
Definition: ketypes.h:268
#define ALIGN_DOWN_BY(size, align)
ULONG StatusWord
Definition: ketypes.h:417
struct _KTSS * TSS
Definition: ke.h:55
ULONG Esp0
Definition: ketypes.h:794
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:489
FNSAVE_FORMAT FnArea
Definition: ketypes.h:448
#define DPRINT1
Definition: precomp.h:8
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define ULONG_PTR
Definition: config.h:101
UCHAR ApcStateIndex
Definition: ketypes.h:1882
#define KeGetCurrentThread
Definition: hal.h:55
PVOID InitialStack
Definition: ketypes.h:1604
ULONG EFlags
Definition: ketypes.h:389
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108

◆ NtCallbackReturn()

NTSTATUS NTAPI NtCallbackReturn ( _In_ PVOID  Result,
_In_ ULONG  ResultLength,
_In_ NTSTATUS  CallbackStatus 
)

Definition at line 386 of file usercall.c.

390 {
391  PKTHREAD CurrentThread;
392  PKCALLOUT_FRAME CalloutFrame;
393  PKTRAP_FRAME CallbackTrapFrame, TrapFrame;
394  PFX_SAVE_AREA FxSaveArea, CbFxSaveArea;
395  ULONG Size;
396  PKPCR Pcr;
397  PKTSS Tss;
398 
399  /* Get the current thread and make sure we have a callback stack */
400  CurrentThread = KeGetCurrentThread();
401  CalloutFrame = CurrentThread->CallbackStack;
402  if (CalloutFrame == NULL)
403  {
405  }
406 
407  /* Get the trap frame */
408  CallbackTrapFrame = CurrentThread->TrapFrame;
409 
410  /* Restore the exception list */
411  Pcr = KeGetPcr();
412  Pcr->NtTib.ExceptionList = CallbackTrapFrame->ExceptionList;
413 
414  /* Store the results in the callback stack */
415  *((PVOID*)CalloutFrame->Result) = Result;
416  *((ULONG*)CalloutFrame->ResultLength) = ResultLength;
417 
418  /* Disable interrupts for NPX save and stack switch */
419  _disable();
420 
421  /* Set desination and origin NPX Frames */
422  CbFxSaveArea = (PVOID)((ULONG)CurrentThread->InitialStack - sizeof(FX_SAVE_AREA));
423  FxSaveArea = (PVOID)(CalloutFrame->InitialStack - sizeof(FX_SAVE_AREA));
424 
425  /* Now copy back NPX State */
426  FxSaveArea->U.FnArea.ControlWord = CbFxSaveArea->U.FnArea.ControlWord;
427  FxSaveArea->U.FnArea.StatusWord = CbFxSaveArea->U.FnArea.StatusWord;
428  FxSaveArea->U.FnArea.TagWord = CbFxSaveArea->U.FnArea.TagWord;
429  FxSaveArea->U.FnArea.DataSelector = CbFxSaveArea->U.FnArea.DataSelector;
430  FxSaveArea->Cr0NpxState = CbFxSaveArea->Cr0NpxState;
431 
432  /* Get the previous trap frame */
433  TrapFrame = (PKTRAP_FRAME)CalloutFrame->TrapFrame;
434 
435  /* Check if we failed in user mode */
437  {
438  /* Check if we came from v86 mode */
439  if (CallbackTrapFrame->EFlags & EFLAGS_V86_MASK)
440  {
441  Size = sizeof(KTRAP_FRAME) - FIELD_OFFSET(KTRAP_FRAME, SegFs);
442  }
443  else
444  {
446  }
447 
448  /* Copy back part of the trap frame */
449  RtlCopyMemory(&TrapFrame->SegFs, &CallbackTrapFrame->SegFs, Size);
450  }
451 
452  /* Clear DR7 */
453  TrapFrame->Dr7 = 0;
454 
455  /* Check if debugging was active */
456  if (CurrentThread->Header.DebugActive & 0xFF)
457  {
458  /* Copy debug registers data from it */
459  TrapFrame->Dr0 = CallbackTrapFrame->Dr0;
460  TrapFrame->Dr1 = CallbackTrapFrame->Dr1;
461  TrapFrame->Dr2 = CallbackTrapFrame->Dr2;
462  TrapFrame->Dr3 = CallbackTrapFrame->Dr3;
463  TrapFrame->Dr6 = CallbackTrapFrame->Dr6;
464  TrapFrame->Dr7 = CallbackTrapFrame->Dr7;
465  }
466 
467  /* Get TSS */
468  Tss = Pcr->TSS;
469 
470  /* Check for V86 mode */
471  if (TrapFrame->EFlags & EFLAGS_V86_MASK)
472  {
473  /* Set new stack address in TSS (full trap frame) */
474  Tss->Esp0 = (ULONG_PTR)(TrapFrame + 1);
475  }
476  else
477  {
478  /* Set new stack address in TSS (non-V86 trap frame) */
479  Tss->Esp0 = (ULONG_PTR)&TrapFrame->V86Es;
480  }
481 
482  /* Get the initial stack and restore it */
483  CurrentThread->InitialStack = (PVOID)CalloutFrame->InitialStack;
484 
485  /* Restore the trap frame and the previous callback stack */
486  CurrentThread->TrapFrame = TrapFrame;
487  CurrentThread->CallbackStack = (PVOID)CalloutFrame->CallbackStack;
488 
489  /* Bring interrupts back */
490  _enable();
491 
492  /* Now switch back to the old stack */
493  KiCallbackReturn(&CalloutFrame->Edi, CallbackStatus);
494 }
ULONG DataSelector
Definition: ketypes.h:422
ULONG V86Es
Definition: ketypes.h:273
union _FX_SAVE_AREA::@2412 U
#define STATUS_CALLBACK_POP_STACK
Definition: ntstatus.h:961
ULONG TagWord
Definition: ketypes.h:418
void __cdecl _enable(void)
Definition: intrin_arm.h:373
USHORT SegFs
Definition: ketypes.h:371
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1714
ULONG64 TrapFrame
Definition: ketypes.h:953
Definition: ke.h:289
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define KeGetPcr()
Definition: ke.h:26
#define EFLAGS_V86_MASK
Definition: ketypes.h:132
struct _KTRAP_FRAME KTRAP_FRAME
UINT64 Dr2
Definition: ketypes.h:349
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
Definition: ketypes.h:790
ULONG Cr0NpxState
Definition: ketypes.h:452
void * PVOID
Definition: retypes.h:9
struct _FX_SAVE_AREA FX_SAVE_AREA
struct _EXCEPTION_REGISTRATION_RECORD * ExceptionList
Definition: compat.h:711
UINT64 Dr6
Definition: ketypes.h:351
struct _EXCEPTION_REGISTRATION_RECORD FAR * ExceptionList
Definition: ketypes.h:261
UINT64 Dr3
Definition: ketypes.h:350
ULONG ControlWord
Definition: ketypes.h:416
_In_ FLT_PREOP_CALLBACK_STATUS CallbackStatus
Definition: fltkernel.h:1020
UINT64 Dr1
Definition: ketypes.h:348
NT_TIB NtTib
Definition: ke.h:293
BOOLEAN DebugActive
Definition: ketypes.h:781
DECLSPEC_NORETURN VOID FASTCALL KiCallbackReturn(IN PVOID Stack, IN NTSTATUS Status)
UINT64 Dr0
Definition: ketypes.h:347
ULONG StatusWord
Definition: ketypes.h:417
#define STATUS_NO_CALLBACK_ACTIVE
Definition: ntstatus.h:726
struct _KTSS * TSS
Definition: ke.h:55
ULONG Esp0
Definition: ketypes.h:794
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
FNSAVE_FORMAT FnArea
Definition: ketypes.h:448
DISPATCHER_HEADER Header
Definition: ketypes.h:1601
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
struct _KTRAP_FRAME * PKTRAP_FRAME
UINT64 Dr7
Definition: ketypes.h:352
#define KeGetCurrentThread
Definition: hal.h:55
PVOID InitialStack
Definition: ketypes.h:1604
ULONG EFlags
Definition: ketypes.h:389

Variable Documentation

◆ KeGdiFlushUserBatch

PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch

Definition at line 20 of file win32.c.

Referenced by KeUserModeCallback(), and PsEstablishWin32Callouts().