ReactOS 0.4.17-dev-804-g023d8af
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 257 of file ParaNdis-Debug.c.

◆ MAX_HISTORY

#define MAX_HISTORY   2

Definition at line 261 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 157 of file ParaNdis-Debug.c.

158{
159 DPrintf(level, ("[%s]=>", s));
160}
#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 162 of file ParaNdis-Debug.c.

163{
164 DPrintf(level, ("[%s]<=0x%X", s, value));
165}
Definition: pdh_main.c:96

◆ _LogOutString()

void _LogOutString ( int  level,
const char s 
)

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

168{
169 DPrintf(level, ("[%s]", s));
170}

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 313 of file ParaNdis-Debug.c.

314{
315 UINT i, n = 0;
317 for (i = 0; i < MAX_CONTEXTS; ++i)
318 {
321 if (!p) continue;
322 pSave->nofPacketsToComplete = p->NetTxPacketsToReturn;
323 pSave->nofReadyTxBuffers = p->nofFreeHardwareBuffers;
325 pSave->LastTxCompletionTimeStamp = p->LastTxCompletionTimeStamp;
327 ++n;
328 }
329 return n;
330}
#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
unsigned int UINT
Definition: sysinfo.c:13
if(dx< 0)
Definition: linetemp.h:194
void ParaNdis_CallOnBugCheck(PARANDIS_ADAPTER *pContext)
#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 243 of file ParaNdis-Debug.c.

244{
245#ifdef OVERRIDE_DEBUG_BREAK
246 if (sizeof(PVOID) == sizeof(ULONG) && pDbgBreakPoint)
247 {
248 DPrintf(0, ("Restoring original BP handler at %p", pDbgBreakPoint));
249 RtlCopyMemory(pDbgBreakPoint, DbgBreakPointChunk, sizeof(DbgBreakPointChunk));
250 }
251#endif
253 WPP_CLEANUP(pDriverObject);
254}
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 198 of file ParaNdis-Debug.c.

199{
200 NDIS_STRING usRegister, usDeregister, usPrint;
201 PVOID pr, pd;
202 BOOLEAN res;
204
208 NdisInitUnicodeString(&usPrint, L"vDbgPrintEx");
209 NdisInitUnicodeString(&usRegister, L"KeRegisterBugCheckReasonCallback");
210 NdisInitUnicodeString(&usDeregister, L"KeDeregisterBugCheckReasonCallback");
211 pd = MmGetSystemRoutineAddress(&usPrint);
212 if (pd) PrintProcedure = (vDbgPrintExType)pd;
213 pr = MmGetSystemRoutineAddress(&usRegister);
214 pd = MmGetSystemRoutineAddress(&usDeregister);
215 if (pr && pd)
216 {
219 }
220 res = BugCheckRegisterCallback(&CallbackRecord, ParaNdis_OnBugCheck, KbCallbackSecondaryDumpData, "NetKvm");
221 DPrintf(0, ("[%s] Crash callback %sregistered", __FUNCTION__, res ? "" : "NOT "));
222
223#ifdef OVERRIDE_DEBUG_BREAK
224 if (sizeof(PVOID) == sizeof(ULONG))
225 {
226 UCHAR replace[5] = {0xe9,0,0,0,0};
227 ULONG replacement;
228 NDIS_STRING usDbgBreakPointName;
229 NdisInitUnicodeString(&usDbgBreakPointName, L"DbgBreakPoint");
230 pDbgBreakPoint = (PUCHAR)MmGetSystemRoutineAddress(&usDbgBreakPointName);
231 if (pDbgBreakPoint)
232 {
233 DPrintf(0, ("Replacing original BP handler at %p", pDbgBreakPoint));
234 replacement = RtlPointerToOffset(pDbgBreakPoint + 5, AnotherDbgBreak);
235 RtlCopyMemory(replace + 1, &replacement, sizeof(replacement));
236 RtlCopyMemory(DbgBreakPointChunk, pDbgBreakPoint, sizeof(DbgBreakPointChunk));
237 RtlCopyMemory(pDbgBreakPoint, replace, sizeof(replace));
238 }
239 }
240#endif
241}
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
Definition: actypes.h:127
#define L(x)
Definition: resources.c:13
#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
INT replace(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], DWORD dwFlags, BOOL *doMore)
Definition: replace.c:38
PVOID NTAPI MmGetSystemRoutineAddress(IN PUNICODE_STRING SystemRoutineName)
Definition: sysldr.c:3669
unsigned char UCHAR
Definition: typedefs.h:53
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:1378

Referenced by DriverEntry().

◆ ParaNdis_DebugRegisterMiniport()

void ParaNdis_DebugRegisterMiniport ( PARANDIS_ADAPTER pContext,
BOOLEAN  bRegister 
)

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

299{
300 UINT i;
302 for (i = 0; i < MAX_CONTEXTS; ++i)
303 {
304 UINT64 val1 = bRegister ? 0 : (UINT_PTR)pContext;
305 UINT64 val2 = bRegister ? (UINT_PTR)pContext : 0;
306 if (BugCheckData.StaticData.PerNicData[i].Context != val1) continue;
308 break;
309 }
311}
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
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 332 of file ParaNdis-Debug.c.

338{
340 if (KbCallbackSecondaryDumpData == Reason && ReasonSpecificDataLength >= sizeof(*pDump))
341 {
342 ULONG dumpSize = sizeof(BugCheckData.Location);
343 if (!pDump->OutBuffer)
344 {
345 UINT nSaved;
346 nSaved = FillDataOnBugCheck();
347 if (pDump->InBufferLength >= dumpSize)
348 {
349 pDump->OutBuffer = pDump->InBuffer;
350 pDump->OutBufferLength = dumpSize;
351 }
352 else
353 {
355 pDump->OutBufferLength = dumpSize;
356 bNative = FALSE;
357 }
358 DPrintf(0, ("[%s] system buffer of %d, saving data for %d NIC", __FUNCTION__,pDump->InBufferLength, nSaved));
359 DPrintf(0, ("[%s] using %s buffer", __FUNCTION__, bNative ? "native" : "own"));
360 }
361 else if (pDump->OutBuffer == pDump->InBuffer)
362 {
363 RtlCopyMemory(&pDump->Guid, &ParaNdis_CrashGuid, sizeof(pDump->Guid));
364 RtlCopyMemory(pDump->InBuffer, &BugCheckData.Location, dumpSize);
365 pDump->OutBufferLength = dumpSize;
367 DPrintf(0, ("[%s] dump data (%d) at %p", __FUNCTION__, pDump->OutBufferLength, pDump->OutBuffer));
368 }
369 }
370}
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:322
_In_ struct _KBUGCHECK_REASON_CALLBACK_RECORD _Inout_ PVOID ReasonSpecificData
Definition: ketypes.h:321

◆ ParaNdis_PrepareBugCheckData()

VOID ParaNdis_PrepareBugCheckData ( )
static

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

282{
296}
#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 172 of file ParaNdis-Debug.c.

178{
179#if WPP_USE_BYPASS
180 DPrintfBypass(0, ("[%s] %s, flags %X, level %d",
181 __FUNCTION__, Enable ? "enabled" : "disabled",
182 Flags, (ULONG)Level));
183#endif
186}
int nDebugLevel
int bDebugPrint
_In_ ULONG _In_ UCHAR Level
Definition: dispmprt.h:1329
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define DPrintfBypass(Level, Fmt)
Definition: kdebugprint.h:63
_In_ ULONGLONG _In_ ULONGLONG _In_ BOOLEAN Enable
Definition: ntddpcm.h:142

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 279 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 149 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 150 of file ParaNdis-Debug.c.