ReactOS 0.4.15-dev-7942-gd23573b
ParaNdis-Debug.c File Reference
#include "ndis56common.h"
#include "stdarg.h"
#include "ntstrsafe.h"
Include dependency graph for ParaNdis-Debug.c:

Go to the source code of this file.

Classes

struct  _tagBugCheckStaticData
 
struct  _tagBugCheckData
 

Macros

#define MAX_CONTEXTS   4
 
#define MAX_HISTORY   2
 

Typedefs

typedef BOOLEAN(NTAPIKeRegisterBugCheckReasonCallbackType) (__out PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord, __in PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine, __in KBUGCHECK_CALLBACK_REASON Reason, __in PUCHAR Component)
 
typedef BOOLEAN(NTAPIKeDeregisterBugCheckReasonCallbackType) (__inout PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord)
 
typedef ULONG(NTAPIvDbgPrintExType) (__in ULONG ComponentId, __in ULONG Level, __in PCCH Format, __in va_list arglist)
 
typedef struct _tagBugCheckStaticData tBugCheckStaticData
 
typedef struct _tagBugCheckData tBugCheckData
 

Functions

static VOID NTAPI ParaNdis_OnBugCheck (IN KBUGCHECK_CALLBACK_REASON Reason, IN PKBUGCHECK_REASON_CALLBACK_RECORD Record, IN OUT PVOID ReasonSpecificData, IN ULONG ReasonSpecificDataLength)
 
static VOID ParaNdis_PrepareBugCheckData ()
 
static ULONG NTAPI DummyPrintProcedure (__in ULONG ComponentId, __in ULONG Level, __in PCCH Format, __in va_list arglist)
 
static BOOLEAN NTAPI KeRegisterBugCheckReasonCallbackDummyProc (__out PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord, __in PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine, __in KBUGCHECK_CALLBACK_REASON Reason, __in PUCHAR Component)
 
BOOLEAN NTAPI KeDeregisterBugCheckReasonCallbackDummyProc (__inout PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord)
 
void _LogOutEntry (int level, const char *s)
 defined(WPP_EVENT_TRACING) || defined(WPP_USE_BYPASS)
 
void _LogOutExitValue (int level, const char *s, ULONG value)
 
void _LogOutString (int level, const char *s)
 
VOID WppEnableCallback (__in LPCGUID Guid, __in __int64 Logger, __in BOOLEAN Enable, __in ULONG Flags, __in UCHAR Level)
 
void ParaNdis_DebugInitialize (PVOID DriverObject, PVOID RegistryPath)
 
void ParaNdis_DebugCleanup (PDRIVER_OBJECT pDriverObject)
 
void ParaNdis_DebugRegisterMiniport (PARANDIS_ADAPTER *pContext, BOOLEAN bRegister)
 
static UINT FillDataOnBugCheck ()
 

Variables

int virtioDebugLevel = 1
 
int nDebugLevel = 1
 
int bDebugPrint = 1
 
static NDIS_SPIN_LOCK CrashLock
 
static KBUGCHECK_REASON_CALLBACK_ROUTINE ParaNdis_OnBugCheck
 
static vDbgPrintExType PrintProcedure = DummyPrintProcedure
 
static KeRegisterBugCheckReasonCallbackType BugCheckRegisterCallback = KeRegisterBugCheckReasonCallbackDummyProc
 
static KeDeregisterBugCheckReasonCallbackType BugCheckDeregisterCallback = KeDeregisterBugCheckReasonCallbackDummyProc
 
KBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord
 
DEBUGPRINTFUNC pDebugPrint = DbgPrint
 
DEBUGPRINTFUNC VirtioDebugPrintProc = DbgPrint
 
static tBugCheckData BugCheckData
 
static BOOLEAN bNative = TRUE
 

Macro Definition Documentation

◆ MAX_CONTEXTS

#define MAX_CONTEXTS   4

Definition at line 253 of file ParaNdis-Debug.c.

◆ MAX_HISTORY

#define MAX_HISTORY   2

Definition at line 257 of file ParaNdis-Debug.c.

Typedef Documentation

◆ KeDeregisterBugCheckReasonCallbackType

typedef BOOLEAN(NTAPI * KeDeregisterBugCheckReasonCallbackType) (__inout PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord)

Definition at line 61 of file ParaNdis-Debug.c.

◆ KeRegisterBugCheckReasonCallbackType

◆ tBugCheckData

◆ tBugCheckStaticData

◆ vDbgPrintExType

Definition at line 65 of file ParaNdis-Debug.c.

Function Documentation

◆ _LogOutEntry()

void _LogOutEntry ( int  level,
const char s 
)

defined(WPP_EVENT_TRACING) || defined(WPP_USE_BYPASS)

Definition at line 153 of file ParaNdis-Debug.c.

154{
155 DPrintf(level, ("[%s]=>", s));
156}
#define DPrintf(Level, Fmt)
Definition: kdebugprint.h:61
GLint level
Definition: gl.h:1546
GLdouble s
Definition: gl.h:2039

◆ _LogOutExitValue()

void _LogOutExitValue ( int  level,
const char s,
ULONG  value 
)

Definition at line 158 of file ParaNdis-Debug.c.

159{
160 DPrintf(level, ("[%s]<=0x%X", s, value));
161}
Definition: pdh_main.c:94

◆ _LogOutString()

void _LogOutString ( int  level,
const char s 
)

Definition at line 163 of file ParaNdis-Debug.c.

164{
165 DPrintf(level, ("[%s]", s));
166}

Referenced by DriverEntry().

◆ DummyPrintProcedure()

static ULONG NTAPI DummyPrintProcedure ( __in ULONG  ComponentId,
__in ULONG  Level,
__in PCCH  Format,
__in va_list  arglist 
)
static

Definition at line 72 of file ParaNdis-Debug.c.

78{
79 return 0;
80}

◆ FillDataOnBugCheck()

static UINT FillDataOnBugCheck ( )
static

Definition at line 309 of file ParaNdis-Debug.c.

310{
311 UINT i, n = 0;
313 for (i = 0; i < MAX_CONTEXTS; ++i)
314 {
317 if (!p) continue;
318 pSave->nofPacketsToComplete = p->NetTxPacketsToReturn;
319 pSave->nofReadyTxBuffers = p->nofFreeHardwareBuffers;
321 pSave->LastTxCompletionTimeStamp = p->LastTxCompletionTimeStamp;
323 ++n;
324 }
325 return n;
326}
#define PARANDIS_GET_LAST_INTERRUPT_TIMESTAMP(p)
Definition: DebugData.h:109
static tBugCheckData BugCheckData
#define MAX_CONTEXTS
GLdouble n
Definition: glext.h:7729
GLfloat GLfloat p
Definition: glext.h:8902
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
if(dx< 0)
Definition: linetemp.h:194
void ParaNdis_CallOnBugCheck(PARANDIS_ADAPTER *pContext)
unsigned int UINT
Definition: ndis.h:50
#define NdisGetCurrentSystemTime
Definition: ndis.h:4462
tBugCheckStaticData StaticData
LARGE_INTEGER LastInterruptTimeStamp
Definition: DebugData.h:119
LARGE_INTEGER LastTxCompletionTimeStamp
Definition: DebugData.h:120
LARGE_INTEGER qCrashTime
Definition: DebugData.h:78
tBugCheckPerNicDataContent PerNicData[MAX_CONTEXTS]
tBugCheckStaticDataHeader Header
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by ParaNdis_OnBugCheck().

◆ KeDeregisterBugCheckReasonCallbackDummyProc()

BOOLEAN NTAPI KeDeregisterBugCheckReasonCallbackDummyProc ( __inout PKBUGCHECK_REASON_CALLBACK_RECORD  CallbackRecord)

Definition at line 92 of file ParaNdis-Debug.c.

95{
96 return FALSE;
97}
#define FALSE
Definition: types.h:117

◆ KeRegisterBugCheckReasonCallbackDummyProc()

static BOOLEAN NTAPI KeRegisterBugCheckReasonCallbackDummyProc ( __out PKBUGCHECK_REASON_CALLBACK_RECORD  CallbackRecord,
__in PKBUGCHECK_REASON_CALLBACK_ROUTINE  CallbackRoutine,
__in KBUGCHECK_CALLBACK_REASON  Reason,
__in PUCHAR  Component 
)
static

Definition at line 81 of file ParaNdis-Debug.c.

87{
89 return FALSE;
90}
KBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord

◆ ParaNdis_DebugCleanup()

void ParaNdis_DebugCleanup ( PDRIVER_OBJECT  pDriverObject)

Definition at line 239 of file ParaNdis-Debug.c.

240{
241#ifdef OVERRIDE_DEBUG_BREAK
242 if (sizeof(PVOID) == sizeof(ULONG) && pDbgBreakPoint)
243 {
244 DPrintf(0, ("Restoring original BP handler at %p", pDbgBreakPoint));
245 RtlCopyMemory(pDbgBreakPoint, DbgBreakPointChunk, sizeof(DbgBreakPointChunk));
246 }
247#endif
249 WPP_CLEANUP(pDriverObject);
250}
static KeDeregisterBugCheckReasonCallbackType BugCheckDeregisterCallback
#define WPP_CLEANUP(a)
Definition: kdebugprint.h:57
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59

Referenced by ParaVirtualNICUnload().

◆ ParaNdis_DebugInitialize()

void ParaNdis_DebugInitialize ( PVOID  DriverObject,
PVOID  RegistryPath 
)

Definition at line 194 of file ParaNdis-Debug.c.

195{
196 NDIS_STRING usRegister, usDeregister, usPrint;
197 PVOID pr, pd;
198 BOOLEAN res;
200
204 NdisInitUnicodeString(&usPrint, L"vDbgPrintEx");
205 NdisInitUnicodeString(&usRegister, L"KeRegisterBugCheckReasonCallback");
206 NdisInitUnicodeString(&usDeregister, L"KeDeregisterBugCheckReasonCallback");
207 pd = MmGetSystemRoutineAddress(&usPrint);
208 if (pd) PrintProcedure = (vDbgPrintExType)pd;
209 pr = MmGetSystemRoutineAddress(&usRegister);
210 pd = MmGetSystemRoutineAddress(&usDeregister);
211 if (pr && pd)
212 {
215 }
216 res = BugCheckRegisterCallback(&CallbackRecord, ParaNdis_OnBugCheck, KbCallbackSecondaryDumpData, "NetKvm");
217 DPrintf(0, ("[%s] Crash callback %sregistered", __FUNCTION__, res ? "" : "NOT "));
218
219#ifdef OVERRIDE_DEBUG_BREAK
220 if (sizeof(PVOID) == sizeof(ULONG))
221 {
222 UCHAR replace[5] = {0xe9,0,0,0,0};
223 ULONG replacement;
224 NDIS_STRING usDbgBreakPointName;
225 NdisInitUnicodeString(&usDbgBreakPointName, L"DbgBreakPoint");
226 pDbgBreakPoint = (PUCHAR)MmGetSystemRoutineAddress(&usDbgBreakPointName);
227 if (pDbgBreakPoint)
228 {
229 DPrintf(0, ("Replacing original BP handler at %p", pDbgBreakPoint));
230 replacement = RtlPointerToOffset(pDbgBreakPoint + 5, AnotherDbgBreak);
231 RtlCopyMemory(replace + 1, &replacement, sizeof(replacement));
232 RtlCopyMemory(DbgBreakPointChunk, pDbgBreakPoint, sizeof(DbgBreakPointChunk));
233 RtlCopyMemory(pDbgBreakPoint, replace, sizeof(replace));
234 }
235 }
236#endif
237}
BOOLEAN(NTAPI * KeDeregisterBugCheckReasonCallbackType)(__inout PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord)
BOOLEAN(NTAPI * KeRegisterBugCheckReasonCallbackType)(__out PKBUGCHECK_REASON_CALLBACK_RECORD CallbackRecord, __in PKBUGCHECK_REASON_CALLBACK_ROUTINE CallbackRoutine, __in KBUGCHECK_CALLBACK_REASON Reason, __in PUCHAR Component)
static KeRegisterBugCheckReasonCallbackType BugCheckRegisterCallback
ULONG(NTAPI * vDbgPrintExType)(__in ULONG ComponentId, __in ULONG Level, __in PCCH Format, __in va_list arglist)
static NDIS_SPIN_LOCK CrashLock
static VOID ParaNdis_PrepareBugCheckData()
static vDbgPrintExType PrintProcedure
static KBUGCHECK_REASON_CALLBACK_ROUTINE ParaNdis_OnBugCheck
unsigned char BOOLEAN
#define __FUNCTION__
Definition: types.h:116
#define WPP_INIT_TRACING(a, b)
Definition: kdebugprint.h:56
VOID EXPORT NdisInitUnicodeString(IN OUT PNDIS_STRING DestinationString, IN PCWSTR SourceString)
Definition: string.c:130
GLuint res
Definition: glext.h:9613
#define RtlPointerToOffset(Base, Pointer)
Definition: ndis56common.h:54
#define NdisAllocateSpinLock(_SpinLock)
Definition: ndis.h:4088
#define L(x)
Definition: ntvdm.h:50
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:47
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3604
unsigned char * PUCHAR
Definition: typedefs.h:53
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define KeInitializeCallbackRecord(CallbackRecord)
Definition: kefuncs.h:1387
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by DriverEntry().

◆ ParaNdis_DebugRegisterMiniport()

void ParaNdis_DebugRegisterMiniport ( PARANDIS_ADAPTER pContext,
BOOLEAN  bRegister 
)

Definition at line 294 of file ParaNdis-Debug.c.

295{
296 UINT i;
298 for (i = 0; i < MAX_CONTEXTS; ++i)
299 {
300 UINT64 val1 = bRegister ? 0 : (UINT_PTR)pContext;
301 UINT64 val2 = bRegister ? (UINT_PTR)pContext : 0;
302 if (BugCheckData.StaticData.PerNicData[i].Context != val1) continue;
304 break;
305 }
307}
unsigned long long UINT64
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
#define NdisReleaseSpinLock(_SpinLock)
Definition: ndis.h:4115
#define NdisAcquireSpinLock(_SpinLock)
Definition: ndis.h:4106

Referenced by ParaNdis5_Halt(), and ParaNdis5_Initialize().

◆ ParaNdis_OnBugCheck()

static VOID NTAPI ParaNdis_OnBugCheck ( IN KBUGCHECK_CALLBACK_REASON  Reason,
IN PKBUGCHECK_REASON_CALLBACK_RECORD  Record,
IN OUT PVOID  ReasonSpecificData,
IN ULONG  ReasonSpecificDataLength 
)
static

Definition at line 328 of file ParaNdis-Debug.c.

334{
336 if (KbCallbackSecondaryDumpData == Reason && ReasonSpecificDataLength >= sizeof(*pDump))
337 {
338 ULONG dumpSize = sizeof(BugCheckData.Location);
339 if (!pDump->OutBuffer)
340 {
341 UINT nSaved;
342 nSaved = FillDataOnBugCheck();
343 if (pDump->InBufferLength >= dumpSize)
344 {
345 pDump->OutBuffer = pDump->InBuffer;
346 pDump->OutBufferLength = dumpSize;
347 }
348 else
349 {
351 pDump->OutBufferLength = dumpSize;
352 bNative = FALSE;
353 }
354 DPrintf(0, ("[%s] system buffer of %d, saving data for %d NIC", __FUNCTION__,pDump->InBufferLength, nSaved));
355 DPrintf(0, ("[%s] using %s buffer", __FUNCTION__, bNative ? "native" : "own"));
356 }
357 else if (pDump->OutBuffer == pDump->InBuffer)
358 {
359 RtlCopyMemory(&pDump->Guid, &ParaNdis_CrashGuid, sizeof(pDump->Guid));
360 RtlCopyMemory(pDump->InBuffer, &BugCheckData.Location, dumpSize);
361 pDump->OutBufferLength = dumpSize;
363 DPrintf(0, ("[%s] dump data (%d) at %p", __FUNCTION__, pDump->OutBufferLength, pDump->OutBuffer));
364 }
365 }
366}
static const GUID ParaNdis_CrashGuid
Definition: DebugData.h:68
static BOOLEAN bNative
static UINT FillDataOnBugCheck()
PVOID PVOID PWCHAR PVOID USHORT PULONG Reason
Definition: env.c:47
tBugCheckDataLocation Location
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD _Inout_ PVOID _In_ ULONG ReasonSpecificDataLength
Definition: ketypes.h:270
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD _Inout_ PVOID ReasonSpecificData
Definition: ketypes.h:269

◆ ParaNdis_PrepareBugCheckData()

VOID ParaNdis_PrepareBugCheckData ( )
static

Definition at line 277 of file ParaNdis-Debug.c.

278{
292}
#define PARANDIS_DEBUG_PER_NIC_DATA_VERSION
Definition: DebugData.h:92
tBugCheckHistoryDataEntry_V1 tBugCheckHistoryDataEntry
Definition: DebugData.h:161
#define PARANDIS_DEBUG_HISTORY_DATA_VERSION
Definition: DebugData.h:93
#define PARANDIS_DEBUG_STATIC_DATA_VERSION
Definition: DebugData.h:91
#define MAX_HISTORY
tBugCheckStaticDataContent Data
tBugCheckHistoryDataEntry History[MAX_HISTORY]
void * PVOID
Definition: typedefs.h:50

Referenced by ParaNdis_DebugInitialize().

◆ WppEnableCallback()

VOID WppEnableCallback ( __in LPCGUID  Guid,
__in __int64  Logger,
__in BOOLEAN  Enable,
__in ULONG  Flags,
__in UCHAR  Level 
)

Definition at line 168 of file ParaNdis-Debug.c.

174{
175#if WPP_USE_BYPASS
176 DPrintfBypass(0, ("[%s] %s, flags %X, level %d",
177 __FUNCTION__, Enable ? "enabled" : "disabled",
178 Flags, (ULONG)Level));
179#endif
182}
int nDebugLevel
int bDebugPrint
#define DPrintfBypass(Level, Fmt)
Definition: kdebugprint.h:63
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:56
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Variable Documentation

◆ bDebugPrint

int bDebugPrint = 1

Definition at line 41 of file ParaNdis-Debug.c.

Referenced by ReadNicConfiguration(), and WppEnableCallback().

◆ bNative

BOOLEAN bNative = TRUE
static

Definition at line 275 of file ParaNdis-Debug.c.

Referenced by ParaNdis_OnBugCheck().

◆ BugCheckData

◆ BugCheckDeregisterCallback

◆ BugCheckRegisterCallback

Definition at line 100 of file ParaNdis-Debug.c.

Referenced by ParaNdis_DebugInitialize().

◆ CallbackRecord

◆ CrashLock

NDIS_SPIN_LOCK CrashLock
static

Definition at line 43 of file ParaNdis-Debug.c.

Referenced by ParaNdis_DebugInitialize(), and ParaNdis_DebugRegisterMiniport().

◆ nDebugLevel

int nDebugLevel = 1

Definition at line 40 of file ParaNdis-Debug.c.

Referenced by ReadNicConfiguration(), and WppEnableCallback().

◆ ParaNdis_OnBugCheck

VOID NTAPI ParaNdis_OnBugCheck
static

Definition at line 45 of file ParaNdis-Debug.c.

Referenced by ParaNdis_DebugInitialize().

◆ pDebugPrint

DEBUGPRINTFUNC pDebugPrint = DbgPrint

Definition at line 145 of file ParaNdis-Debug.c.

◆ PrintProcedure

vDbgPrintExType PrintProcedure = DummyPrintProcedure
static

Definition at line 99 of file ParaNdis-Debug.c.

Referenced by ParaNdis_DebugInitialize().

◆ virtioDebugLevel

int virtioDebugLevel = 1

Definition at line 39 of file ParaNdis-Debug.c.

◆ VirtioDebugPrintProc

DEBUGPRINTFUNC VirtioDebugPrintProc = DbgPrint

Definition at line 146 of file ParaNdis-Debug.c.