2006-07-01 03:36:15 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: ntoskrnl/io/error.c
|
|
|
|
* PURPOSE: I/O Error Functions and Error Log Support
|
|
|
|
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
|
|
|
|
* Eric Kohl
|
1998-08-25 04:27:26 +00:00
|
|
|
*/
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2004-08-15 16:39:12 +00:00
|
|
|
#include <ntoskrnl.h>
|
2005-04-26 14:51:18 +00:00
|
|
|
#define NDEBUG
|
2008-08-30 16:31:06 +00:00
|
|
|
#include <debug.h>
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2005-04-26 14:51:18 +00:00
|
|
|
/* TYPES *********************************************************************/
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
typedef struct _IOP_ERROR_LOG_WORKER_DPC
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
KDPC Dpc;
|
|
|
|
KTIMER Timer;
|
|
|
|
} IOP_ERROR_LOG_WORKER_DPC, *PIOP_ERROR_LOG_WORKER_DPC;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
LONG IopTotalLogSize;
|
2007-02-19 18:52:23 +00:00
|
|
|
LIST_ENTRY IopErrorLogListHead;
|
2006-07-01 03:36:15 +00:00
|
|
|
KSPIN_LOCK IopLogListLock;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
BOOLEAN IopLogWorkerRunning;
|
|
|
|
BOOLEAN IopLogPortConnected;
|
|
|
|
HANDLE IopLogPort;
|
|
|
|
WORK_QUEUE_ITEM IopErrorLogWorkItem;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-10-17 05:14:57 +00:00
|
|
|
PDEVICE_OBJECT IopErrorLogObject;
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2006-10-17 05:14:57 +00:00
|
|
|
/* PRIVATE FUNCTIONS *********************************************************/
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopLogDpcRoutine(IN PKDPC Dpc,
|
|
|
|
IN PVOID DeferredContext,
|
|
|
|
IN PVOID SystemArgument1,
|
|
|
|
IN PVOID SystemArgument2)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* If we have a DPC, free it */
|
|
|
|
if (Dpc) ExFreePool(Dpc);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Initialize and queue the work item */
|
|
|
|
ExInitializeWorkItem(&IopErrorLogWorkItem, IopLogWorker, NULL);
|
|
|
|
ExQueueWorkItem(&IopErrorLogWorkItem, DelayedWorkQueue);
|
|
|
|
}
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
PLIST_ENTRY
|
|
|
|
NTAPI
|
|
|
|
IopGetErrorLogEntry(VOID)
|
|
|
|
{
|
|
|
|
KIRQL OldIrql;
|
|
|
|
PLIST_ENTRY ListEntry;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Acquire the lock and check if the list is empty */
|
|
|
|
KeAcquireSpinLock(&IopLogListLock, &OldIrql);
|
2007-02-19 18:52:23 +00:00
|
|
|
if (IsListEmpty(&IopErrorLogListHead))
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* List is empty, disable the worker and return NULL */
|
|
|
|
IopLogWorkerRunning = FALSE;
|
|
|
|
ListEntry = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, remove an entry */
|
2007-02-19 18:52:23 +00:00
|
|
|
ListEntry = RemoveHeadList(&IopErrorLogListHead);
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Release the lock and return the entry */
|
|
|
|
KeReleaseSpinLock(&IopLogListLock, OldIrql);
|
|
|
|
return ListEntry;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopRestartLogWorker(VOID)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PIOP_ERROR_LOG_WORKER_DPC WorkerDpc;
|
|
|
|
LARGE_INTEGER Timeout;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Allocate a DPC Context */
|
|
|
|
WorkerDpc = ExAllocatePool(NonPagedPool, sizeof(IOP_ERROR_LOG_WORKER_DPC));
|
|
|
|
if (!WorkerDpc)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Fail */
|
|
|
|
IopLogWorkerRunning = FALSE;
|
|
|
|
return;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Initialize DPC and Timer */
|
|
|
|
KeInitializeDpc(&WorkerDpc->Dpc, IopLogDpcRoutine, WorkerDpc);
|
|
|
|
KeInitializeTimer(&WorkerDpc->Timer);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Restart after 30 seconds */
|
|
|
|
Timeout.QuadPart = (LONGLONG)-300000000;
|
|
|
|
KeSetTimer(&WorkerDpc->Timer, Timeout, &WorkerDpc->Dpc);
|
|
|
|
}
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
BOOLEAN
|
|
|
|
NTAPI
|
|
|
|
IopConnectLogPort(VOID)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\ErrorLogPort");
|
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
/* Make sure we're not already connected */
|
|
|
|
if (IopLogPortConnected) return TRUE;
|
|
|
|
|
|
|
|
/* Connect the port */
|
|
|
|
Status = ZwConnectPort(&IopLogPort,
|
|
|
|
&PortName,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
if (NT_SUCCESS(Status))
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2008-08-23 16:30:14 +00:00
|
|
|
/* Remember we're connected */
|
2006-07-01 03:36:15 +00:00
|
|
|
IopLogPortConnected = TRUE;
|
|
|
|
return TRUE;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* We failed, try again */
|
|
|
|
IopRestartLogWorker();
|
|
|
|
return FALSE;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopLogWorker(IN PVOID Parameter)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PELF_API_MSG Message;
|
|
|
|
PIO_ERROR_LOG_MESSAGE ErrorMessage;
|
|
|
|
PLIST_ENTRY ListEntry;
|
|
|
|
PERROR_LOG_ENTRY LogEntry;
|
|
|
|
PIO_ERROR_LOG_PACKET Packet;
|
|
|
|
PCHAR StringBuffer;
|
|
|
|
ULONG RemainingLength;
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
ULONG DriverNameLength = 0, DeviceNameLength;
|
|
|
|
UNICODE_STRING DriverNameString;
|
|
|
|
NTSTATUS Status;
|
|
|
|
UCHAR Buffer[256];
|
|
|
|
POBJECT_NAME_INFORMATION ObjectNameInfo = (POBJECT_NAME_INFORMATION)&Buffer;
|
|
|
|
POBJECT_NAME_INFORMATION PoolObjectNameInfo = NULL;
|
|
|
|
ULONG ReturnedLength, MessageLength;
|
|
|
|
PWCHAR p;
|
|
|
|
ULONG ExtraStringLength;
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Connect to the port */
|
|
|
|
if (!IopConnectLogPort()) return;
|
|
|
|
|
|
|
|
/* Allocate the message */
|
|
|
|
Message = ExAllocatePool(PagedPool, IO_ERROR_LOG_MESSAGE_LENGTH);
|
|
|
|
if (!Message)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Couldn't allocate, try again */
|
|
|
|
IopRestartLogWorker();
|
|
|
|
return;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Copy the message */
|
|
|
|
RtlZeroMemory(Message, sizeof(ELF_API_MSG));
|
|
|
|
|
|
|
|
/* Get the actual I/O Structure */
|
|
|
|
ErrorMessage = &Message->IoErrorMessage;
|
|
|
|
|
|
|
|
/* Start loop */
|
|
|
|
while (TRUE)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Get an entry */
|
|
|
|
ListEntry = IopGetErrorLogEntry();
|
|
|
|
if (!ListEntry) break;
|
|
|
|
LogEntry = CONTAINING_RECORD(ListEntry, ERROR_LOG_ENTRY, ListEntry);
|
|
|
|
|
|
|
|
/* Get pointer to the log packet */
|
|
|
|
Packet = (PIO_ERROR_LOG_PACKET)((ULONG_PTR)LogEntry +
|
|
|
|
sizeof(ERROR_LOG_ENTRY));
|
|
|
|
|
|
|
|
/* Calculate the total length of the message only */
|
|
|
|
MessageLength = sizeof(IO_ERROR_LOG_MESSAGE) -
|
|
|
|
sizeof(ERROR_LOG_ENTRY) -
|
|
|
|
sizeof(IO_ERROR_LOG_PACKET) +
|
|
|
|
LogEntry->Size;
|
|
|
|
|
|
|
|
/* Copy the packet */
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(&ErrorMessage->EntryData,
|
2006-07-01 03:36:15 +00:00
|
|
|
Packet,
|
|
|
|
LogEntry->Size - sizeof(ERROR_LOG_ENTRY));
|
|
|
|
|
|
|
|
/* Set the timestamp and time */
|
|
|
|
ErrorMessage->TimeStamp = LogEntry->TimeStamp;
|
|
|
|
ErrorMessage->Type = IO_TYPE_ERROR_MESSAGE;
|
|
|
|
|
|
|
|
/* Check if this message has any strings */
|
|
|
|
if (Packet->NumberOfStrings)
|
|
|
|
{
|
|
|
|
/* String buffer is after the current strings */
|
|
|
|
StringBuffer = (PCHAR)&ErrorMessage->EntryData +
|
|
|
|
Packet->StringOffset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise, string buffer is at the end */
|
|
|
|
StringBuffer = (PCHAR)ErrorMessage + MessageLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Align the buffer */
|
2008-08-27 22:40:17 +00:00
|
|
|
StringBuffer = ALIGN_UP_POINTER(StringBuffer, WCHAR);
|
2006-07-01 03:36:15 +00:00
|
|
|
|
|
|
|
/* Set the offset for the driver's name to the current buffer */
|
2008-08-27 22:40:17 +00:00
|
|
|
ErrorMessage->DriverNameOffset = (ULONG_PTR)(StringBuffer -
|
2006-07-01 03:36:15 +00:00
|
|
|
(ULONG_PTR)ErrorMessage);
|
|
|
|
|
|
|
|
/* Check how much space we have left for the device string */
|
|
|
|
RemainingLength = (ULONG)((ULONG_PTR)Message +
|
|
|
|
IO_ERROR_LOG_MESSAGE_LENGTH -
|
|
|
|
(ULONG_PTR)StringBuffer);
|
|
|
|
|
|
|
|
/* Now check if there is a driver object */
|
|
|
|
DriverObject = LogEntry->DriverObject;
|
|
|
|
if (DriverObject)
|
|
|
|
{
|
|
|
|
/* Check if the driver has a name */
|
|
|
|
if (DriverObject->DriverName.Buffer)
|
|
|
|
{
|
|
|
|
/* Use its name */
|
|
|
|
DriverNameString.Buffer = DriverObject->DriverName.Buffer;
|
|
|
|
DriverNameLength = DriverObject->DriverName.Length;
|
|
|
|
}
|
2006-07-10 11:42:28 +00:00
|
|
|
else
|
|
|
|
DriverNameString.Buffer = NULL;
|
2006-07-01 03:36:15 +00:00
|
|
|
|
|
|
|
/* Check if there isn't a valid name*/
|
|
|
|
if (!DriverNameLength)
|
|
|
|
{
|
|
|
|
/* Query the name directly */
|
|
|
|
Status = ObQueryNameString(DriverObject,
|
|
|
|
ObjectNameInfo,
|
|
|
|
sizeof(Buffer),
|
|
|
|
&ReturnedLength);
|
|
|
|
if (!(NT_SUCCESS(Status)) || !(ObjectNameInfo->Name.Length))
|
|
|
|
{
|
|
|
|
/* We don't have a name */
|
|
|
|
DriverNameLength = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Use default name */
|
|
|
|
DriverNameString.Buffer = L"Application Popup";
|
|
|
|
DriverNameLength = wcslen(DriverNameString.Buffer) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a driver name by here */
|
|
|
|
if (DriverNameLength)
|
|
|
|
{
|
|
|
|
/* Skip to the end of the driver's name */
|
|
|
|
p = &DriverNameString.Buffer[DriverNameLength / sizeof(WCHAR)];
|
|
|
|
|
|
|
|
/* Now we'll walk backwards and assume the minimum size */
|
|
|
|
DriverNameLength = sizeof(WCHAR);
|
|
|
|
p--;
|
|
|
|
while ((*p != L'\\') && (p != DriverNameString.Buffer))
|
|
|
|
{
|
|
|
|
/* No backslash found, keep going */
|
|
|
|
p--;
|
|
|
|
DriverNameLength += sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now we probably hit the backslash itself, skip past it */
|
|
|
|
if (*p == L'\\')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
DriverNameLength -= sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now make sure that the driver name fits in our buffer, minus 3
|
|
|
|
* NULL chars, and copy the name in our string buffer
|
|
|
|
*/
|
|
|
|
DriverNameLength = min(DriverNameLength,
|
|
|
|
RemainingLength - 3 * sizeof(UNICODE_NULL));
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(StringBuffer, p, DriverNameLength);
|
2006-07-01 03:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Null-terminate the driver name */
|
|
|
|
*((PWSTR)(StringBuffer + DriverNameLength)) = L'\0';
|
|
|
|
DriverNameLength += sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* Go to the next string buffer position */
|
|
|
|
StringBuffer += DriverNameLength;
|
|
|
|
RemainingLength -= DriverNameLength;
|
|
|
|
|
|
|
|
/* Update the string offset and check if we have a device object */
|
|
|
|
ErrorMessage->EntryData.StringOffset = (USHORT)
|
|
|
|
((ULONG_PTR)StringBuffer -
|
|
|
|
(ULONG_PTR)ErrorMessage);
|
|
|
|
if (LogEntry->DeviceObject)
|
|
|
|
{
|
|
|
|
/* We do, query its name */
|
|
|
|
Status = ObQueryNameString(LogEntry->DeviceObject,
|
|
|
|
ObjectNameInfo,
|
|
|
|
sizeof(OBJECT_NAME_INFORMATION) +
|
|
|
|
100 -
|
|
|
|
DriverNameLength,
|
|
|
|
&ReturnedLength);
|
|
|
|
if ((!NT_SUCCESS(Status)) || !(ObjectNameInfo->Name.Length))
|
|
|
|
{
|
|
|
|
/* Setup an empty name */
|
|
|
|
ObjectNameInfo->Name.Length = 0;
|
|
|
|
ObjectNameInfo->Name.Buffer = L"";
|
|
|
|
|
|
|
|
/* Check if we failed because our buffer wasn't large enough */
|
|
|
|
if (Status == STATUS_INFO_LENGTH_MISMATCH)
|
|
|
|
{
|
|
|
|
/* Then we'll allocate one... we really want this name! */
|
|
|
|
PoolObjectNameInfo = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
ReturnedLength,
|
|
|
|
TAG_IO);
|
|
|
|
if (PoolObjectNameInfo)
|
|
|
|
{
|
|
|
|
/* Query it again */
|
|
|
|
ObjectNameInfo = PoolObjectNameInfo;
|
|
|
|
Status = ObQueryNameString(LogEntry->DeviceObject,
|
|
|
|
ObjectNameInfo,
|
|
|
|
ReturnedLength,
|
|
|
|
&ReturnedLength);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Success, update the information */
|
2007-08-05 11:27:39 +00:00
|
|
|
ObjectNameInfo->Name.Length =
|
|
|
|
100 - (USHORT)DriverNameLength;
|
2006-07-01 03:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* No device object, setup an empty name */
|
|
|
|
ObjectNameInfo->Name.Length = 0;
|
|
|
|
ObjectNameInfo->Name.Buffer = L"";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now make sure that the device name fits in our buffer, minus 2
|
|
|
|
* NULL chars, and copy the name in our string buffer
|
|
|
|
*/
|
|
|
|
DeviceNameLength = min(ObjectNameInfo->Name.Length,
|
|
|
|
RemainingLength - 2 * sizeof(UNICODE_NULL));
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(StringBuffer,
|
2006-07-01 03:36:15 +00:00
|
|
|
ObjectNameInfo->Name.Buffer,
|
|
|
|
DeviceNameLength);
|
|
|
|
|
|
|
|
/* Null-terminate the device name */
|
|
|
|
*((PWSTR)(StringBuffer + DeviceNameLength)) = L'\0';
|
|
|
|
DeviceNameLength += sizeof(WCHAR);
|
|
|
|
|
|
|
|
/* Free the buffer if we had one */
|
|
|
|
if (PoolObjectNameInfo) ExFreePool(PoolObjectNameInfo);
|
|
|
|
|
|
|
|
/* Go to the next string buffer position */
|
|
|
|
ErrorMessage->EntryData.NumberOfStrings++;
|
|
|
|
StringBuffer += DeviceNameLength;
|
|
|
|
RemainingLength -= DeviceNameLength;
|
|
|
|
|
|
|
|
/* Check if we have any extra strings */
|
|
|
|
if (Packet->NumberOfStrings)
|
|
|
|
{
|
|
|
|
/* Find out the size of the extra strings */
|
|
|
|
ExtraStringLength = LogEntry->Size -
|
|
|
|
sizeof(ERROR_LOG_ENTRY) -
|
|
|
|
Packet->StringOffset;
|
|
|
|
|
|
|
|
/* Make sure that the extra strings fit in our buffer */
|
|
|
|
if (ExtraStringLength > (RemainingLength - sizeof(UNICODE_NULL)))
|
|
|
|
{
|
|
|
|
/* They wouldn't, so set normalize the length */
|
|
|
|
MessageLength -= ExtraStringLength - RemainingLength;
|
|
|
|
ExtraStringLength = RemainingLength - sizeof(UNICODE_NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now copy the extra strings */
|
2006-10-22 09:06:58 +00:00
|
|
|
RtlCopyMemory(StringBuffer,
|
2006-07-01 03:36:15 +00:00
|
|
|
(PCHAR)Packet + Packet->StringOffset,
|
|
|
|
ExtraStringLength);
|
|
|
|
|
|
|
|
/* Null-terminate them */
|
|
|
|
*((PWSTR)(StringBuffer + ExtraStringLength)) = L'\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the driver name length */
|
|
|
|
ErrorMessage->DriverNameLength = (USHORT)DriverNameLength;
|
|
|
|
|
|
|
|
/* Update the message length to include the device and driver names */
|
|
|
|
MessageLength += DeviceNameLength + DriverNameLength;
|
|
|
|
ErrorMessage->Size = (USHORT)MessageLength;
|
|
|
|
|
|
|
|
/* Now update it again, internally, for the size of the actual LPC */
|
|
|
|
MessageLength += (FIELD_OFFSET(ELF_API_MSG, IoErrorMessage) -
|
|
|
|
FIELD_OFFSET(ELF_API_MSG, Unknown[0]));
|
|
|
|
|
|
|
|
/* Set the total and data lengths */
|
|
|
|
Message->h.u1.s1.TotalLength = (USHORT)(sizeof(PORT_MESSAGE) +
|
|
|
|
MessageLength);
|
|
|
|
Message->h.u1.s1.DataLength = (USHORT)(MessageLength);
|
|
|
|
|
|
|
|
/* Send the message */
|
|
|
|
Status = NtRequestPort(IopLogPort, (PPORT_MESSAGE)Message);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
/* Requeue log message and restart the worker */
|
2007-02-19 18:52:23 +00:00
|
|
|
ExInterlockedInsertTailList(&IopErrorLogListHead,
|
2006-07-01 03:36:15 +00:00
|
|
|
&LogEntry->ListEntry,
|
|
|
|
&IopLogListLock);
|
|
|
|
IopLogWorkerRunning = FALSE;
|
|
|
|
IopRestartLogWorker();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Derefernece the device object */
|
|
|
|
if (LogEntry->DeviceObject) ObDereferenceObject(LogEntry->DeviceObject);
|
|
|
|
if (DriverObject) ObDereferenceObject(LogEntry->DriverObject);
|
|
|
|
|
|
|
|
/* Update size */
|
|
|
|
InterlockedExchangeAdd(&IopTotalLogSize,
|
2007-08-04 08:49:47 +00:00
|
|
|
-(LONG)(LogEntry->Size -
|
|
|
|
sizeof(ERROR_LOG_ENTRY)));
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Free the LPC Message */
|
|
|
|
ExFreePool(Message);
|
|
|
|
}
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopFreeApc(IN PKAPC Apc,
|
|
|
|
IN PKNORMAL_ROUTINE *NormalRoutine,
|
|
|
|
IN PVOID *NormalContext,
|
|
|
|
IN PVOID *SystemArgument1,
|
|
|
|
IN PVOID *SystemArgument2)
|
|
|
|
{
|
|
|
|
/* Free the APC */
|
|
|
|
ExFreePool(Apc);
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IopRaiseHardError(IN PKAPC Apc,
|
|
|
|
IN PKNORMAL_ROUTINE *NormalRoutine,
|
|
|
|
IN PVOID *NormalContext,
|
|
|
|
IN PVOID *SystemArgument1,
|
|
|
|
IN PVOID *SystemArgument2)
|
|
|
|
{
|
|
|
|
PIRP Irp = (PIRP)NormalContext;
|
|
|
|
//PVPB Vpb = (PVPB)SystemArgument1;
|
|
|
|
//PDEVICE_OBJECT DeviceObject = (PDEVICE_OBJECT)SystemArgument2;
|
|
|
|
|
2009-08-15 09:42:14 +00:00
|
|
|
UNIMPLEMENTED;
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* FIXME: UNIMPLEMENTED */
|
|
|
|
Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_DISK_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUBLIC FUNCTIONS **********************************************************/
|
1998-08-25 04:27:26 +00:00
|
|
|
|
2003-07-10 15:47:00 +00:00
|
|
|
/*
|
2005-04-26 14:51:18 +00:00
|
|
|
* @implemented
|
2003-07-10 15:47:00 +00:00
|
|
|
*/
|
2006-07-01 03:36:15 +00:00
|
|
|
PVOID
|
|
|
|
NTAPI
|
|
|
|
IoAllocateErrorLogEntry(IN PVOID IoObject,
|
|
|
|
IN UCHAR EntrySize)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PERROR_LOG_ENTRY LogEntry;
|
|
|
|
ULONG LogEntrySize;
|
|
|
|
PDRIVER_OBJECT DriverObject;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
|
|
|
|
/* Make sure we have an object */
|
|
|
|
if (!IoObject) return NULL;
|
|
|
|
|
|
|
|
/* Check if we're past our buffer */
|
|
|
|
if (IopTotalLogSize > PAGE_SIZE) return NULL;
|
|
|
|
|
|
|
|
/* Calculate the total size and allocate it */
|
|
|
|
LogEntrySize = sizeof(ERROR_LOG_ENTRY) + EntrySize;
|
|
|
|
LogEntry = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
LogEntrySize,
|
|
|
|
TAG_ERROR_LOG);
|
|
|
|
if (!LogEntry) return NULL;
|
|
|
|
|
|
|
|
/* Check if this is a device object or driver object */
|
|
|
|
if (((PDEVICE_OBJECT)IoObject)->Type == IO_TYPE_DEVICE)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* It's a device, get the driver */
|
|
|
|
DeviceObject = (PDEVICE_OBJECT)IoObject;
|
|
|
|
DriverObject = DeviceObject->DriverObject;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
2006-07-01 03:36:15 +00:00
|
|
|
else if (((PDEVICE_OBJECT)IoObject)->Type == IO_TYPE_DRIVER)
|
|
|
|
{
|
|
|
|
/* It's a driver, so we don' thave a device */
|
|
|
|
DeviceObject = NULL;
|
|
|
|
DriverObject = IoObject;
|
|
|
|
}
|
|
|
|
else
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Fail */
|
|
|
|
return NULL;
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Reference the Objects */
|
|
|
|
if (DeviceObject) ObReferenceObject(DeviceObject);
|
|
|
|
if (DriverObject) ObReferenceObject(DriverObject);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Update log size */
|
|
|
|
InterlockedExchangeAdd(&IopTotalLogSize, EntrySize);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Clear the entry and set it up */
|
|
|
|
RtlZeroMemory(LogEntry, EntrySize);
|
|
|
|
LogEntry->Type = IO_TYPE_ERROR_LOG;
|
|
|
|
LogEntry->Size = EntrySize;
|
|
|
|
LogEntry->DeviceObject = DeviceObject;
|
|
|
|
LogEntry->DriverObject = DriverObject;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Return the entry data */
|
|
|
|
return (PVOID)((ULONG_PTR)LogEntry + sizeof(ERROR_LOG_ENTRY));
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2005-04-26 14:51:18 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2005-04-26 14:51:18 +00:00
|
|
|
IoFreeErrorLogEntry(IN PVOID ElEntry)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PERROR_LOG_ENTRY LogEntry;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Make sure there's an entry */
|
|
|
|
if (!ElEntry) return;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Get the actual header */
|
|
|
|
LogEntry = (PERROR_LOG_ENTRY)((ULONG_PTR)ElEntry - sizeof(ERROR_LOG_ENTRY));
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Dereference both objects */
|
|
|
|
if (LogEntry->DeviceObject) ObDereferenceObject(LogEntry->DeviceObject);
|
|
|
|
if (LogEntry->DriverObject) ObDereferenceObject(LogEntry->DriverObject);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Decrease total allocation size and free the entry */
|
|
|
|
InterlockedExchangeAdd(&IopTotalLogSize,
|
2007-08-04 08:49:47 +00:00
|
|
|
-(LONG)(LogEntry->Size - sizeof(ERROR_LOG_ENTRY)));
|
2006-07-01 03:36:15 +00:00
|
|
|
ExFreePool(LogEntry);
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2006-07-01 03:36:15 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
IoWriteErrorLogEntry(IN PVOID ElEntry)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PERROR_LOG_ENTRY LogEntry;
|
|
|
|
KIRQL Irql;
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Get the main header */
|
|
|
|
LogEntry = (PERROR_LOG_ENTRY)((ULONG_PTR)ElEntry -
|
|
|
|
sizeof(ERROR_LOG_ENTRY));
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Get time stamp */
|
|
|
|
KeQuerySystemTime(&LogEntry->TimeStamp);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Acquire the lock and insert this write in the list */
|
|
|
|
KeAcquireSpinLock(&IopLogListLock, &Irql);
|
2007-02-19 18:52:23 +00:00
|
|
|
InsertHeadList(&IopErrorLogListHead, &LogEntry->ListEntry);
|
2005-04-26 14:51:18 +00:00
|
|
|
|
2008-08-23 16:30:14 +00:00
|
|
|
/* Check if the worker is running */
|
2006-07-01 03:36:15 +00:00
|
|
|
if (!IopLogWorkerRunning)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
2007-04-09 13:00:38 +00:00
|
|
|
#if 0
|
2006-07-01 03:36:15 +00:00
|
|
|
/* It's not, initialize it and queue it */
|
|
|
|
ExInitializeWorkItem(&IopErrorLogWorkItem,
|
|
|
|
IopLogWorker,
|
|
|
|
&IopErrorLogWorkItem);
|
|
|
|
ExQueueWorkItem(&IopErrorLogWorkItem, DelayedWorkQueue);
|
|
|
|
IopLogWorkerRunning = TRUE;
|
2007-04-09 13:00:38 +00:00
|
|
|
#endif
|
2005-04-26 14:51:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Release the lock and return */
|
|
|
|
KeReleaseSpinLock(&IopLogListLock, Irql);
|
2005-05-09 01:38:29 +00:00
|
|
|
}
|
2005-04-26 14:51:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
VOID
|
2006-07-01 03:36:15 +00:00
|
|
|
NTAPI
|
|
|
|
IoRaiseHardError(IN PIRP Irp,
|
|
|
|
IN PVPB Vpb,
|
|
|
|
IN PDEVICE_OBJECT RealDeviceObject)
|
2005-04-26 14:51:18 +00:00
|
|
|
{
|
|
|
|
PETHREAD Thread = (PETHREAD)&Irp->Tail.Overlay.Thread;
|
|
|
|
PKAPC ErrorApc;
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-26 14:51:18 +00:00
|
|
|
/* Don't do anything if hard errors are disabled on the thread */
|
|
|
|
if (Thread->HardErrorsAreDisabled)
|
|
|
|
{
|
|
|
|
/* Complete the request */
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_DISK_INCREMENT);
|
|
|
|
return;
|
|
|
|
}
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-26 14:51:18 +00:00
|
|
|
/* Setup an APC */
|
2005-05-09 01:38:29 +00:00
|
|
|
ErrorApc = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
sizeof(KAPC),
|
2006-07-01 03:36:15 +00:00
|
|
|
TAG_APC);
|
2005-04-26 14:51:18 +00:00
|
|
|
KeInitializeApc(ErrorApc,
|
|
|
|
&Thread->Tcb,
|
|
|
|
Irp->ApcEnvironment,
|
|
|
|
NULL,
|
|
|
|
(PKRUNDOWN_ROUTINE)IopFreeApc,
|
|
|
|
(PKNORMAL_ROUTINE)IopRaiseHardError,
|
|
|
|
KernelMode,
|
|
|
|
Irp);
|
2005-05-09 01:38:29 +00:00
|
|
|
|
2005-04-26 14:51:18 +00:00
|
|
|
/* Queue an APC to deal with the error (see osr documentation) */
|
|
|
|
KeInsertQueueApc(ErrorApc, Vpb, RealDeviceObject, 0);
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
|
|
|
|
2003-07-10 15:47:00 +00:00
|
|
|
/*
|
|
|
|
* @unimplemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
BOOLEAN
|
2006-07-01 03:36:15 +00:00
|
|
|
NTAPI
|
|
|
|
IoRaiseInformationalHardError(IN NTSTATUS ErrorStatus,
|
|
|
|
IN PUNICODE_STRING String,
|
|
|
|
IN PKTHREAD Thread)
|
1998-08-25 04:27:26 +00:00
|
|
|
{
|
2005-04-26 14:51:18 +00:00
|
|
|
UNIMPLEMENTED;
|
2008-08-23 16:30:14 +00:00
|
|
|
return FALSE;
|
1998-08-25 04:27:26 +00:00
|
|
|
}
|
2000-03-26 19:38:32 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/*
|
IO Manager Cleanup continues:
- Removed many extra files that expanded the I/O Manager too much. We usually stick with the standard of
one object/class per file, like io/device.c or io/controller.c, so it was very confusing to have some
objects split up in 5 or 6 different files, some containing only one api. Additionally, even a third
system was used, were objects were bunched up together by class. This mess was so bad that NtCreateFile,
IopCreateFile, IoCreateFile, IopDeleteFile, NtDeleteFile and NtWriteFile were in 5 different files (as an
example).
- Cleaned up some IRP code and fixed a couple of bugs, mainly:
- Write I/O Type in IRP
- Write proper IRP Flags where they shoudl be used (Will help for completing requests when i clean up that code)
- Do *NOT* zero out buffers or data that shouldn't be zeroed. Scsiport actually dependen on this incorrect
behaviour. Code should never depend on a buffer being zeroed!
- Remove a lot of duplicated code and helper/alternate functions that weren't really useful.
- Free MDL and IRP on some failures where we didn't
- Alphabetized some of the large io files for easier lookup of functions. This and the deletions have resulted
in a completely bloated diff file. I will provide a cleaned up diff on request by manually downloading the
old revision and copy/pasting the new code directly above it. The functions which we touched are:
- IoAllocateIrp
- IoBuild[A]SyncronousFsdRequest
- IoBuildDeviceIoControlRequest
- IoInitializeIrp
- IoPageRead, IoSynchronousPageWrite
svn path=/trunk/; revision=14837
2005-04-28 00:54:59 +00:00
|
|
|
* @implemented
|
|
|
|
*/
|
2005-05-09 01:38:29 +00:00
|
|
|
BOOLEAN
|
2006-07-01 03:36:15 +00:00
|
|
|
NTAPI
|
IO Manager Cleanup continues:
- Removed many extra files that expanded the I/O Manager too much. We usually stick with the standard of
one object/class per file, like io/device.c or io/controller.c, so it was very confusing to have some
objects split up in 5 or 6 different files, some containing only one api. Additionally, even a third
system was used, were objects were bunched up together by class. This mess was so bad that NtCreateFile,
IopCreateFile, IoCreateFile, IopDeleteFile, NtDeleteFile and NtWriteFile were in 5 different files (as an
example).
- Cleaned up some IRP code and fixed a couple of bugs, mainly:
- Write I/O Type in IRP
- Write proper IRP Flags where they shoudl be used (Will help for completing requests when i clean up that code)
- Do *NOT* zero out buffers or data that shouldn't be zeroed. Scsiport actually dependen on this incorrect
behaviour. Code should never depend on a buffer being zeroed!
- Remove a lot of duplicated code and helper/alternate functions that weren't really useful.
- Free MDL and IRP on some failures where we didn't
- Alphabetized some of the large io files for easier lookup of functions. This and the deletions have resulted
in a completely bloated diff file. I will provide a cleaned up diff on request by manually downloading the
old revision and copy/pasting the new code directly above it. The functions which we touched are:
- IoAllocateIrp
- IoBuild[A]SyncronousFsdRequest
- IoBuildDeviceIoControlRequest
- IoInitializeIrp
- IoPageRead, IoSynchronousPageWrite
svn path=/trunk/; revision=14837
2005-04-28 00:54:59 +00:00
|
|
|
IoSetThreadHardErrorMode(IN BOOLEAN HardErrorEnabled)
|
|
|
|
{
|
2006-07-01 03:36:15 +00:00
|
|
|
PETHREAD Thread = PsGetCurrentThread();
|
2008-08-23 16:30:14 +00:00
|
|
|
BOOLEAN OldMode;
|
IO Manager Cleanup continues:
- Removed many extra files that expanded the I/O Manager too much. We usually stick with the standard of
one object/class per file, like io/device.c or io/controller.c, so it was very confusing to have some
objects split up in 5 or 6 different files, some containing only one api. Additionally, even a third
system was used, were objects were bunched up together by class. This mess was so bad that NtCreateFile,
IopCreateFile, IoCreateFile, IopDeleteFile, NtDeleteFile and NtWriteFile were in 5 different files (as an
example).
- Cleaned up some IRP code and fixed a couple of bugs, mainly:
- Write I/O Type in IRP
- Write proper IRP Flags where they shoudl be used (Will help for completing requests when i clean up that code)
- Do *NOT* zero out buffers or data that shouldn't be zeroed. Scsiport actually dependen on this incorrect
behaviour. Code should never depend on a buffer being zeroed!
- Remove a lot of duplicated code and helper/alternate functions that weren't really useful.
- Free MDL and IRP on some failures where we didn't
- Alphabetized some of the large io files for easier lookup of functions. This and the deletions have resulted
in a completely bloated diff file. I will provide a cleaned up diff on request by manually downloading the
old revision and copy/pasting the new code directly above it. The functions which we touched are:
- IoAllocateIrp
- IoBuild[A]SyncronousFsdRequest
- IoBuildDeviceIoControlRequest
- IoInitializeIrp
- IoPageRead, IoSynchronousPageWrite
svn path=/trunk/; revision=14837
2005-04-28 00:54:59 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Get the current value */
|
2008-08-23 16:30:14 +00:00
|
|
|
OldMode = !Thread->HardErrorsAreDisabled;
|
IO Manager Cleanup continues:
- Removed many extra files that expanded the I/O Manager too much. We usually stick with the standard of
one object/class per file, like io/device.c or io/controller.c, so it was very confusing to have some
objects split up in 5 or 6 different files, some containing only one api. Additionally, even a third
system was used, were objects were bunched up together by class. This mess was so bad that NtCreateFile,
IopCreateFile, IoCreateFile, IopDeleteFile, NtDeleteFile and NtWriteFile were in 5 different files (as an
example).
- Cleaned up some IRP code and fixed a couple of bugs, mainly:
- Write I/O Type in IRP
- Write proper IRP Flags where they shoudl be used (Will help for completing requests when i clean up that code)
- Do *NOT* zero out buffers or data that shouldn't be zeroed. Scsiport actually dependen on this incorrect
behaviour. Code should never depend on a buffer being zeroed!
- Remove a lot of duplicated code and helper/alternate functions that weren't really useful.
- Free MDL and IRP on some failures where we didn't
- Alphabetized some of the large io files for easier lookup of functions. This and the deletions have resulted
in a completely bloated diff file. I will provide a cleaned up diff on request by manually downloading the
old revision and copy/pasting the new code directly above it. The functions which we touched are:
- IoAllocateIrp
- IoBuild[A]SyncronousFsdRequest
- IoBuildDeviceIoControlRequest
- IoInitializeIrp
- IoPageRead, IoSynchronousPageWrite
svn path=/trunk/; revision=14837
2005-04-28 00:54:59 +00:00
|
|
|
|
2006-07-01 03:36:15 +00:00
|
|
|
/* Set the new one and return the old */
|
|
|
|
Thread->HardErrorsAreDisabled = !HardErrorEnabled;
|
2008-08-23 16:30:14 +00:00
|
|
|
return OldMode;
|
IO Manager Cleanup continues:
- Removed many extra files that expanded the I/O Manager too much. We usually stick with the standard of
one object/class per file, like io/device.c or io/controller.c, so it was very confusing to have some
objects split up in 5 or 6 different files, some containing only one api. Additionally, even a third
system was used, were objects were bunched up together by class. This mess was so bad that NtCreateFile,
IopCreateFile, IoCreateFile, IopDeleteFile, NtDeleteFile and NtWriteFile were in 5 different files (as an
example).
- Cleaned up some IRP code and fixed a couple of bugs, mainly:
- Write I/O Type in IRP
- Write proper IRP Flags where they shoudl be used (Will help for completing requests when i clean up that code)
- Do *NOT* zero out buffers or data that shouldn't be zeroed. Scsiport actually dependen on this incorrect
behaviour. Code should never depend on a buffer being zeroed!
- Remove a lot of duplicated code and helper/alternate functions that weren't really useful.
- Free MDL and IRP on some failures where we didn't
- Alphabetized some of the large io files for easier lookup of functions. This and the deletions have resulted
in a completely bloated diff file. I will provide a cleaned up diff on request by manually downloading the
old revision and copy/pasting the new code directly above it. The functions which we touched are:
- IoAllocateIrp
- IoBuild[A]SyncronousFsdRequest
- IoBuildDeviceIoControlRequest
- IoInitializeIrp
- IoPageRead, IoSynchronousPageWrite
svn path=/trunk/; revision=14837
2005-04-28 00:54:59 +00:00
|
|
|
}
|