00383 :
00384
00385 This function
is called to dispatch an exception to
the proper mode and
00386 to cause
the exception dispatcher to be called.
00387
00388 If
the exception
is a data misalignment,
this is the first chance
for
00389 handling
the exception, and
the current thread has enabled automatic
00390 alignment fixup, then an attempt
is made to emulate
the unaligned
00391 reference.
00392
00393 If
the exception
is a floating exception (N.B. the pseudo status
00394 STATUS_FLOAT_STACK_CHECK is used to signify
this), we convert
the
00395 exception code to
the correct STATUS based on
the FPSCR.
00396 It
is up to
the handler to figure
out what to
do to emulate/repair
00397
the operation.
00398
00399 If
the exception
is neither a data misalignment nor a floating point
00400 exception and
the the previous mode
is kernel, then
the exception
00401 dispatcher
is called directly to process
the exception. Otherwise
the
00402 exception record, exception frame, and trap frame contents are copied
00403 to
the user mode stack. The contents of
the exception frame and trap
00404 are then modified such that when
control is returned, execution will
00405 commence in user mode in a routine which will call
the exception
00406 dispatcher.
00407
00408 Arguments:
00409
00410 ExceptionRecord - Supplies a pointer to an exception record.
00411
00412 ExceptionFrame - Supplies a pointer to an exception frame.
00413
00414 TrapFrame - Supplies a pointer to a trap frame.
00415
00416 PreviousMode - Supplies
the previous processor mode.
00417
00418 FirstChance - Supplies a
boolean variable that specifies whether
this
00419
is the first (TRUE) or second (FALSE) time that this exception has
00420 been processed.
00421
00422 Return Value:
00423
00424 None.
00425
00426 --*/
00427
00428 {
00429
00430 CONTEXT ContextFrame;
00431 EXCEPTION_RECORD ExceptionRecord1;
00432 LONG Length;
00433 BOOLEAN UserApcPending;
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
if (ExceptionRecord->ExceptionCode == STATUS_DATATYPE_MISALIGNMENT) {
00446
if (FirstChance !=
FALSE) {
00447
00448
00449
00450
00451
00452
00453
if ((
KiEnableAlignmentFaultExceptions ==
FALSE) ||
00454 (
KeGetCurrentThread()->AutoAlignment !=
FALSE) ||
00455 (
KeGetCurrentThread()->ApcState.Process->AutoAlignment !=
FALSE)) {
00456
if (
KiEmulateReference(ExceptionRecord, ExceptionFrame, TrapFrame) !=
FALSE) {
00457
KeGetCurrentPrcb()->KeAlignmentFixupCount += 1;
00458
goto Handled2;
00459 }
00460 }
else {
00461
if (
KiEmulateDcbz(ExceptionRecord, ExceptionFrame, TrapFrame) !=
FALSE) {
00462
KeGetCurrentPrcb()->KeAlignmentFixupCount += 1;
00463
goto Handled2;
00464 }
00465 }
00466 }
00467 }
00468
00469
00470
00471
00472
00473
00474
00475
if (ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) {
00476
00477 ULONG Instr = ExceptionRecord->ExceptionInformation[0];
00478
00479
if ((Instr & 0xffe0ffff) ==
DIVIDE_BREAKPOINT ||
00480 (Instr & 0xffe0ffff) ==
UDIVIDE_BREAKPOINT) {
00481 ExceptionRecord->ExceptionCode = STATUS_INTEGER_DIVIDE_BY_ZERO;
00482 }
else if (Instr ==
KDDEBUG_BREAKPOINT) {
00483 TrapFrame->Iar += 4;
00484 }
00485 }
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
if (ExceptionRecord->ExceptionCode == STATUS_FLOAT_STACK_CHECK) {
00496
00497 PFPSCR Fpscr = (PFPSCR)(&TrapFrame->Fpscr);
00498
00499
if ((Fpscr->XE == 1) && (Fpscr->XX == 1)) {
00500
00501 ExceptionRecord->ExceptionCode = STATUS_FLOAT_INEXACT_RESULT;
00502 Fpscr->XE = 0;
00503
00504 }
00505
else if ((Fpscr->ZE == 1) && (Fpscr->ZX == 1)) {
00506
00507 ExceptionRecord->ExceptionCode = STATUS_FLOAT_DIVIDE_BY_ZERO;
00508 Fpscr->ZE = 0;
00509
00510 }
00511
else if ((Fpscr->UE == 1) && (Fpscr->UX == 1)) {
00512
00513 ExceptionRecord->ExceptionCode = STATUS_FLOAT_UNDERFLOW;
00514 Fpscr->UE = 0;
00515
00516 }
00517
00518
else if ((Fpscr->OE == 1) && (Fpscr->OX == 1)) {
00519
00520 ExceptionRecord->ExceptionCode = STATUS_FLOAT_OVERFLOW;
00521 Fpscr->OE = 0;
00522
00523 }
00524
else {
00525
00526
00527
00528 ExceptionRecord->ExceptionCode = STATUS_FLOAT_INVALID_OPERATION;
00529 Fpscr->VE = 0;
00530 }
00531 }
00532
00533
00534
00535
00536
00537
00538 ContextFrame.ContextFlags =
CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS;
00539
KeContextFromKframes(TrapFrame, ExceptionFrame, &ContextFrame);
00540
KeGetCurrentPrcb()->KeExceptionDispatchCount += 1;
00541
00542
00543
00544
00545
00546
if (PreviousMode ==
KernelMode) {
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
if (FirstChance !=
FALSE) {
00566
00567
00568
00569
00570
00571
00572
00573
if ((
KiDebugRoutine !=
NULL) &&
00574 ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) ||
00575 (ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP)) &&
00576 (
KdIsThisAKdTrap(ExceptionRecord,
00577 &ContextFrame,
00578 KernelMode) !=
FALSE)) {
00579
00580
if (((
KiDebugRoutine) (TrapFrame,
00581 ExceptionFrame,
00582 ExceptionRecord,
00583 &ContextFrame,
00584
KernelMode,
00585
FALSE)) !=
FALSE) {
00586
00587
goto Handled1;
00588 }
00589 }
00590
00591
00592
00593
00594
00595
if (
RtlDispatchException(ExceptionRecord, &ContextFrame) !=
FALSE) {
00596
goto Handled1;
00597 }
00598 }
00599
00600
00601
00602
00603
00604
if (
KiDebugRoutine !=
NULL) {
00605
if (((
KiDebugRoutine) (TrapFrame,
00606 ExceptionFrame,
00607 ExceptionRecord,
00608 &ContextFrame,
00609 PreviousMode,
00610
TRUE)) !=
FALSE) {
00611
goto Handled1;
00612 }
00613 }
00614
00615
KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
00616 ExceptionRecord->ExceptionCode,
00617 (ULONG)ExceptionRecord->ExceptionAddress,
00618 ExceptionRecord->ExceptionInformation[0],
00619 ExceptionRecord->ExceptionInformation[1]);
00620
00621 }
else {
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
if (FirstChance !=
FALSE) {
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
if ((
KiDebugRoutine !=
NULL) &&
00660 ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) ||
00661 (ExceptionRecord->ExceptionCode == STATUS_SINGLE_STEP)) &&
00662 (
KdIsThisAKdTrap(ExceptionRecord,
00663 &ContextFrame,
00664 UserMode) !=
FALSE) &&
00665 ((
PsGetCurrentProcess()->DebugPort ==
NULL) ||
00666 ((
PsGetCurrentProcess()->DebugPort !=
NULL) &&
00667 (ExceptionRecord->ExceptionInformation[0] !=
00668
KERNEL_BREAKPOINT_INSTRUCTION)))) {
00669
00670
if (((
KiDebugRoutine) (TrapFrame,
00671 ExceptionFrame,
00672 ExceptionRecord,
00673 &ContextFrame,
00674
UserMode,
00675
FALSE)) !=
FALSE) {
00676
00677
goto Handled1;
00678 }
00679 }
00680
00681
00682
00683
00684
00685
if (
DbgkForwardException(ExceptionRecord, TRUE, FALSE)) {
00686 TrapFrame->Fpscr = SANITIZE_FPSCR(TrapFrame->Fpscr, UserMode);
00687
goto Handled2;
00688 }
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 repeat:
00735
try {
00736
00737
00738
00739
00740
00741 ULONG Length = (
sizeof (STACK_FRAME_HEADER) +
sizeof (EXCEPTION_RECORD) +
00742
sizeof (CONTEXT) +
sizeof (ULONG) + STK_SLACK_SPACE + 7) & (~7);
00743
00744 ULONG UserStack = (ContextFrame.Gpr1 & (~7)) - Length;
00745 ULONG ExceptSlot = UserStack +
sizeof (STACK_FRAME_HEADER);
00746 ULONG ContextSlot = ExceptSlot +
sizeof (EXCEPTION_RECORD);
00747 ULONG TocSlot = ContextSlot +
sizeof (CONTEXT);
00748
00749
00750
00751
00752
00753
00754
ProbeForWrite((PCHAR) UserStack, ContextFrame.Gpr1 - UserStack,
sizeof(QUAD));
00755 RtlMoveMemory((PVOID) ExceptSlot, ExceptionRecord,
sizeof (EXCEPTION_RECORD));
00756 RtlMoveMemory((PVOID) ContextSlot, &ContextFrame,
sizeof (CONTEXT));
00757
00758
00759
00760
00761
00762
00763 *((PULONG) TocSlot) = ContextFrame.Gpr2;
00764
00765
00766
00767
00768
00769 *((PULONG) UserStack) = ContextFrame.Gpr1;
00770
00771
00772
00773
00774
00775
00776 TrapFrame->Gpr1 = UserStack;
00777 TrapFrame->Gpr3 = ExceptSlot;
00778 TrapFrame->Gpr4 = ContextSlot;
00779
00780
00781
00782
00783
00784
00785 TrapFrame->Fpscr = SANITIZE_FPSCR(ContextFrame.Fpscr, UserMode);
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795 {
00796 PULONG FnDesc = (PULONG)
KeUserExceptionDispatcher;
00797 TrapFrame->Iar = FnDesc[0];
00798 TrapFrame->Gpr2 = FnDesc[1];
00799 }
00800
00801
return;
00802
00803
00804
00805
00806
00807
00808 } except (
KiCopyInformation(&ExceptionRecord1,
00809 (GetExceptionInformation())->ExceptionRecord)) {
00810
00811
00812
00813
00814
00815
00816
00817
00818
if (ExceptionRecord1.ExceptionCode == STATUS_STACK_OVERFLOW) {
00819 ExceptionRecord1.ExceptionAddress = ExceptionRecord->ExceptionAddress;
00820 RtlMoveMemory((PVOID)ExceptionRecord,
00821 &ExceptionRecord1,
sizeof(EXCEPTION_RECORD));
00822
goto repeat;
00823 }
00824 }
00825 }
00826
00827
00828
00829
00830
00831 UserApcPending =
KeGetCurrentThread()->ApcState.UserApcPending;
00832
if (
DbgkForwardException(ExceptionRecord, TRUE, TRUE)) {
00833 TrapFrame->Fpscr = SANITIZE_FPSCR(TrapFrame->Fpscr, UserMode);
00834
goto Handled2;
00835
00836 }
else if (
DbgkForwardException(ExceptionRecord, FALSE, TRUE)) {
00837
00838
00839
00840
00841
00842
00843
00844
00845
if ((UserApcPending ==
FALSE) &&
00846 (
KeGetCurrentThread()->ApcState.UserApcPending !=
FALSE)) {
00847
00848
00849
00850 }
00851
00852 TrapFrame->Fpscr = SANITIZE_FPSCR(TrapFrame->Fpscr, UserMode);
00853
goto Handled2;
00854
00855 }
else {
00856 ZwTerminateProcess(NtCurrentProcess(), ExceptionRecord->ExceptionCode);
00857
KeBugCheckEx(KMODE_EXCEPTION_NOT_HANDLED,
00858 ExceptionRecord->ExceptionCode,
00859 (ULONG)ExceptionRecord->ExceptionAddress,
00860 ExceptionRecord->ExceptionInformation[0],
00861 ExceptionRecord->ExceptionInformation[1]);
00862 }
00863 }
00864
00865
00866
00867
00868
00869
00870 Handled1:
00871
KeContextToKframes(TrapFrame, ExceptionFrame, &ContextFrame,
00872 ContextFrame.ContextFlags, PreviousMode);
00873
00874
00875
00876
00877
00878
00879
00880
00881 Handled2:
00882
return;
00883 }