77575551c3995b2403b433f6b5ddbb88bcd9b6ce
[reactos.git] / reactos / ntoskrnl / ex / error.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ex/error.c
5 * PURPOSE: Error Functions and Status/Exception Dispatching/Raising
6 *
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net) - Created File
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <internal/debug.h>
15
16 /* GLOBALS ****************************************************************/
17
18 BOOLEAN ExReadyForErrors = FALSE;
19 PEPORT ExpDefaultErrorPort = NULL;
20 PEPROCESS ExpDefaultErrorPortProcess = NULL;
21
22 /* FUNCTIONS ****************************************************************/
23
24 /*
25 * @implemented
26 */
27 VOID
28 STDCALL
29 ExRaiseAccessViolation(VOID)
30 {
31 /* Raise the Right Status */
32 ExRaiseStatus (STATUS_ACCESS_VIOLATION);
33 }
34
35 /*
36 * @implemented
37 */
38 VOID
39 STDCALL
40 ExRaiseDatatypeMisalignment (VOID)
41 {
42 /* Raise the Right Status */
43 ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
44 }
45
46 /*
47 * @implemented
48 */
49 VOID
50 STDCALL
51 ExRaiseStatus(IN NTSTATUS Status)
52 {
53 EXCEPTION_RECORD ExceptionRecord;
54
55 DPRINT("ExRaiseStatus(%x)\n", Status);
56
57 /* Set up an Exception Record */
58 ExceptionRecord.ExceptionRecord = NULL;
59 ExceptionRecord.NumberParameters = 0;
60 ExceptionRecord.ExceptionCode = Status;
61 ExceptionRecord.ExceptionFlags = 0;
62
63 /* Call the Rtl Function */
64 RtlRaiseException(&ExceptionRecord);
65 }
66
67 /*
68 * @implemented
69 */
70 VOID
71 STDCALL
72 ExRaiseException (PEXCEPTION_RECORD ExceptionRecord)
73 {
74 /* Call the Rtl function */
75 RtlRaiseException(ExceptionRecord);
76 }
77
78 /*
79 * @implemented
80 */
81 LONG
82 STDCALL
83 ExSystemExceptionFilter(VOID)
84 {
85 return KeGetPreviousMode() != KernelMode ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
86 }
87
88 /*
89 * @unimplemented
90 */
91 VOID
92 STDCALL
93 ExRaiseHardError(IN NTSTATUS ErrorStatus,
94 IN ULONG NumberOfParameters,
95 IN PUNICODE_STRING UnicodeStringParameterMask OPTIONAL,
96 IN PVOID *Parameters,
97 IN HARDERROR_RESPONSE_OPTION ResponseOption,
98 OUT PHARDERROR_RESPONSE Response)
99 {
100 UNIMPLEMENTED;
101 }
102
103 NTSTATUS
104 STDCALL
105 NtRaiseHardError(IN NTSTATUS ErrorStatus,
106 IN ULONG NumberOfParameters,
107 IN PUNICODE_STRING UnicodeStringParameterMask OPTIONAL,
108 IN PVOID *Parameters,
109 IN HARDERROR_RESPONSE_OPTION ResponseOption,
110 OUT PHARDERROR_RESPONSE Response)
111 {
112 DPRINT1("Hard error %x\n", ErrorStatus);
113
114 /* Call the Executive Function (WE SHOULD PUT SEH HERE/CAPTURE!) */
115 ExRaiseHardError(ErrorStatus,
116 NumberOfParameters,
117 UnicodeStringParameterMask,
118 Parameters,
119 ResponseOption,
120 Response);
121
122 /* Return Success */
123 return STATUS_SUCCESS;
124 }
125
126 NTSTATUS
127 STDCALL
128 NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
129 {
130
131 KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
132 NTSTATUS Status = STATUS_UNSUCCESSFUL;
133
134 /* Check if we have the Privilege */
135 if(!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode)) {
136
137 DPRINT1("NtSetDefaultHardErrorPort: Caller requires the SeTcbPrivilege privilege!\n");
138 return STATUS_PRIVILEGE_NOT_HELD;
139 }
140
141 /* Only called once during bootup, make sure we weren't called yet */
142 if(!ExReadyForErrors) {
143
144 Status = ObReferenceObjectByHandle(PortHandle,
145 0,
146 LpcPortObjectType,
147 PreviousMode,
148 (PVOID*)&ExpDefaultErrorPort,
149 NULL);
150
151 /* Check for Success */
152 if(NT_SUCCESS(Status)) {
153
154 /* Save the data */
155 ExpDefaultErrorPortProcess = PsGetCurrentProcess();
156 ExReadyForErrors = TRUE;
157 }
158 }
159
160 return Status;
161 }
162
163 /* EOF */