ReactOS  0.4.15-dev-4603-gb922b6d
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)
return STATUS_NOT_IMPLEMENTED

◆ 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,
151  Parameters,
152  (PreviousMode != KernelMode) ? TRUE : FALSE);
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  {
194  _SEH2_TRY
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,
227  Parameters,
228  (PreviousMode != KernelMode) ? TRUE : FALSE);
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,
251  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 */
275  Message->Response = ResponseReturnToCaller;
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 KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
#define SEM_FAILCRITICALERRORS
Definition: rtltypes.h:69
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define TRUE
Definition: types.h:120
PEPROCESS ExpDefaultErrorPortProcess
Definition: harderr.c:19
#define KeGetPreviousMode()
Definition: ketypes.h:1108
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI LpcRequestWaitReplyPort(IN PVOID PortObject, IN PPORT_MESSAGE LpcRequest, OUT PPORT_MESSAGE LpcReply)
Definition: send.c:178
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define HARDERROR_OVERRIDE_ERRORMODE
Definition: extypes.h:146
#define FALSE
Definition: types.h:117
BOOLEAN ExReadyForErrors
Definition: harderr.c:17
#define PsGetCurrentProcess
Definition: psfuncs.h:17
Definition: bufpool.h:45
struct _HARDERROR_MSG HARDERROR_MSG
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2652
#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
#define NOTHING
Definition: env_spec_w32.h:461
ULONG SystemThread
Definition: pstypes.h:1182
const LUID SeTcbPrivilege
Definition: priv.c:26
Definition: compat.h:694
const LUID SeShutdownPrivilege
Definition: priv.c:38
_SEH2_END
Definition: create.c:4400
struct _HARDERROR_MSG * PHARDERROR_MSG
#define PORT_MAXIMUM_MESSAGE_LENGTH
Definition: iotypes.h:2029
#define NULL
Definition: types.h:112
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
NTSTATUS NTAPI ExpSystemErrorHandler(IN NTSTATUS ErrorStatus, IN ULONG NumberOfParameters, IN ULONG UnicodeStringParameterMask, IN PULONG_PTR Parameters, IN BOOLEAN Shutdown)
Definition: harderr.c:53
_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:18
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG HardErrorsAreDisabled
Definition: pstypes.h:1183
#define PAGED_CODE()

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 }
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ASSERT(a)
Definition: mode.c:44
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
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#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

Referenced by ExpRaiseHardError().

◆ ExRaiseAccessViolation()

VOID NTAPI ExRaiseAccessViolation ( VOID  )

Definition at line 308 of file harderr.c.

309 {
310  /* Raise the Right Status */
312 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#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 }
DECLSPEC_NORETURN NTSYSAPI VOID NTAPI RtlRaiseStatus(_In_ NTSTATUS Status)
#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;
395  PVOID UserData = NULL;
396  PHARDERROR_USER_PARAMETERS UserParams;
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],
419  (PVOID)Parameters[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,
432  MEM_COMMIT,
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 */
446  _SEH2_TRY
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,
509  MEM_RELEASE);
510  }
511 
512  /* Return status and the response */
513  *Response = SafeResponse;
514  return Status;
515 }
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
LONG NTSTATUS
Definition: precomp.h:26
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define MEM_COMMIT
Definition: nt_native.h:1313
UNICODE_STRING Strings[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:127
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
_SEH2_TRY
Definition: create.c:4226
Definition: bufpool.h:45
#define NtCurrentProcess()
Definition: nt_native.h:1657
Status
Definition: gdiplustypes.h:24
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
struct tagUserData UserData
ULONG_PTR Parameters[MAXIMUM_HARDERROR_PARAMETERS]
Definition: ex.h:126
Definition: ncftp.h:89
ULONG_PTR SIZE_T
Definition: typedefs.h:80
_SEH2_END
Definition: create.c:4400
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 FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NULL
Definition: types.h:112
WCHAR Buffer[ANYSIZE_ARRAY]
Definition: ex.h:128
#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:99
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGED_CODE()

Referenced by NtRaiseHardError().

◆ ExSystemExceptionFilter()

LONG NTAPI ExSystemExceptionFilter ( VOID  )

Definition at line 349 of file harderr.c.

350 {
351  return KeGetPreviousMode() != KernelMode ?
353 }
#define KeGetPreviousMode()
Definition: ketypes.h:1108
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#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 */
583  if (PreviousMode != KernelMode)
584  {
585  /* First validate the responses */
586  switch (ValidResponseOptions)
587  {
588  /* Check all valid cases */
590  case OptionOk:
591  case OptionOkCancel:
592  case OptionRetryCancel:
593  case OptionYesNo:
594  case OptionYesNoCancel:
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 */
620  _SEH2_TRY
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 */
684  _SEH2_TRY
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 ProbeForWriteUlong(Ptr)
Definition: probe.h:36
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:863
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:384
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3063
_SEH2_TRY
Definition: create.c:4226
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:476
Status
Definition: gdiplustypes.h:24
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
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
_SEH2_END
Definition: create.c:4400
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 NULL
Definition: types.h:112
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
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
uint32_t * PULONG_PTR
Definition: typedefs.h:65
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define STATUS_SUCCESS
Definition: shellext.h:65
#define MAXIMUM_HARDERROR_PARAMETERS
Definition: extypes.h:145
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define TAG_ERR
Definition: tag.h:31
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define PAGED_CODE()

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 */
759  Status = ObReferenceObjectByHandle(PortHandle,
760  0,
762  PreviousMode,
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 }
#define STATUS_PRIVILEGE_NOT_HELD
Definition: DriverTester.h:9
#define TRUE
Definition: types.h:120
PEPROCESS ExpDefaultErrorPortProcess
Definition: harderr.c:19
LONG NTSTATUS
Definition: precomp.h:26
KPROCESSOR_MODE NTAPI ExGetPreviousMode(VOID)
Definition: sysinfo.c:3063
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
BOOLEAN ExReadyForErrors
Definition: harderr.c:17
#define PsGetCurrentProcess
Definition: psfuncs.h:17
POBJECT_TYPE LpcPortObjectType
Definition: port.c:17
Status
Definition: gdiplustypes.h:24
_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
const LUID SeTcbPrivilege
Definition: priv.c:26
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
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 ObReferenceObject
Definition: obfuncs.h:204
PVOID ExpDefaultErrorPort
Definition: harderr.c:18
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()

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().