From 58b09f3345df5439554b6960bf3090e372b9d4b7 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Fri, 20 Jun 2003 22:43:27 +0000 Subject: [PATCH] Initial work on error logging. svn path=/trunk/; revision=4935 --- reactos/ntoskrnl/include/internal/io.h | 8 ++- reactos/ntoskrnl/io/errlog.c | 96 +++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 12 deletions(-) diff --git a/reactos/ntoskrnl/include/internal/io.h b/reactos/ntoskrnl/include/internal/io.h index 56c740c571c..32af4261df7 100644 --- a/reactos/ntoskrnl/include/internal/io.h +++ b/reactos/ntoskrnl/include/internal/io.h @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: io.h,v 1.31 2003/05/22 00:47:04 gdalsnes Exp $ +/* $Id: io.h,v 1.32 2003/06/20 22:42:18 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -337,6 +337,12 @@ NTSTATUS IoDestroyDriverList(VOID); +/* errlog.c */ + +NTSTATUS +IopInitErrorLog (VOID); + + /* rawfs.c */ BOOLEAN diff --git a/reactos/ntoskrnl/io/errlog.c b/reactos/ntoskrnl/io/errlog.c index eb60e40ec56..4f605c4485a 100644 --- a/reactos/ntoskrnl/io/errlog.c +++ b/reactos/ntoskrnl/io/errlog.c @@ -1,4 +1,4 @@ -/* $Id: errlog.c,v 1.8 2002/09/08 10:23:24 chorns Exp $ +/* $Id: errlog.c,v 1.9 2003/06/20 22:43:27 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -15,13 +15,11 @@ #include +//#define NDEBUG #include /* TYPES *********************************************************************/ -#define LOG_FILE_APPLICATION L"\\SystemRoot\\System32\\Config\\AppEvent.Evt" -#define LOG_FILE_SECURITY L"\\SystemRoot\\System32\\Config\\SecEvent.Evt" -#define LOG_FILE_SYSTEM L"\\SystemRoot\\System32\\Config\\SysEvent.Evt" typedef struct _IO_ERROR_LOG_PACKET { @@ -40,21 +38,97 @@ typedef struct _IO_ERROR_LOG_PACKET ULONG DumpData[1]; } IO_ERROR_LOG_PACKET, *PIO_ERROR_LOG_PACKET; +typedef struct _ERROR_LOG_ENTRY +{ + ULONG EntrySize; +} ERROR_LOG_ENTRY, *PERROR_LOG_ENTRY; + + +/* GLOBALS *******************************************************************/ + +static KSPIN_LOCK IopAllocationLock; +static ULONG IopTotalLogSize; + + /* FUNCTIONS *****************************************************************/ -NTSTATUS IoInitErrorLog(VOID) +NTSTATUS +IopInitErrorLog (VOID) { - return(STATUS_SUCCESS); + IopTotalLogSize = 0; + KeInitializeSpinLock (&IopAllocationLock); + + return STATUS_SUCCESS; } -PVOID STDCALL IoAllocateErrorLogEntry(PVOID IoObject, UCHAR EntrySize) + +PVOID STDCALL +IoAllocateErrorLogEntry (IN PVOID IoObject, + IN UCHAR EntrySize) { - UNIMPLEMENTED; + PERROR_LOG_ENTRY LogEntry; + ULONG LogEntrySize; + KIRQL Irql; + + DPRINT1 ("IoAllocateErrorLogEntry() called\n"); + + if (IoObject == NULL) + return NULL; + + KeAcquireSpinLock (&IopAllocationLock, + &Irql); + + if (IopTotalLogSize > PAGE_SIZE) + { + KeReleaseSpinLock (&IopAllocationLock, + Irql); + return NULL; + } + + LogEntrySize = sizeof(ERROR_LOG_ENTRY) + EntrySize; + LogEntry = ExAllocatePool (NonPagedPool, + LogEntrySize); + if (LogEntry == NULL) + { + KeReleaseSpinLock (&IopAllocationLock, + Irql); + return NULL; + } + + IopTotalLogSize += EntrySize; + + LogEntry->EntrySize = LogEntrySize; + + KeReleaseSpinLock (&IopAllocationLock, + Irql); + + return (PVOID)((ULONG_PTR)LogEntry + sizeof(ERROR_LOG_ENTRY)); } -VOID STDCALL IoWriteErrorLogEntry(PVOID ElEntry) -{ -} +VOID STDCALL +IoWriteErrorLogEntry (IN PVOID ElEntry) +{ + PERROR_LOG_ENTRY LogEntry; + KIRQL Irql; + + DPRINT1 ("IoWriteErrorLogEntry() called\n"); + + LogEntry = (PERROR_LOG_ENTRY)((ULONG_PTR)ElEntry - sizeof(ERROR_LOG_ENTRY)); + + + /* FIXME: Write log entry to the error log port or keep it in a list */ + + + /* Release error log entry */ + KeAcquireSpinLock (&IopAllocationLock, + &Irql); + + IopTotalLogSize -= LogEntry->EntrySize; + ExFreePool (LogEntry); + + KeReleaseSpinLock (&IopAllocationLock, + Irql); +} /* EOF */