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

memprint.h File Reference

Go to the source code of this file.

Defines

#define MEM_PRINT_FLAG_CONSOLE   0x01
#define MEM_PRINT_FLAG_FILE   0x02
#define MEM_PRINT_FLAG_HEADER   0x04
#define MEM_PRINT_DEF_BUFFER_SIZE   65536
#define MEM_PRINT_DEF_SUBBUFFER_COUNT   16
#define MEM_PRINT_MAX_SUBBUFFER_COUNT   64
#define MEM_PRINT_LOG_FILE_NAME   "\\SystemRoot\\Logfile"
#define DbgPrint   MemPrint

Functions

VOID MemPrintInitialize (VOID)
VOID MemPrint (CHAR *Format,...)
VOID MemPrintFlush (VOID)

Variables

ULONG MemPrintFlags


Define Documentation

#define DbgPrint   MemPrint
 

Definition at line 79 of file memprint.h.

Referenced by AggregatePages(), ArbpIndent(), bCheckIfDualBootingWithWin31(), BrokenConnection(), CcWriteBehind(), CheckPool(), CloseAProc(), CmpAppendStringToMultiSz(), CmpCheckOperator(), CmpDoFileSetSize(), CmpEnumKeyObjectCallback(), CmpFileFlush(), CmpFileRead(), CmpFileWrite(), CmpFindACPITable(), CmpFindRSDTTable(), CmpFlushNotify(), CmpFreePostBlock(), CmpMatchInfList(), CmpOpenInfFile(), CmpProcessBitRegLine(), CmpSecurityExceptionFilter(), CmpSetVersionData(), ConnectToTerminalServer(), ConsoleWindowProc(), ConvertToFullScreen(), CreateConsoleBitmap(), CreateDAclToken(), CreateWindowsWindow(), CsrClientCallServer(), CsrpConnectToServer(), CTAccess(), CtLnpQos(), CtLpcQos(), CTToken(), CtxBadAppDelay(), DbgSsHandleKmApiMsg(), DbgUiContinue(), DbgUiWaitStateChange(), DeleteAProc(), DeleteBProc(), DoBitMapTest(), DoCreateScreenBuffer(), DoEventTest(), DoExceptionTest(), DoHandleTest(), DoInfoTest(), DoLuidTest(), DoMemoryTest(), DoMutantTest(), DoPartyTest(), DoResourceTest(), DoSemaphoreTest(), DoTest(), DoTimerTest(), DoZoneTest(), DrChangeDisplaySettings(), DrGetDeviceName(), DrivesupDebugPrint(), DumpAcl(), DumpAclSizeInfo(), DumpAllocatedPool(), DumpAProc(), DumpBProc(), DumpIt(), DumpObjectDirs(), DumpPool(), DumpString(), ExAllocatePool(), ExceptionTest(), ExExtendZone(), ExFreePool(), ExFreePoolWithTag(), ExInitializeZone(), ExpCheckForResource(), ExpCreateWorkerThread(), ExpDetectWorkerThreadDeadlock(), ExpGetGlobalAtomTable(), ExpWaitForResource(), ExpWaitForResourceDdk(), ExpWorkerThread(), ExRaiseException(), ExRaiseStatus(), ExTest(), FindImeHotKeyByKey(), fp_emulate(), FreeDesktop(), FsRtlAddToTunnelCache(), FsRtlDeleteKeyFromTunnelCache(), FsRtlFindInTunnelCache(), FsRtlPruneTunnelCache(), GetRegistryValues(), ImmIsUIMessageWorker(), InitExtendedEditKeys(), InitSwitchWndInfo(), InputExceptionFilter(), IoInitSystem(), IopAssign(), IopBuildCmResourceLists(), IopCallDriverAddDevice(), IopChildToRootTranslation(), IopCreateArcNames(), IopDriverCorrectnessPrintBuffer(), IopDriverCorrectnessPrintIrp(), IopDriverCorrectnessPrintIrpStack(), IopDriverCorrectnessPrompt(), IopDumpCmResourceDescriptor(), IopDumpCmResourceList(), IopDumpResourceDescriptor(), IopDumpResourceRequirementsList(), IopEnumerateDevice(), IopGetDeviceInterfaces(), IopGetRelatedTargetDevice(), IopInitializeBootDrivers(), IopInitializeBuiltinDriver(), IopLoadDriver(), IopMakeGloballyUniqueId(), IopNotifyDeviceClassChange(), IopNotifyHwProfileChange(), IopNotifyTargetDeviceChange(), IopPlacementForReservation(), IopQueryDeviceResources(), IopQueryLegacyBusInformation(), IopQueryPnpBusInformation(), IopRequestHwProfileChangeNotification(), IopReserveBootResourcesInternal(), IopReserveLegacyBootResources(), IopResourceRequirementsListToReqList(), IopRestoreResourcesInternal(), IopStoreSystemPartitionInformation(), IopUnloadAttachedDriver(), IoRegisterPlugPlayNotification(), IoReportTargetDeviceChange(), IoReportTargetDeviceChangeAsynchronous(), IoShutdownSystem(), IovpCompleteRequest3(), IovSpecialIrpCallDriver(), KeBugCheckEx(), KeConnectInterrupt(), KeContextFromKframes(), KeContextToKframes(), KeContextToKframesSpecial(), KeRestoreFloatingPointState(), KeSetAutoAlignmentThread(), KiDispatchException(), KiFlushUserRseState(), KiGetVectorInfo(), KiIA32ExceptionAlignmentFault(), KiIA32ExceptionBound(), KiIA32ExceptionBreak(), KiIA32ExceptionDebug(), KiIA32ExceptionFPFault(), KiIA32ExceptionGPFault(), KiIA32ExceptionInvalidOp(), KiIA32ExceptionKNI(), KiIA32ExceptionNoDevice(), KiIA32ExceptionOverflow(), KiIA32ExceptionSegmentNotPresent(), KiIA32ExceptionStack(), KiIA32ExceptionVectorHandler(), KiIA32InterceptGate(), KiIA32InterceptInstruction(), KiIA32InterceptionVectorHandler(), KiIA32InterceptLock(), KiIA32InterceptSystemFlag(), KiIA32InterruptionVectorHandler(), KiIA32InterruptVector(), KiInitExceptionFilter(), KiInitializeKernel(), KillProcess(), KiMachineCheck(), KiNatExceptions(), KiSystemServiceHandler(), LdrGetDllHandle(), LdrpAllocateTls(), LdrpCallTlsInitializers(), LdrpCheckForLoadedDll(), LdrpCreateDllSection(), LdrpDphDetectSnapRoutines(), LdrpDphInitializeTargetDll(), LdrpDphSnapImports(), LdrpGetFileVersion(), LdrpGetProcedureAddress(), LdrpInitialize(), LdrpInitializeProcess(), LdrpInitializeTls(), LdrpLoadDll(), LdrpMapDll(), LdrpResolveDllName(), LdrpRunInitializeRoutines(), LdrpSnapThunk(), LdrpUpdateLoadCount(), LdrpWalkImportDescriptor(), LdrRelocateImage(), LdrShutdownProcess(), LdrUnloadDll(), LoadLinkInfo(), main(), MemPrint(), MemPrintFlush(), MemPrintInitialize(), MemPrintWriteCompleteApc(), MemPrintWriteThread(), MergeAttrStrings(), MiAllocatePoolPages(), MiAttemptPageFileReduction(), MiBuildImportsForBootDrivers(), MiCheckAndSetSystemTrimCriteria(), MiCheckMemoryDescriptorList(), MiCheckPdeForSessionSpace(), MiCheckProcessTrimCriteria(), MiCheckSessionPoolAllocations(), MiCleanSection(), MiCloneProcessAddressSpace(), MiCompleteProtoPteFault(), MiCopyOnWrite(), MiDecrementCloneBlockReference(), MiDeletePte(), MiDeleteSystemPagableVm(), MiDeleteVirtualAddresses(), MiDereferenceSegmentThread(), MiDispatchFault(), MiEnablePagingOfDriver(), MiEnsureAvailablePageOrWait(), MiFindInitializationCode(), MiFlushSectionInternal(), MiFreePoolPages(), MiFreeSessionSpaceMap(), MiGatherMappedPages(), MiGatherPagefilePages(), MiInitializePfn(), MiInitializePfnForOtherProcess(), MiInitMachineDependent(), MiInsertWsle(), MiLoadImageSection(), MiLoadSystemImage(), MiMapImageHeaderInHyperSpace(), MiMapPageInHyperSpace(), MiMapPageToZeroInHyperSpace(), MiMapViewOfImageSection(), MiMapViewOfPhysicalSection(), MiPurgeImageSection(), MiRearrangeWorkingSetExpansionList(), MiReleaseSystemPtes(), MiReloadBootLoadedDrivers(), MiRemoveUnusedSegments(), MiRemoveUserPhysicalPagesVad(), MiRemoveWorkingSetPages(), MiRemoveWsle(), MiReserveSystemPtes2(), MiResolvePageFileFault(), MiResolveProtoPteFault(), MiResolveTransitionFault(), MiSectionDelete(), MiSegmentDelete(), MiSessionCommitImagePages(), MiSessionCreateInternal(), MiSessionDeletePde(), MiSessionInitializeWorkingSetList(), MiSessionInSwapProcess(), MiSessionOutSwapProcess(), MiSessionWideReserveImageAddress(), MiUnlinkPageFromList(), MiVerifyingDriverUnloading(), MiWaitForInPageComplete(), MiWriteComplete(), MmAccessFault(), MmAllocatePagesForMdl(), MmCleanProcessAddressSpace(), MmCreateKernelStack(), MmCreateSection(), MmDeleteKernelStack(), MmExtendSection(), MmInitializeProcessAddressSpace(), MmInitSystem(), MmLockPagableDataSection(), MmProbeAndLockPages(), MmPurgeSection(), MmRemovePhysicalMemory(), MmResetDriverPaging(), MmSessionDelete(), MmUnloadSystemImage(), MmWorkingSetManager(), NpxNpSkipInstruction(), NtAllocateVirtualMemory(), NtCreatePagingFile(), NtCreateProfile(), NtCreateSection(), NtDuplicateToken(), NtFilterToken(), NtFreeVirtualMemory(), NtMapViewOfSection(), NtProtectVirtualMemory(), NtQueryOpenSubKeys(), NtQuerySystemInformation(), NtQueryVirtualMemory(), NtRaiseHardError(), NtSetEvent(), ObpAllocateObject(), ObpFreeObject(), obtest(), OpenAProc(), OpenKeyboardLayoutFile(), ParseAProc(), PrintTimeFields(), PrintTimerQueue(), PrintTree(), ProcessResizeWindow(), Ps386GetVdmIoHandler(), PsLocateSystemDll(), Psp386GetVdmIoHandler(), Psp386InsertVdmIoHandlerBlock(), Psp386InstallIoHandler(), Psp386RemoveIoHandler(), PspCreateThread(), PspGetContext(), PspInitializeSystemDll(), PspMapSystemDll(), PspSetContext(), Reader(), ReaderTurnedWriter(), ReadLayoutFile(), ReplyMessageToTerminalServer(), RtlAcquireResourceExclusive(), RtlAcquireResourceShared(), RtlAssert(), RtlCancelTimer(), RtlCheckForOrphanedCriticalSections(), RtlConvertExclusiveToShared(), RtlConvertSharedToExclusive(), RtlCreateTimer(), RtlCreateTimerQueue(), RtlCreateUserThread(), RtlDebugPrintTimes(), RtlDeleteTimer(), RtlDeleteTimerQueueEx(), RtlDeregisterWaitEx(), RtlDispatchException(), RtlDumpResource(), RtlFindClearRuns(), RtlFreeHandle(), RtlGetNtProductType(), RtlGetUnwindFunctionEntry(), RtlLookupDirectFunctionEntry(), RtlLookupFunctionEntry(), RtlLookupStaticFunctionEntry(), RtlNtStatusToDosErrorNoTeb(), RtlpAsyncCallbackCompletion(), RtlpCallQueryRegistryRoutine(), RtlpCheckHeapSignature(), RtlpContextDump(), RtlpCreateStack(), RtlpDebugPageHeapAllocate(), RtlpDebugPageHeapBreak(), RtlpDebugPageHeapCommitVM(), RtlpDebugPageHeapCreate(), RtlpDebugPageHeapDecommitVM(), RtlpDebugPageHeapDestroy(), RtlpDebugPageHeapFree(), RtlpDebugPageHeapReAllocate(), RtlpDebugPageHeapRobustProtectVM(), RtlpDeleteTimer(), RtlpDeleteTimerQueueComplete(), RtlpDeleteWait(), RtlpDphDllHeapCreate(), RtlpDphInternalValidatePageHeap(), RtlpDphNormalHeapSize(), RtlpDphNormalHeapValidate(), RtlpDphReportCorruptedBlock(), RtlpDphTargetDllsLoadCallBack(), RtlpExceptionRegistrationDump(), RtlpExceptionReportDump(), RtlpFindWaitThread(), RtlpFireTimers(), RtlpFreeStack(), RtlpInitDeferedCriticalSection(), RtlpLpcServerCallback(), RtlpLpcWorkerThread(), RtlpNotOwnerCriticalSection(), RtlpOpenImageFile(), RtlpProcessWaitCompletion(), RtlpQueryRegistryDirect(), RtlpQueueIOWorkerRequest(), RtlpQueueWorkerRequest(), RtlpServiceTimer(), RtlpUnWaitCriticalSection(), RtlpValidateHeapHeaders(), RtlpWaitForCriticalSection(), RtlpWaitForEvent(), RtlpWaitThread(), RtlQueryEnvironmentVariable_U(), RtlQueryProcessLockInformation(), RtlQueryRegistryValues(), RtlRaiseException(), RtlRaiseStatus(), RtlRegisterWait(), RtlReleaseResource(), RtlSetTimer(), RtlUnwind2(), RtlUnwindReturn(), RtlUnwindRfp(), RtlUpdateTimer(), RtlVirtualUnwind(), RtlWalkFrameChain(), Scroll1(), Scroll2(), Scroll3(), Scroll4(), Scroll5(), SeAccessCheck(), SeFilterToken(), SeImpersonateClient(), SeMain(), SeMakeAnonymousLogonToken(), SeMakeSystemToken(), SepClientInitialize(), SepClientTest(), SepDequeueWorkItem(), SepDeReferenceLogonSession(), SepDumpSecurityDescriptor(), SepDumpTokenInfo(), SepDuplicateToken(), SepFilterToken(), SepPrintAcl(), SepPrintSid(), SepQueueWorkItem(), SepReferenceLogonSession(), SepRmCallLsa(), SepRmSetAuditLogWrkr(), SepServerInitialize(), SepServerTest(), SepServerTestAnonymous(), SepServerTestDynamic(), SepServerTestEffectiveOnly(), SepServerTestIdentification(), SepServerTestImpersonation(), SepServerTestNotEffectiveOnly(), SepServerTestStatic(), SeRtlTest(), SeSubProcessToken(), SeTest(), ShadowHotkey(), StringCompare(), StringEqual(), Test(), TestAccessCheck(), TestAddAce(), TestAddEntry(), TestAssignSecurity(), TestCaptureSecurityDescriptor(), TestChild(), TestCreateAcl(), TestDefaultObjectMethod(), TestDeleteAce(), TestDupHandle1(), TestDupHandle4(), TestGetAce(), TestGetEntry(), TestLookupEntry(), TestLookupLastEntry(), TestMakeSystemToken(), TestParent(), TestpCompareDuplicateToken(), TestProcess(), TestQueryInformationAcl(), TestRemoveEntry(), TestSeAccess(), TestSeAclRtl(), TestSeNamedCreate(), TestSeQuerySecurity(), TestSeRtl(), TestSeSecurityDescriptor(), TestSeSetSecurity(), TestSeSid(), TestSetInformationAcl(), TestSeUnnamedCreate(), TestTokenAdjustGroups(), TestTokenAdjustPrivileges(), TestTokenAssignPrimary(), TestTokenCopy(), TestTokenCreate(), TestTokenDuplicate(), TestTokenFilter(), TestTokenImpersonation(), TestTokenInitialize(), TestTokenOpenPrimary(), TestTokenQuery(), TestTokenSet(), TestTokenSize(), Tkm(), TSeAcc(), turtl(), UdbgTest1(), UdbgTest2(), vAddType1Font(), VdmFlushPrinterWriteData(), VdmpExceptionHandler(), VdmpInitialize(), VdmPrinterStatus(), VdmSkipNpxInstruction(), VectorTest(), VerifierMapLockedPages(), VerifierMapLockedPagesSpecifyCache(), ViPrintString(), vLoadT1Fonts(), Writer(), xHalIoAssignDriveLetters(), xxxNextWindow(), xxxShowSwitchWindow(), and ZwLastChance().

#define MEM_PRINT_DEF_BUFFER_SIZE   65536
 

Definition at line 38 of file memprint.h.

#define MEM_PRINT_DEF_SUBBUFFER_COUNT   16
 

Definition at line 52 of file memprint.h.

#define MEM_PRINT_FLAG_CONSOLE   0x01
 

Definition at line 29 of file memprint.h.

Referenced by MemPrint().

#define MEM_PRINT_FLAG_FILE   0x02
 

Definition at line 30 of file memprint.h.

Referenced by MemPrintWriteThread().

#define MEM_PRINT_FLAG_HEADER   0x04
 

Definition at line 31 of file memprint.h.

Referenced by MemPrint().

#define MEM_PRINT_LOG_FILE_NAME   "\\SystemRoot\\Logfile"
 

Definition at line 55 of file memprint.h.

Referenced by MemPrintWriteThread().

#define MEM_PRINT_MAX_SUBBUFFER_COUNT   64
 

Definition at line 53 of file memprint.h.

Referenced by MemPrintInitialize(), and MemPrintWriteThread().


Function Documentation

VOID MemPrint CHAR Format,
  ...
 

Definition at line 250 of file memprint.c.

References ASSERT, CHAR, DbgPrint, FALSE, GET_MEM_PRINT_SUBBUFFER, KeAcquireSpinLock, KeReleaseSpinLock(), KeSetEvent(), MEM_PRINT_FLAG_CONSOLE, MEM_PRINT_FLAG_HEADER, MEM_PRINT_MAX_MESSAGE_SIZE, MemPrintBuffer, MemPrintBufferSize, MemPrintCurrentSubbuffer, MemPrintFlags, MemPrintIndex, MemPrintInitialized, MemPrintSpinLock, MemPrintSubbufferCount, MemPrintSubbufferFullEvent, MemPrintSubbufferWriting, PMEM_PRINT_MESSAGE_HEADER, _MEM_PRINT_MESSAGE_HEADER::Size, strlen(), TRUE, _MEM_PRINT_MESSAGE_HEADER::Type, and USHORT.

00256 : 00257 00258 This routine is called in place of DbgPrint to process in-memory 00259 printing. 00260 00261 Arguments: 00262 00263 Format - A format string in the style of DbgPrint. 00264 00265 - formatting arguments. 00266 00267 Return Value: 00268 00269 None. 00270 00271 --*/ 00272 00273 { 00274 va_list arglist; 00275 KIRQL oldIrql; 00276 CLONG nextSubbuffer; 00277 PMEM_PRINT_MESSAGE_HEADER messageHeader; 00278 CHAR tempBuffer[MEM_PRINT_MAX_MESSAGE_SIZE]; 00279 00280 va_start(arglist, Format); 00281 _vsnprintf( tempBuffer, sizeof( tempBuffer ), Format, arglist ); 00282 va_end(arglist); 00283 00284 // 00285 // If memory DbgPrint has not been initialized, simply print to the 00286 // console. 00287 // 00288 00289 if ( !MemPrintInitialized ) { 00290 00291 DbgPrint( "%s", tempBuffer ); 00292 return; 00293 } 00294 00295 // 00296 // Acquire the spin lock that synchronizes access to the pointers 00297 // and circular buffer. 00298 // 00299 00300 KeAcquireSpinLock( &MemPrintSpinLock, &oldIrql ); 00301 00302 // 00303 // Make sure that the request will fit. xx_sprintf will just dump 00304 // all it gets, so assume the message is maximum size, and, if the 00305 // request would go into the next subbuffer and it is writing, fail 00306 // the request. 00307 // 00308 00309 nextSubbuffer = 00310 GET_MEM_PRINT_SUBBUFFER( MemPrintIndex + MEM_PRINT_MAX_MESSAGE_SIZE ); 00311 00312 if ( nextSubbuffer != MemPrintCurrentSubbuffer ) { 00313 00314 // 00315 // The request will go to a new subbuffer. Check if we should 00316 // wrap around to the first subbuffer (i.e. start of circular 00317 // buffer). 00318 // 00319 00320 if ( nextSubbuffer == MemPrintSubbufferCount ) { 00321 nextSubbuffer = 0; 00322 } 00323 00324 // 00325 // Is that subbuffer available for use? 00326 // 00327 00328 if ( MemPrintSubbufferWriting[nextSubbuffer] ) { 00329 00330 // 00331 // It is in use. Print to the console. Oh well. 00332 // 00333 00334 KeReleaseSpinLock( &MemPrintSpinLock, oldIrql ); 00335 00336 DbgPrint( "%s", tempBuffer ); 00337 00338 return; 00339 } 00340 00341 // 00342 // If we went to subbuffer 0 and it is available to receive 00343 // data, set up the "end of last subbuffer" conditions and reset 00344 // the index into the circular buffer. By setting a special 00345 // type value in the message header that precedes the garbage at 00346 // the end of the last subbuffer, an interpreter program can 00347 // know to skip over the garbage by using the size in the 00348 // header. This is done instead of writing only good data so 00349 // that we can write just full sectors to disk, thereby 00350 // enhancing write performance. 00351 // 00352 00353 if ( nextSubbuffer == 0 ) { 00354 00355 // 00356 // Set up the message header. This always gets done at the 00357 // end of the circular buffer, regardless of the flags bit. 00358 // 00359 00360 messageHeader = 00361 (PMEM_PRINT_MESSAGE_HEADER)&MemPrintBuffer[MemPrintIndex]; 00362 RtlStoreUshort( 00363 &messageHeader->Size, 00364 (USHORT)(MemPrintBufferSize - MemPrintIndex - 1) 00365 ); 00366 RtlStoreUshort( 00367 &messageHeader->Type, 00368 (USHORT)0xffff 00369 ); 00370 00371 // 00372 // Zero out the rest of the subbuffer. 00373 // 00374 00375 for ( MemPrintIndex += sizeof(MEM_PRINT_MESSAGE_HEADER); 00376 MemPrintIndex < MemPrintBufferSize; 00377 MemPrintIndex++ ) { 00378 00379 MemPrintBuffer[MemPrintIndex] = 0; 00380 } 00381 00382 // 00383 // Reset the index to start at the beginning of the circular 00384 // buffer. 00385 // 00386 00387 MemPrintIndex = 0; 00388 } 00389 } 00390 00391 // 00392 // Store a pointer to the location that will contain the message 00393 // header. 00394 // 00395 00396 messageHeader = (PMEM_PRINT_MESSAGE_HEADER)&MemPrintBuffer[MemPrintIndex]; 00397 00398 if ( MemPrintFlags & MEM_PRINT_FLAG_HEADER ) { 00399 MemPrintIndex += sizeof(MEM_PRINT_MESSAGE_HEADER); 00400 } 00401 00402 // 00403 // Dump the formatted string to the subbuffer. xx_sprintf is a special 00404 // version of sprintf that takes a variable argument list. 00405 // 00406 00407 ASSERT( MemPrintIndex + MEM_PRINT_MAX_MESSAGE_SIZE - 00408 sizeof(MEM_PRINT_MESSAGE_HEADER) <= MemPrintBufferSize ); 00409 00410 00411 RtlMoveMemory( &MemPrintBuffer[MemPrintIndex], tempBuffer, strlen(tempBuffer)+1 ); 00412 00413 MemPrintIndex += strlen(tempBuffer); 00414 00415 // 00416 // Write the total message size to the message header. 00417 // 00418 00419 if ( MemPrintFlags & MEM_PRINT_FLAG_HEADER ) { 00420 messageHeader->Size = 00421 (USHORT)( &MemPrintBuffer[MemPrintIndex] - (PCHAR)messageHeader ); 00422 messageHeader->Type = (USHORT)0xdead; 00423 messageHeader++; 00424 } 00425 00426 // 00427 // If it was too large, there's a potential problem with writing off 00428 // the end of the circular buffer. Print the offending message to 00429 // the console and breakpoint. 00430 // 00431 00432 if ( &MemPrintBuffer[MemPrintIndex] - (PCHAR)messageHeader > 00433 MEM_PRINT_MAX_MESSAGE_SIZE ) { 00434 DbgPrint( "Message too long!! :\n" ); 00435 DbgPrint( "%s", messageHeader ); 00436 DbgBreakPoint( ); 00437 } 00438 00439 // 00440 // Print to the console if the appropriate flag is on. 00441 // 00442 00443 if ( MemPrintFlags & MEM_PRINT_FLAG_CONSOLE ) { 00444 DbgPrint( "%s", messageHeader ); 00445 } 00446 00447 // 00448 // Calculate whether we have stepped into a new subbuffer. 00449 // 00450 00451 nextSubbuffer = GET_MEM_PRINT_SUBBUFFER( MemPrintIndex ); 00452 00453 if ( nextSubbuffer != MemPrintCurrentSubbuffer ) { 00454 00455 //DbgPrint( "Subbuffer %ld complete.\n", MemPrintCurrentSubbuffer ); 00456 00457 // 00458 // We did step into a new subbuffer, so set the boolean to 00459 // indicate that the old subbuffer is writing to disk, thereby 00460 // preventing it from being overwritten until the write is 00461 // complete. 00462 // 00463 00464 MemPrintSubbufferWriting[MemPrintCurrentSubbuffer] = TRUE; 00465 00466 // 00467 // Set the event that will wake up the thread writing subbuffers 00468 // to disk. 00469 // 00470 00471 KeSetEvent( 00472 &MemPrintSubbufferFullEvent[MemPrintCurrentSubbuffer], 00473 2, 00474 FALSE 00475 ); 00476 00477 // 00478 // Update the current subbuffer. 00479 // 00480 00481 MemPrintCurrentSubbuffer = nextSubbuffer; 00482 } 00483 00484 KeReleaseSpinLock( &MemPrintSpinLock, oldIrql ); 00485 00486 return; 00487 00488 } // MemPrint

VOID MemPrintFlush VOID   ) 
 

Definition at line 492 of file memprint.c.

References DbgPrint, FALSE, KeAcquireSpinLock, KeDelayExecutionThread(), KeReleaseSpinLock(), KernelMode, KeSetEvent(), MEM_PRINT_SUBBUFFER_SIZE, MemPrintBuffer, MemPrintBufferSize, MemPrintCurrentSubbuffer, MemPrintIndex, MemPrintSpinLock, MemPrintSubbufferFullEvent, MemPrintSubbufferWriting, PMEM_PRINT_MESSAGE_HEADER, _MEM_PRINT_MESSAGE_HEADER::Size, TRUE, _MEM_PRINT_MESSAGE_HEADER::Type, and USHORT.

00498 : 00499 00500 This routine causes the current subbuffer to be written to disk, 00501 regardless of how full it is. The unwritten part of the subbuffer 00502 is zeroed before writing. 00503 00504 Arguments: 00505 00506 None. 00507 00508 Return Value: 00509 00510 None. 00511 00512 --*/ 00513 00514 { 00515 KIRQL oldIrql; 00516 PMEM_PRINT_MESSAGE_HEADER messageHeader; 00517 CLONG nextSubbufferIndex; 00518 LARGE_INTEGER delayInterval; 00519 00520 // 00521 // Acquire the spin lock that protects memory DbgPrint variables. 00522 // 00523 00524 KeAcquireSpinLock( &MemPrintSpinLock, &oldIrql ); 00525 00526 DbgPrint( "Flushing subbuffer %ld\n", MemPrintCurrentSubbuffer ); 00527 00528 // 00529 // Set up the header that indicates that unused space follows. 00530 // 00531 00532 messageHeader = 00533 (PMEM_PRINT_MESSAGE_HEADER)&MemPrintBuffer[MemPrintIndex]; 00534 messageHeader->Size = 00535 (USHORT)(MemPrintBufferSize - MemPrintIndex - 1); 00536 messageHeader->Type = (USHORT)0xffff; 00537 00538 // 00539 // Determine where the next subbuffer starts. 00540 // 00541 00542 nextSubbufferIndex = 00543 (MemPrintCurrentSubbuffer + 1) * MEM_PRINT_SUBBUFFER_SIZE; 00544 00545 // 00546 // Zero out the rest of the subbuffer. 00547 // 00548 00549 for ( MemPrintIndex += sizeof(MEM_PRINT_MESSAGE_HEADER); 00550 MemPrintIndex < nextSubbufferIndex; 00551 MemPrintIndex++ ) { 00552 00553 MemPrintBuffer[MemPrintIndex] = 0; 00554 } 00555 00556 // 00557 // Indicate that the subbuffer should be written to disk. 00558 // 00559 00560 MemPrintSubbufferWriting[MemPrintCurrentSubbuffer] = TRUE; 00561 00562 KeSetEvent( 00563 &MemPrintSubbufferFullEvent[MemPrintCurrentSubbuffer], 00564 8, 00565 FALSE 00566 ); 00567 00568 // 00569 // Increment the current subbuffer so that it corresponds with the 00570 // buffer index. 00571 // 00572 00573 MemPrintCurrentSubbuffer++; 00574 00575 KeReleaseSpinLock( &MemPrintSpinLock, oldIrql ); 00576 00577 // 00578 // Delay so that the memory print write thread wakes up and performs 00579 // the write to disk. 00580 // 00581 // !!! This is obviously not a perfect solution--the write thread 00582 // may never wake up, so this could complete before the flush 00583 // is really done. 00584 // 00585 00586 delayInterval.QuadPart = -10*10*1000*1000; 00587 00588 DbgPrint( "Delaying...\n" ); 00589 KeDelayExecutionThread( KernelMode, TRUE, &delayInterval ); 00590 DbgPrint( "Woke up.\n" ); 00591 00592 return; 00593 00594 } // MemPrintFlush

VOID MemPrintInitialize VOID   ) 
 

Definition at line 124 of file memprint.c.

References DbgPrint, ExAllocatePoolWithTag, FALSE, KeInitializeEvent, KeInitializeSpinLock(), MEM_PRINT_MAX_SUBBUFFER_COUNT, MemPrintBuffer, MemPrintBufferSize, MemPrintInitialized, MemPrintSpinLock, MemPrintSubbufferCount, MemPrintSubbufferFullEvent, MemPrintSubbufferWriting, MemPrintWriteThread(), NonPagedPool, NT_SUCCESS, NTSTATUS(), NULL, PsCreateSystemThread(), and TRUE.

00130 : 00131 00132 This is the initialization routine for the in-memory DbgPrint routine. 00133 It should be called before the first call to MemPrint to set up the 00134 various structures used and to start the log file write thread. 00135 00136 Arguments: 00137 00138 None. 00139 00140 Return Value: 00141 00142 None. 00143 00144 --*/ 00145 00146 { 00147 CLONG i; 00148 NTSTATUS status; 00149 HANDLE threadHandle; 00150 00151 if ( MemPrintInitialized ) { 00152 return; 00153 } 00154 00155 // 00156 // Allocate memory for the circular buffer that will receive 00157 // the text and data. If we can't do it, try again with a buffer 00158 // half as large. If that fails, quit trying. 00159 // 00160 00161 MemPrintBuffer = ExAllocatePoolWithTag( NonPagedPool, MemPrintBufferSize, 'rPeM' ); 00162 00163 if ( MemPrintBuffer == NULL ) { 00164 00165 MemPrintBufferSize /= 2; 00166 DbgPrint( "Unable to allocate DbgPrint buffer--trying size = %ld\n", 00167 MemPrintBufferSize ); 00168 MemPrintBuffer = ExAllocatePoolWithTag( NonPagedPool, MemPrintBufferSize, 'rPeM' ); 00169 00170 if ( MemPrintBuffer == NULL ) { 00171 DbgPrint( "Couldn't allocate DbgPrint buffer.\n" ); 00172 return; 00173 } else { 00174 //DbgPrint( "MemPrint buffer from %lx to %lx\n", 00175 // MemPrintBuffer, MemPrintBuffer + MemPrintBufferSize ); 00176 } 00177 00178 } else { 00179 //DbgPrint( "MemPrint buffer from %lx to %lx\n", 00180 // MemPrintBuffer, MemPrintBuffer + MemPrintBufferSize ); 00181 } 00182 00183 // 00184 // Allocate the spin lock that protects access to the various 00185 // pointers and the circular buffer. This ensures integrity of the 00186 // buffer. 00187 // 00188 00189 KeInitializeSpinLock( &MemPrintSpinLock ); 00190 00191 // 00192 // Make sure that the subbuffer count is in range. (We assume that 00193 // the number is a power of 2.) 00194 // 00195 00196 if ( MemPrintSubbufferCount < 2 ) { 00197 MemPrintSubbufferCount = 2; 00198 } else if ( MemPrintSubbufferCount > MEM_PRINT_MAX_SUBBUFFER_COUNT ) { 00199 MemPrintSubbufferCount = MEM_PRINT_MAX_SUBBUFFER_COUNT; 00200 } 00201 00202 // 00203 // Initialize the array of BOOLEANs that determines which subbuffers 00204 // are being written to disk and therefore cannot be used to store 00205 // new DbgPrint data. 00206 // 00207 // Initialize the array of events that indicates that a subbuffer is 00208 // ready to be written to disk. 00209 // 00210 00211 for ( i = 0; i < MemPrintSubbufferCount; i++ ) { 00212 MemPrintSubbufferWriting[i] = FALSE; 00213 KeInitializeEvent( 00214 &MemPrintSubbufferFullEvent[i], 00215 SynchronizationEvent, 00216 FALSE 00217 ); 00218 } 00219 00220 // 00221 // Start the thread that writes subbuffers from the large circular 00222 // buffer to disk. 00223 // 00224 00225 status = PsCreateSystemThread( 00226 &threadHandle, 00227 PROCESS_ALL_ACCESS, 00228 NULL, 00229 NtCurrentProcess(), 00230 NULL, 00231 MemPrintWriteThread, 00232 NULL 00233 ); 00234 00235 if ( !NT_SUCCESS(status) ) { 00236 DbgPrint( "MemPrintInitialize: PsCreateSystemThread failed: %X\n", 00237 status ); 00238 return; 00239 } 00240 00241 MemPrintInitialized = TRUE; 00242 ZwClose( threadHandle ); 00243 00244 return; 00245 00246 } // MemPrintInitialize


Variable Documentation

ULONG MemPrintFlags
 

Definition at line 33 of file memprint.h.

Referenced by MemPrint(), and MemPrintWriteThread().


Generated on Sat May 15 19:44:37 2004 for test by doxygen 1.3.7