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/usertrap.c
22 * PURPOSE: Handling usermode exceptions.
23 * PROGRAMMER: David Welch (welch@cwcom.net)
25 * 18/11/01: Split from ntoskrnl/ke/i386/exp.c
28 /* INCLUDES *****************************************************************/
30 #include <ddk/ntddk.h>
32 #include <internal/ntoskrnl.h>
33 #include <internal/ke.h>
34 #include <internal/i386/segment.h>
35 #include <internal/i386/mm.h>
36 #include <internal/module.h>
37 #include <internal/mm.h>
38 #include <internal/ps.h>
39 #include <internal/trap.h>
40 #include <ntdll/ldr.h>
41 #include <internal/safe.h>
44 #include <internal/debug.h>
46 /* FUNCTIONS ****************************************************************/
49 print_user_address(PVOID address)
51 PLIST_ENTRY current_entry;
53 PEPROCESS CurrentProcess;
55 ULONG_PTR RelativeAddress;
59 CurrentProcess = PsGetCurrentProcess();
60 if (NULL != CurrentProcess)
62 Peb = CurrentProcess->Peb;
67 DbgPrint("<%x>", address);
71 Status = MmSafeCopyFromUser(&Ldr, &Peb->Ldr, sizeof(PPEB_LDR_DATA));
72 if (!NT_SUCCESS(Status))
74 DbgPrint("<%x>", address);
77 current_entry = Ldr->InLoadOrderModuleList.Flink;
79 while (current_entry != &Ldr->InLoadOrderModuleList &&
80 current_entry != NULL)
83 CONTAINING_RECORD(current_entry, LDR_MODULE, InLoadOrderModuleList);
85 if (address >= (PVOID)current->BaseAddress &&
86 address < (PVOID)(current->BaseAddress + current->SizeOfImage))
89 (ULONG_PTR) address - (ULONG_PTR)current->BaseAddress;
90 DbgPrint("<%wZ: %x>", ¤t->BaseDllName, RelativeAddress);
94 current_entry = current_entry->Flink;
100 KiUserTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2)
104 if (ExceptionNr == 0)
106 Er.ExceptionCode = STATUS_INTEGER_DIVIDE_BY_ZERO;
108 else if (ExceptionNr == 1)
110 Er.ExceptionCode = STATUS_SINGLE_STEP;
112 else if (ExceptionNr == 3)
114 Er.ExceptionCode = STATUS_BREAKPOINT;
116 else if (ExceptionNr == 4)
118 Er.ExceptionCode = STATUS_INTEGER_OVERFLOW;
120 else if (ExceptionNr == 5)
122 Er.ExceptionCode = STATUS_ARRAY_BOUNDS_EXCEEDED;
124 else if (ExceptionNr == 6)
126 Er.ExceptionCode = STATUS_ILLEGAL_INSTRUCTION;
130 Er.ExceptionCode = STATUS_ACCESS_VIOLATION;
132 Er.ExceptionFlags = 0;
133 Er.ExceptionRecord = NULL;
134 Er.ExceptionAddress = (PVOID)Tf->Eip;
135 if (ExceptionNr == 14)
137 Er.NumberParameters = 2;
138 Er.ExceptionInformation[0] = Tf->ErrorCode & 0x1;
139 Er.ExceptionInformation[1] = (ULONG)Cr2;
143 Er.NumberParameters = 0;
147 Er.ExceptionFlags = (STATUS_SINGLE_STEP == (NTSTATUS) Er.ExceptionCode || STATUS_BREAKPOINT == (NTSTATUS) Er.ExceptionCode ?
148 0 : EXCEPTION_NONCONTINUABLE);
150 KiDispatchException(&Er, 0, Tf, UserMode, TRUE);