2005-03-12 21:26:29 +00:00
|
|
|
/*
|
2005-12-29 18:28:05 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
2006-06-28 15:56:09 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2011-09-29 06:48:19 +00:00
|
|
|
* FILE: ntoskrnl/ex/harderr.c
|
2005-03-12 21:26:29 +00:00
|
|
|
* PURPOSE: Error Functions and Status/Exception Dispatching/Raising
|
2005-12-29 18:28:05 +00:00
|
|
|
* PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
|
2005-03-12 21:26:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#include <ntoskrnl.h>
|
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
2005-03-12 21:26:29 +00:00
|
|
|
|
2018-04-01 20:34:17 +00:00
|
|
|
/* GLOBALS ******************************************************************/
|
2005-03-12 21:26:29 +00:00
|
|
|
|
|
|
|
BOOLEAN ExReadyForErrors = FALSE;
|
2006-10-30 14:17:37 +00:00
|
|
|
PVOID ExpDefaultErrorPort = NULL;
|
2005-03-12 21:26:29 +00:00
|
|
|
PEPROCESS ExpDefaultErrorPortProcess = NULL;
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
/*++
|
2008-12-29 06:24:46 +00:00
|
|
|
* @name ExpSystemErrorHandler
|
2006-10-26 04:55:34 +00:00
|
|
|
*
|
|
|
|
* For now it's a stub
|
|
|
|
*
|
|
|
|
* @param ErrorStatus
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @param NumberOfParameters
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @param UnicodeStringParameterMask
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @param Parameters
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @param ValidResponseOptions
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @param Response
|
|
|
|
* FILLME
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*
|
|
|
|
* @remarks None
|
|
|
|
*
|
|
|
|
*--*/
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
ExpSystemErrorHandler(IN NTSTATUS ErrorStatus,
|
|
|
|
IN ULONG NumberOfParameters,
|
|
|
|
IN ULONG UnicodeStringParameterMask,
|
|
|
|
IN PULONG_PTR Parameters,
|
|
|
|
IN BOOLEAN Shutdown)
|
|
|
|
{
|
2009-10-08 20:06:37 +00:00
|
|
|
ULONG_PTR BugCheckParameters[MAXIMUM_HARDERROR_PARAMETERS] = {0, 0, 0, 0};
|
|
|
|
ULONG i;
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
ASSERT(NumberOfParameters <= MAXIMUM_HARDERROR_PARAMETERS);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* KeBugCheck expects MAXIMUM_HARDERROR_PARAMETERS parameters,
|
|
|
|
* but we might get called with less, so use a local buffer here.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NumberOfParameters; i++)
|
|
|
|
{
|
|
|
|
/* Copy them over */
|
|
|
|
BugCheckParameters[i] = Parameters[i];
|
|
|
|
}
|
2009-09-30 18:31:26 +00:00
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
/* FIXME: STUB */
|
|
|
|
KeBugCheckEx(FATAL_UNHANDLED_HARD_ERROR,
|
|
|
|
ErrorStatus,
|
2009-10-08 20:06:37 +00:00
|
|
|
(ULONG_PTR)BugCheckParameters,
|
2006-10-26 04:55:34 +00:00
|
|
|
0,
|
|
|
|
0);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name ExpRaiseHardError
|
2018-04-01 13:06:45 +00:00
|
|
|
* @implemented
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* See ExRaiseHardError and NtRaiseHardError, same parameters.
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* This function performs the central work for both ExRaiseHardError
|
|
|
|
* and NtRaiseHardError. ExRaiseHardError is the service for kernel-mode
|
|
|
|
* that copies the parameters to user-mode, and NtRaiseHardError is the
|
|
|
|
* service for both kernel-mode and user-mode that performs parameters
|
|
|
|
* validation and capture if necessary.
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2006-10-26 04:55:34 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
|
|
|
ExpRaiseHardError(IN NTSTATUS ErrorStatus,
|
|
|
|
IN ULONG NumberOfParameters,
|
|
|
|
IN ULONG UnicodeStringParameterMask,
|
|
|
|
IN PULONG_PTR Parameters,
|
|
|
|
IN ULONG ValidResponseOptions,
|
|
|
|
OUT PULONG Response)
|
|
|
|
{
|
2018-04-01 13:53:49 +00:00
|
|
|
NTSTATUS Status;
|
2006-10-26 04:55:34 +00:00
|
|
|
PEPROCESS Process = PsGetCurrentProcess();
|
|
|
|
PETHREAD Thread = PsGetCurrentThread();
|
|
|
|
UCHAR Buffer[PORT_MAXIMUM_MESSAGE_LENGTH];
|
|
|
|
PHARDERROR_MSG Message = (PHARDERROR_MSG)Buffer;
|
|
|
|
HANDLE PortHandle;
|
|
|
|
KPROCESSOR_MODE PreviousMode = KeGetPreviousMode();
|
2018-04-01 13:53:49 +00:00
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Check if this error will shutdown the system */
|
|
|
|
if (ValidResponseOptions == OptionShutdownSystem)
|
|
|
|
{
|
2018-04-01 12:46:19 +00:00
|
|
|
/*
|
|
|
|
* Check if we have the privileges.
|
|
|
|
*
|
|
|
|
* NOTE: In addition to the Shutdown privilege we also check whether
|
|
|
|
* the caller has the Tcb privilege. The purpose is to allow only
|
|
|
|
* SYSTEM processes to "shutdown" the system on hard errors (BSOD)
|
|
|
|
* while forbidding regular processes to do so. This behaviour differs
|
|
|
|
* from Windows, where any user-mode process, as soon as it has the
|
|
|
|
* Shutdown privilege, can trigger a hard-error BSOD.
|
|
|
|
*/
|
|
|
|
if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode) ||
|
|
|
|
!SeSinglePrivilegeCheck(SeShutdownPrivilege, PreviousMode))
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
|
|
|
/* No rights */
|
2012-03-14 23:08:48 +00:00
|
|
|
*Response = ResponseNotHandled;
|
2006-10-26 04:55:34 +00:00
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't handle any new hard errors */
|
|
|
|
ExReadyForErrors = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if hard errors are not disabled */
|
|
|
|
if (!Thread->HardErrorsAreDisabled)
|
|
|
|
{
|
|
|
|
/* Check if we can't do errors anymore, and this is serious */
|
2016-05-15 22:23:14 +00:00
|
|
|
if (!ExReadyForErrors && NT_ERROR(ErrorStatus))
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
|
|
|
/* Use the system handler */
|
|
|
|
ExpSystemErrorHandler(ErrorStatus,
|
|
|
|
NumberOfParameters,
|
|
|
|
UnicodeStringParameterMask,
|
|
|
|
Parameters,
|
2018-04-01 13:25:15 +00:00
|
|
|
(PreviousMode != KernelMode) ? TRUE : FALSE);
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 13:25:15 +00:00
|
|
|
/*
|
|
|
|
* Enable hard error processing if it is enabled for the process
|
|
|
|
* or if the exception status forces it.
|
|
|
|
*/
|
|
|
|
if ((Process->DefaultHardErrorProcessing & SEM_FAILCRITICALERRORS) ||
|
2016-05-15 22:23:14 +00:00
|
|
|
(ErrorStatus & HARDERROR_OVERRIDE_ERRORMODE))
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Check if we have an exception port */
|
|
|
|
if (Process->ExceptionPort)
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
|
|
|
/* Use the port */
|
|
|
|
PortHandle = Process->ExceptionPort;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Use our default system port */
|
|
|
|
PortHandle = ExpDefaultErrorPort;
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Don't process the error */
|
|
|
|
PortHandle = NULL;
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If hard errors are disabled, do nothing */
|
|
|
|
if (Thread->HardErrorsAreDisabled) PortHandle = NULL;
|
|
|
|
|
2018-04-01 13:53:49 +00:00
|
|
|
/*
|
|
|
|
* If this is not the system thread, check whether hard errors are
|
|
|
|
* disabled for this thread on user-mode side, and if so, do nothing.
|
|
|
|
*/
|
|
|
|
if (!Thread->SystemThread && (PortHandle != NULL))
|
|
|
|
{
|
|
|
|
/* Check if we have a TEB */
|
|
|
|
PTEB Teb = PsGetCurrentThread()->Tcb.Teb;
|
|
|
|
if (Teb)
|
|
|
|
{
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
if (Teb->HardErrorMode & RTL_SEM_FAILCRITICALERRORS)
|
|
|
|
{
|
|
|
|
PortHandle = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
NOTHING;
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
/* Now check if we have a port */
|
2016-05-15 22:23:14 +00:00
|
|
|
if (PortHandle == NULL)
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
2016-05-15 22:23:14 +00:00
|
|
|
/* Just return to caller */
|
|
|
|
*Response = ResponseReturnToCaller;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2006-10-26 04:55:34 +00:00
|
|
|
|
2016-05-15 22:23:14 +00:00
|
|
|
/* Check if this is the default process */
|
|
|
|
if (Process == ExpDefaultErrorPortProcess)
|
|
|
|
{
|
|
|
|
/* We can't handle the error, check if this is critical */
|
|
|
|
if (NT_ERROR(ErrorStatus))
|
2006-10-30 14:20:45 +00:00
|
|
|
{
|
2016-05-15 22:23:14 +00:00
|
|
|
/* It is, invoke the system handler */
|
|
|
|
ExpSystemErrorHandler(ErrorStatus,
|
|
|
|
NumberOfParameters,
|
|
|
|
UnicodeStringParameterMask,
|
|
|
|
Parameters,
|
2018-04-01 13:25:15 +00:00
|
|
|
(PreviousMode != KernelMode) ? TRUE : FALSE);
|
2006-10-30 14:20:45 +00:00
|
|
|
|
2016-05-15 22:23:14 +00:00
|
|
|
/* If we survived, return to caller */
|
|
|
|
*Response = ResponseReturnToCaller;
|
|
|
|
return STATUS_SUCCESS;
|
2006-10-30 14:20:45 +00:00
|
|
|
}
|
2016-05-15 22:23:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup the LPC Message */
|
|
|
|
Message->h.u1.Length = (sizeof(HARDERROR_MSG) << 16) |
|
|
|
|
(sizeof(HARDERROR_MSG) - sizeof(PORT_MESSAGE));
|
|
|
|
Message->h.u2.ZeroInit = 0;
|
|
|
|
Message->h.u2.s2.Type = LPC_ERROR_EVENT;
|
|
|
|
Message->Status = ErrorStatus & ~HARDERROR_OVERRIDE_ERRORMODE;
|
|
|
|
Message->ValidResponseOptions = ValidResponseOptions;
|
|
|
|
Message->UnicodeStringParameterMask = UnicodeStringParameterMask;
|
|
|
|
Message->NumberOfParameters = NumberOfParameters;
|
|
|
|
KeQuerySystemTime(&Message->ErrorTime);
|
|
|
|
|
|
|
|
/* Copy the parameters */
|
2018-04-01 20:34:17 +00:00
|
|
|
if (Parameters)
|
|
|
|
{
|
|
|
|
RtlMoveMemory(&Message->Parameters,
|
|
|
|
Parameters,
|
|
|
|
sizeof(ULONG_PTR) * NumberOfParameters);
|
|
|
|
}
|
2016-05-15 22:23:14 +00:00
|
|
|
|
|
|
|
/* Send the LPC Message */
|
|
|
|
Status = LpcRequestWaitReplyPort(PortHandle,
|
|
|
|
(PPORT_MESSAGE)Message,
|
|
|
|
(PPORT_MESSAGE)Message);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Check what kind of response we got */
|
|
|
|
if ((Message->Response != ResponseReturnToCaller) &&
|
|
|
|
(Message->Response != ResponseNotHandled) &&
|
|
|
|
(Message->Response != ResponseAbort) &&
|
|
|
|
(Message->Response != ResponseCancel) &&
|
|
|
|
(Message->Response != ResponseIgnore) &&
|
|
|
|
(Message->Response != ResponseNo) &&
|
|
|
|
(Message->Response != ResponseOk) &&
|
|
|
|
(Message->Response != ResponseRetry) &&
|
|
|
|
(Message->Response != ResponseYes) &&
|
|
|
|
(Message->Response != ResponseTryAgain) &&
|
|
|
|
(Message->Response != ResponseContinue))
|
2012-03-14 23:08:48 +00:00
|
|
|
{
|
2016-05-15 22:23:14 +00:00
|
|
|
/* Reset to a default one */
|
|
|
|
Message->Response = ResponseReturnToCaller;
|
2012-03-14 23:08:48 +00:00
|
|
|
}
|
2016-05-15 22:23:14 +00:00
|
|
|
|
|
|
|
/* Set the response */
|
|
|
|
*Response = Message->Response;
|
2006-10-30 14:20:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-15 22:23:14 +00:00
|
|
|
/* Set the response */
|
2006-10-30 14:20:45 +00:00
|
|
|
*Response = ResponseReturnToCaller;
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
|
2006-10-30 14:20:45 +00:00
|
|
|
/* Return status */
|
|
|
|
return Status;
|
2005-12-29 18:28:05 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name ExRaiseAccessViolation
|
2005-03-12 21:26:29 +00:00
|
|
|
* @implemented
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* The ExRaiseAccessViolation routine can be used with structured exception
|
|
|
|
* handling to throw a driver-determined exception for a memory access
|
|
|
|
* violation that occurs when a driver processes I/O requests.
|
|
|
|
* See: http://msdn.microsoft.com/library/en-us/Kernel_r/hh/Kernel_r/k102_71b4c053-599c-4a6d-8a59-08aae6bdc534.xml.asp?frame=true
|
|
|
|
* http://www.osronline.com/ddkx/kmarch/k102_814i.htm
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*
|
|
|
|
* @remarks None
|
|
|
|
*
|
|
|
|
*--*/
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2005-03-12 21:26:29 +00:00
|
|
|
ExRaiseAccessViolation(VOID)
|
|
|
|
{
|
|
|
|
/* Raise the Right Status */
|
Major refactoring of the exception handling code + misc fixes:
- Fix/add prototypes for RtlCaptureContext, RtlDispatchException and RtlUnwind
- Fix EXCEPTION_REGISTRATION_RECORD structure and PEXCEPTION_ROUTINE
- Add w32api excpt.h (based on mingw) with PSDK compatibility fixes
- Fix seriously broken User-Mode Ldr thunk and APC Callback prototypes
- Fix KiUserExceptionDispatcher
- Remove useless NTDLL entrypoint
- Implement NTDLL Ki* callbacks in ASM
- Implement RtlCaptureContext
- Fix RtlRaiseException to handle cases when a user-mode debugger is present
- Fix RtlRaiseStatus as above, plus set the exception address and capture context
- Little cleanup of RTL headers
- Implement RtlpGetStackLimits, RtlpGetExceptionList, RtlpSetExceptionList, RtlpGetExceptionAddress in ASM
- Fix RtlDispatchException, add cases for exceptions in the DPC stack and validate the validity of the
exception frames. Add support for exception logging by the global flag. Use TRAP_FRAME/EXCPETION_FRAME instead of
Context.
- Fix RtlUnwind logic, support cases where it's called with custom arguments instead of NULL.
- Reimplement RtlpCaptureContext to work properly, convert exception handler calling functions to INTEL syntax
and fix some bugs (like checking for the right unwind flag, clearing volatile register values, etc. Also use some
optimizations to increase speed.
- Modify some kernel functions (like KeContextToTrapFrame, KiDispatchException, KiInitializeUserApc, etc.) to
support a PKEXCEPTION_FRAME for future PPC compatibility.
- Reimplement RtlCaptureUnicodeString/FreeUnicodeString as inlined probe macros and optimize them.
- Export ExRaiseStatus/Exception as Rtl*
- Reimplement NtContinue to have more platform-independent code, and to protect and validate user-mode context
and parameters with SEH.
- Implement KiRaiseException, add SEH to all user-mode parameters and when copying data to the user-mode stack.
- Fix KiInitializeUserApc to use KeTrapFrameToContext, to save the debug registers, not to deliver APCs during
v86 mode, and to protect user-mode stack operations in SEH and probing. Also make it generate the proper stack for the
user-mode callback.
- Implement KiUnexpectedInterrupt and KiCoprocessorError
- Reimplement NtRaiseException in ASM to take advantage of optimizations due to the trap frame being in the
stack when called through System call interface.
- Fix Ntcontinue to respect AlertThread paramter
- Fix some functiosn to return with KiServiceExit2 instead of KiServiceExit when required/needed
- Fix KiDispatchException's logic, fix hacks when calling KeUserExceptionDispatcher, use correct context
flags,...
- Make NTDLL Ki* callbacks have SEH to protect them and return to kernel-mode with notification of any
exceptions (the kernel-mode code to handle this isn't written yet though)
svn path=/trunk/; revision=17811
2005-09-11 22:32:20 +00:00
|
|
|
RtlRaiseStatus(STATUS_ACCESS_VIOLATION);
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name ExRaiseDatatypeMisalignment
|
2005-03-12 21:26:29 +00:00
|
|
|
* @implemented
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* ExRaiseDatatypeMisalignment raises an exception with the exception
|
|
|
|
* code set to STATUS_DATATYPE_MISALIGNMENT
|
|
|
|
* See: MSDN / DDK
|
|
|
|
* http://www.osronline.com/ddkx/kmarch/k102_814i.htm
|
|
|
|
*
|
|
|
|
* @return None
|
|
|
|
*
|
|
|
|
* @remarks None
|
|
|
|
*
|
|
|
|
*--*/
|
2005-03-12 21:26:29 +00:00
|
|
|
VOID
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2006-06-28 15:56:09 +00:00
|
|
|
ExRaiseDatatypeMisalignment(VOID)
|
2005-03-12 21:26:29 +00:00
|
|
|
{
|
|
|
|
/* Raise the Right Status */
|
Major refactoring of the exception handling code + misc fixes:
- Fix/add prototypes for RtlCaptureContext, RtlDispatchException and RtlUnwind
- Fix EXCEPTION_REGISTRATION_RECORD structure and PEXCEPTION_ROUTINE
- Add w32api excpt.h (based on mingw) with PSDK compatibility fixes
- Fix seriously broken User-Mode Ldr thunk and APC Callback prototypes
- Fix KiUserExceptionDispatcher
- Remove useless NTDLL entrypoint
- Implement NTDLL Ki* callbacks in ASM
- Implement RtlCaptureContext
- Fix RtlRaiseException to handle cases when a user-mode debugger is present
- Fix RtlRaiseStatus as above, plus set the exception address and capture context
- Little cleanup of RTL headers
- Implement RtlpGetStackLimits, RtlpGetExceptionList, RtlpSetExceptionList, RtlpGetExceptionAddress in ASM
- Fix RtlDispatchException, add cases for exceptions in the DPC stack and validate the validity of the
exception frames. Add support for exception logging by the global flag. Use TRAP_FRAME/EXCPETION_FRAME instead of
Context.
- Fix RtlUnwind logic, support cases where it's called with custom arguments instead of NULL.
- Reimplement RtlpCaptureContext to work properly, convert exception handler calling functions to INTEL syntax
and fix some bugs (like checking for the right unwind flag, clearing volatile register values, etc. Also use some
optimizations to increase speed.
- Modify some kernel functions (like KeContextToTrapFrame, KiDispatchException, KiInitializeUserApc, etc.) to
support a PKEXCEPTION_FRAME for future PPC compatibility.
- Reimplement RtlCaptureUnicodeString/FreeUnicodeString as inlined probe macros and optimize them.
- Export ExRaiseStatus/Exception as Rtl*
- Reimplement NtContinue to have more platform-independent code, and to protect and validate user-mode context
and parameters with SEH.
- Implement KiRaiseException, add SEH to all user-mode parameters and when copying data to the user-mode stack.
- Fix KiInitializeUserApc to use KeTrapFrameToContext, to save the debug registers, not to deliver APCs during
v86 mode, and to protect user-mode stack operations in SEH and probing. Also make it generate the proper stack for the
user-mode callback.
- Implement KiUnexpectedInterrupt and KiCoprocessorError
- Reimplement NtRaiseException in ASM to take advantage of optimizations due to the trap frame being in the
stack when called through System call interface.
- Fix Ntcontinue to respect AlertThread paramter
- Fix some functiosn to return with KiServiceExit2 instead of KiServiceExit when required/needed
- Fix KiDispatchException's logic, fix hacks when calling KeUserExceptionDispatcher, use correct context
flags,...
- Make NTDLL Ki* callbacks have SEH to protect them and return to kernel-mode with notification of any
exceptions (the kernel-mode code to handle this isn't written yet though)
svn path=/trunk/; revision=17811
2005-09-11 22:32:20 +00:00
|
|
|
RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name ExSystemExceptionFilter
|
2005-03-12 21:26:29 +00:00
|
|
|
* @implemented
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* TODO: Add description
|
|
|
|
*
|
|
|
|
* @return FILLME
|
|
|
|
*
|
|
|
|
* @remarks None
|
|
|
|
*
|
|
|
|
*--*/
|
2005-05-06 22:25:30 +00:00
|
|
|
LONG
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2005-03-12 21:26:29 +00:00
|
|
|
ExSystemExceptionFilter(VOID)
|
|
|
|
{
|
2005-12-29 18:28:05 +00:00
|
|
|
return KeGetPreviousMode() != KernelMode ?
|
|
|
|
EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name ExRaiseHardError
|
|
|
|
* @implemented
|
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* See NtRaiseHardError and ExpRaiseHardError.
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* @param ErrorStatus
|
|
|
|
* Error Code
|
|
|
|
*
|
|
|
|
* @param NumberOfParameters
|
|
|
|
* Number of optional parameters in Parameters array
|
|
|
|
*
|
|
|
|
* @param UnicodeStringParameterMask
|
|
|
|
* Optional string parameter (can be only one per error code)
|
|
|
|
*
|
|
|
|
* @param Parameters
|
2006-09-07 05:07:34 +00:00
|
|
|
* Array of ULONG parameters for use in error message string
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* @param ValidResponseOptions
|
|
|
|
* See HARDERROR_RESPONSE_OPTION for possible values description
|
|
|
|
*
|
|
|
|
* @param Response
|
|
|
|
* Pointer to HARDERROR_RESPONSE enumeration
|
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* @return Status
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2006-10-26 04:55:34 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2005-03-12 21:26:29 +00:00
|
|
|
ExRaiseHardError(IN NTSTATUS ErrorStatus,
|
2005-05-09 01:38:29 +00:00
|
|
|
IN ULONG NumberOfParameters,
|
2005-09-04 18:00:59 +00:00
|
|
|
IN ULONG UnicodeStringParameterMask,
|
|
|
|
IN PULONG_PTR Parameters,
|
|
|
|
IN ULONG ValidResponseOptions,
|
|
|
|
OUT PULONG Response)
|
2005-03-12 21:26:29 +00:00
|
|
|
{
|
2018-04-01 15:52:10 +00:00
|
|
|
NTSTATUS Status;
|
2010-01-13 22:35:43 +00:00
|
|
|
SIZE_T Size;
|
2006-10-26 04:55:34 +00:00
|
|
|
UNICODE_STRING CapturedParams[MAXIMUM_HARDERROR_PARAMETERS];
|
|
|
|
ULONG i;
|
2011-09-29 06:48:19 +00:00
|
|
|
PVOID UserData = NULL;
|
|
|
|
PHARDERROR_USER_PARAMETERS UserParams;
|
2006-10-26 04:55:34 +00:00
|
|
|
PWSTR BufferBase;
|
2018-04-01 15:59:31 +00:00
|
|
|
ULONG SafeResponse = ResponseNotHandled;
|
2018-04-01 15:52:10 +00:00
|
|
|
|
2006-10-26 04:55:34 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Check if we have parameters */
|
|
|
|
if (Parameters)
|
|
|
|
{
|
|
|
|
/* Check if we have strings */
|
|
|
|
if (UnicodeStringParameterMask)
|
|
|
|
{
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Calculate the required size */
|
|
|
|
Size = FIELD_OFFSET(HARDERROR_USER_PARAMETERS, Buffer[0]);
|
2006-10-26 04:55:34 +00:00
|
|
|
|
|
|
|
/* Loop each parameter */
|
|
|
|
for (i = 0; i < NumberOfParameters; i++)
|
|
|
|
{
|
|
|
|
/* Check if it's part of the mask */
|
|
|
|
if (UnicodeStringParameterMask & (1 << i))
|
|
|
|
{
|
|
|
|
/* Copy it */
|
|
|
|
RtlMoveMemory(&CapturedParams[i],
|
2011-09-29 06:48:19 +00:00
|
|
|
(PVOID)Parameters[i],
|
2006-10-26 04:55:34 +00:00
|
|
|
sizeof(UNICODE_STRING));
|
|
|
|
|
|
|
|
/* Increase the size */
|
|
|
|
Size += CapturedParams[i].MaximumLength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the user data region */
|
|
|
|
Status = ZwAllocateVirtualMemory(NtCurrentProcess(),
|
2011-09-29 06:48:19 +00:00
|
|
|
&UserData,
|
2006-10-26 04:55:34 +00:00
|
|
|
0,
|
|
|
|
&Size,
|
|
|
|
MEM_COMMIT,
|
|
|
|
PAGE_READWRITE);
|
2018-04-01 15:59:31 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Return failure */
|
|
|
|
*Response = ResponseNotHandled;
|
|
|
|
return Status;
|
|
|
|
}
|
2006-10-26 04:55:34 +00:00
|
|
|
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Set the pointers to our data */
|
|
|
|
UserParams = UserData;
|
|
|
|
BufferBase = UserParams->Buffer;
|
2006-10-26 04:55:34 +00:00
|
|
|
|
2018-04-01 15:52:10 +00:00
|
|
|
/* Enter SEH block as we are writing to user-mode space */
|
|
|
|
_SEH2_TRY
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
2018-04-01 15:52:10 +00:00
|
|
|
/* Loop parameters again */
|
|
|
|
for (i = 0; i < NumberOfParameters; i++)
|
2006-10-26 04:55:34 +00:00
|
|
|
{
|
2018-04-01 15:52:10 +00:00
|
|
|
/* Check if we are in the mask */
|
|
|
|
if (UnicodeStringParameterMask & (1 << i))
|
|
|
|
{
|
|
|
|
/* Update the base */
|
|
|
|
UserParams->Parameters[i] = (ULONG_PTR)&UserParams->Strings[i];
|
|
|
|
|
|
|
|
/* Copy the string buffer */
|
|
|
|
RtlMoveMemory(BufferBase,
|
|
|
|
CapturedParams[i].Buffer,
|
|
|
|
CapturedParams[i].MaximumLength);
|
|
|
|
|
|
|
|
/* Set buffer */
|
|
|
|
CapturedParams[i].Buffer = BufferBase;
|
|
|
|
|
|
|
|
/* Copy the string structure */
|
|
|
|
UserParams->Strings[i] = CapturedParams[i];
|
|
|
|
|
|
|
|
/* Update the pointer */
|
|
|
|
BufferBase += CapturedParams[i].MaximumLength;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No need to copy any strings */
|
|
|
|
UserParams->Parameters[i] = Parameters[i];
|
|
|
|
}
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 15:52:10 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
/* Return the exception code */
|
|
|
|
Status = _SEH2_GetExceptionCode();
|
|
|
|
DPRINT1("ExRaiseHardError - Exception when writing data to user-mode, Status 0x%08lx\n", Status);
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2006-10-26 04:55:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Just keep the data as is */
|
|
|
|
UserData = Parameters;
|
|
|
|
}
|
|
|
|
}
|
2005-12-29 18:28:05 +00:00
|
|
|
|
|
|
|
/* Now call the worker function */
|
2006-10-26 04:55:34 +00:00
|
|
|
Status = ExpRaiseHardError(ErrorStatus,
|
|
|
|
NumberOfParameters,
|
|
|
|
UnicodeStringParameterMask,
|
|
|
|
UserData,
|
|
|
|
ValidResponseOptions,
|
|
|
|
&SafeResponse);
|
|
|
|
|
|
|
|
/* Check if we had done user-mode allocation */
|
|
|
|
if ((UserData) && (UserData != Parameters))
|
|
|
|
{
|
|
|
|
/* We did! Delete it */
|
|
|
|
Size = 0;
|
|
|
|
ZwFreeVirtualMemory(NtCurrentProcess(),
|
2011-09-29 06:48:19 +00:00
|
|
|
&UserData,
|
2006-10-26 04:55:34 +00:00
|
|
|
&Size,
|
|
|
|
MEM_RELEASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status and the response */
|
|
|
|
*Response = SafeResponse;
|
|
|
|
return Status;
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name NtRaiseHardError
|
|
|
|
* @implemented
|
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* This function sends HARDERROR_MSG LPC message to a hard-error listener,
|
|
|
|
* typically CSRSS.EXE. See NtSetDefaultHardErrorPort for more information.
|
|
|
|
* See also: http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Error/NtRaiseHardError.html
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* @param ErrorStatus
|
|
|
|
* Error Code
|
|
|
|
*
|
|
|
|
* @param NumberOfParameters
|
|
|
|
* Number of optional parameters in Parameters array
|
|
|
|
*
|
|
|
|
* @param UnicodeStringParameterMask
|
|
|
|
* Optional string parameter (can be only one per error code)
|
|
|
|
*
|
|
|
|
* @param Parameters
|
2009-10-08 20:06:37 +00:00
|
|
|
* Array of ULONG_PTR parameters for use in error message string
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* @param ValidResponseOptions
|
|
|
|
* See HARDERROR_RESPONSE_OPTION for possible values description
|
|
|
|
*
|
|
|
|
* @param Response
|
|
|
|
* Pointer to HARDERROR_RESPONSE enumeration
|
|
|
|
*
|
|
|
|
* @return Status
|
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* @remarks NtRaiseHardError constitutes an easy way to display messages
|
|
|
|
* in GUI without loading any Win32 API libraries.
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
*--*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2005-03-12 21:26:29 +00:00
|
|
|
NtRaiseHardError(IN NTSTATUS ErrorStatus,
|
|
|
|
IN ULONG NumberOfParameters,
|
2005-09-04 18:00:59 +00:00
|
|
|
IN ULONG UnicodeStringParameterMask,
|
|
|
|
IN PULONG_PTR Parameters,
|
|
|
|
IN ULONG ValidResponseOptions,
|
|
|
|
OUT PULONG Response)
|
2005-03-12 21:26:29 +00:00
|
|
|
{
|
2005-12-29 20:51:14 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2009-01-07 10:13:43 +00:00
|
|
|
PULONG_PTR SafeParams = NULL;
|
2018-04-01 15:59:31 +00:00
|
|
|
ULONG SafeResponse = ResponseNotHandled;
|
2005-12-29 18:28:05 +00:00
|
|
|
UNICODE_STRING SafeString;
|
|
|
|
ULONG i;
|
2012-09-29 13:22:31 +00:00
|
|
|
ULONG ParamSize = 0;
|
2005-12-29 18:28:05 +00:00
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2018-04-01 15:59:31 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2005-12-29 18:28:05 +00:00
|
|
|
/* Validate parameter count */
|
|
|
|
if (NumberOfParameters > MAXIMUM_HARDERROR_PARAMETERS)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure we have some at least */
|
2012-09-29 13:22:31 +00:00
|
|
|
if ((Parameters != NULL) && (NumberOfParameters == 0))
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
return STATUS_INVALID_PARAMETER_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we were called from user-mode */
|
|
|
|
if (PreviousMode != KernelMode)
|
|
|
|
{
|
|
|
|
/* First validate the responses */
|
|
|
|
switch (ValidResponseOptions)
|
|
|
|
{
|
|
|
|
/* Check all valid cases */
|
|
|
|
case OptionAbortRetryIgnore:
|
|
|
|
case OptionOk:
|
|
|
|
case OptionOkCancel:
|
|
|
|
case OptionRetryCancel:
|
|
|
|
case OptionYesNo:
|
|
|
|
case OptionYesNoCancel:
|
|
|
|
case OptionShutdownSystem:
|
2016-05-15 22:32:17 +00:00
|
|
|
case OptionOkNoWait:
|
|
|
|
case OptionCancelTryContinue:
|
2005-12-29 18:28:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Anything else is invalid */
|
|
|
|
default:
|
|
|
|
return STATUS_INVALID_PARAMETER_4;
|
|
|
|
}
|
|
|
|
|
2012-09-29 13:22:31 +00:00
|
|
|
/* Check if we have parameters */
|
|
|
|
if (Parameters)
|
|
|
|
{
|
|
|
|
/* Calculate size of the parameters */
|
|
|
|
ParamSize = sizeof(ULONG_PTR) * NumberOfParameters;
|
|
|
|
|
|
|
|
/* Allocate a safe buffer */
|
|
|
|
SafeParams = ExAllocatePoolWithTag(PagedPool, ParamSize, TAG_ERR);
|
|
|
|
if (!SafeParams)
|
|
|
|
{
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 18:28:05 +00:00
|
|
|
/* Enter SEH Block */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
|
|
|
/* Validate the response pointer */
|
|
|
|
ProbeForWriteUlong(Response);
|
|
|
|
|
|
|
|
/* Check if we have parameters */
|
|
|
|
if (Parameters)
|
|
|
|
{
|
|
|
|
/* Validate the parameter pointers */
|
|
|
|
ProbeForRead(Parameters, ParamSize, sizeof(ULONG_PTR));
|
|
|
|
|
|
|
|
/* Copy them */
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(SafeParams, Parameters, ParamSize);
|
2005-12-29 18:28:05 +00:00
|
|
|
|
2011-09-29 06:48:19 +00:00
|
|
|
/* Now check if there's strings in it */
|
2005-12-29 18:28:05 +00:00
|
|
|
if (UnicodeStringParameterMask)
|
|
|
|
{
|
|
|
|
/* Loop every string */
|
|
|
|
for (i = 0; i < NumberOfParameters; i++)
|
|
|
|
{
|
|
|
|
/* Check if this parameter is a string */
|
|
|
|
if (UnicodeStringParameterMask & (1 << i))
|
|
|
|
{
|
|
|
|
/* Probe the structure */
|
|
|
|
ProbeForRead((PVOID)SafeParams[i],
|
|
|
|
sizeof(UNICODE_STRING),
|
|
|
|
sizeof(ULONG_PTR));
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:28:05 +00:00
|
|
|
/* Capture it */
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(&SafeString,
|
2005-12-29 18:28:05 +00:00
|
|
|
(PVOID)SafeParams[i],
|
|
|
|
sizeof(UNICODE_STRING));
|
|
|
|
|
|
|
|
/* Probe the buffer */
|
|
|
|
ProbeForRead(SafeString.Buffer,
|
|
|
|
SafeString.MaximumLength,
|
|
|
|
sizeof(UCHAR));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
|
|
|
/* Free captured buffer */
|
2011-06-01 13:39:36 +00:00
|
|
|
if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
|
2009-08-26 17:31:02 +00:00
|
|
|
|
|
|
|
/* Return the exception code */
|
|
|
|
_SEH2_YIELD(return _SEH2_GetExceptionCode());
|
2005-12-29 18:28:05 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-12-29 18:28:05 +00:00
|
|
|
|
|
|
|
/* Call the system function directly, because we probed */
|
2018-04-01 15:59:31 +00:00
|
|
|
Status = ExpRaiseHardError(ErrorStatus,
|
|
|
|
NumberOfParameters,
|
|
|
|
UnicodeStringParameterMask,
|
|
|
|
SafeParams,
|
|
|
|
ValidResponseOptions,
|
|
|
|
&SafeResponse);
|
|
|
|
|
|
|
|
/* Free captured buffer */
|
2011-06-01 13:39:36 +00:00
|
|
|
if (SafeParams) ExFreePoolWithTag(SafeParams, TAG_ERR);
|
2005-12-29 18:28:05 +00:00
|
|
|
|
2018-04-01 15:59:31 +00:00
|
|
|
/* Enter SEH Block to return the response */
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_TRY
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
|
|
|
/* Return the response */
|
|
|
|
*Response = SafeResponse;
|
|
|
|
}
|
2009-08-26 17:31:02 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
2009-08-26 17:31:02 +00:00
|
|
|
/* Get the exception code */
|
2008-11-24 13:40:26 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-12-29 18:28:05 +00:00
|
|
|
}
|
2008-11-24 13:40:26 +00:00
|
|
|
_SEH2_END;
|
2005-12-29 18:28:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-01 15:59:31 +00:00
|
|
|
/* Reuse variable */
|
|
|
|
SafeParams = Parameters;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the Executive Function. It will probe
|
|
|
|
* and copy pointers to user-mode.
|
|
|
|
*/
|
|
|
|
Status = ExRaiseHardError(ErrorStatus,
|
|
|
|
NumberOfParameters,
|
|
|
|
UnicodeStringParameterMask,
|
|
|
|
SafeParams,
|
|
|
|
ValidResponseOptions,
|
|
|
|
&SafeResponse);
|
|
|
|
|
2005-12-29 18:28:05 +00:00
|
|
|
/* Return the response */
|
|
|
|
*Response = SafeResponse;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return status */
|
|
|
|
return Status;
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
|
2006-06-28 15:56:09 +00:00
|
|
|
/*++
|
|
|
|
* @name NtSetDefaultHardErrorPort
|
|
|
|
* @implemented
|
|
|
|
*
|
2018-04-01 13:06:45 +00:00
|
|
|
* NtSetDefaultHardErrorPort is typically called only once. After the call,
|
|
|
|
* the kernel sets a BOOLEAN flag named ExReadyForErrors to TRUE, and all other
|
|
|
|
* attempts to change the default port fail with STATUS_UNSUCCESSFUL error code.
|
|
|
|
* See: http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/Error/NtSetDefaultHardErrorPort.html
|
|
|
|
* https://web.archive.org/web/20070716133753/http://www.windowsitlibrary.com/Content/356/08/2.html
|
2006-06-28 15:56:09 +00:00
|
|
|
*
|
|
|
|
* @param PortHandle
|
|
|
|
* Handle to named port object
|
|
|
|
*
|
|
|
|
* @return Status
|
|
|
|
*
|
|
|
|
* @remarks Privileges: SE_TCB_PRIVILEGE
|
|
|
|
*
|
|
|
|
*--*/
|
2005-05-09 01:38:29 +00:00
|
|
|
NTSTATUS
|
2005-12-29 18:28:05 +00:00
|
|
|
NTAPI
|
2005-03-12 21:26:29 +00:00
|
|
|
NtSetDefaultHardErrorPort(IN HANDLE PortHandle)
|
|
|
|
{
|
|
|
|
KPROCESSOR_MODE PreviousMode = ExGetPreviousMode();
|
|
|
|
NTSTATUS Status = STATUS_UNSUCCESSFUL;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2018-04-01 15:59:31 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2018-03-31 20:12:44 +00:00
|
|
|
/* Check if we have the privileges */
|
2006-10-26 04:55:34 +00:00
|
|
|
if (!SeSinglePrivilegeCheck(SeTcbPrivilege, PreviousMode))
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtSetDefaultHardErrorPort: Caller requires "
|
|
|
|
"the SeTcbPrivilege privilege!\n");
|
2005-03-12 21:26:29 +00:00
|
|
|
return STATUS_PRIVILEGE_NOT_HELD;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-03-12 21:26:29 +00:00
|
|
|
/* Only called once during bootup, make sure we weren't called yet */
|
2006-10-26 04:55:34 +00:00
|
|
|
if (!ExReadyForErrors)
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
2018-03-31 20:12:44 +00:00
|
|
|
/* Reference the hard-error port */
|
2005-03-12 21:26:29 +00:00
|
|
|
Status = ObReferenceObjectByHandle(PortHandle,
|
|
|
|
0,
|
|
|
|
LpcPortObjectType,
|
|
|
|
PreviousMode,
|
|
|
|
(PVOID*)&ExpDefaultErrorPort,
|
|
|
|
NULL);
|
2006-10-26 04:55:34 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
2005-12-29 18:28:05 +00:00
|
|
|
{
|
2018-03-31 20:12:44 +00:00
|
|
|
/* Keep also a reference to the process handling the hard errors */
|
2005-03-12 21:26:29 +00:00
|
|
|
ExpDefaultErrorPortProcess = PsGetCurrentProcess();
|
2018-03-31 20:12:44 +00:00
|
|
|
ObReferenceObject(ExpDefaultErrorPortProcess);
|
2005-03-12 21:26:29 +00:00
|
|
|
ExReadyForErrors = TRUE;
|
2018-03-31 20:12:44 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2005-03-12 21:26:29 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-12-29 18:28:05 +00:00
|
|
|
/* Return status to caller */
|
2005-03-12 21:26:29 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2005-09-26 05:41:35 +00:00
|
|
|
VOID
|
|
|
|
__cdecl
|
|
|
|
_purecall(VOID)
|
|
|
|
{
|
|
|
|
/* Not supported in Kernel Mode */
|
|
|
|
RtlRaiseStatus(STATUS_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
2005-03-12 21:26:29 +00:00
|
|
|
/* EOF */
|