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
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net) - Created File
10 /* INCLUDES *****************************************************************/
14 #include <internal/debug.h>
16 /* GLOBALS ****************************************************************/
18 BOOLEAN ExReadyForErrors
= FALSE
;
19 PEPORT ExpDefaultErrorPort
= NULL
;
20 PEPROCESS ExpDefaultErrorPortProcess
= NULL
;
22 /* FUNCTIONS ****************************************************************/
29 ExRaiseAccessViolation(VOID
)
31 /* Raise the Right Status */
32 ExRaiseStatus (STATUS_ACCESS_VIOLATION
);
40 ExRaiseDatatypeMisalignment (VOID
)
42 /* Raise the Right Status */
43 ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT
);
51 ExRaiseStatus(IN NTSTATUS Status
)
53 EXCEPTION_RECORD ExceptionRecord
;
55 DPRINT("ExRaiseStatus(%x)\n", Status
);
57 /* Set up an Exception Record */
58 ExceptionRecord
.ExceptionRecord
= NULL
;
59 ExceptionRecord
.NumberParameters
= 0;
60 ExceptionRecord
.ExceptionCode
= Status
;
61 ExceptionRecord
.ExceptionFlags
= 0;
63 /* Call the Rtl Function */
64 RtlRaiseException(&ExceptionRecord
);
72 ExRaiseException (PEXCEPTION_RECORD ExceptionRecord
)
74 /* Call the Rtl function */
75 RtlRaiseException(ExceptionRecord
);
83 ExSystemExceptionFilter(VOID
)
85 return KeGetPreviousMode() != KernelMode
? EXCEPTION_EXECUTE_HANDLER
: EXCEPTION_CONTINUE_SEARCH
;
93 ExRaiseHardError(IN NTSTATUS ErrorStatus
,
94 IN ULONG NumberOfParameters
,
95 IN PUNICODE_STRING UnicodeStringParameterMask OPTIONAL
,
97 IN HARDERROR_RESPONSE_OPTION ResponseOption
,
98 OUT PHARDERROR_RESPONSE Response
)
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
)
112 DPRINT1("Hard error %x\n", ErrorStatus
);
114 /* Call the Executive Function (WE SHOULD PUT SEH HERE/CAPTURE!) */
115 ExRaiseHardError(ErrorStatus
,
117 UnicodeStringParameterMask
,
123 return STATUS_SUCCESS
;
128 NtSetDefaultHardErrorPort(IN HANDLE PortHandle
)
131 KPROCESSOR_MODE PreviousMode
= ExGetPreviousMode();
132 NTSTATUS Status
= STATUS_UNSUCCESSFUL
;
134 /* Check if we have the Privilege */
135 if(!SeSinglePrivilegeCheck(SeTcbPrivilege
, PreviousMode
)) {
137 DPRINT1("NtSetDefaultHardErrorPort: Caller requires the SeTcbPrivilege privilege!\n");
138 return STATUS_PRIVILEGE_NOT_HELD
;
141 /* Only called once during bootup, make sure we weren't called yet */
142 if(!ExReadyForErrors
) {
144 Status
= ObReferenceObjectByHandle(PortHandle
,
148 (PVOID
*)&ExpDefaultErrorPort
,
151 /* Check for Success */
152 if(NT_SUCCESS(Status
)) {
155 ExpDefaultErrorPortProcess
= PsGetCurrentProcess();
156 ExReadyForErrors
= TRUE
;