Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

logger.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1992 Microsoft Corporation 00004 00005 Module Name: 00006 00007 logger.c 00008 00009 Abstract: 00010 00011 This file contains the code for the debug logging facility. 00012 00013 Author: 00014 00015 Steve Wood (stevewo) 20-Jun-1992 00016 00017 Environment: 00018 00019 kernel mode callable only. 00020 00021 Revision History: 00022 00023 20-Jun-1992 Steve Wood (stevewo) Created. 00024 00025 --*/ 00026 00027 #include "exp.h" 00028 00029 PEX_DEBUG_LOG 00030 ExCreateDebugLog( 00031 IN UCHAR MaximumNumberOfTags, 00032 IN ULONG MaximumNumberOfEvents 00033 ) 00034 { 00035 PEX_DEBUG_LOG Log; 00036 ULONG Size; 00037 00038 Size = sizeof( EX_DEBUG_LOG ) + 00039 (MaximumNumberOfTags * 00040 sizeof( EX_DEBUG_LOG_TAG ) 00041 ) + 00042 (MaximumNumberOfEvents * 00043 sizeof( EX_DEBUG_LOG_EVENT ) 00044 ); 00045 00046 00047 Log = ExAllocatePoolWithTag( NonPagedPool, Size, 'oLbD' ); 00048 if (Log != NULL) { 00049 RtlZeroMemory( Log, Size ); 00050 KeInitializeSpinLock( &Log->Lock ); 00051 Log->MaximumNumberOfTags = MaximumNumberOfTags; 00052 Log->Tags = (PEX_DEBUG_LOG_TAG)(Log + 1); 00053 Log->First = (PEX_DEBUG_LOG_EVENT)(Log->Tags + MaximumNumberOfTags); 00054 Log->Last = Log->First + MaximumNumberOfEvents; 00055 Log->Next = Log->First; 00056 } 00057 00058 return Log; 00059 } 00060 00061 UCHAR 00062 ExCreateDebugLogTag( 00063 IN PEX_DEBUG_LOG Log, 00064 IN PCHAR Name, 00065 IN UCHAR Format1, 00066 IN UCHAR Format2, 00067 IN UCHAR Format3, 00068 IN UCHAR Format4 00069 ) 00070 { 00071 KIRQL OldIrql; 00072 ULONG Size; 00073 PEX_DEBUG_LOG_TAG Tag; 00074 UCHAR TagIndex; 00075 PCHAR CapturedName; 00076 00077 Size = strlen( Name ); 00078 CapturedName = ExAllocatePoolWithTag( NonPagedPool, Size, 'oLbD' ); 00079 RtlMoveMemory( CapturedName, Name, Size + 1 ); 00080 00081 ExAcquireSpinLock( &Log->Lock, &OldIrql ); 00082 00083 if (Log->NumberOfTags < Log->MaximumNumberOfTags) { 00084 TagIndex = (UCHAR)(Log->NumberOfTags++); 00085 Tag = &Log->Tags[ TagIndex ]; 00086 Tag->Name = CapturedName; 00087 Tag->Format[ 0 ] = Format1; 00088 Tag->Format[ 1 ] = Format2; 00089 Tag->Format[ 2 ] = Format3; 00090 Tag->Format[ 3 ] = Format4; 00091 CapturedName = NULL; 00092 } 00093 else { 00094 TagIndex = (UCHAR)0xFF; 00095 } 00096 00097 ExReleaseSpinLock( &Log->Lock, OldIrql ); 00098 00099 if (CapturedName != NULL) { 00100 ExFreePool( CapturedName ); 00101 } 00102 return TagIndex; 00103 } 00104 00105 VOID 00106 ExDebugLogEvent( 00107 IN PEX_DEBUG_LOG Log, 00108 IN UCHAR Tag, 00109 IN ULONG Data1, 00110 IN ULONG Data2, 00111 IN ULONG Data3, 00112 IN ULONG Data4 00113 ) 00114 { 00115 KIRQL OldIrql; 00116 PEX_DEBUG_LOG_EVENT p; 00117 PETHREAD Thread = PsGetCurrentThread(); 00118 LARGE_INTEGER CurrentTime; 00119 00120 KeQuerySystemTime( &CurrentTime ); 00121 00122 ExAcquireSpinLock( &Log->Lock, &OldIrql ); 00123 00124 p = Log->Next; 00125 if (p == Log->Last) { 00126 p = Log->First; 00127 } 00128 Log->Next = p + 1; 00129 00130 p->ThreadId = Thread->Cid.UniqueThread; 00131 p->ProcessId = Thread->Cid.UniqueProcess; 00132 p->Time = CurrentTime.LowPart; 00133 p->Tag = Tag; 00134 p->Data[ 0 ] = Data1; 00135 p->Data[ 1 ] = Data2; 00136 p->Data[ 2 ] = Data3; 00137 p->Data[ 3 ] = Data4; 00138 00139 ExReleaseSpinLock( &Log->Lock, OldIrql ); 00140 00141 return; 00142 }

Generated on Sat May 15 19:40:39 2004 for test by doxygen 1.3.7