2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/ke/i386/traphdlr.c
5 * PURPOSE: Kernel Trap Handlers
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 VOID
KiFastCallEntry(VOID
);
16 VOID
KiFastCallEntryWithSingleStep(VOID
);
18 /* GLOBALS ********************************************************************/
20 UCHAR KiTrapPrefixTable
[] =
23 0xF3, /* REP INS/OUTS */
35 UCHAR KiTrapIoTable
[] =
51 PFAST_SYSTEM_CALL_EXIT KiFastCallExitHandler
;
52 #if DBG && !defined(_WINKD_)
53 PKDBG_PRESERVICEHOOK KeWin32PreServiceHook
= NULL
;
54 PKDBG_POSTSERVICEHOOK KeWin32PostServiceHook
= NULL
;
57 BOOLEAN StopChecking
= FALSE
;
61 /* TRAP EXIT CODE *************************************************************/
65 KiVdmTrap(IN PKTRAP_FRAME TrapFrame
)
67 /* Either the V8086 flag is on, or this is user-mode with a VDM */
68 return ((TrapFrame
->EFlags
& EFLAGS_V86_MASK
) ||
69 ((KiUserTrap(TrapFrame
)) && (PsGetCurrentProcess()->VdmObjects
)));
74 KiV86Trap(IN PKTRAP_FRAME TrapFrame
)
76 /* Check if the V8086 flag is on */
77 return ((TrapFrame
->EFlags
& EFLAGS_V86_MASK
) != 0);
82 KiIsFrameEdited(IN PKTRAP_FRAME TrapFrame
)
84 /* An edited frame changes esp. It is marked by clearing the bits
85 defined by FRAME_EDITED in the SegCs field of the trap frame */
86 return ((TrapFrame
->SegCs
& FRAME_EDITED
) == 0);
91 KiCommonExit(IN PKTRAP_FRAME TrapFrame
, BOOLEAN SkipPreviousMode
)
93 /* Disable interrupts until we return */
96 /* Check for APC delivery */
97 KiCheckForApcDelivery(TrapFrame
);
99 /* Restore the SEH handler chain */
100 KeGetPcr()->NtTib
.ExceptionList
= TrapFrame
->ExceptionList
;
102 /* Check if there are active debug registers */
103 if (__builtin_expect(TrapFrame
->Dr7
& ~DR7_RESERVED_MASK
, 0))
105 /* Check if the frame was from user mode or v86 mode */
106 if (KiUserTrap(TrapFrame
) ||
107 (TrapFrame
->EFlags
& EFLAGS_V86_MASK
))
109 /* Handle debug registers */
110 KiHandleDebugRegistersOnTrapExit(TrapFrame
);
114 /* Debugging checks */
115 KiExitTrapDebugChecks(TrapFrame
, SkipPreviousMode
);
121 KiEoiHelper(IN PKTRAP_FRAME TrapFrame
)
123 /* Common trap exit code */
124 KiCommonExit(TrapFrame
, TRUE
);
126 /* Check if this was a V8086 trap */
127 if (TrapFrame
->EFlags
& EFLAGS_V86_MASK
) KiTrapReturnNoSegments(TrapFrame
);
129 /* Check for user mode exit */
130 if (KiUserTrap(TrapFrame
)) KiTrapReturn(TrapFrame
);
132 /* Check for edited frame */
133 if (KiIsFrameEdited(TrapFrame
)) KiEditedTrapReturn(TrapFrame
);
135 /* Check if we have single stepping enabled */
136 if (TrapFrame
->EFlags
& EFLAGS_TF
) KiTrapReturnNoSegments(TrapFrame
);
138 /* Exit the trap to kernel mode */
139 KiTrapReturnNoSegmentsRet8(TrapFrame
);
145 KiServiceExit(IN PKTRAP_FRAME TrapFrame
,
148 ASSERT((TrapFrame
->EFlags
& EFLAGS_V86_MASK
) == 0);
149 ASSERT(!KiIsFrameEdited(TrapFrame
));
151 /* Copy the status into EAX */
152 TrapFrame
->Eax
= Status
;
154 /* Common trap exit code */
155 KiCommonExit(TrapFrame
, FALSE
);
157 /* Restore previous mode */
158 KeGetCurrentThread()->PreviousMode
= (CCHAR
)TrapFrame
->PreviousPreviousMode
;
160 /* Check for user mode exit */
161 if (KiUserTrap(TrapFrame
))
163 /* Check if we were single stepping */
164 if (TrapFrame
->EFlags
& EFLAGS_TF
)
166 /* Must use the IRET handler */
167 KiSystemCallTrapReturn(TrapFrame
);
171 /* We can use the sysexit handler */
172 KiFastCallExitHandler(TrapFrame
);
176 /* Exit to kernel mode */
177 KiSystemCallReturn(TrapFrame
);
183 KiServiceExit2(IN PKTRAP_FRAME TrapFrame
)
185 /* Common trap exit code */
186 KiCommonExit(TrapFrame
, FALSE
);
188 /* Restore previous mode */
189 KeGetCurrentThread()->PreviousMode
= (CCHAR
)TrapFrame
->PreviousPreviousMode
;
191 /* Check if this was a V8086 trap */
192 if (TrapFrame
->EFlags
& EFLAGS_V86_MASK
) KiTrapReturnNoSegments(TrapFrame
);
194 /* Check for user mode exit */
195 if (KiUserTrap(TrapFrame
)) KiTrapReturn(TrapFrame
);
197 /* Check for edited frame */
198 if (KiIsFrameEdited(TrapFrame
)) KiEditedTrapReturn(TrapFrame
);
200 /* Check if we have single stepping enabled */
201 if (TrapFrame
->EFlags
& EFLAGS_TF
) KiTrapReturnNoSegments(TrapFrame
);
203 /* Exit the trap to kernel mode */
204 KiTrapReturnNoSegmentsRet8(TrapFrame
);
208 /* TRAP HANDLERS **************************************************************/
213 KiDebugHandler(IN PKTRAP_FRAME TrapFrame
,
218 /* Check for VDM trap */
219 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
221 /* Enable interrupts if the trap came from user-mode */
222 if (KiUserTrap(TrapFrame
)) _enable();
224 /* Dispatch the exception */
225 KiDispatchExceptionFromTrapFrame(STATUS_BREAKPOINT
,
238 KiNpxHandler(IN PKTRAP_FRAME TrapFrame
,
240 IN PFX_SAVE_AREA SaveArea
)
242 ULONG Cr0
, Mask
, Error
, ErrorOffset
, DataOffset
;
244 /* Check for VDM trap */
245 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
247 /* Check for kernel trap */
248 if (!KiUserTrap(TrapFrame
))
250 /* Kernel might've tripped a delayed error */
251 SaveArea
->Cr0NpxState
|= CR0_TS
;
253 /* Only valid if it happened during a restore */
254 //if ((PVOID)TrapFrame->Eip == FrRestore)
256 /* It did, so just skip the instruction */
257 //TrapFrame->Eip += 3; /* sizeof(FRSTOR) */
258 //KiEoiHelper(TrapFrame);
262 /* User or kernel trap -- get ready to issue an exception */
263 //if (Thread->NpxState == NPX_STATE_NOT_LOADED)
267 Cr0
&= ~(CR0_MP
| CR0_EM
| CR0_TS
);
271 Ke386SaveFpuState(SaveArea
);
273 /* Mark CR0 state dirty */
274 Cr0
|= NPX_STATE_NOT_LOADED
;
275 Cr0
|= SaveArea
->Cr0NpxState
;
278 /* Update NPX state */
279 Thread
->NpxState
= NPX_STATE_NOT_LOADED
;
280 KeGetCurrentPrcb()->NpxThread
= NULL
;
283 /* Clear the TS bit and re-enable interrupts */
284 SaveArea
->Cr0NpxState
&= ~CR0_TS
;
287 /* Check if we should get the FN or FX error */
288 if (KeI386FxsrPresent
)
291 Mask
= SaveArea
->U
.FxArea
.ControlWord
;
292 Error
= SaveArea
->U
.FxArea
.StatusWord
;
294 /* Get the FPU exception address too */
295 ErrorOffset
= SaveArea
->U
.FxArea
.ErrorOffset
;
296 DataOffset
= SaveArea
->U
.FxArea
.DataOffset
;
301 Mask
= SaveArea
->U
.FnArea
.ControlWord
;
302 Error
= SaveArea
->U
.FnArea
.StatusWord
;
304 /* Get the FPU exception address too */
305 ErrorOffset
= SaveArea
->U
.FnArea
.ErrorOffset
;
306 DataOffset
= SaveArea
->U
.FnArea
.DataOffset
;
309 /* Get legal exceptions that software should handle */
310 /* We do this by first masking off from the Mask the bits we need, */
311 /* This is done so we can keep the FSW_STACK_FAULT bit in Error. */
312 Mask
&= (FSW_INVALID_OPERATION
|
320 /* Check for invalid operation */
321 if (Error
& FSW_INVALID_OPERATION
)
323 /* NOTE: Stack fault is handled differently than any other case. */
324 /* 1. It's only raised for invalid operation. */
325 /* 2. It's only raised if invalid operation is not masked. */
326 if (Error
& FSW_STACK_FAULT
)
328 /* Issue stack check fault */
329 KiDispatchException2Args(STATUS_FLOAT_STACK_CHECK
,
337 KiDispatchException1Args(STATUS_FLOAT_INVALID_OPERATION
,
343 /* Check for divide by zero */
344 if (Error
& FSW_ZERO_DIVIDE
)
347 KiDispatchException1Args(STATUS_FLOAT_DIVIDE_BY_ZERO
,
353 /* Check for denormal */
354 if (Error
& FSW_DENORMAL
)
357 KiDispatchException1Args(STATUS_FLOAT_INVALID_OPERATION
,
363 /* Check for overflow */
364 if (Error
& FSW_OVERFLOW
)
367 KiDispatchException1Args(STATUS_FLOAT_OVERFLOW
,
373 /* Check for underflow */
374 if (Error
& FSW_UNDERFLOW
)
377 KiDispatchException1Args(STATUS_FLOAT_UNDERFLOW
,
383 /* Check for precision fault */
384 if (Error
& FSW_PRECISION
)
387 KiDispatchException1Args(STATUS_FLOAT_INEXACT_RESULT
,
393 /* Unknown FPU fault */
394 KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN
, 1, Error
, 0, 0, TrapFrame
);
400 KiTrap00Handler(IN PKTRAP_FRAME TrapFrame
)
402 /* Save trap frame */
403 KiEnterTrap(TrapFrame
);
405 /* Check for VDM trap */
406 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
408 /* Enable interrupts */
411 /* Dispatch the exception */
412 KiDispatchException0Args(STATUS_INTEGER_DIVIDE_BY_ZERO
,
420 KiTrap01Handler(IN PKTRAP_FRAME TrapFrame
)
422 /* Save trap frame */
423 KiEnterTrap(TrapFrame
);
425 /* Check for VDM trap */
426 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
428 /* Check if this was a single step after sysenter */
429 if (TrapFrame
->Eip
== (ULONG
)KiFastCallEntry
)
431 /* Disable single stepping */
432 TrapFrame
->EFlags
&= ~EFLAGS_TF
;
434 /* Re-enter at the alternative sysenter entry point */
435 TrapFrame
->Eip
= (ULONG
)KiFastCallEntryWithSingleStep
;
438 KiEoiHelper(TrapFrame
);
441 /* Enable interrupts if the trap came from user-mode */
442 if (KiUserTrap(TrapFrame
)) _enable();
444 /* Mask out trap flag and dispatch the exception */
445 TrapFrame
->EFlags
&= ~EFLAGS_TF
;
446 KiDispatchException0Args(STATUS_SINGLE_STEP
,
460 KTRAP_FRAME TrapFrame
;
464 // In some sort of strange recursion case, we might end up here with the IF
465 // flag incorrectly on the interrupt frame -- during a normal NMI this would
466 // normally already be set.
468 // For sanity's sake, make sure interrupts are disabled for sure.
469 // NMIs will already be since the CPU does it for us.
474 // Get the current TSS, thread, and process
477 Thread
= ((PKIPCR
)PCR
)->PrcbData
.CurrentThread
;
478 Process
= Thread
->ApcState
.Process
;
481 // Save data usually not in the TSS
483 Tss
->CR3
= Process
->DirectoryTableBase
[0];
484 Tss
->IoMapBase
= Process
->IopmOffset
;
485 Tss
->LDT
= Process
->LdtDescriptor
.LimitLow
? KGDT_LDT
: 0;
488 // Now get the base address of the NMI TSS
490 TssGdt
= &((PKIPCR
)KeGetPcr())->GDT
[KGDT_NMI_TSS
/ sizeof(KGDTENTRY
)];
491 NmiTss
= (PKTSS
)(ULONG_PTR
)(TssGdt
->BaseLow
|
492 TssGdt
->HighWord
.Bytes
.BaseMid
<< 16 |
493 TssGdt
->HighWord
.Bytes
.BaseHi
<< 24);
496 // Switch to it and activate it, masking off the nested flag
498 // Note that in reality, we are already on the NMI tss -- we just need to
499 // update the PCR to reflect this
502 __writeeflags(__readeflags() &~ EFLAGS_NESTED_TASK
);
503 TssGdt
->HighWord
.Bits
.Dpl
= 0;
504 TssGdt
->HighWord
.Bits
.Pres
= 1;
505 TssGdt
->HighWord
.Bits
.Type
= I386_TSS
;
508 // Now build the trap frame based on the original TSS
510 // The CPU does a hardware "Context switch" / task switch of sorts and so it
511 // takes care of saving our context in the normal TSS.
513 // We just have to go get the values...
515 RtlZeroMemory(&TrapFrame
, sizeof(KTRAP_FRAME
));
516 TrapFrame
.HardwareSegSs
= Tss
->Ss0
;
517 TrapFrame
.HardwareEsp
= Tss
->Esp0
;
518 TrapFrame
.EFlags
= Tss
->EFlags
;
519 TrapFrame
.SegCs
= Tss
->Cs
;
520 TrapFrame
.Eip
= Tss
->Eip
;
521 TrapFrame
.Ebp
= Tss
->Ebp
;
522 TrapFrame
.Ebx
= Tss
->Ebx
;
523 TrapFrame
.Esi
= Tss
->Esi
;
524 TrapFrame
.Edi
= Tss
->Edi
;
525 TrapFrame
.SegFs
= Tss
->Fs
;
526 TrapFrame
.ExceptionList
= PCR
->NtTib
.ExceptionList
;
527 TrapFrame
.PreviousPreviousMode
= -1;
528 TrapFrame
.Eax
= Tss
->Eax
;
529 TrapFrame
.Ecx
= Tss
->Ecx
;
530 TrapFrame
.Edx
= Tss
->Edx
;
531 TrapFrame
.SegDs
= Tss
->Ds
;
532 TrapFrame
.SegEs
= Tss
->Es
;
533 TrapFrame
.SegGs
= Tss
->Gs
;
534 TrapFrame
.DbgEip
= Tss
->Eip
;
535 TrapFrame
.DbgEbp
= Tss
->Ebp
;
538 // Store the trap frame in the KPRCB
540 KiSaveProcessorState(&TrapFrame
, NULL
);
543 // Call any registered NMI handlers and see if they handled it or not
548 // They did not, so call the platform HAL routine to bugcheck the system
550 // Make sure the HAL believes it's running at HIGH IRQL... we can't use
551 // the normal APIs here as playing with the IRQL could change the system
555 PCR
->Irql
= HIGH_LEVEL
;
561 // Although the CPU disabled NMIs, we just did a BIOS Call, which could've
562 // totally changed things.
564 // We have to make sure we're still in our original NMI -- a nested NMI
565 // will point back to the NMI TSS, and in that case we're hosed.
567 if (PCR
->TSS
->Backlink
!= KGDT_NMI_TSS
)
570 // Restore original TSS
575 // Set it back to busy
577 TssGdt
->HighWord
.Bits
.Dpl
= 0;
578 TssGdt
->HighWord
.Bits
.Pres
= 1;
579 TssGdt
->HighWord
.Bits
.Type
= I386_ACTIVE_TSS
;
582 // Restore nested flag
584 __writeeflags(__readeflags() | EFLAGS_NESTED_TASK
);
587 // Handled, return from interrupt
593 // Unhandled: crash the system
595 KiSystemFatalException(EXCEPTION_NMI
, NULL
);
601 KiTrap03Handler(IN PKTRAP_FRAME TrapFrame
)
603 /* Save trap frame */
604 KiEnterTrap(TrapFrame
);
606 /* Continue with the common handler */
607 KiDebugHandler(TrapFrame
, BREAKPOINT_BREAK
, 0, 0);
613 KiTrap04Handler(IN PKTRAP_FRAME TrapFrame
)
615 /* Save trap frame */
616 KiEnterTrap(TrapFrame
);
618 /* Check for VDM trap */
619 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
621 /* Enable interrupts */
624 /* Dispatch the exception */
625 KiDispatchException0Args(STATUS_INTEGER_OVERFLOW
,
633 KiTrap05Handler(IN PKTRAP_FRAME TrapFrame
)
635 /* Save trap frame */
636 KiEnterTrap(TrapFrame
);
638 /* Check for VDM trap */
639 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
641 /* Check for kernel-mode fault */
642 if (!KiUserTrap(TrapFrame
)) KiSystemFatalException(EXCEPTION_BOUND_CHECK
, TrapFrame
);
644 /* Enable interrupts */
647 /* Dispatch the exception */
648 KiDispatchException0Args(STATUS_ARRAY_BOUNDS_EXCEEDED
,
656 KiTrap06Handler(IN PKTRAP_FRAME TrapFrame
)
662 /* Check for V86 GPF */
663 if (__builtin_expect(KiV86Trap(TrapFrame
), 1))
666 KiEnterV86Trap(TrapFrame
);
668 /* Must be a VDM process */
669 if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects
, 0))
671 /* Enable interrupts */
674 /* Setup illegal instruction fault */
675 KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION
,
680 /* Go to APC level */
681 OldIrql
= KfRaiseIrql(APC_LEVEL
);
685 if (!VdmDispatchBop(TrapFrame
))
687 /* Should only happen in VDM mode */
688 UNIMPLEMENTED_FATAL();
691 /* Bring IRQL back */
692 KfLowerIrql(OldIrql
);
695 /* Do a quick V86 exit if possible */
696 KiExitV86Trap(TrapFrame
);
699 /* Save trap frame */
700 KiEnterTrap(TrapFrame
);
702 /* Enable interrupts */
703 Instruction
= (PUCHAR
)TrapFrame
->Eip
;
706 /* Check for user trap */
707 if (KiUserTrap(TrapFrame
))
711 /* Scan next 4 opcodes */
712 for (i
= 0; i
< 4; i
++)
714 /* Check for LOCK instruction */
715 if (Instruction
[i
] == 0xF0)
717 /* Send invalid lock sequence exception */
718 KiDispatchException0Args(STATUS_INVALID_LOCK_SEQUENCE
,
724 /* FIXME: SEH ends here */
727 /* Kernel-mode or user-mode fault (but not LOCK) */
728 KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION
,
737 KiTrap07Handler(IN PKTRAP_FRAME TrapFrame
)
739 PKTHREAD Thread
, NpxThread
;
740 PFX_SAVE_AREA SaveArea
, NpxSaveArea
;
743 /* Save trap frame */
744 KiEnterTrap(TrapFrame
);
746 /* Try to handle NPX delay load */
749 /* Get the current thread */
750 Thread
= KeGetCurrentThread();
752 /* Get the NPX frame */
753 SaveArea
= KiGetThreadNpxArea(Thread
);
755 /* Check if emulation is enabled */
756 if (SaveArea
->Cr0NpxState
& CR0_EM
)
758 /* Not implemented */
759 UNIMPLEMENTED_FATAL();
762 /* Save CR0 and check NPX state */
764 if (Thread
->NpxState
!= NPX_STATE_LOADED
)
767 Cr0
&= ~(CR0_MP
| CR0_EM
| CR0_TS
);
770 /* Get the NPX thread */
771 NpxThread
= KeGetCurrentPrcb()->NpxThread
;
774 /* Get the NPX frame */
775 NpxSaveArea
= KiGetThreadNpxArea(NpxThread
);
778 DPRINT("FIXME: Save FPU state: %p\n", NpxSaveArea
);
779 //Ke386SaveFpuState(NpxSaveArea);
781 /* Update NPX state */
782 NpxThread
->NpxState
= NPX_STATE_NOT_LOADED
;
786 //Ke386LoadFpuState(SaveArea);
788 /* Update NPX state */
789 Thread
->NpxState
= NPX_STATE_LOADED
;
790 KeGetCurrentPrcb()->NpxThread
= Thread
;
792 /* Enable interrupts */
795 /* Check if CR0 needs to be reloaded due to context switch */
796 if (!SaveArea
->Cr0NpxState
) KiEoiHelper(TrapFrame
);
798 /* Otherwise, we need to reload CR0, disable interrupts */
803 Cr0
|= SaveArea
->Cr0NpxState
;
806 /* Now restore interrupts and check for TS */
808 if (Cr0
& CR0_TS
) KiEoiHelper(TrapFrame
);
810 /* We're still here -- clear TS and try again */
811 __writecr0(__readcr0() &~ CR0_TS
);
816 /* This is an actual fault, not a lack of FPU state */
821 /* TS should not be set */
825 * If it's incorrectly set, then maybe the state is actually still valid
826 * but we could've lock track of that due to a BIOS call.
827 * Make sure MP is still set, which should verify the theory.
831 /* Indeed, the state is actually still valid, so clear TS */
832 __writecr0(__readcr0() &~ CR0_TS
);
833 KiEoiHelper(TrapFrame
);
836 /* Otherwise, something strange is going on */
837 KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN
, 2, Cr0
, 0, 0, TrapFrame
);
840 /* It's not a delayed load, so process this trap as an NPX fault */
841 KiNpxHandler(TrapFrame
, Thread
, SaveArea
);
847 KiTrap08Handler(IN PKTRAP_FRAME TrapFrame
)
849 /* FIXME: Not handled */
850 KiSystemFatalException(EXCEPTION_DOUBLE_FAULT
, TrapFrame
);
856 KiTrap09Handler(IN PKTRAP_FRAME TrapFrame
)
858 /* Save trap frame */
859 KiEnterTrap(TrapFrame
);
861 /* Enable interrupts and kill the system */
863 KiSystemFatalException(EXCEPTION_NPX_OVERRUN
, TrapFrame
);
869 KiTrap0AHandler(IN PKTRAP_FRAME TrapFrame
)
871 /* Save trap frame */
872 KiEnterTrap(TrapFrame
);
874 /* Check for VDM trap */
875 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
877 /* Kill the system */
878 KiSystemFatalException(EXCEPTION_INVALID_TSS
, TrapFrame
);
884 KiTrap0BHandler(IN PKTRAP_FRAME TrapFrame
)
886 /* Save trap frame */
887 KiEnterTrap(TrapFrame
);
889 /* FIXME: Kill the system */
891 KiSystemFatalException(EXCEPTION_SEGMENT_NOT_PRESENT
, TrapFrame
);
897 KiTrap0CHandler(IN PKTRAP_FRAME TrapFrame
)
899 /* Save trap frame */
900 KiEnterTrap(TrapFrame
);
902 /* FIXME: Kill the system */
904 KiSystemFatalException(EXCEPTION_STACK_FAULT
, TrapFrame
);
910 KiTrap0DHandler(IN PKTRAP_FRAME TrapFrame
)
913 BOOLEAN Privileged
= FALSE
;
915 UCHAR Instruction
= 0;
918 /* Check for V86 GPF */
919 if (__builtin_expect(KiV86Trap(TrapFrame
), 1))
922 KiEnterV86Trap(TrapFrame
);
924 /* Must be a VDM process */
925 if (__builtin_expect(!PsGetCurrentProcess()->VdmObjects
, 0))
927 /* Enable interrupts */
930 /* Setup illegal instruction fault */
931 KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION
,
936 /* Go to APC level */
937 OldIrql
= KfRaiseIrql(APC_LEVEL
);
940 /* Handle the V86 opcode */
941 if (__builtin_expect(Ki386HandleOpcodeV86(TrapFrame
) == 0xFF, 0))
943 /* Should only happen in VDM mode */
944 UNIMPLEMENTED_FATAL();
947 /* Bring IRQL back */
948 KfLowerIrql(OldIrql
);
951 /* Do a quick V86 exit if possible */
952 KiExitV86Trap(TrapFrame
);
955 /* Save trap frame */
956 KiEnterTrap(TrapFrame
);
958 /* Check for user-mode GPF */
959 if (KiUserTrap(TrapFrame
))
961 /* Should not be VDM */
962 ASSERT(KiVdmTrap(TrapFrame
) == FALSE
);
964 /* Enable interrupts and check error code */
966 if (!TrapFrame
->ErrCode
)
969 Instructions
= (PUCHAR
)TrapFrame
->Eip
;
971 /* Scan next 15 bytes */
972 for (i
= 0; i
< 15; i
++)
974 /* Skip prefix instructions */
975 for (j
= 0; j
< sizeof(KiTrapPrefixTable
); j
++)
977 /* Is this a prefix instruction? */
978 if (Instructions
[i
] == KiTrapPrefixTable
[j
])
985 /* Is this NOT any prefix instruction? */
986 if (j
== sizeof(KiTrapPrefixTable
))
988 /* We can go ahead and handle the fault now */
989 Instruction
= Instructions
[i
];
994 /* If all we found was prefixes, then this instruction is too long */
997 /* Setup illegal instruction fault */
998 KiDispatchException0Args(STATUS_ILLEGAL_INSTRUCTION
,
1003 /* Check for privileged instructions */
1004 DPRINT("Instruction (%lu) at fault: %lx %lx %lx %lx\n",
1007 Instructions
[i
+ 1],
1008 Instructions
[i
+ 2],
1009 Instructions
[i
+ 3]);
1010 if (Instruction
== 0xF4) // HLT
1012 /* HLT is privileged */
1015 else if (Instruction
== 0x0F)
1017 /* Test if it's any of the privileged two-byte opcodes */
1018 if (((Instructions
[i
+ 1] == 0x00) && // LLDT or LTR
1019 (((Instructions
[i
+ 2] & 0x38) == 0x10) || // LLDT
1020 (Instructions
[i
+ 2] == 0x18))) || // LTR
1021 ((Instructions
[i
+ 1] == 0x01) && // LGDT or LIDT or LMSW
1022 (((Instructions
[i
+ 2] & 0x38) == 0x10) || // LGDT
1023 (Instructions
[i
+ 2] == 0x18) || // LIDT
1024 (Instructions
[i
+ 2] == 0x30))) || // LMSW
1025 (Instructions
[i
+ 1] == 0x08) || // INVD
1026 (Instructions
[i
+ 1] == 0x09) || // WBINVD
1027 (Instructions
[i
+ 1] == 0x35) || // SYSEXIT
1028 (Instructions
[i
+ 1] == 0x21) || // MOV DR, XXX
1029 (Instructions
[i
+ 1] == 0x06) || // CLTS
1030 (Instructions
[i
+ 1] == 0x20) || // MOV CR, XXX
1031 (Instructions
[i
+ 1] == 0x22) || // MOV XXX, CR
1032 (Instructions
[i
+ 1] == 0x23) || // MOV YYY, DR
1033 (Instructions
[i
+ 1] == 0x30) || // WRMSR
1034 (Instructions
[i
+ 1] == 0x33)) // RDPMC
1035 // INVLPG, INVLPGA, SYSRET
1037 /* These are all privileged */
1043 /* Get the IOPL and compare with the RPL mask */
1044 Iopl
= (TrapFrame
->EFlags
& EFLAGS_IOPL
) >> 12;
1045 if ((TrapFrame
->SegCs
& RPL_MASK
) > Iopl
)
1047 /* I/O privilege error -- check for known instructions */
1048 if ((Instruction
== 0xFA) || (Instruction
== 0xFB)) // CLI or STI
1050 /* These are privileged */
1055 /* Last hope: an IN/OUT instruction */
1056 for (j
= 0; j
< sizeof(KiTrapIoTable
); j
++)
1058 /* Is this an I/O instruction? */
1059 if (Instruction
== KiTrapIoTable
[j
])
1061 /* Then it's privileged */
1070 /* So now... was the instruction privileged or not? */
1073 /* Whew! We have a privileged instruction, so dispatch the fault */
1074 KiDispatchException0Args(STATUS_PRIVILEGED_INSTRUCTION
,
1080 /* If we got here, send an access violation */
1081 KiDispatchException2Args(STATUS_ACCESS_VIOLATION
,
1089 * Check for a fault during checking of the user instruction.
1091 * Note that the SEH handler will catch invalid EIP, but we could be dealing
1092 * with an invalid CS, which will generate another GPF instead.
1095 if (((PVOID
)TrapFrame
->Eip
>= (PVOID
)KiTrap0DHandler
) &&
1096 ((PVOID
)TrapFrame
->Eip
< (PVOID
)KiTrap0DHandler
))
1098 /* Not implemented */
1099 UNIMPLEMENTED_FATAL();
1103 * NOTE: The ASM trap exit code would restore segment registers by doing
1104 * a POP <SEG>, which could cause an invalid segment if someone had messed
1105 * with the segment values.
1107 * Another case is a bogus SS, which would hit a GPF when doing the iret.
1108 * This could only be done through a buggy or malicious driver, or perhaps
1109 * the kernel debugger.
1111 * The kernel normally restores the "true" segment if this happens.
1113 * However, since we're restoring in C, not ASM, we can't detect
1114 * POP <SEG> since the actual instructions will be different.
1116 * A better technique would be to check the EIP and somehow edit the
1117 * trap frame before restarting the instruction -- but we would need to
1118 * know the extract instruction that was used first.
1120 * We could force a special instrinsic to use stack instructions, or write
1121 * a simple instruction length checker.
1123 * Nevertheless, this is a lot of work for the purpose of avoiding a crash
1124 * when the user is purposedly trying to create one from kernel-mode, so
1125 * we should probably table this for now since it's not a "real" issue.
1129 * NOTE2: Another scenario is the IRET during a V8086 restore (BIOS Call)
1130 * which will cause a GPF since the trap frame is a total mess (on purpose)
1131 * as built in KiEnterV86Mode.
1133 * The idea is to scan for IRET, scan for the known EIP adress, validate CS
1134 * and then manually issue a jump to the V8086 return EIP.
1136 Instructions
= (PUCHAR
)TrapFrame
->Eip
;
1137 if (Instructions
[0] == 0xCF)
1140 * Some evil shit is going on here -- this is not the SS:ESP you're
1141 * looking for! Instead, this is actually CS:EIP you're looking at!
1142 * Why? Because part of the trap frame actually corresponds to the IRET
1143 * stack during the trap exit!
1145 if ((TrapFrame
->HardwareEsp
== (ULONG
)Ki386BiosCallReturnAddress
) &&
1146 (TrapFrame
->HardwareSegSs
== (KGDT_R0_CODE
| RPL_MASK
)))
1148 /* Exit the V86 trap! */
1149 Ki386BiosCallReturnAddress(TrapFrame
);
1153 /* Otherwise, this is another kind of IRET fault */
1154 UNIMPLEMENTED_FATAL();
1158 /* So since we're not dealing with the above case, check for RDMSR/WRMSR */
1159 if ((Instructions
[0] == 0xF) && // 2-byte opcode
1160 ((Instructions
[1] == 0x32) || // RDMSR
1161 (Instructions
[1] == 0x30))) // WRMSR
1163 /* Unknown CPU MSR, so raise an access violation */
1164 KiDispatchException0Args(STATUS_ACCESS_VIOLATION
,
1169 /* Check for lazy segment load */
1170 if (TrapFrame
->SegDs
!= (KGDT_R3_DATA
| RPL_MASK
))
1173 TrapFrame
->SegDs
= (KGDT_R3_DATA
| RPL_MASK
);
1175 else if (TrapFrame
->SegEs
!= (KGDT_R3_DATA
| RPL_MASK
))
1178 TrapFrame
->SegEs
= (KGDT_R3_DATA
| RPL_MASK
);
1182 /* Whatever it is, we can't handle it */
1183 KiSystemFatalException(EXCEPTION_GP_FAULT
, TrapFrame
);
1186 /* Return to where we came from */
1187 KiTrapReturn(TrapFrame
);
1193 KiTrap0EHandler(IN PKTRAP_FRAME TrapFrame
)
1199 /* Save trap frame */
1200 KiEnterTrap(TrapFrame
);
1202 /* Check if this is the base frame */
1203 Thread
= KeGetCurrentThread();
1204 if (KeGetTrapFrame(Thread
) != TrapFrame
)
1206 /* It isn't, check if this is a second nested frame */
1207 if (((ULONG_PTR
)KeGetTrapFrame(Thread
) - (ULONG_PTR
)TrapFrame
) <=
1208 FIELD_OFFSET(KTRAP_FRAME
, EFlags
))
1210 /* The stack is somewhere in between frames, we need to fix it */
1211 UNIMPLEMENTED_FATAL();
1218 /* Enable interupts */
1221 /* Check if we came in with interrupts disabled */
1222 if (!(TrapFrame
->EFlags
& EFLAGS_INTERRUPT_MASK
))
1224 /* This is completely illegal, bugcheck the system */
1225 KeBugCheckWithTf(IRQL_NOT_LESS_OR_EQUAL
,
1228 TrapFrame
->ErrCode
& 2 ? TRUE
: FALSE
,
1233 /* Check for S-LIST fault in kernel mode */
1234 if (TrapFrame
->Eip
== (ULONG_PTR
)ExpInterlockedPopEntrySListFault
)
1236 PSLIST_HEADER SListHeader
;
1238 /* Sanity check that the assembly is correct:
1239 This must be mov ebx, [eax]
1240 Followed by cmpxchg8b [ebp] */
1241 ASSERT((((UCHAR
*)TrapFrame
->Eip
)[0] == 0x8B) &&
1242 (((UCHAR
*)TrapFrame
->Eip
)[1] == 0x18) &&
1243 (((UCHAR
*)TrapFrame
->Eip
)[2] == 0x0F) &&
1244 (((UCHAR
*)TrapFrame
->Eip
)[3] == 0xC7) &&
1245 (((UCHAR
*)TrapFrame
->Eip
)[4] == 0x4D) &&
1246 (((UCHAR
*)TrapFrame
->Eip
)[5] == 0x00));
1248 /* Get the pointer to the SLIST_HEADER */
1249 SListHeader
= (PSLIST_HEADER
)TrapFrame
->Ebp
;
1251 /* Check if the Next member of the SLIST_HEADER was changed */
1252 if (SListHeader
->Next
.Next
!= (PSLIST_ENTRY
)TrapFrame
->Eax
)
1254 /* Restart the operation */
1255 TrapFrame
->Eip
= (ULONG_PTR
)ExpInterlockedPopEntrySListResume
;
1257 /* Continue execution */
1258 KiEoiHelper(TrapFrame
);
1263 /* Do what windows does and issue an invalid access violation */
1264 KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION
,
1266 TrapFrame
->ErrCode
& 2 ? TRUE
: FALSE
,
1273 /* Call the access fault handler */
1274 Status
= MmAccessFault(TrapFrame
->ErrCode
& 1,
1276 KiUserTrap(TrapFrame
),
1278 if (NT_SUCCESS(Status
)) KiEoiHelper(TrapFrame
);
1280 /* Check for syscall fault */
1282 if ((TrapFrame
->Eip
== (ULONG_PTR
)CopyParams
) ||
1283 (TrapFrame
->Eip
== (ULONG_PTR
)ReadBatch
))
1285 /* Not yet implemented */
1286 UNIMPLEMENTED_FATAL();
1289 /* Check for VDM trap */
1290 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
1292 /* Either kernel or user trap (non VDM) so dispatch exception */
1293 if (Status
== STATUS_ACCESS_VIOLATION
)
1295 /* This status code is repurposed so we can recognize it later */
1296 KiDispatchException2Args(KI_EXCEPTION_ACCESS_VIOLATION
,
1298 TrapFrame
->ErrCode
& 2 ? TRUE
: FALSE
,
1302 else if ((Status
== STATUS_GUARD_PAGE_VIOLATION
) ||
1303 (Status
== STATUS_STACK_OVERFLOW
))
1305 /* These faults only have two parameters */
1306 KiDispatchException2Args(Status
,
1308 TrapFrame
->ErrCode
& 2 ? TRUE
: FALSE
,
1313 /* Only other choice is an in-page error, with 3 parameters */
1314 KiDispatchExceptionFromTrapFrame(STATUS_IN_PAGE_ERROR
,
1318 TrapFrame
->ErrCode
& 2 ? TRUE
: FALSE
,
1327 KiTrap0FHandler(IN PKTRAP_FRAME TrapFrame
)
1329 /* Save trap frame */
1330 KiEnterTrap(TrapFrame
);
1332 /* FIXME: Kill the system */
1334 KiSystemFatalException(EXCEPTION_RESERVED_TRAP
, TrapFrame
);
1340 KiTrap10Handler(IN PKTRAP_FRAME TrapFrame
)
1343 PFX_SAVE_AREA SaveArea
;
1345 /* Save trap frame */
1346 KiEnterTrap(TrapFrame
);
1348 /* Check if this is the NPX thrad */
1349 Thread
= KeGetCurrentThread();
1350 SaveArea
= KiGetThreadNpxArea(Thread
);
1351 if (Thread
!= KeGetCurrentPrcb()->NpxThread
)
1353 /* It isn't, enable interrupts and set delayed error */
1355 SaveArea
->Cr0NpxState
|= CR0_TS
;
1358 KiEoiHelper(TrapFrame
);
1361 /* Otherwise, proceed with NPX fault handling */
1362 KiNpxHandler(TrapFrame
, Thread
, SaveArea
);
1368 KiTrap11Handler(IN PKTRAP_FRAME TrapFrame
)
1370 /* Save trap frame */
1371 KiEnterTrap(TrapFrame
);
1373 /* Enable interrupts and kill the system */
1375 KiSystemFatalException(EXCEPTION_ALIGNMENT_CHECK
, TrapFrame
);
1381 KiTrap13Handler(IN PKTRAP_FRAME TrapFrame
)
1384 PFX_SAVE_AREA SaveArea
;
1385 ULONG Cr0
, MxCsrMask
, Error
;
1387 /* Save trap frame */
1388 KiEnterTrap(TrapFrame
);
1390 /* Check if this is the NPX thrad */
1391 Thread
= KeGetCurrentThread();
1392 if (Thread
!= KeGetCurrentPrcb()->NpxThread
)
1394 /* It isn't, kill the system */
1395 KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN
, 13, (ULONG_PTR
)Thread
, 0, 0, TrapFrame
);
1398 /* Get the NPX frame */
1399 SaveArea
= KiGetThreadNpxArea(Thread
);
1401 /* Check for VDM trap */
1402 ASSERT((KiVdmTrap(TrapFrame
)) == FALSE
);
1404 /* Check for user trap */
1405 if (!KiUserTrap(TrapFrame
))
1407 /* Kernel should not fault on XMMI */
1408 KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN
, 13, 0, 0, 2, TrapFrame
);
1413 Cr0
&= ~(CR0_MP
| CR0_EM
| CR0_TS
);
1416 /* Save FPU state */
1417 Ke386SaveFpuState(SaveArea
);
1419 /* Mark CR0 state dirty */
1420 Cr0
|= NPX_STATE_NOT_LOADED
;
1421 Cr0
|= SaveArea
->Cr0NpxState
;
1424 /* Update NPX state */
1425 Thread
->NpxState
= NPX_STATE_NOT_LOADED
;
1426 KeGetCurrentPrcb()->NpxThread
= NULL
;
1428 /* Clear the TS bit and re-enable interrupts */
1429 SaveArea
->Cr0NpxState
&= ~CR0_TS
;
1432 /* Now look at MxCsr to get the mask of errors we should care about */
1433 MxCsrMask
= ~((USHORT
)SaveArea
->U
.FxArea
.MXCsr
>> 7);
1435 /* Get legal exceptions that software should handle */
1436 Error
= (USHORT
)SaveArea
->U
.FxArea
.MXCsr
& (FSW_INVALID_OPERATION
|
1444 /* Now handle any of those legal errors */
1445 if (Error
& (FSW_INVALID_OPERATION
|
1452 /* By issuing an exception */
1453 KiDispatchException1Args(STATUS_FLOAT_MULTIPLE_TRAPS
,
1459 /* Unknown XMMI fault */
1460 KeBugCheckWithTf(TRAP_CAUSE_UNKNOWN
, 13, 0, 0, 1, TrapFrame
);
1463 /* SOFTWARE SERVICES **********************************************************/
1467 KiRaiseSecurityCheckFailureHandler(IN PKTRAP_FRAME TrapFrame
)
1469 /* Save trap frame */
1470 KiEnterTrap(TrapFrame
);
1472 /* Decrement EIP to point to the INT29 instruction (2 bytes, not 1 like INT3) */
1473 TrapFrame
->Eip
-= 2;
1475 /* Check if this is a user trap */
1476 if (KiUserTrap(TrapFrame
))
1478 /* Dispatch exception to user mode */
1479 KiDispatchExceptionFromTrapFrame(STATUS_STACK_BUFFER_OVERRUN
,
1480 EXCEPTION_NONCONTINUABLE
,
1490 EXCEPTION_RECORD ExceptionRecord
;
1492 /* Bugcheck the system */
1493 ExceptionRecord
.ExceptionCode
= STATUS_STACK_BUFFER_OVERRUN
;
1494 ExceptionRecord
.ExceptionFlags
= EXCEPTION_NONCONTINUABLE
;
1495 ExceptionRecord
.ExceptionRecord
= NULL
;
1496 ExceptionRecord
.ExceptionAddress
= (PVOID
)TrapFrame
->Eip
;
1497 ExceptionRecord
.NumberParameters
= 1;
1498 ExceptionRecord
.ExceptionInformation
[0] = TrapFrame
->Ecx
;
1500 KeBugCheckWithTf(KERNEL_SECURITY_CHECK_FAILURE
,
1502 (ULONG_PTR
)TrapFrame
,
1503 (ULONG_PTR
)&ExceptionRecord
,
1511 KiGetTickCountHandler(IN PKTRAP_FRAME TrapFrame
)
1513 UNIMPLEMENTED_DBGBREAK();
1518 KiCallbackReturnHandler(IN PKTRAP_FRAME TrapFrame
)
1523 /* Save the SEH chain, NtCallbackReturn will restore this */
1524 TrapFrame
->ExceptionList
= KeGetPcr()->NtTib
.ExceptionList
;
1526 /* Set thread fields */
1527 Thread
= KeGetCurrentThread();
1528 Thread
->TrapFrame
= TrapFrame
;
1529 Thread
->PreviousMode
= KiUserTrap(TrapFrame
);
1530 NT_ASSERT(Thread
->PreviousMode
!= KernelMode
);
1532 /* Pass the register parameters to NtCallbackReturn.
1533 Result pointer is in ecx, result length in edx, status in eax */
1534 Status
= NtCallbackReturn((PVOID
)TrapFrame
->Ecx
,
1538 /* If we got here, something went wrong. Return an error to the caller */
1539 KiServiceExit(TrapFrame
, Status
);
1545 KiRaiseAssertionHandler(IN PKTRAP_FRAME TrapFrame
)
1547 /* Save trap frame */
1548 KiEnterTrap(TrapFrame
);
1550 /* Decrement EIP to point to the INT2C instruction (2 bytes, not 1 like INT3) */
1551 TrapFrame
->Eip
-= 2;
1553 /* Dispatch the exception */
1554 KiDispatchException0Args(STATUS_ASSERTION_FAILURE
,
1562 KiDebugServiceHandler(IN PKTRAP_FRAME TrapFrame
)
1564 /* Save trap frame */
1565 KiEnterTrap(TrapFrame
);
1567 /* Increment EIP to skip the INT3 instruction */
1570 /* Continue with the common handler */
1571 KiDebugHandler(TrapFrame
, TrapFrame
->Eax
, TrapFrame
->Ecx
, TrapFrame
->Edx
);
1577 KiDbgPreServiceHook(ULONG SystemCallNumber
, PULONG_PTR Arguments
)
1579 #if DBG && !defined(_WINKD_)
1580 if (SystemCallNumber
>= 0x1000 && KeWin32PreServiceHook
)
1581 KeWin32PreServiceHook(SystemCallNumber
, Arguments
);
1587 KiDbgPostServiceHook(ULONG SystemCallNumber
, ULONG_PTR Result
)
1589 #if DBG && !defined(_WINKD_)
1590 if (SystemCallNumber
>= 0x1000 && KeWin32PostServiceHook
)
1591 return KeWin32PostServiceHook(SystemCallNumber
, Result
);
1599 KiSystemServiceHandler(IN PKTRAP_FRAME TrapFrame
,
1603 PKSERVICE_TABLE_DESCRIPTOR DescriptorTable
;
1604 ULONG Id
, Offset
, StackBytes
, Result
;
1606 ULONG SystemCallNumber
= TrapFrame
->Eax
;
1608 /* Get the current thread */
1609 Thread
= KeGetCurrentThread();
1611 /* Set debug header */
1612 KiFillTrapFrameDebug(TrapFrame
);
1614 /* Chain trap frames */
1615 TrapFrame
->Edx
= (ULONG_PTR
)Thread
->TrapFrame
;
1618 TrapFrame
->ErrCode
= 0;
1620 /* Save previous mode */
1621 TrapFrame
->PreviousPreviousMode
= Thread
->PreviousMode
;
1623 /* Save the SEH chain and terminate it for now */
1624 TrapFrame
->ExceptionList
= KeGetPcr()->NtTib
.ExceptionList
;
1625 KeGetPcr()->NtTib
.ExceptionList
= EXCEPTION_CHAIN_END
;
1627 /* Default to debugging disabled */
1630 /* Check if the frame was from user mode */
1631 if (KiUserTrap(TrapFrame
))
1633 /* Check for active debugging */
1634 if (KeGetCurrentThread()->Header
.DebugActive
& 0xFF)
1636 /* Handle debug registers */
1637 KiHandleDebugRegistersOnTrapEntry(TrapFrame
);
1641 /* Set thread fields */
1642 Thread
->TrapFrame
= TrapFrame
;
1643 Thread
->PreviousMode
= KiUserTrap(TrapFrame
);
1645 /* Enable interrupts */
1648 /* Decode the system call number */
1649 Offset
= (SystemCallNumber
>> SERVICE_TABLE_SHIFT
) & SERVICE_TABLE_MASK
;
1650 Id
= SystemCallNumber
& SERVICE_NUMBER_MASK
;
1652 /* Get descriptor table */
1653 DescriptorTable
= (PVOID
)((ULONG_PTR
)Thread
->ServiceTable
+ Offset
);
1655 /* Validate the system call number */
1656 if (__builtin_expect(Id
>= DescriptorTable
->Limit
, 0))
1658 /* Check if this is a GUI call */
1659 if (!(Offset
& SERVICE_TABLE_TEST
))
1662 Result
= STATUS_INVALID_SYSTEM_SERVICE
;
1666 /* Convert us to a GUI thread -- must wrap in ASM to get new EBP */
1667 Result
= KiConvertToGuiThread();
1669 /* Reload trap frame and descriptor table pointer from new stack */
1670 TrapFrame
= *(volatile PVOID
*)&Thread
->TrapFrame
;
1671 DescriptorTable
= (PVOID
)(*(volatile ULONG_PTR
*)&Thread
->ServiceTable
+ Offset
);
1673 if (!NT_SUCCESS(Result
))
1675 /* Set the last error and fail */
1676 NtCurrentTeb()->LastErrorValue
= RtlNtStatusToDosError(Result
);
1680 /* Validate the system call number again */
1681 if (Id
>= DescriptorTable
->Limit
)
1684 Result
= STATUS_INVALID_SYSTEM_SERVICE
;
1689 /* Check if this is a GUI call */
1690 if (__builtin_expect(Offset
& SERVICE_TABLE_TEST
, 0))
1692 /* Get the batch count and flush if necessary */
1693 if (NtCurrentTeb()->GdiBatchCount
) KeGdiFlushUserBatch();
1696 /* Increase system call count */
1697 KeGetCurrentPrcb()->KeSystemCalls
++;
1699 /* FIXME: Increase individual counts on debug systems */
1700 //KiIncreaseSystemCallCount(DescriptorTable, Id);
1702 /* Get stack bytes */
1703 StackBytes
= DescriptorTable
->Number
[Id
];
1705 /* Probe caller stack */
1706 if (__builtin_expect((Arguments
< (PVOID
)MmUserProbeAddress
) && !(KiUserTrap(TrapFrame
)), 0))
1708 /* Access violation */
1709 UNIMPLEMENTED_FATAL();
1712 /* Call pre-service debug hook */
1713 KiDbgPreServiceHook(SystemCallNumber
, Arguments
);
1715 /* Get the handler and make the system call */
1716 Handler
= (PVOID
)DescriptorTable
->Base
[Id
];
1717 Result
= KiSystemCallTrampoline(Handler
, Arguments
, StackBytes
);
1719 /* Call post-service debug hook */
1720 Result
= KiDbgPostServiceHook(SystemCallNumber
, Result
);
1722 /* Make sure we're exiting correctly */
1723 KiExitSystemCallDebugChecks(Id
, TrapFrame
);
1725 /* Restore the old trap frame */
1727 Thread
->TrapFrame
= (PKTRAP_FRAME
)TrapFrame
->Edx
;
1729 /* Exit from system call */
1730 KiServiceExit(TrapFrame
, Result
);
1738 Kei386EoiHelper(VOID
)
1740 /* We should never see this call happening */
1741 ERROR_FATAL("Mismatched NT/HAL version");