ReactOS  0.4.15-dev-1384-g878186b
ke.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifndef __ASM__
4 
5 #include "intrin_i.h"
6 
7 //
8 // Thread Dispatcher Header DebugActive Mask
9 //
10 #define DR_MASK(x) (1 << (x))
11 #define DR_REG_MASK 0x4F
12 
13 //
14 // INT3 is 1 byte long
15 //
16 #define KD_BREAKPOINT_TYPE UCHAR
17 #define KD_BREAKPOINT_SIZE sizeof(UCHAR)
18 #define KD_BREAKPOINT_VALUE 0xCC
19 
20 //
21 // Macros for getting and setting special purpose registers in portable code
22 //
23 #define KeGetContextPc(Context) \
24  ((Context)->Eip)
25 
26 #define KeSetContextPc(Context, ProgramCounter) \
27  ((Context)->Eip = (ProgramCounter))
28 
29 #define KeGetTrapFramePc(TrapFrame) \
30  ((TrapFrame)->Eip)
31 
32 #define KiGetLinkedTrapFrame(x) \
33  (PKTRAP_FRAME)((x)->Edx)
34 
35 #define KeGetContextReturnRegister(Context) \
36  ((Context)->Eax)
37 
38 #define KeSetContextReturnRegister(Context, ReturnValue) \
39  ((Context)->Eax = (ReturnValue))
40 
41 //
42 // Macro to get trap and exception frame from a thread stack
43 //
44 #define KeGetTrapFrame(Thread) \
45  (PKTRAP_FRAME)((ULONG_PTR)((Thread)->InitialStack) - \
46  sizeof(KTRAP_FRAME) - \
47  sizeof(FX_SAVE_AREA))
48 
49 #define KeGetExceptionFrame(Thread) \
50  NULL
51 
52 //
53 // Macro to get context switches from the PRCB
54 // All architectures but x86 have it in the PRCB's KeContextSwitches
55 //
56 #define KeGetContextSwitches(Prcb) \
57  CONTAINING_RECORD(Prcb, KIPCR, PrcbData)->ContextSwitches
58 
59 //
60 // Macro to get the second level cache size field name which differs between
61 // CISC and RISC architectures, as the former has unified I/D cache
62 //
63 #define KiGetSecondLevelDCacheSize() ((PKIPCR)KeGetPcr())->SecondLevelCacheSize
64 
65 //
66 // Returns the Interrupt State from a Trap Frame.
67 // ON = TRUE, OFF = FALSE
68 //
69 #define KeGetTrapFrameInterruptState(TrapFrame) \
70  BooleanFlagOn((TrapFrame)->EFlags, EFLAGS_INTERRUPT_MASK)
71 
72 //
73 // Flags for exiting a trap
74 //
75 #define KTE_SKIP_PM_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipPreviousMode = TRUE } }).Bits)
76 #define KTE_SKIP_SEG_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipSegments = TRUE } }).Bits)
77 #define KTE_SKIP_VOL_BIT (((KTRAP_EXIT_SKIP_BITS) { { .SkipVolatiles = TRUE } }).Bits)
78 
79 typedef union _KTRAP_EXIT_SKIP_BITS
80 {
81  struct
82  {
87  };
90 
91 
92 //
93 // Flags used by the VDM/V8086 emulation engine for determining instruction prefixes
94 //
95 #define PFX_FLAG_ES 0x00000100
96 #define PFX_FLAG_CS 0x00000200
97 #define PFX_FLAG_SS 0x00000400
98 #define PFX_FLAG_DS 0x00000800
99 #define PFX_FLAG_FS 0x00001000
100 #define PFX_FLAG_GS 0x00002000
101 #define PFX_FLAG_OPER32 0x00004000
102 #define PFX_FLAG_ADDR32 0x00008000
103 #define PFX_FLAG_LOCK 0x00010000
104 #define PFX_FLAG_REPNE 0x00020000
105 #define PFX_FLAG_REP 0x00040000
106 
107 //
108 // VDM Helper Macros
109 //
110 // All VDM/V8086 opcode emulators have the same FASTCALL function definition.
111 // We need to keep 2 parameters while the original ASM implementation uses 4:
112 // TrapFrame, PrefixFlags, Eip, InstructionSize;
113 //
114 // We pass the trap frame, and prefix flags, in our two parameters.
115 //
116 // We then realize that since the smallest prefix flag is 0x100, this gives us
117 // a count of up to 0xFF. So we OR in the instruction size with the prefix flags
118 //
119 // We further realize that we always have access to EIP from the trap frame, and
120 // that if we want the *current instruction* EIP, we simply have to add the
121 // instruction size *MINUS ONE*, and that gives us the EIP we should be looking
122 // at now, so we don't need to use the stack to push this parameter.
123 //
124 // We actually only care about the *current instruction* EIP in one location,
125 // so although it may be slightly more expensive to re-calculate the EIP one
126 // more time, this way we don't redefine ALL opcode handlers to have 3 parameters,
127 // which would be forcing stack usage in all other scenarios.
128 //
129 #define KiVdmSetVdmEFlags(x) InterlockedOr((PLONG)KiNtVdmState, (x));
130 #define KiVdmClearVdmEFlags(x) InterlockedAnd((PLONG)KiNtVdmState, ~(x))
131 #define KiCallVdmHandler(x) KiVdmOpcode##x(TrapFrame, Flags)
132 #define KiCallVdmPrefixHandler(x) KiVdmOpcodePrefix(TrapFrame, Flags | x)
133 #define KiVdmUnhandledOpcode(x) \
134  BOOLEAN \
135  FASTCALL \
136  KiVdmOpcode##x(IN PKTRAP_FRAME TrapFrame, \
137  IN ULONG Flags) \
138  { \
139  /* Not yet handled */ \
140  UNIMPLEMENTED_DBGBREAK(); \
141  return FALSE; \
142  }
143 
145 
146 //
147 // Local parameters
148 //
149 typedef struct _KV86_FRAME
150 {
155 
156 //
157 // Virtual Stack Frame
158 //
159 typedef struct _KV8086_STACK_FRAME
160 {
165 
166 //
167 // Large Pages Support
168 //
169 typedef struct _LARGE_IDENTITY_MAP
170 {
177 
178 /* Diable interrupts and return whether they were enabled before */
180 BOOLEAN
182 {
183  ULONG Flags;
184  BOOLEAN Return;
185 
186  /* Get EFLAGS and check if the interrupt bit is set */
187  Flags = __readeflags();
188  Return = (Flags & EFLAGS_INTERRUPT_MASK) ? TRUE: FALSE;
189 
190  /* Disable interrupts */
191  _disable();
192  return Return;
193 }
194 
195 /* Restore previous interrupt state */
197 VOID
199 {
200  if (WereEnabled) _enable();
201 }
202 
203 //
204 // Registers an interrupt handler with an IDT vector
205 //
207 VOID
209  IN PVOID Handler)
210 {
211  UCHAR Entry;
213  PKIPCR Pcr = (PKIPCR)KeGetPcr();
214 
215  //
216  // Get the entry from the HAL
217  //
220 
221  //
222  // Now set the data
223  //
224  Pcr->IDT[Entry].ExtendedOffset = (USHORT)(Address >> 16);
225  Pcr->IDT[Entry].Offset = (USHORT)Address;
226 }
227 
228 //
229 // Returns the registered interrupt handler for a given IDT vector
230 //
232 PVOID
234 {
235  PKIPCR Pcr = (PKIPCR)KeGetPcr();
236  UCHAR Entry;
237 
238  //
239  // Get the entry from the HAL
240  //
242 
243  //
244  // Read the entry from the IDT
245  //
246  return (PVOID)(((Pcr->IDT[Entry].ExtendedOffset << 16) & 0xFFFF0000) |
247  (Pcr->IDT[Entry].Offset & 0xFFFF));
248 }
249 
250 //
251 // Invalidates the TLB entry for a specified address
252 //
254 VOID
256 {
257  /* Invalidate the TLB entry for this address */
258  __invlpg(Address);
259 }
260 
262 VOID
264 {
265  /* Flush the TLB by resetting CR3 */
267 }
268 
270 VOID
272  IN SIZE_T FlushSize)
273 {
274  //
275  // Always sweep the whole cache
276  //
278  UNREFERENCED_PARAMETER(FlushSize);
279  __wbinvd();
280 }
281 
283 PRKTHREAD
285 {
286  /* Return the current thread */
287  return ((PKIPCR)KeGetPcr())->PrcbData.CurrentThread;
288 }
289 
291 VOID
293 {
294 #ifndef CONFIG_SMP
295  /* Check if this is the NPX Thread */
296  if (KeGetCurrentPrcb()->NpxThread == Thread)
297  {
298  /* Clear it */
299  KeGetCurrentPrcb()->NpxThread = NULL;
300  Ke386FnInit();
301  }
302 #else
303  /* Nothing to do */
304 #endif
305 }
306 
308 VOID
310 {
311  GdtEntry->BaseLow = (USHORT)((ULONG_PTR)BaseAddress & 0xFFFF);
312  GdtEntry->HighWord.Bytes.BaseMid = (UCHAR)((ULONG_PTR)BaseAddress >> 16);
313  GdtEntry->HighWord.Bytes.BaseHi = (UCHAR)((ULONG_PTR)BaseAddress >> 24);
314 }
315 
317 VOID
318 KiSetTebBase(PKPCR Pcr, PVOID TebAddress)
319 {
320  Pcr->NtTib.Self = TebAddress;
321  Ke386SetGdtEntryBase(&Pcr->GDT[KGDT_R3_TEB / sizeof(KGDTENTRY)], TebAddress);
322 }
323 
324 VOID
325 FASTCALL
327  IN PKTSS Tss,
328  IN PKIDTENTRY Idt,
329  IN PKGDTENTRY Gdt
330 );
331 
332 VOID
333 NTAPI
335 
336 VOID
337 NTAPI
339 
340 BOOLEAN
341 NTAPI
343  VOID
344 );
345 
346 BOOLEAN
347 NTAPI
349  VOID
350 );
351 
352 VOID
353 NTAPI
355 
356 ULONG
357 NTAPI
359 
360 VOID
361 NTAPI
363 
364 NTSTATUS
365 NTAPI
368  IN ULONG Offset,
370 );
371 
372 VOID
373 NTAPI
375  IN FLOATING_SAVE_AREA *SaveArea
376 );
377 
378 VOID
379 NTAPI
381  IN PKTRAP_FRAME TrapFrame
382 );
383 
384 VOID
385 NTAPI
387  OUT PTEB VdmTeb
388 );
389 
390 VOID
391 NTAPI
393  VOID
394 );
395 
396 ULONG_PTR
397 NTAPI
400 );
401 
402 ULONG_PTR
403 NTAPI
406 );
407 
408 BOOLEAN
409 NTAPI
411  IN PLARGE_IDENTITY_MAP IdentityMap,
412  IN PVOID StartPtr,
413  IN ULONG Length
414 );
415 
416 VOID
417 NTAPI
419  IN PLARGE_IDENTITY_MAP IdentityMap
420 );
421 
422 VOID
423 NTAPI
425  IN ULONG_PTR StartAddress,
426  IN ULONG Cr3
427 );
428 
429 VOID
430 NTAPI
432  VOID
433 );
434 
435 VOID
436 NTAPI
438  VOID
439 );
440 
441 VOID
442 NTAPI
444  IN BOOLEAN FinalCpu
445 );
446 
447 VOID
448 NTAPI
450  VOID
451 );
452 
453 VOID
454 NTAPI
456  VOID
457 );
458 
459 ULONG_PTR
460 NTAPI
463 );
464 
465 ULONG_PTR
466 NTAPI
469 );
470 
471 ULONG_PTR
472 NTAPI
475 );
476 
477 BOOLEAN
478 NTAPI
480  IN PKTRAP_FRAME TrapFrame
481 );
482 
483 BOOLEAN
484 NTAPI
486  _In_ PKTRAP_FRAME TrapFrame
487 );
488 
489 BOOLEAN
490 FASTCALL
492  IN PKTRAP_FRAME TrapFrame,
493  IN ULONG Flags
494 );
495 
496 BOOLEAN
497 FASTCALL
499  IN PKTRAP_FRAME TrapFrame
500 );
501 
503 VOID
504 FASTCALL
506  IN PKTRAP_FRAME TrapFrame
507 );
508 
509 VOID
510 FASTCALL
512  IN PKTRAP_FRAME TrapFrame
513 );
514 
515 ULONG_PTR
516 FASTCALL
518  IN PKTRAP_FRAME TrapFrame
519 );
520 
522 VOID
523 NTAPI
525  IN NTSTATUS Code,
526  IN ULONG Flags,
528  IN ULONG ParameterCount,
529  IN ULONG_PTR Parameter1,
530  IN ULONG_PTR Parameter2,
531  IN ULONG_PTR Parameter3,
532  IN PKTRAP_FRAME TrapFrame
533 );
534 
535 NTSTATUS
536 NTAPI
538  VOID
539 );
540 
541 //
542 // Global x86 only Kernel data
543 //
544 extern PVOID Ki386IopmSaveArea;
551 extern ULONG KeI386NpxPresent;
552 extern ULONG KeI386XMMIPresent;
553 extern ULONG KeI386FxsrPresent;
554 extern ULONG KiMXCsrMask;
555 extern ULONG KeI386CpuType;
556 extern ULONG KeI386CpuStep;
560 extern VOID __cdecl KiTrap02(VOID);
561 extern VOID __cdecl KiTrap08(VOID);
562 extern VOID __cdecl KiTrap13(VOID);
566 extern VOID __cdecl CopyParams(VOID);
567 extern VOID __cdecl ReadBatch(VOID);
569 extern CHAR KiSystemCallExit[];
570 extern CHAR KiSystemCallExit2[];
571 
572 //
573 // Trap Macros
574 //
575 #include "trap_x.h"
576 
577 //
578 // Returns a thread's FPU save area
579 //
583 {
584  ASSERT((ULONG_PTR)Thread->InitialStack % 16 == 0);
585  return (PFX_SAVE_AREA)((ULONG_PTR)Thread->InitialStack - sizeof(FX_SAVE_AREA));
586 }
587 
588 //
589 // Sanitizes a selector
590 //
592 ULONG
595 {
596  //
597  // Check if we're in kernel-mode, and force CPL 0 if so.
598  // Otherwise, force CPL 3.
599  //
600  return ((Mode == KernelMode) ?
601  (Cs & (0xFFFF & ~RPL_MASK)) :
602  (RPL_MASK | (Cs & 0xFFFF)));
603 }
604 
605 //
606 // Sanitizes EFLAGS
607 //
609 ULONG
612 {
613  //
614  // Check if we're in kernel-mode, and sanitize EFLAGS if so.
615  // Otherwise, also force interrupt mask on.
616  //
617  return ((Mode == KernelMode) ?
620 }
621 
622 //
623 // Sanitizes a Debug Register
624 //
626 PVOID
629 {
630  //
631  // Check if we're in kernel-mode, and return the address directly if so.
632  // Otherwise, make sure it's not inside the kernel-mode address space.
633  // If it is, then clear the address.
634  //
635  return ((Mode == KernelMode) ? DrAddress :
636  (DrAddress <= MM_HIGHEST_USER_ADDRESS) ? DrAddress : 0);
637 }
638 
639 //
640 // Exception with no arguments
641 //
644 VOID
647  IN PKTRAP_FRAME TrapFrame)
648 {
649  /* Helper for exceptions with no arguments */
650  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 0, 0, 0, 0, TrapFrame);
651 }
652 
653 //
654 // Exception with one argument
655 //
658 VOID
661  IN ULONG P1,
662  IN PKTRAP_FRAME TrapFrame)
663 {
664  /* Helper for exceptions with no arguments */
665  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 1, P1, 0, 0, TrapFrame);
666 }
667 
668 //
669 // Exception with two arguments
670 //
673 VOID
676  IN ULONG P1,
677  IN ULONG P2,
678  IN PKTRAP_FRAME TrapFrame)
679 {
680  /* Helper for exceptions with no arguments */
681  KiDispatchExceptionFromTrapFrame(Code, 0, Address, 2, P1, P2, 0, TrapFrame);
682 }
683 
684 //
685 // Performs a system call
686 //
687 
688  /*
689  * This sequence does a RtlCopyMemory(Stack - StackBytes, Arguments, StackBytes)
690  * and then calls the function associated with the system call.
691  *
692  * It's done in assembly for two reasons: we need to muck with the stack,
693  * and the call itself restores the stack back for us. The only way to do
694  * this in C is to do manual C handlers for every possible number of args on
695  * the stack, and then have the handler issue a call by pointer. This is
696  * wasteful since it'll basically push the values twice and require another
697  * level of call indirection.
698  *
699  * The ARM kernel currently does this, but it should probably be changed
700  * later to function like this as well.
701  *
702  */
703 #ifdef __GNUC__
705 NTSTATUS
706 KiSystemCallTrampoline(IN PVOID Handler,
707  IN PVOID Arguments,
708  IN ULONG StackBytes)
709 {
711 
712  __asm__ __volatile__
713  (
714  "subl %1, %%esp\n\t"
715  "movl %%esp, %%edi\n\t"
716  "movl %2, %%esi\n\t"
717  "shrl $2, %1\n\t"
718  "rep movsd\n\t"
719  "call *%3\n\t"
720  "movl %%eax, %0"
721  : "=r"(Result)
722  : "c"(StackBytes),
723  "d"(Arguments),
724  "r"(Handler)
725  : "%esp", "%esi", "%edi"
726  );
727  return Result;
728 }
729 #elif defined(_MSC_VER)
731 NTSTATUS
732 KiSystemCallTrampoline(IN PVOID Handler,
733  IN PVOID Arguments,
734  IN ULONG StackBytes)
735 {
736  __asm
737  {
738  mov ecx, StackBytes
739  mov esi, Arguments
740  mov eax, Handler
741  sub esp, ecx
742  mov edi, esp
743  shr ecx, 2
744  rep movsd
745  call eax
746  }
747  /* Return with result in EAX */
748 }
749 #else
750 #error Unknown Compiler
751 #endif
752 
753 
754 //
755 // Checks for pending APCs
756 //
758 VOID
760 {
762  KIRQL OldIrql;
763 
764  /* Check for V8086 or user-mode trap */
765  if ((TrapFrame->EFlags & EFLAGS_V86_MASK) || (KiUserTrap(TrapFrame)))
766  {
767  /* Get the thread */
769  while (TRUE)
770  {
771  /* Turn off the alerted state for kernel mode */
772  Thread->Alerted[KernelMode] = FALSE;
773 
774  /* Are there pending user APCs? */
775  if (!Thread->ApcState.UserApcPending) break;
776 
777  /* Raise to APC level and enable interrupts */
779  _enable();
780 
781  /* Deliver APCs */
782  KiDeliverApc(UserMode, NULL, TrapFrame);
783 
784  /* Restore IRQL and disable interrupts once again */
786  _disable();
787  }
788  }
789 }
790 
791 //
792 // Switches from boot loader to initial kernel stack
793 //
795 VOID
797 {
799 
800  /* We have to switch to a new stack before continuing kernel initialization */
801 #ifdef __GNUC__
802  __asm__
803  (
804  "movl %0, %%esp\n\t"
805  "subl %1, %%esp\n\t"
806  "pushl %2\n\t"
807  "jmp _KiSystemStartupBootStack@0"
808  :
809  : "c"(InitialStack),
811  "i"(CR0_EM | CR0_TS | CR0_MP),
813  : "%esp"
814  );
815 #elif defined(_MSC_VER)
816  __asm
817  {
818  mov esp, InitialStack
820  push (CR0_EM | CR0_TS | CR0_MP)
822  }
823 #else
824 #error Unknown Compiler
825 #endif
826 }
827 
828 //
829 // Emits the iret instruction for C code
830 //
833 VOID
835 {
836 #if defined(__GNUC__)
837  __asm__ __volatile__
838  (
839  "iret"
840  );
841 #elif defined(_MSC_VER)
842  __asm
843  {
844  iretd
845  }
846 #else
847 #error Unsupported compiler
848 #endif
849  UNREACHABLE;
850 }
851 
852 //
853 // Normally this is done by the HAL, but on x86 as an optimization, the kernel
854 // initiates the end by calling back into the HAL and exiting the trap here.
855 //
857 VOID
859  IN PKTRAP_FRAME TrapFrame)
860 {
861  /* Disable interrupts and end the interrupt */
862  _disable();
863  HalEndSystemInterrupt(Irql, TrapFrame);
864 
865  /* Exit the interrupt */
866  KiEoiHelper(TrapFrame);
867 }
868 
869 //
870 // PERF Code
871 //
873 VOID
875 {
878  DbgPrint("Boot took %I64u cycles!\n", BootCyclesEnd - BootCycles);
879  DbgPrint("Interrupts: %u System Calls: %u Context Switches: %u\n",
880  KeGetCurrentPrcb()->InterruptCount,
881  KeGetCurrentPrcb()->KeSystemCalls,
883 }
884 
886 PULONG
888 {
890 }
891 
892 #endif
VOID NTAPI ExpInterlockedPopEntrySListResume(VOID)
#define CR0_EM
Definition: asm.h:247
KV86_FRAME V86Frame
Definition: ke.h:163
struct _NT_TIB * Self
Definition: compat.h:579
#define MM_HIGHEST_USER_ADDRESS
Definition: armddk.h:17
#define IN
Definition: typedefs.h:39
VOID NTAPI HalEndSystemInterrupt(IN KIRQL OldIrql, IN PKTRAP_FRAME TrapFrame)
Definition: pic.c:335
BOOLEAN KiI386PentiumLockErrataPresent
Definition: cpu.c:40
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ WDFIORESLIST _In_ PIO_RESOURCE_DESCRIPTOR Descriptor
Definition: wdfresource.h:339
struct _KGDTENTRY::@2408::@2409 Bytes
#define NPX_FRAME_LENGTH
Definition: asm.h:246
UCHAR SkipSegments
Definition: ke.h:84
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException2Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN ULONG P2, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:674
struct _Entry Entry
Definition: kefuncs.h:627
CHAR KiSystemCallExit2[]
#define __cdecl
Definition: accygwin.h:79
_In_ ULONG Mode
Definition: hubbusif.h:303
#define DbgPrint
Definition: loader.c:25
ULONG_PTR StartAddress
Definition: ke.h:173
FX_SAVE_AREA NpxArea
Definition: ke.h:162
VOID NTAPI KiSetCR0Bits(VOID)
Definition: cpu.c:728
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esi
Definition: synth_sse3d.h:103
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
USHORT BaseLow
Definition: ketypes.h:336
struct _KV8086_STACK_FRAME * PKV8086_STACK_FRAME
ULONGLONG BootCycles
Definition: kiinit.c:30
ULONG KiFastSystemCallDisable
Definition: cpu.c:26
BOOLEAN NTAPI Ki386CreateIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap, IN PVOID StartPtr, IN ULONG Length)
char CHAR
Definition: xmlstorage.h:175
FORCEINLINE ULONG Ke386SanitizeFlags(IN ULONG Eflags, IN KPROCESSOR_MODE Mode)
Definition: ke.h:610
void __cdecl _enable(void)
Definition: intrin_arm.h:373
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN FASTCALL Ki386HandleOpcodeV86(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:456
ULONG KiGetFeatureBits(VOID)
Definition: cpu.c:127
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1075
ULONG KeI386EFlagsOrMaskV86
Definition: v86vdm.c:22
struct _KIPCR * PKIPCR
VOID NTAPI Ki386AdjustEsp0(IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:280
DECLSPEC_NORETURN VOID NTAPI KiDispatchExceptionFromTrapFrame(IN NTSTATUS Code, IN ULONG Flags, IN ULONG_PTR Address, IN ULONG ParameterCount, IN ULONG_PTR Parameter1, IN ULONG_PTR Parameter2, IN ULONG_PTR Parameter3, IN PKTRAP_FRAME TrapFrame)
Definition: exp.c:1100
PVOID PcrTeb
Definition: ke.h:153
PPC_QUAL unsigned long long __rdtsc(void)
Definition: intrin_ppc.h:688
VOID NTAPI KiInitializeMTRR(IN BOOLEAN FinalCpu)
Definition: mtrr.c:22
FORCEINLINE PVOID Ke386SanitizeDr(IN PVOID DrAddress, IN KPROCESSOR_MODE Mode)
Definition: ke.h:627
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1706
ULONG KeI386NpxPresent
Definition: cpu.c:31
BOOLEAN NTAPI KiIsNpxErrataPresent(VOID)
Definition: cpu.c:1205
Definition: ke.h:289
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1747
union _KTRAP_EXIT_SKIP_BITS KTRAP_EXIT_SKIP_BITS
ULONG_PTR NTAPI Ki386EnableGlobalPage(IN ULONG_PTR Context)
Definition: patpge.c:23
FORCEINLINE PULONG_PTR KiGetUserModeStackAddress(void)
Definition: ke.h:388
ULONG_PTR NTAPI Ki386EnableDE(IN ULONG_PTR Context)
Definition: cpu.c:1045
#define FASTCALL
Definition: nt_native.h:50
union _KTRAP_EXIT_SKIP_BITS * PKTRAP_EXIT_SKIP_BITS
_Out_ PKIRQL Irql
Definition: csq.h:179
DECLSPEC_NORETURN VOID FASTCALL KiEoiHelper(IN PKTRAP_FRAME TrapFrame)
Definition: traphdlr.c:126
#define DECLSPEC_NORETURN
Definition: ntbasedef.h:176
FORCEINLINE PVOID KeQueryInterruptHandler(IN ULONG Vector)
Definition: ke.h:264
ULONG KeI386FxsrPresent
Definition: cpu.c:31
#define EFLAGS_V86_MASK
Definition: ketypes.h:129
uint32_t ULONG_PTR
Definition: typedefs.h:65
BOOLEAN NTAPI KiIsNpxPresent(VOID)
Definition: cpu.c:1164
UCHAR KIRQL
Definition: env_spec_w32.h:591
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1723
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1603
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PVOID ThreadStack
Definition: ke.h:151
#define FALSE
Definition: types.h:117
UCHAR Reserved
Definition: ke.h:86
ULONG PagesCount
Definition: ke.h:174
NTKERNELAPI KIRQL NTAPI KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
FORCEINLINE PRKTHREAD KeGetCurrentThread(VOID)
Definition: ke.h:284
#define EFLAGS_USER_SANITIZE
Definition: ketypes.h:133
#define RPL_MASK
Definition: ketypes.h:69
unsigned char BOOLEAN
NTSTATUS NTAPI KiConvertToGuiThread(VOID)
VOID NTAPI KiInitializePAT(VOID)
Definition: patpge.c:61
struct _KV86_FRAME KV86_FRAME
static WCHAR Address[46]
Definition: ping.c:68
_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
VOID NTAPI Ki386FreeIdentityMap(IN PLARGE_IDENTITY_MAP IdentityMap)
Definition: ketypes.h:789
FORCEINLINE BOOLEAN KeDisableInterrupts(VOID)
Definition: ke.h:176
FORCEINLINE VOID Ki386PerfEnd(VOID)
Definition: ke.h:874
ULONG KeI386XMMIPresent
Definition: cpu.c:30
FORCEINLINE VOID Ke386SetGdtEntryBase(PKGDTENTRY GdtEntry, PVOID BaseAddress)
Definition: ke.h:309
ULONGLONG BootCyclesEnd
Definition: kiinit.c:30
VOID __cdecl CopyParams(VOID)
UCHAR SkipPreviousMode
Definition: ke.h:83
ULONG KiMXCsrMask
Definition: cpu.c:28
VOID NTAPI ExpInterlockedPopEntrySListFault(VOID)
#define PtrToUlong(u)
Definition: config.h:107
FORCEINLINE PFX_SAVE_AREA KiGetThreadNpxArea(IN PKTHREAD Thread)
Definition: ke.h:582
UCHAR KiDebugRegisterTrapOffsets[9]
FORCEINLINE VOID KiCheckForApcDelivery(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:759
VOID FASTCALL Ki386InitializeTss(IN PKTSS Tss, IN PKIDTENTRY Idt, IN PKGDTENTRY Gdt)
Definition: cpu.c:799
FORCEINLINE VOID KeInvalidateTlbEntry(IN PVOID Address)
Definition: ke.h:201
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl eax
Definition: synth_sse3d.h:85
#define ASSERT(a)
Definition: mode.c:45
ecx edi ebx edx edi decl ecx esi eax jecxz decl eax andl eax esi movl edx movl TEMP incl eax andl eax ecx incl ebx eax jnz xchgl ecx incl TEMP esp ecx subl ebx pushl ecx ecx edx ecx ecx mm0 mm4 mm0 mm4 mm1 mm5 mm1 mm5 mm2 mm6 mm2 mm6 mm3 mm7 mm3 mm7 paddd mm0 paddd mm4 paddd mm0 paddd mm4 paddd mm0 paddd mm4 movq mm1 movq mm5 mm1 mm5 paddd mm0 paddd mm4 mm0 mm4 packssdw mm0 packssdw mm4 mm1 punpckldq mm0 pand mm1 pand mm0 por mm1 movq edi esi edx edi decl ecx jnz popl ecx ecx jecxz mm0 mm0 mm1 mm1 mm2 mm2 mm3 mm3 paddd mm0 paddd mm0 paddd mm0 movq mm1 mm1 paddd mm0 mm0 packssdw mm0 movd eax movw edi esi edx edi
Definition: synth_sse3d.h:185
C_ASSERT(NPX_FRAME_LENGTH==sizeof(FX_SAVE_AREA))
uint64_t ULONGLONG
Definition: typedefs.h:67
#define APC_LEVEL
VOID NTAPI KiRestoreFastSyscallReturnState(VOID)
Definition: cpu.c:1011
ULONG HardwareEsp
Definition: ketypes.h:270
ULONG KeI386CpuType
Definition: cpu.c:28
#define KGDT_R3_TEB
Definition: ketypes.h:81
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
VOID KiGetCacheInformation(VOID)
Definition: cpu.c:217
USHORT Offset
Definition: ketypes.h:386
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
PPC_QUAL void __wbinvd(void)
Definition: intrin_ppc.h:759
BOOLEAN FASTCALL KiVdmOpcodePrefix(IN PKTRAP_FRAME TrapFrame, IN ULONG Flags)
Definition: v86vdm.c:442
USHORT ExtendedOffset
Definition: ketypes.h:389
PVOID ThreadTeb
Definition: ke.h:152
FORCEINLINE DECLSPEC_NORETURN VOID KiIret(VOID)
Definition: ke.h:834
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG KeI386CpuStep
Definition: cpu.c:29
NTSTATUS NTAPI Ke386GetGdtEntryThread(IN PKTHREAD Thread, IN ULONG Offset, IN PKGDTENTRY Descriptor)
Definition: ldt.c:26
VOID NTAPI Ki386SetupAndExitToV86Mode(OUT PTEB VdmTeb)
VOID __cdecl KiTrap13(VOID)
struct _KV8086_STACK_FRAME KV8086_STACK_FRAME
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
VOID NTAPI KiSystemStartupBootStack(VOID)
Definition: krnlinit.c:57
VOID FASTCALL Ki386BiosCallReturnAddress(IN PKTRAP_FRAME TrapFrame)
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
Definition: wdfdevice.h:1697
ULONG_PTR FASTCALL KiExitV86Mode(IN PKTRAP_FRAME TrapFrame)
Definition: v86vdm.c:468
PVOID Ki386IopmSaveArea
Definition: v86vdm.c:23
VOID KiSwitchToBootStack(IN ULONG_PTR InitialStack)
Definition: ke.h:796
ULONG_PTR NTAPI Ki386EnableXMMIExceptions(IN ULONG_PTR Context)
Definition: cpu.c:1065
NT_TIB NtTib
Definition: ke.h:293
struct _LARGE_IDENTITY_MAP LARGE_IDENTITY_MAP
FORCEINLINE BOOLEAN KiUserTrap(IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:301
ACPI_PHYSICAL_ADDRESS ACPI_SIZE BOOLEAN Warn BOOLEAN Physical UINT32 ACPI_TABLE_HEADER *OutTableHeader ACPI_TABLE_HEADER **OutTable ACPI_HANDLE UINT32 ACPI_WALK_CALLBACK ACPI_WALK_CALLBACK void void **ReturnValue UINT32 ACPI_BUFFER *RetPathPtr ACPI_OBJECT_HANDLER Handler
Definition: acpixf.h:668
UCHAR KiDebugRegisterContextOffsets[9]
FORCEINLINE ULONG Ke386SanitizeSeg(IN ULONG Cs, IN KPROCESSOR_MODE Mode)
Definition: ke.h:593
FORCEINLINE PKPCR KeGetPcr(VOID)
Definition: ke.h:327
FORCEINLINE VOID KeRegisterInterruptHandler(IN ULONG Vector, IN PVOID Handler)
Definition: ke.h:238
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
KIDTENTRY KiIdt[MAXIMUM_IDTVECTOR+1]
Definition: except.c:50
#define _In_
Definition: no_sal2.h:158
PUSHORT GDT
Definition: ke.h:54
ULONG_PTR SIZE_T
Definition: typedefs.h:80
VOID __cdecl ReadBatch(VOID)
Definition: compat.h:694
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException0Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:645
struct _KV86_FRAME * PKV86_FRAME
FORCEINLINE DECLSPEC_NORETURN VOID KiDispatchException1Args(IN NTSTATUS Code, IN ULONG_PTR Address, IN ULONG P1, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:659
VOID __cdecl KiTrap08(VOID)
unsigned short USHORT
Definition: pedump.c:61
PHARDWARE_PTE TopLevelDirectory
Definition: ke.h:171
union _KGDTENTRY::@2408 HighWord
BOOLEAN NTAPI VdmDispatchPageFault(_In_ PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:367
PVOID PagesList[30]
Definition: ke.h:175
ULONG KeI386EFlagsAndMaskV86
Definition: v86vdm.c:21
NTKERNELAPI VOID NTAPI KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
#define CR0_TS
Definition: asm.h:248
#define FORCEINLINE
Definition: wdftypes.h:67
VOID NTAPI KiFlushNPXState(IN FLOATING_SAVE_AREA *SaveArea)
FORCEINLINE VOID KeRestoreInterrupts(BOOLEAN WereEnabled)
Definition: ke.h:191
UCHAR SkipVolatiles
Definition: ke.h:85
FORCEINLINE VOID KiRundownThread(IN PKTHREAD Thread)
Definition: ke.h:230
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
VOID NTAPI KiAmdK6InitializeMTRR(VOID)
Definition: mtrr.c:31
BOOLEAN NTAPI VdmDispatchBop(IN PKTRAP_FRAME TrapFrame)
Definition: vdmexec.c:313
FORCEINLINE VOID KiEndInterrupt(IN KIRQL Irql, IN PKTRAP_FRAME TrapFrame)
Definition: ke.h:291
KDESCRIPTOR KiIdtDescriptor
Definition: except.c:51
FORCEINLINE VOID KeFlushProcessTb(VOID)
Definition: ke.h:209
__INTRIN_INLINE void __invlpg(void *Address)
Definition: intrin_x86.h:1897
VOID NTAPI KeI386VdmInitialize(VOID)
Definition: stubs.c:156
#define OUT
Definition: typedefs.h:40
VOID __cdecl KiTrap02(VOID)
VOID NTAPI Ki386EnableCurrentLargePage(IN ULONG_PTR StartAddress, IN ULONG Cr3)
VOID NTAPI KiThreadStartup(VOID)
Definition: thrdini.c:63
void __cdecl _disable(void)
Definition: intrin_arm.h:365
unsigned int ULONG
Definition: retypes.h:1
CHAR KiSystemCallExitBranch[]
FORCEINLINE VOID KiSetTebBase(PKPCR Pcr, PVOID TebAddress)
Definition: ke.h:318
struct _LARGE_IDENTITY_MAP * PLARGE_IDENTITY_MAP
#define UNREACHABLE
VOID __cdecl KiFastCallEntry(VOID)
#define ULONG_PTR
Definition: config.h:101
#define KTRAP_FRAME_LENGTH
Definition: asm.h:126
ULONG_PTR NTAPI Ki386EnableTargetLargePage(IN ULONG_PTR Context)
Definition: patpge.c:70
static void push(calc_node_t *op)
Definition: rpn_ieee.c:113
VOID KiSetProcessorType(VOID)
Definition: cpu.c:56
#define CR0_MP
Definition: asm.h:246
BOOLEAN KeI386VirtualIntExtensions
Definition: v86vdm.c:24
PKIDTENTRY IDT
Definition: ketypes.h:758
ULONG_PTR NTAPI Ki386EnableFxsr(IN ULONG_PTR Context)
Definition: cpu.c:1055
CHAR KiSystemCallExit[]
#define KTRAP_FRAME_ALIGN
Definition: asm.h:125
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define KeGetContextSwitches(Prcb)
Definition: ke.h:56
#define MAXIMUM_IDTVECTOR
Definition: asm.h:277
base of all file and directory entries
Definition: entries.h:82
FORCEINLINE VOID KeSweepICache(IN PVOID BaseAddress, IN SIZE_T FlushSize)
Definition: ke.h:217
VOID NTAPI KiI386PentiumLockErrataFixup(VOID)
Definition: cpu.c:1088
KTRAP_FRAME TrapFrame
Definition: ke.h:161
#define EFLAGS_INTERRUPT_MASK
Definition: ketypes.h:126
jmp_buf jmp
Definition: mach.c:35
#define HalVectorToIDTEntry
Definition: halfuncs.h:51