ReactOS 0.4.15-dev-7788-g1ad9096
harderr.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for harderr.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI ExpSystemErrorHandler (IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN BOOLEAN Shutdown)
 
NTSTATUS NTAPI ExpRaiseHardError (IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
 
VOID NTAPI ExRaiseAccessViolation (VOID)
 
VOID NTAPI ExRaiseDatatypeMisalignment (VOID)
 
LONG NTAPI ExSystemExceptionFilter (VOID)
 
NTSTATUS NTAPI ExRaiseHardError (IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
 
NTSTATUS NTAPI NtRaiseHardError (IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
 
NTSTATUS NTAPI NtSetDefaultHardErrorPort (IN HANDLE PortHandle)
 
VOID __cdecl _purecall (VOID)
 

Variables

BOOLEAN ExReadyForErrors = FALSE
 
PVOID ExpDefaultErrorPort = NULL
 
PEPROCESS ExpDefaultErrorPortProcess = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file harderr.c.

Function Documentation

◆ _purecall()

VOID __cdecl _purecall ( VOID  )

Definition at line 781 of file harderr.c.

782{
783 /* Not supported in Kernel Mode */
785}
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239

◆ ExpRaiseHardError()

NTSTATUS NTAPI ExpRaiseHardError ( IN NTSTATUS  ErrorStatus,
IN ULONG  NumberOfParameters,
IN ULONG  UnicodeStringParameterMask,
IN PULONG_PTR  Parameters,
IN ULONG  ValidResponseOptions,
OUT PULONG  Response 
)

Definition at line 99 of file harderr.c.

105{
111 HANDLE PortHandle;
113
114 PAGED_CODE();
115
116 /* Check if this error will shutdown the system */
117 if (ValidResponseOptions == OptionShutdownSystem)
118 {
119 /*
120 * Check if we have the privileges.
121 *
122 * NOTE: In addition to the Shutdown privilege we also check whether
123 * the caller has the Tcb privilege. The purpose is to allow only
124 * SYSTEM processes to "shutdown" the system on hard errors (BSOD)
125 * while forbidding regular processes to do so. This behaviour differs
126 * from Windows, where any user-mode process, as soon as it has the
127 * Shutdown privilege, can trigger a hard-error BSOD.
128 */
131 {
132 /* No rights */
135 }
136
137 /* Don't handle any new hard errors */
139 }
140
141 /* Check if hard errors are not disabled */
143 {
144 /* Check if we can't do errors anymore, and this is serious */
145 if (!ExReadyForErrors && NT_ERROR(ErrorStatus))
146 {
147 /* Use the system handler */
148 ExpSystemErrorHandler(ErrorStatus,
149 NumberOfParameters,
150 UnicodeStringParameterMask,
153 }
154 }
155
156 /*
157 * Enable hard error processing if it is enabled for the process
158 * or if the exception status forces it.
159 */
160 if ((Process->DefaultHardErrorProcessing & SEM_FAILCRITICALERRORS) ||
161 (ErrorStatus & HARDERROR_OVERRIDE_ERRORMODE))
162 {
163 /* Check if we have an exception port */
164 if (Process->ExceptionPort)
165 {
166 /* Use the port */
167 PortHandle = Process->ExceptionPort;
168 }
169 else
170 {
171 /* Use our default system port */
172 PortHandle = ExpDefaultErrorPort;
173 }
174 }
175 else
176 {
177 /* Don't process the error */
178 PortHandle = NULL;
179 }
180
181 /* If hard errors are disabled, do nothing */
182 if (Thread->HardErrorsAreDisabled) PortHandle = NULL;
183
184 /*
185 * If this is not the system thread, check whether hard errors are
186 * disabled for this thread on user-mode side, and if so, do nothing.
187 */
188 if (!Thread->SystemThread && (PortHandle != NULL))
189 {
190 /* Check if we have a TEB */
191 PTEB Teb = PsGetCurrentThread()->Tcb.Teb;
192 if (Teb)
193 {
195 {
196 if (Teb->HardErrorMode & RTL_SEM_FAILCRITICALERRORS)
197 {
198 PortHandle = NULL;
199 }
200 }
202 {
203 NOTHING;
204 }
205 _SEH2_END;
206 }
207 }
208
209 /* Now check if we have a port */
210 if (PortHandle == NULL)
211 {
212 /* Just return to caller */
214 return STATUS_SUCCESS;
215 }
216
217 /* Check if this is the default process */
219 {
220 /* We can't handle the error, check if this is critical */
221 if (NT_ERROR(ErrorStatus))
222 {
223 /* It is, invoke the system handler */
224 ExpSystemErrorHandler(ErrorStatus,
225 NumberOfParameters,
226 UnicodeStringParameterMask,
229
230 /* If we survived, return to caller */
232 return STATUS_SUCCESS;
233 }
234 }
235
236 /* Setup the LPC Message */
237 Message->h.u1.Length = (sizeof(HARDERROR_MSG) << 16) |
238 (sizeof(HARDERROR_MSG) - sizeof(PORT_MESSAGE));
239 Message->h.u2.ZeroInit = 0;
240 Message->h.u2.s2.Type = LPC_ERROR_EVENT;
241 Message->Status = ErrorStatus & ~HARDERROR_OVERRIDE_ERRORMODE;
242 Message->ValidResponseOptions = ValidResponseOptions;
243 Message->UnicodeStringParameterMask = UnicodeStringParameterMask;
244 Message->NumberOfParameters = NumberOfParameters;
245 KeQuerySystemTime(&Message->ErrorTime);
246
247 /* Copy the parameters */
248 if (Parameters)
249 {
250 RtlMoveMemory(&Message->Parameters,
252 sizeof(ULONG_PTR) * NumberOfParameters);
253 }
254
255 /* Send the LPC Message */
256 Status = LpcRequestWaitReplyPort(PortHandle,
259 if (NT_SUCCESS(Status))
260 {
261 /* Check what kind of response we got */
262 if ((Message->Response != ResponseReturnToCaller) &&
263 (Message->Response != ResponseNotHandled) &&
264 (Message->Response != ResponseAbort) &&
265 (Message->Response != ResponseCancel) &&
266 (Message->Response != ResponseIgnore) &&
267 (Message->Response != ResponseNo) &&
268 (Message->Response != ResponseOk) &&
269 (Message->Response != ResponseRetry) &&
270 (Message->Response != ResponseYes) &&
271 (Message->Response != ResponseTryAgain) &&
272 (Message->Response != ResponseContinue))
273 {
274 /* Reset to a default one */
276 }
277
278 /* Set the response */
279 *Response = Message->Response;
280 }
281 else
282 {
283 /* Set the response */
285 }
286
287 /* Return status */
288 return Status;
289}
#define PAGED_CODE()
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR Message[]
Definition: register.c:74
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
Status
Definition: gdiplustypes.h:25
PVOID ExpDefaultErrorPort
Definition: harderr.c:18
PEPROCESS ExpDefaultErrorPortProcess
Definition: harderr.c:19
NTSTATUS NTAPI ExpSystemErrorHandler(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN BOOLEAN Shutdown)
Definition: harderr.c:53
BOOLEAN ExReadyForErrors
Definition: harderr.c:17
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define NOTHING
Definition: input_list.c:10
#define LPC_ERROR_EVENT
Definition: port.c:101
#define KernelMode
Definition: asm.h:34
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define HARDERROR_OVERRIDE_ERRORMODE
Definition: extypes.h:146
struct _HARDERROR_MSG HARDERROR_MSG
@ OptionShutdownSystem
Definition: extypes.h:192
struct _HARDERROR_MSG * PHARDERROR_MSG
@ ResponseNo
Definition: extypes.h:204
@ ResponseNotHandled
Definition: extypes.h:200
@ ResponseTryAgain
Definition: extypes.h:208
@ ResponseOk
Definition: extypes.h:205
@ ResponseRetry
Definition: extypes.h:206
@ ResponseReturnToCaller
Definition: extypes.h:199
@ ResponseIgnore
Definition: extypes.h:203
@ ResponseCancel
Definition: extypes.h:202
@ ResponseYes
Definition: extypes.h:207
@ ResponseAbort
Definition: extypes.h:201
@ ResponseContinue
Definition: extypes.h:209
#define RTL_SEM_FAILCRITICALERRORS
Definition: rtltypes.h:74
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
const LUID SeTcbPrivilege
Definition: priv.c:26
const LUID SeShutdownPrivilege
Definition: priv.c:38
NTSTATUS NTAPI LpcRequestWaitReplyPort(IN PVOID PortObject, IN PPORT_MESSAGE LpcRequest, OUT PPORT_MESSAGE LpcReply)
Definition: send.c:178
BOOLEAN NTAPI SeSinglePrivilegeCheck(_In_ LUID PrivilegeValue, _In_ KPROCESSOR_MODE PreviousMode)
Checks if a single privilege is present in the context of the calling thread.
Definition: priv.c:744
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: ncftp.h:89
ULONG SystemThread
Definition: pstypes.h:1182
ULONG HardErrorsAreDisabled
Definition: pstypes.h:1183
Definition: compat.h:836
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define NT_ERROR(Status)
Definition: umtypes.h:106
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
#define PORT_MAXIMUM_MESSAGE_LENGTH
Definition: iotypes.h:2029
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define PsGetCurrentProcess
Definition: psfuncs.h:17
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by ExRaiseHardError(), and NtRaiseHardError().

◆ ExpSystemErrorHandler()

NTSTATUS NTAPI ExpSystemErrorHandler ( IN NTSTATUS  ErrorStatus,
IN ULONG  NumberOfParameters,
IN ULONG  UnicodeStringParameterMask,
IN PULONG_PTR  Parameters,
IN BOOLEAN  Shutdown 
)

Definition at line 53 of file harderr.c.

58{
59 ULONG_PTR BugCheckParameters[MAXIMUM_HARDERROR_PARAMETERS] = {0, 0, 0, 0};
60 ULONG i;
61
62 /* Sanity check */
63 ASSERT(NumberOfParameters <= MAXIMUM_HARDERROR_PARAMETERS);
64
65 /*
66 * KeBugCheck expects MAXIMUM_HARDERROR_PARAMETERS parameters,
67 * but we might get called with less, so use a local buffer here.
68 */
69 for (i = 0; i < NumberOfParameters; i++)
70 {
71 /* Copy them over */
72 BugCheckParameters[i] = Parameters[i];
73 }
74
75 /* FIXME: STUB */
76 KeBugCheckEx(FATAL_UNHANDLED_HARD_ERROR,
77 ErrorStatus,
78 (ULONG_PTR)BugCheckParameters,
79 0,
80 0);
81 return STATUS_SUCCESS;
82}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ASSERT(a)
Definition: mode.c:44
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ExpRaiseHardError().

◆ ExRaiseAccessViolation()

VOID NTAPI ExRaiseAccessViolation ( VOID  )

Definition at line 308 of file harderr.c.

309{
310 /* Raise the Right Status */
312}
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242

Referenced by ProbeForRead(), and ProbeForWrite().

◆ ExRaiseDatatypeMisalignment()

VOID NTAPI ExRaiseDatatypeMisalignment ( VOID  )

Definition at line 330 of file harderr.c.

331{
332 /* Raise the Right Status */
334}
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183

Referenced by ProbeForRead(), and ProbeForWrite().

◆ ExRaiseHardError()

NTSTATUS NTAPI ExRaiseHardError ( IN NTSTATUS  ErrorStatus,
IN ULONG  NumberOfParameters,
IN ULONG  UnicodeStringParameterMask,
IN PULONG_PTR  Parameters,
IN ULONG  ValidResponseOptions,
OUT PULONG  Response 
)

Definition at line 384 of file harderr.c.

390{
392 SIZE_T Size;
394 ULONG i;
397 PWSTR BufferBase;
398 ULONG SafeResponse = ResponseNotHandled;
399
400 PAGED_CODE();
401
402 /* Check if we have parameters */
403 if (Parameters)
404 {
405 /* Check if we have strings */
406 if (UnicodeStringParameterMask)
407 {
408 /* Calculate the required size */
410
411 /* Loop each parameter */
412 for (i = 0; i < NumberOfParameters; i++)
413 {
414 /* Check if it's part of the mask */
415 if (UnicodeStringParameterMask & (1 << i))
416 {
417 /* Copy it */
418 RtlMoveMemory(&CapturedParams[i],
420 sizeof(UNICODE_STRING));
421
422 /* Increase the size */
423 Size += CapturedParams[i].MaximumLength;
424 }
425 }
426
427 /* Allocate the user data region */
428 Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
429 &UserData,
430 0,
431 &Size,
434 if (!NT_SUCCESS(Status))
435 {
436 /* Return failure */
438 return Status;
439 }
440
441 /* Set the pointers to our data */
442 UserParams = UserData;
443 BufferBase = UserParams->Buffer;
444
445 /* Enter SEH block as we are writing to user-mode space */
447 {
448 /* Loop parameters again */
449 for (i = 0; i < NumberOfParameters; i++)
450 {
451 /* Check if we are in the mask */
452 if (UnicodeStringParameterMask & (1 << i))
453 {
454 /* Update the base */
455 UserParams->Parameters[i] = (ULONG_PTR)&UserParams->Strings[i];
456
457 /* Copy the string buffer */
458 RtlMoveMemory(BufferBase,
459 CapturedParams[i].Buffer,
460 CapturedParams[i].MaximumLength);
461
462 /* Set buffer */
463 CapturedParams[i].Buffer = BufferBase;
464
465 /* Copy the string structure */
466 UserParams->Strings[i] = CapturedParams[i];
467
468 /* Update the pointer */
469 BufferBase += CapturedParams[i].MaximumLength;
470 }
471 else
472 {
473 /* No need to copy any strings */
474 UserParams->Parameters[i] = Parameters[i];
475 }
476 }
477 }
479 {
480 /* Return the exception code */
482 DPRINT1("ExRaiseHardError - Exception when writing data to user-mode, Status 0x%08lx\n", Status);
483 }
484 _SEH2_END;
485 }
486 else
487 {
488 /* Just keep the data as is */
490 }
491 }
492
493 /* Now call the worker function */
494 Status = ExpRaiseHardError(ErrorStatus,
495 NumberOfParameters,
496 UnicodeStringParameterMask,
497 UserData,
498 ValidResponseOptions,
499 &SafeResponse);
500
501 /* Check if we had done user-mode allocation */
502 if ((UserData) && (UserData != Parameters))
503 {
504 /* We did! Delete it */
505 Size = 0;
506 ZwFreeVirtualMemory(NtCurrentProcess(),
507 &UserData,
508 &Size,
510 }
511
512 /* Return status and the response */
513 *Response = SafeResponse;
514 return Status;
515}
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI ExpRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:99
struct tagUserData UserData
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define MEM_RELEASE
Definition: nt_native.h:1316
#define MEM_COMMIT
Definition: nt_native.h:1313
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
UNICODE_STRING Strings[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:129
ULONG_PTR Parameters[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:128
WCHAR Buffer[ANYSIZE_ARRAY]
Definition: ex.h:130
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength

Referenced by NtRaiseHardError().

◆ ExSystemExceptionFilter()

LONG NTAPI ExSystemExceptionFilter ( VOID  )

Definition at line 349 of file harderr.c.

350{
351 return KeGetPreviousMode() != KernelMode ?
353}
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86

Referenced by _IRQL_requires_max_(), NtAddAtom(), NtAllocateUuids(), NtCancelTimer(), NtCompareTokens(), NtCreateDebugObject(), NtCreateDirectoryObject(), NtCreateEvent(), NtCreateEventPair(), NtCreateIoCompletion(), NtCreateMutant(), NtCreateProfile(), NtCreateSemaphore(), NtCreateSymbolicLinkObject(), NtCreateTimer(), NtFindAtom(), NtOpenDirectoryObject(), NtOpenEvent(), NtOpenEventPair(), NtOpenIoCompletion(), NtOpenMutant(), NtOpenSemaphore(), NtOpenSymbolicLinkObject(), NtOpenTimer(), NtPulseEvent(), NtQueryDefaultLocale(), NtQueryDefaultUILanguage(), NtQueryDirectoryObject(), NtQueryEvent(), NtQueryInformationAtom(), NtQueryInstallUILanguage(), NtQueryIntervalProfile(), NtQueryIoCompletion(), NtQueryMutant(), NtQueryObject(), NtQueryPerformanceCounter(), NtQuerySecurityObject(), NtQuerySemaphore(), NtQuerySymbolicLinkObject(), NtQuerySystemEnvironmentValue(), NtQuerySystemInformation(), NtQueryTimer(), NtReleaseMutant(), NtReleaseSemaphore(), NtRemoveIoCompletion(), NtResetEvent(), NtSetEvent(), NtSetInformationDebugObject(), NtSetSystemTime(), NtSetThreadExecutionState(), NtSetTimer(), NtStartProfile(), NtWaitForDebugEvent(), ObpCaptureObjectCreateInformation(), ObpCaptureObjectName(), ObQueryTypeInfo(), and ProbeAndCaptureObjectAttributes().

◆ NtRaiseHardError()

NTSTATUS NTAPI NtRaiseHardError ( IN NTSTATUS  ErrorStatus,
IN ULONG  NumberOfParameters,
IN ULONG  UnicodeStringParameterMask,
IN PULONG_PTR  Parameters,
IN ULONG  ValidResponseOptions,
OUT PULONG  Response 
)

Definition at line 551 of file harderr.c.

557{
559 PULONG_PTR SafeParams = NULL;
560 ULONG SafeResponse = ResponseNotHandled;
561 UNICODE_STRING SafeString;
562 ULONG i;
563 ULONG ParamSize = 0;
565
566 PAGED_CODE();
567
568 /* Validate parameter count */
569 if (NumberOfParameters > MAXIMUM_HARDERROR_PARAMETERS)
570 {
571 /* Fail */
573 }
574
575 /* Make sure we have some at least */
576 if ((Parameters != NULL) && (NumberOfParameters == 0))
577 {
578 /* Fail */
580 }
581
582 /* Check if we were called from user-mode */
584 {
585 /* First validate the responses */
586 switch (ValidResponseOptions)
587 {
588 /* Check all valid cases */
590 case OptionOk:
591 case OptionOkCancel:
593 case OptionYesNo:
596 case OptionOkNoWait:
598 break;
599
600 /* Anything else is invalid */
601 default:
603 }
604
605 /* Check if we have parameters */
606 if (Parameters)
607 {
608 /* Calculate size of the parameters */
609 ParamSize = sizeof(ULONG_PTR) * NumberOfParameters;
610
611 /* Allocate a safe buffer */
612 SafeParams = ExAllocatePoolWithTag(PagedPool, ParamSize, TAG_ERR);
613 if (!SafeParams)
614 {
616 }
617 }
618
619 /* Enter SEH Block */
621 {
622 /* Validate the response pointer */
624
625 /* Check if we have parameters */
626 if (Parameters)
627 {
628 /* Validate the parameter pointers */
629 ProbeForRead(Parameters, ParamSize, sizeof(ULONG_PTR));
630
631 /* Copy them */
632 RtlCopyMemory(SafeParams, Parameters, ParamSize);
633
634 /* Now check if there's strings in it */
635 if (UnicodeStringParameterMask)
636 {
637 /* Loop every string */
638 for (i = 0; i < NumberOfParameters; i++)
639 {
640 /* Check if this parameter is a string */
641 if (UnicodeStringParameterMask & (1 << i))
642 {
643 /* Probe the structure */
644 ProbeForRead((PVOID)SafeParams[i],
645 sizeof(UNICODE_STRING),
646 sizeof(ULONG_PTR));
647
648 /* Capture it */
649 RtlCopyMemory(&SafeString,
650 (PVOID)SafeParams[i],
651 sizeof(UNICODE_STRING));
652
653 /* Probe the buffer */
654 ProbeForRead(SafeString.Buffer,
655 SafeString.MaximumLength,
656 sizeof(UCHAR));
657 }
658 }
659 }
660 }
661 }
663 {
664 /* Free captured buffer */
665 if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
666
667 /* Return the exception code */
669 }
670 _SEH2_END;
671
672 /* Call the system function directly, because we probed */
673 Status = ExpRaiseHardError(ErrorStatus,
674 NumberOfParameters,
675 UnicodeStringParameterMask,
676 SafeParams,
677 ValidResponseOptions,
678 &SafeResponse);
679
680 /* Free captured buffer */
681 if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
682
683 /* Enter SEH Block to return the response */
685 {
686 /* Return the response */
687 *Response = SafeResponse;
688 }
690 {
691 /* Get the exception code */
693 }
694 _SEH2_END;
695 }
696 else
697 {
698 /* Reuse variable */
699 SafeParams = Parameters;
700
701 /*
702 * Call the Executive Function. It will probe
703 * and copy pointers to user-mode.
704 */
705 Status = ExRaiseHardError(ErrorStatus,
706 NumberOfParameters,
707 UnicodeStringParameterMask,
708 SafeParams,
709 ValidResponseOptions,
710 &SafeResponse);
711
712 /* Return the response */
713 *Response = SafeResponse;
714 }
715
716 /* Return status */
717 return Status;
718}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define ExGetPreviousMode
Definition: ex.h:140
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
NTSTATUS NTAPI ExRaiseHardError(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN ULONG ValidResponseOptions, OUT PULONG Response)
Definition: harderr.c:384
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
@ OptionYesNoCancel
Definition: extypes.h:191
@ OptionYesNo
Definition: extypes.h:190
@ OptionAbortRetryIgnore
Definition: extypes.h:186
@ OptionCancelTryContinue
Definition: extypes.h:194
@ OptionOkCancel
Definition: extypes.h:188
@ OptionRetryCancel
Definition: extypes.h:189
@ OptionOk
Definition: extypes.h:187
@ OptionOkNoWait
Definition: extypes.h:193
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:162
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
#define TAG_ERR
Definition: tag.h:31
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by _Function_class_(), _main(), CreateProcessInternalW(), CsrLoadServerDll(), CsrUnhandledExceptionFilter(), FatalAppExitW(), LdrpMapDll(), LdrpSnapThunk(), MessageBoxTimeoutIndirectW(), NtProcessStartup(), PsLocateSystemDll(), SmpTerminate(), UnhandledExceptionFilter(), and WinMain().

◆ NtSetDefaultHardErrorPort()

NTSTATUS NTAPI NtSetDefaultHardErrorPort ( IN HANDLE  PortHandle)

Definition at line 740 of file harderr.c.

741{
744
745 PAGED_CODE();
746
747 /* Check if we have the privileges */
749 {
750 DPRINT1("NtSetDefaultHardErrorPort: Caller requires "
751 "the SeTcbPrivilege privilege!\n");
753 }
754
755 /* Only called once during bootup, make sure we weren't called yet */
756 if (!ExReadyForErrors)
757 {
758 /* Reference the hard-error port */
760 0,
764 NULL);
765 if (NT_SUCCESS(Status))
766 {
767 /* Keep also a reference to the process handling the hard errors */
772 }
773 }
774
775 /* Return status to caller */
776 return Status;
777}
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by CsrServerInitialization().

Variable Documentation

◆ ExpDefaultErrorPort

PVOID ExpDefaultErrorPort = NULL

Definition at line 18 of file harderr.c.

Referenced by ExpRaiseHardError(), ExShutdownSystem(), and NtSetDefaultHardErrorPort().

◆ ExpDefaultErrorPortProcess

PEPROCESS ExpDefaultErrorPortProcess = NULL

Definition at line 19 of file harderr.c.

Referenced by ExpRaiseHardError(), ExShutdownSystem(), and NtSetDefaultHardErrorPort().

◆ ExReadyForErrors

BOOLEAN ExReadyForErrors = FALSE

Definition at line 17 of file harderr.c.

Referenced by ExpRaiseHardError(), and NtSetDefaultHardErrorPort().