ReactOS  0.4.14-dev-606-g14ebc0b
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
 
#define TAG_ERR   ' rrE'
 

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.

◆ TAG_ERR

#define TAG_ERR   ' rrE'

Definition at line 15 of file harderr.c.

Function Documentation

◆ _purecall()

VOID __cdecl _purecall ( VOID  )

Definition at line 783 of file harderr.c.

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

◆ 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 101 of file harderr.c.

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

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 55 of file harderr.c.

60 {
61  ULONG_PTR BugCheckParameters[MAXIMUM_HARDERROR_PARAMETERS] = {0, 0, 0, 0};
62  ULONG i;
63 
64  /* Sanity check */
65  ASSERT(NumberOfParameters <= MAXIMUM_HARDERROR_PARAMETERS);
66 
67  /*
68  * KeBugCheck expects MAXIMUM_HARDERROR_PARAMETERS parameters,
69  * but we might get called with less, so use a local buffer here.
70  */
71  for (i = 0; i < NumberOfParameters; i++)
72  {
73  /* Copy them over */
74  BugCheckParameters[i] = Parameters[i];
75  }
76 
77  /* FIXME: STUB */
78  KeBugCheckEx(FATAL_UNHANDLED_HARD_ERROR,
79  ErrorStatus,
80  (ULONG_PTR)BugCheckParameters,
81  0,
82  0);
83  return STATUS_SUCCESS;
84 }
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
unsigned int ULONG
Definition: retypes.h:1
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
return STATUS_SUCCESS
Definition: btrfs.c:2938
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:107

Referenced by ExpRaiseHardError().

◆ ExRaiseAccessViolation()

VOID NTAPI ExRaiseAccessViolation ( VOID  )

Definition at line 310 of file harderr.c.

311 {
312  /* Raise the Right Status */
314 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228

Referenced by ProbeForRead(), and ProbeForWrite().

◆ ExRaiseDatatypeMisalignment()

VOID NTAPI ExRaiseDatatypeMisalignment ( VOID  )

Definition at line 332 of file harderr.c.

333 {
334  /* Raise the Right Status */
336 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171

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 386 of file harderr.c.

392 {
394  SIZE_T Size;
396  ULONG i;
397  PVOID UserData = NULL;
398  PHARDERROR_USER_PARAMETERS UserParams;
399  PWSTR BufferBase;
400  ULONG SafeResponse = ResponseNotHandled;
401 
402  PAGED_CODE();
403 
404  /* Check if we have parameters */
405  if (Parameters)
406  {
407  /* Check if we have strings */
408  if (UnicodeStringParameterMask)
409  {
410  /* Calculate the required size */
412 
413  /* Loop each parameter */
414  for (i = 0; i < NumberOfParameters; i++)
415  {
416  /* Check if it's part of the mask */
417  if (UnicodeStringParameterMask & (1 << i))
418  {
419  /* Copy it */
420  RtlMoveMemory(&CapturedParams[i],
421  (PVOID)Parameters[i],
422  sizeof(UNICODE_STRING));
423 
424  /* Increase the size */
425  Size += CapturedParams[i].MaximumLength;
426  }
427  }
428 
429  /* Allocate the user data region */
430  Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
431  &UserData,
432  0,
433  &Size,
434  MEM_COMMIT,
436  if (!NT_SUCCESS(Status))
437  {
438  /* Return failure */
440  return Status;
441  }
442 
443  /* Set the pointers to our data */
444  UserParams = UserData;
445  BufferBase = UserParams->Buffer;
446 
447  /* Enter SEH block as we are writing to user-mode space */
448  _SEH2_TRY
449  {
450  /* Loop parameters again */
451  for (i = 0; i < NumberOfParameters; i++)
452  {
453  /* Check if we are in the mask */
454  if (UnicodeStringParameterMask & (1 << i))
455  {
456  /* Update the base */
457  UserParams->Parameters[i] = (ULONG_PTR)&UserParams->Strings[i];
458 
459  /* Copy the string buffer */
460  RtlMoveMemory(BufferBase,
461  CapturedParams[i].Buffer,
462  CapturedParams[i].MaximumLength);
463 
464  /* Set buffer */
465  CapturedParams[i].Buffer = BufferBase;
466 
467  /* Copy the string structure */
468  UserParams->Strings[i] = CapturedParams[i];
469 
470  /* Update the pointer */
471  BufferBase += CapturedParams[i].MaximumLength;
472  }
473  else
474  {
475  /* No need to copy any strings */
476  UserParams->Parameters[i] = Parameters[i];
477  }
478  }
479  }
481  {
482  /* Return the exception code */
484  DPRINT1("ExRaiseHardError - Exception when writing data to user-mode, Status 0x%08lx\n", Status);
485  }
486  _SEH2_END;
487  }
488  else
489  {
490  /* Just keep the data as is */
492  }
493  }
494 
495  /* Now call the worker function */
496  Status = ExpRaiseHardError(ErrorStatus,
497  NumberOfParameters,
498  UnicodeStringParameterMask,
499  UserData,
500  ValidResponseOptions,
501  &SafeResponse);
502 
503  /* Check if we had done user-mode allocation */
504  if ((UserData) && (UserData != Parameters))
505  {
506  /* We did! Delete it */
507  Size = 0;
508  ZwFreeVirtualMemory(NtCurrentProcess(),
509  &UserData,
510  &Size,
511  MEM_RELEASE);
512  }
513 
514  /* Return status and the response */
515  *Response = SafeResponse;
516  return Status;
517 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
#define MEM_COMMIT
Definition: nt_native.h:1313
UNICODE_STRING Strings[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:124
#define PAGED_CODE()
Definition: video.h:57
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_SEH2_TRY
Definition: create.c:4250
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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct tagUserData UserData
ULONG_PTR Parameters[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:123
Definition: ncftp.h:89
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_SEH2_END
Definition: create.c:4424
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
WCHAR Buffer[ANYSIZE_ARRAY]
Definition: ex.h:125
#define DPRINT1
Definition: precomp.h:8
#define MEM_RELEASE
Definition: nt_native.h:1316
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:101
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by NtRaiseHardError().

◆ ExSystemExceptionFilter()

LONG NTAPI ExSystemExceptionFilter ( VOID  )

Definition at line 351 of file harderr.c.

352 {
353  return KeGetPreviousMode() != KernelMode ?
355 }
#define KeGetPreviousMode()
Definition: ketypes.h:1107
#define EXCEPTION_CONTINUE_SEARCH
Definition: excpt.h:86
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85

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 553 of file harderr.c.

559 {
561  PULONG_PTR SafeParams = NULL;
562  ULONG SafeResponse = ResponseNotHandled;
563  UNICODE_STRING SafeString;
564  ULONG i;
565  ULONG ParamSize = 0;
567 
568  PAGED_CODE();
569 
570  /* Validate parameter count */
571  if (NumberOfParameters > MAXIMUM_HARDERROR_PARAMETERS)
572  {
573  /* Fail */
575  }
576 
577  /* Make sure we have some at least */
578  if ((Parameters != NULL) && (NumberOfParameters == 0))
579  {
580  /* Fail */
582  }
583 
584  /* Check if we were called from user-mode */
585  if (PreviousMode != KernelMode)
586  {
587  /* First validate the responses */
588  switch (ValidResponseOptions)
589  {
590  /* Check all valid cases */
592  case OptionOk:
593  case OptionOkCancel:
594  case OptionRetryCancel:
595  case OptionYesNo:
596  case OptionYesNoCancel:
598  case OptionOkNoWait:
600  break;
601 
602  /* Anything else is invalid */
603  default:
605  }
606 
607  /* Check if we have parameters */
608  if (Parameters)
609  {
610  /* Calculate size of the parameters */
611  ParamSize = sizeof(ULONG_PTR) * NumberOfParameters;
612 
613  /* Allocate a safe buffer */
614  SafeParams = ExAllocatePoolWithTag(PagedPool, ParamSize, TAG_ERR);
615  if (!SafeParams)
616  {
618  }
619  }
620 
621  /* Enter SEH Block */
622  _SEH2_TRY
623  {
624  /* Validate the response pointer */
626 
627  /* Check if we have parameters */
628  if (Parameters)
629  {
630  /* Validate the parameter pointers */
631  ProbeForRead(Parameters, ParamSize, sizeof(ULONG_PTR));
632 
633  /* Copy them */
634  RtlCopyMemory(SafeParams, Parameters, ParamSize);
635 
636  /* Now check if there's strings in it */
637  if (UnicodeStringParameterMask)
638  {
639  /* Loop every string */
640  for (i = 0; i < NumberOfParameters; i++)
641  {
642  /* Check if this parameter is a string */
643  if (UnicodeStringParameterMask & (1 << i))
644  {
645  /* Probe the structure */
646  ProbeForRead((PVOID)SafeParams[i],
647  sizeof(UNICODE_STRING),
648  sizeof(ULONG_PTR));
649 
650  /* Capture it */
651  RtlCopyMemory(&SafeString,
652  (PVOID)SafeParams[i],
653  sizeof(UNICODE_STRING));
654 
655  /* Probe the buffer */
656  ProbeForRead(SafeString.Buffer,
657  SafeString.MaximumLength,
658  sizeof(UCHAR));
659  }
660  }
661  }
662  }
663  }
665  {
666  /* Free captured buffer */
667  if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
668 
669  /* Return the exception code */
671  }
672  _SEH2_END;
673 
674  /* Call the system function directly, because we probed */
675  Status = ExpRaiseHardError(ErrorStatus,
676  NumberOfParameters,
677  UnicodeStringParameterMask,
678  SafeParams,
679  ValidResponseOptions,
680  &SafeResponse);
681 
682  /* Free captured buffer */
683  if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
684 
685  /* Enter SEH Block to return the response */
686  _SEH2_TRY
687  {
688  /* Return the response */
689  *Response = SafeResponse;
690  }
692  {
693  /* Get the exception code */
695  }
696  _SEH2_END;
697  }
698  else
699  {
700  /* Reuse variable */
701  SafeParams = Parameters;
702 
703  /*
704  * Call the Executive Function. It will probe
705  * and copy pointers to user-mode.
706  */
707  Status = ExRaiseHardError(ErrorStatus,
708  NumberOfParameters,
709  UnicodeStringParameterMask,
710  SafeParams,
711  ValidResponseOptions,
712  &SafeResponse);
713 
714  /* Return the response */
715  *Response = SafeResponse;
716  }
717 
718  /* Return status */
719  return Status;
720 }
#define ProbeForWriteUlong(Ptr)
Definition: probe.h:36
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
USHORT MaximumLength
Definition: env_spec_w32.h:370
LONG NTSTATUS
Definition: precomp.h:26
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:386
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
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 EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:462
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
Definition: ncftp.h:89
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID NTAPI ProbeForRead(IN CONST VOID *Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:102
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
Status
Definition: gdiplustypes.h:24
_SEH2_END
Definition: create.c:4424
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:101
#define TAG_ERR
Definition: harderr.c:15
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:63
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:464
return STATUS_SUCCESS
Definition: btrfs.c:2938

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 742 of file harderr.c.

743 {
746 
747  PAGED_CODE();
748 
749  /* Check if we have the privileges */
751  {
752  DPRINT1("NtSetDefaultHardErrorPort: Caller requires "
753  "the SeTcbPrivilege privilege!\n");
755  }
756 
757  /* Only called once during bootup, make sure we weren't called yet */
758  if (!ExReadyForErrors)
759  {
760  /* Reference the hard-error port */
761  Status = ObReferenceObjectByHandle(PortHandle,
762  0,
764  PreviousMode,
766  NULL);
767  if (NT_SUCCESS(Status))
768  {
769  /* Keep also a reference to the process handling the hard errors */
774  }
775  }
776 
777  /* Return status to caller */
778  return Status;
779 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
PEPROCESS ExpDefaultErrorPortProcess
Definition: harderr.c:21
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI SeSinglePrivilegeCheck(IN LUID PrivilegeValue, IN KPROCESSOR_MODE PreviousMode)
Definition: priv.c:524
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3066
#define PAGED_CODE()
Definition: video.h:57
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:496
BOOLEAN ExReadyForErrors
Definition: harderr.c:19
#define PsGetCurrentProcess
Definition: psfuncs.h:17
smooth NULL
Definition: ftsmooth.c:416
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
Status
Definition: gdiplustypes.h:24
const LUID SeTcbPrivilege
Definition: priv.c:28
#define DPRINT1
Definition: precomp.h:8
#define ObReferenceObject
Definition: obfuncs.h:204
PVOID ExpDefaultErrorPort
Definition: harderr.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2938

Referenced by CsrServerInitialization().

Variable Documentation

◆ ExpDefaultErrorPort

PVOID ExpDefaultErrorPort = NULL

Definition at line 20 of file harderr.c.

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

◆ ExpDefaultErrorPortProcess

PEPROCESS ExpDefaultErrorPortProcess = NULL

Definition at line 21 of file harderr.c.

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

◆ ExReadyForErrors

BOOLEAN ExReadyForErrors = FALSE

Definition at line 19 of file harderr.c.

Referenced by ExpRaiseHardError(), and NtSetDefaultHardErrorPort().