3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * PROJECT: ReactOS kernel
21 * FILE: ntoskrnl/ke/i386/exp.c
22 * PURPOSE: Handling exceptions
23 * PROGRAMMERS: David Welch (welch@cwcom.net)
24 * Skywing (skywing@valhallalegends.com)
27 * 09/12/03: KeRaiseUserException added (Skywing).
30 /* INCLUDES *****************************************************************/
35 #include <internal/debug.h>
37 /* GLOBALS *****************************************************************/
39 #define FLAG_IF (1<<9)
42 #define STR(x) _STR(x)
45 # define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0]))
48 extern void interrupt_handler2e(void);
49 extern void interrupt_handler2d(void);
51 extern VOID
KiTrap0(VOID
);
52 extern VOID
KiTrap1(VOID
);
53 extern VOID
KiTrap2(VOID
);
54 extern VOID
KiTrap3(VOID
);
55 extern VOID
KiTrap4(VOID
);
56 extern VOID
KiTrap5(VOID
);
57 extern VOID
KiTrap6(VOID
);
58 extern VOID
KiTrap7(VOID
);
59 extern VOID
KiTrap8(VOID
);
60 extern VOID
KiTrap9(VOID
);
61 extern VOID
KiTrap10(VOID
);
62 extern VOID
KiTrap11(VOID
);
63 extern VOID
KiTrap12(VOID
);
64 extern VOID
KiTrap13(VOID
);
65 extern VOID
KiTrap14(VOID
);
66 extern VOID
KiTrap15(VOID
);
67 extern VOID
KiTrap16(VOID
);
68 extern VOID
KiTrap17(VOID
);
69 extern VOID
KiTrap18(VOID
);
70 extern VOID
KiTrap19(VOID
);
71 extern VOID
KiTrapUnknown(VOID
);
73 extern ULONG init_stack
;
74 extern ULONG init_stack_top
;
76 extern BOOLEAN Ke386NoExecute
;
78 static char *ExceptionTypeStrings
[] =
85 "BOUND range exceeded",
87 "No Math Coprocessor",
91 "Segment Not Present",
92 "Stack Segment Fault",
102 static NTSTATUS ExceptionToNtStatus
[] =
104 STATUS_INTEGER_DIVIDE_BY_ZERO
,
106 STATUS_ACCESS_VIOLATION
,
108 STATUS_INTEGER_OVERFLOW
,
109 STATUS_ARRAY_BOUNDS_EXCEEDED
,
110 STATUS_ILLEGAL_INSTRUCTION
,
111 STATUS_ACCESS_VIOLATION
, /* STATUS_FLT_INVALID_OPERATION */
112 STATUS_ACCESS_VIOLATION
,
113 STATUS_ACCESS_VIOLATION
,
114 STATUS_ACCESS_VIOLATION
,
115 STATUS_ACCESS_VIOLATION
,
116 STATUS_STACK_OVERFLOW
,
117 STATUS_ACCESS_VIOLATION
,
118 STATUS_ACCESS_VIOLATION
,
119 STATUS_ACCESS_VIOLATION
, /* RESERVED */
120 STATUS_ACCESS_VIOLATION
, /* STATUS_FLT_INVALID_OPERATION */
121 STATUS_DATATYPE_MISALIGNMENT
,
122 STATUS_ACCESS_VIOLATION
,
123 STATUS_ACCESS_VIOLATION
/* STATUS_FLT_MULTIPLE_TRAPS? */
126 /* FUNCTIONS ****************************************************************/
128 #if defined(DBG) || defined(KDBG)
130 KeRosPrintAddress(PVOID address
)
132 return KdbSymPrintAddress(address
);
136 KeRosPrintAddress(PVOID address
)
138 PLIST_ENTRY current_entry
;
139 MODULE_TEXT_SECTION
* current
;
140 extern LIST_ENTRY ModuleTextListHead
;
141 ULONG_PTR RelativeAddress
;
143 current_entry
= ModuleTextListHead
.Flink
;
145 while (current_entry
!= &ModuleTextListHead
&&
146 current_entry
!= NULL
)
149 CONTAINING_RECORD(current_entry
, MODULE_TEXT_SECTION
, ListEntry
);
151 if (address
>= (PVOID
)current
->Base
&&
152 address
< (PVOID
)(current
->Base
+ current
->Length
))
154 RelativeAddress
= (ULONG_PTR
) address
- current
->Base
;
155 DbgPrint("<%ws: %x>", current
->Name
, RelativeAddress
);
158 current_entry
= current_entry
->Flink
;
165 KiKernelTrapHandler(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, PVOID Cr2
)
169 Er
.ExceptionFlags
= 0;
170 Er
.ExceptionRecord
= NULL
;
171 Er
.ExceptionAddress
= (PVOID
)Tf
->Eip
;
173 if (ExceptionNr
== 14)
175 Er
.ExceptionCode
= STATUS_ACCESS_VIOLATION
;
176 Er
.NumberParameters
= 2;
177 Er
.ExceptionInformation
[0] = Tf
->ErrorCode
& 0x1;
178 Er
.ExceptionInformation
[1] = (ULONG
)Cr2
;
182 if (ExceptionNr
< ARRAY_SIZE(ExceptionToNtStatus
))
184 Er
.ExceptionCode
= ExceptionToNtStatus
[ExceptionNr
];
188 Er
.ExceptionCode
= STATUS_ACCESS_VIOLATION
;
190 Er
.NumberParameters
= 0;
193 Er
.ExceptionFlags
= ((NTSTATUS
) STATUS_SINGLE_STEP
== (NTSTATUS
) Er
.ExceptionCode
194 || (NTSTATUS
) STATUS_BREAKPOINT
== (NTSTATUS
) Er
.ExceptionCode
) ?
195 EXCEPTION_NONCONTINUABLE
: 0;
197 KiDispatchException(&Er
, 0, Tf
, KernelMode
, TRUE
);
203 KiDoubleFaultHandler(VOID
)
209 ULONG ExceptionNr
= 8;
215 static PVOID StackTrace
[MM_STACK_SIZE
/ sizeof(PVOID
)];
216 static ULONG StackRepeatCount
[MM_STACK_SIZE
/ sizeof(PVOID
)];
217 static ULONG StackRepeatLength
[MM_STACK_SIZE
/ sizeof(PVOID
)];
222 OldTss
= KeGetCurrentKPCR()->TSS
;
227 if (PsGetCurrentThread() != NULL
&&
228 PsGetCurrentThread()->ThreadsProcess
!= NULL
)
231 PsGetCurrentThread()->ThreadsProcess
->Pcb
.DirectoryTableBase
.QuadPart
;
239 * Check for stack underflow
241 if (PsGetCurrentThread() != NULL
&&
242 Esp0
< (ULONG
)PsGetCurrentThread()->Tcb
.StackLimit
)
244 DbgPrint("Stack underflow (tf->esp %x Limit %x)\n",
245 Esp0
, (ULONG
)PsGetCurrentThread()->Tcb
.StackLimit
);
250 * Print out the CPU registers
252 if (ExceptionNr
< ARRAY_SIZE(ExceptionTypeStrings
))
254 DbgPrint("%s Exception: %d(%x)\n", ExceptionTypeStrings
[ExceptionNr
],
259 DbgPrint("Exception: %d(%x)\n", ExceptionNr
, 0);
261 DbgPrint("CS:EIP %x:%x ", OldTss
->Cs
, OldTss
->Eip
);
262 KeRosPrintAddress((PVOID
)OldTss
->Eip
);
264 DbgPrint("cr2 %x cr3 %x ", cr2
, OldCr3
);
265 DbgPrint("Proc: %x ",PsGetCurrentProcess());
266 if (PsGetCurrentProcess() != NULL
)
268 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
269 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
271 if (PsGetCurrentThread() != NULL
)
273 DbgPrint("Thrd: %x Tid: %x",
274 PsGetCurrentThread(),
275 PsGetCurrentThread()->Cid
.UniqueThread
);
278 DbgPrint("DS %x ES %x FS %x GS %x\n", OldTss
->Ds
, OldTss
->Es
,
279 OldTss
->Fs
, OldTss
->Gs
);
280 DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", OldTss
->Eax
, OldTss
->Ebx
,
282 DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x\n ESP: %.8x", OldTss
->Edx
,
283 OldTss
->Ebp
, OldTss
->Esi
, Esp0
);
284 DbgPrint("EDI: %.8x EFLAGS: %.8x ", OldTss
->Edi
, OldTss
->Eflags
);
285 if (OldTss
->Cs
== KERNEL_CS
)
287 DbgPrint("kESP %.8x ", Esp0
);
288 if (PsGetCurrentThread() != NULL
)
290 DbgPrint("kernel stack base %x\n",
291 PsGetCurrentThread()->Tcb
.StackLimit
);
297 DbgPrint("User ESP %.8x\n", OldTss
->Esp
);
299 if ((OldTss
->Cs
& 0xffff) == KERNEL_CS
)
301 if (PsGetCurrentThread() != NULL
)
303 StackLimit
= (ULONG
)PsGetCurrentThread()->Tcb
.StackBase
;
304 StackBase
= (ULONG
)PsGetCurrentThread()->Tcb
.StackLimit
;
308 StackLimit
= (ULONG
)&init_stack_top
;
309 StackBase
= (ULONG
)&init_stack
;
313 Change to an #if 0 to reduce the amount of information printed on
314 a recursive stack trace.
317 DbgPrint("Frames: ");
318 Frame
= (PULONG
)OldTss
->Ebp
;
319 while (Frame
!= NULL
&& (ULONG
)Frame
>= StackBase
)
321 KeRosPrintAddress((PVOID
)Frame
[1]);
322 Frame
= (PULONG
)Frame
[0];
326 DbgPrint("Frames: ");
328 Frame
= (PULONG
)OldTss
->Ebp
;
329 while (Frame
!= NULL
&& (ULONG
)Frame
>= StackBase
)
331 StackTrace
[i
] = (PVOID
)Frame
[1];
332 Frame
= (PULONG
)Frame
[0];
338 while (i
< TraceLength
)
340 StackRepeatCount
[i
] = 0;
343 while ((j
- i
) <= (TraceLength
- j
) && FoundRepeat
== FALSE
)
345 if (memcmp(&StackTrace
[i
], &StackTrace
[j
],
346 (j
- i
) * sizeof(PVOID
)) == 0)
348 StackRepeatCount
[i
] = 2;
349 StackRepeatLength
[i
] = j
- i
;
357 if (FoundRepeat
== FALSE
)
362 j
= j
+ StackRepeatLength
[i
];
363 while ((TraceLength
- j
) >= StackRepeatLength
[i
] &&
366 if (memcmp(&StackTrace
[i
], &StackTrace
[j
],
367 StackRepeatLength
[i
] * sizeof(PVOID
)) == 0)
369 StackRepeatCount
[i
]++;
370 j
= j
+ StackRepeatLength
[i
];
381 while (i
< TraceLength
)
383 if (StackRepeatCount
[i
] == 0)
385 KeRosPrintAddress(StackTrace
[i
]);
391 if (StackRepeatLength
[i
] == 0)
395 for (j
= 0; j
< StackRepeatLength
[i
]; j
++)
397 KeRosPrintAddress(StackTrace
[i
+ j
]);
399 DbgPrint("}*%d", StackRepeatCount
[i
]);
400 i
= i
+ StackRepeatLength
[i
] * StackRepeatCount
[i
];
412 KiDumpTrapFrame(PKTRAP_FRAME Tf
, ULONG Parameter1
, ULONG Parameter2
)
419 ULONG ExceptionNr
= (ULONG
)Tf
->DebugArgMark
;
420 ULONG cr2
= (ULONG
)Tf
->DebugPointer
;
425 * Print out the CPU registers
427 if (ExceptionNr
< ARRAY_SIZE(ExceptionTypeStrings
))
429 DbgPrint("%s Exception: %d(%x)\n", ExceptionTypeStrings
[ExceptionNr
],
430 ExceptionNr
, Tf
->ErrorCode
&0xffff);
434 DbgPrint("Exception: %d(%x)\n", ExceptionNr
, Tf
->ErrorCode
&0xffff);
436 DbgPrint("Processor: %d CS:EIP %x:%x ", KeGetCurrentProcessorNumber(),
437 Tf
->Cs
&0xffff, Tf
->Eip
);
438 KeRosPrintAddress((PVOID
)Tf
->Eip
);
440 Ke386GetPageTableDirectory(cr3_
);
441 DbgPrint("cr2 %x cr3 %x ", cr2
, cr3_
);
442 DbgPrint("Proc: %x ",PsGetCurrentProcess());
443 if (PsGetCurrentProcess() != NULL
)
445 DbgPrint("Pid: %x <", PsGetCurrentProcess()->UniqueProcessId
);
446 DbgPrint("%.8s> ", PsGetCurrentProcess()->ImageFileName
);
448 if (PsGetCurrentThread() != NULL
)
450 DbgPrint("Thrd: %x Tid: %x",
451 PsGetCurrentThread(),
452 PsGetCurrentThread()->Cid
.UniqueThread
);
455 DbgPrint("DS %x ES %x FS %x GS %x\n", Tf
->Ds
&0xffff, Tf
->Es
&0xffff,
456 Tf
->Fs
&0xffff, Tf
->Gs
&0xfff);
457 DbgPrint("EAX: %.8x EBX: %.8x ECX: %.8x\n", Tf
->Eax
, Tf
->Ebx
, Tf
->Ecx
);
458 DbgPrint("EDX: %.8x EBP: %.8x ESI: %.8x ESP: %.8x\n", Tf
->Edx
,
459 Tf
->Ebp
, Tf
->Esi
, Esp0
);
460 DbgPrint("EDI: %.8x EFLAGS: %.8x ", Tf
->Edi
, Tf
->Eflags
);
461 if ((Tf
->Cs
&0xffff) == KERNEL_CS
)
463 DbgPrint("kESP %.8x ", Esp0
);
464 if (PsGetCurrentThread() != NULL
)
466 DbgPrint("kernel stack base %x\n",
467 PsGetCurrentThread()->Tcb
.StackLimit
);
472 if (PsGetCurrentThread() != NULL
)
474 StackLimit
= (ULONG
)PsGetCurrentThread()->Tcb
.StackBase
;
478 StackLimit
= (ULONG
)&init_stack_top
;
482 * Dump the stack frames
484 DbgPrint("Frames: ");
485 /* Change to an #if 0 if no frames are printed because of fpo. */
488 Frame
= (PULONG
)Tf
->Ebp
;
489 while (Frame
!= NULL
)
493 Status
= MmSafeCopyFromUser(&Eip
, Frame
+ 1, sizeof(Eip
));
494 if (!NT_SUCCESS(Status
))
496 DbgPrint("<INVALID>");
499 if (!KeRosPrintAddress(Eip
))
501 DbgPrint("<%X>", Eip
);
503 Status
= MmSafeCopyFromUser(&Frame
, Frame
, sizeof(Frame
));
504 if (!NT_SUCCESS(Status
))
513 Frame
= (PULONG
)((ULONG_PTR
)Esp0
+ KTRAP_FRAME_EFLAGS
);
514 while (Frame
< (PULONG
)PsGetCurrentThread()->Tcb
.StackBase
&& i
< 50)
516 ULONG Address
= *Frame
;
517 if (KeRosPrintAddress((PVOID
)Address
))
527 KiTrapHandler(PKTRAP_FRAME Tf
, ULONG ExceptionNr
)
529 * FUNCTION: Called by the lowlevel execption handlers to print an amusing
530 * message and halt the computer
532 * Complete CPU context
539 /* Store the exception number in an unused field in the trap frame. */
540 Tf
->DebugArgMark
= (PVOID
)ExceptionNr
;
542 /* Use the address of the trap frame as approximation to the ring0 esp */
543 Esp0
= (ULONG
)&Tf
->Eip
;
547 Tf
->DebugPointer
= (PVOID
)cr2
;
549 if (ExceptionNr
== 14 && Tf
->Eflags
& FLAG_IF
)
551 Ke386EnableInterrupts();
555 * If this was a V86 mode exception then handle it specially
557 if (Tf
->Eflags
& (1 << 17))
559 return(KeV86Exception(ExceptionNr
, Tf
, cr2
));
563 * Check for stack underflow, this may be obsolete
565 if (PsGetCurrentThread() != NULL
&&
566 Esp0
< (ULONG
)PsGetCurrentThread()->Tcb
.StackLimit
)
568 DbgPrint("Stack underflow (tf->esp %x Limit %x)\n",
569 Esp0
, (ULONG
)PsGetCurrentThread()->Tcb
.StackLimit
);
574 * Maybe handle the page fault and return
576 if (ExceptionNr
== 14)
578 if (Ke386NoExecute
&& Tf
->ErrorCode
& 0x10 && cr2
>= KERNEL_BASE
)
580 KEBUGCHECKWITHTF(ATTEMPTED_EXECUTE_OF_NOEXECUTE_MEMORY
, 0, 0, 0, 0, Tf
);
582 Status
= MmPageFault(Tf
->Cs
&0xffff,
587 if (NT_SUCCESS(Status
))
594 * Check for a breakpoint that was only for the attention of the debugger.
596 if (ExceptionNr
== 3 && Tf
->Eip
== ((ULONG
)DbgBreakPointNoBugCheck
) + 1)
599 EIP is already adjusted by the processor to point to the instruction
600 after the breakpoint.
606 * Try to handle device-not-present, math-fault and xmm-fault exceptions.
608 if (ExceptionNr
== 7 || ExceptionNr
== 16 || ExceptionNr
== 19)
610 Status
= KiHandleFpuFault(Tf
, ExceptionNr
);
611 if (NT_SUCCESS(Status
))
618 * Handle user exceptions differently
620 if ((Tf
->Cs
& 0xFFFF) == USER_CS
)
622 return(KiUserTrapHandler(Tf
, ExceptionNr
, (PVOID
)cr2
));
626 return(KiKernelTrapHandler(Tf
, ExceptionNr
, (PVOID
)cr2
));
631 KeDumpStackFrames(PULONG Frame
)
633 PULONG StackBase
, StackEnd
;
634 MEMORY_BASIC_INFORMATION mbi
;
635 ULONG ResultLength
= sizeof(mbi
);
638 DbgPrint("Frames: ");
641 Status
= MiQueryVirtualMemory (
644 MemoryBasicInformation
,
648 if ( !NT_SUCCESS(Status
) )
650 DPRINT1("Can't dump stack frames: NtQueryVirtualMemory() failed: %x\n", Status
);
655 StackEnd
= mbi
.BaseAddress
+ mbi
.RegionSize
;
657 while ( Frame
>= StackBase
&& Frame
< StackEnd
)
659 ULONG Addr
= Frame
[1];
660 if (!KeRosPrintAddress((PVOID
)Addr
))
661 DbgPrint("<%X>", Addr
);
662 if ( Addr
== 0 || Addr
== 0xDEADBEEF )
665 Frame
= (PULONG
)Frame
[0];
677 KeRosDumpStackFrames ( PULONG Frame
, ULONG FrameCount
)
680 PULONG StackBase
, StackEnd
;
681 MEMORY_BASIC_INFORMATION mbi
;
682 ULONG ResultLength
= sizeof(mbi
);
685 DbgPrint("Frames: ");
691 __asm__("mov %%ebp, %%ebx" : "=b" (Frame
) : );
692 #elif defined(_MSC_VER)
693 __asm mov
[Frame
], ebp
695 //Frame = (PULONG)Frame[0]; // step out of KeRosDumpStackFrames
698 Status
= MiQueryVirtualMemory (
701 MemoryBasicInformation
,
705 if ( !NT_SUCCESS(Status
) )
707 DPRINT1("Can't dump stack frames: NtQueryVirtualMemory() failed: %x\n", Status
);
712 StackEnd
= mbi
.BaseAddress
+ mbi
.RegionSize
;
714 while ( Frame
>= StackBase
&& Frame
< StackEnd
&& i
++ < FrameCount
)
716 ULONG Addr
= Frame
[1];
717 if (!KeRosPrintAddress((PVOID
)Addr
))
718 DbgPrint("<%X>", Addr
);
719 if ( Addr
== 0 || Addr
== 0xDEADBEEF )
722 Frame
= (PULONG
)Frame
[0];
734 KeRosGetStackFrames ( PULONG Frames
, ULONG FrameCount
)
737 PULONG StackBase
, StackEnd
, Frame
;
738 MEMORY_BASIC_INFORMATION mbi
;
739 ULONG ResultLength
= sizeof(mbi
);
745 __asm__("mov %%ebp, %%ebx" : "=b" (Frame
) : );
746 #elif defined(_MSC_VER)
747 __asm mov
[Frame
], ebp
750 Status
= MiQueryVirtualMemory (
753 MemoryBasicInformation
,
757 if ( !NT_SUCCESS(Status
) )
759 DPRINT1("Can't get stack frames: NtQueryVirtualMemory() failed: %x\n", Status
);
764 StackEnd
= mbi
.BaseAddress
+ mbi
.RegionSize
;
766 while ( Count
< FrameCount
&& Frame
>= StackBase
&& Frame
< StackEnd
)
768 Frames
[Count
++] = Frame
[1];
770 Frame
= (PULONG
)Frame
[0];
781 set_system_call_gate(unsigned int sel
, unsigned int func
)
783 DPRINT("sel %x %d\n",sel
,sel
);
784 KiIdt
[sel
].a
= (((int)func
)&0xffff) +
786 KiIdt
[sel
].b
= 0xef00 + (((int)func
)&0xffff0000);
787 DPRINT("idt[sel].b %x\n",KiIdt
[sel
].b
);
790 static void set_interrupt_gate(unsigned int sel
, unsigned int func
)
792 DPRINT("set_interrupt_gate(sel %d, func %x)\n",sel
,func
);
793 KiIdt
[sel
].a
= (((int)func
)&0xffff) +
795 KiIdt
[sel
].b
= 0x8e00 + (((int)func
)&0xffff0000);
798 static void set_trap_gate(unsigned int sel
, unsigned int func
, unsigned int dpl
)
800 DPRINT("set_trap_gate(sel %d, func %x, dpl %d)\n",sel
, func
, dpl
);
802 KiIdt
[sel
].a
= (((int)func
)&0xffff) +
804 KiIdt
[sel
].b
= 0x8f00 + (dpl
<< 13) + (((int)func
)&0xffff0000);
808 set_task_gate(unsigned int sel
, unsigned task_sel
)
810 KiIdt
[sel
].a
= task_sel
<< 16;
811 KiIdt
[sel
].b
= 0x8500;
815 KeInitExceptions(VOID
)
817 * FUNCTION: Initalize CPU exception handling
822 DPRINT("KeInitExceptions()\n");
825 * Set up the other gates
827 set_trap_gate(0, (ULONG
)KiTrap0
, 0);
828 set_trap_gate(1, (ULONG
)KiTrap1
, 0);
829 set_trap_gate(2, (ULONG
)KiTrap2
, 0);
830 set_trap_gate(3, (ULONG
)KiTrap3
, 3);
831 set_trap_gate(4, (ULONG
)KiTrap4
, 0);
832 set_trap_gate(5, (ULONG
)KiTrap5
, 0);
833 set_trap_gate(6, (ULONG
)KiTrap6
, 0);
834 set_trap_gate(7, (ULONG
)KiTrap7
, 0);
835 set_task_gate(8, TRAP_TSS_SELECTOR
);
836 set_trap_gate(9, (ULONG
)KiTrap9
, 0);
837 set_trap_gate(10, (ULONG
)KiTrap10
, 0);
838 set_trap_gate(11, (ULONG
)KiTrap11
, 0);
839 set_trap_gate(12, (ULONG
)KiTrap12
, 0);
840 set_trap_gate(13, (ULONG
)KiTrap13
, 0);
841 set_interrupt_gate(14, (ULONG
)KiTrap14
);
842 set_trap_gate(15, (ULONG
)KiTrap15
, 0);
843 set_trap_gate(16, (ULONG
)KiTrap16
, 0);
844 set_trap_gate(17, (ULONG
)KiTrap17
, 0);
845 set_trap_gate(18, (ULONG
)KiTrap18
, 0);
846 set_trap_gate(19, (ULONG
)KiTrap19
, 0);
848 for (i
= 20; i
< 256; i
++)
850 set_trap_gate(i
,(int)KiTrapUnknown
, 0);
853 set_system_call_gate(0x2d,(int)interrupt_handler2d
);
854 set_system_call_gate(0x2e,(int)interrupt_handler2e
);
862 KeRaiseUserException(IN NTSTATUS ExceptionCode
)
864 /* FIXME: This needs SEH */
866 PKTHREAD Thread
= KeGetCurrentThread();
868 ProbeForWrite(&Thread
->Teb
->ExceptionCode
, sizeof(NTSTATUS
), sizeof(NTSTATUS
)); /* NT doesn't check this -- bad? */
869 OldEip
= Thread
->TrapFrame
->Eip
;
870 Thread
->TrapFrame
->Eip
= (ULONG_PTR
)LdrpGetSystemDllRaiseExceptionDispatcher();
871 Thread
->Teb
->ExceptionCode
= ExceptionCode
;
872 return((NTSTATUS
)OldEip
);
877 KeRosTrapReturn ( PKTRAP_FRAME TrapFrame
, PKTRAP_FRAME PrevTrapFrame
);
884 IN PEXCEPTION_RECORD ExceptionRecord
,
886 IN BOOLEAN SearchFrames
)
888 PKTRAP_FRAME TrapFrame
= KeGetCurrentThread()->TrapFrame
;
889 PKTRAP_FRAME PrevTrapFrame
= (PKTRAP_FRAME
)TrapFrame
->Edx
;
891 KeGetCurrentKPCR()->Tib
.ExceptionList
= TrapFrame
->ExceptionList
;
893 KiDispatchException(ExceptionRecord
,
895 PsGetCurrentThread()->Tcb
.TrapFrame
,
896 (KPROCESSOR_MODE
)ExGetPreviousMode(),
899 KeRosTrapReturn ( TrapFrame
, PrevTrapFrame
);
900 return(STATUS_SUCCESS
);