Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 1999-2002 Microsoft Corporation
  3. Module Name:
  4. irptrace.c
  5. Abstract:
  6. This module implements an IRP tracing facility.
  7. Author:
  8. Keith Moore (keithmo) 10-Aug-1999
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #if !ENABLE_IRP_TRACE
  13. static int g_IrpTraceDummyDeclarationToKeepW4WarningsQuiet;
  14. #else
  15. /***************************************************************************++
  16. Routine Description:
  17. Creates a new (empty) IRP trace log buffer.
  18. Arguments:
  19. LogSize - Supplies the number of entries in the log.
  20. ExtraBytesInHeader - Supplies the number of extra bytes to include
  21. in the log header. This is useful for adding application-
  22. specific data to the log.
  23. Return Value:
  24. PTRACE_LOG - Pointer to the newly created log if successful,
  25. NULL otherwise.
  26. --***************************************************************************/
  27. PTRACE_LOG
  28. CreateIrpTraceLog(
  29. IN LONG LogSize,
  30. IN LONG ExtraBytesInHeader
  31. )
  32. {
  33. return CreateTraceLog(
  34. IRP_TRACE_LOG_SIGNATURE,
  35. LogSize,
  36. ExtraBytesInHeader,
  37. sizeof(IRP_TRACE_LOG_ENTRY),
  38. TRACELOG_HIGH_PRIORITY,
  39. UL_REF_TRACE_LOG_POOL_TAG
  40. );
  41. } // CreateIrpTraceLog
  42. /***************************************************************************++
  43. Routine Description:
  44. Destroys an IRP trace log buffer created with CreateIrpTraceLog().
  45. Arguments:
  46. pLog - Supplies the IRP trace log buffer to destroy.
  47. --***************************************************************************/
  48. VOID
  49. DestroyIrpTraceLog(
  50. IN PTRACE_LOG pLog
  51. )
  52. {
  53. DestroyTraceLog( pLog, UL_REF_TRACE_LOG_POOL_TAG );
  54. } // DestroyIrpTraceLog
  55. /***************************************************************************++
  56. Routine Description:
  57. Writes a new entry to the specified IRP trace log.
  58. Arguments:
  59. pLog - Supplies the log to write to.
  60. Action - Supplies an action code for the new log entry.
  61. pIrp - Supplies the IRP for the log entry.
  62. pFileName - Supplies the filename of the routine writing the log entry.
  63. LineNumber - Supplies the line number of the routine writing the log
  64. entry.
  65. --***************************************************************************/
  66. VOID
  67. WriteIrpTraceLog(
  68. IN PTRACE_LOG pLog,
  69. IN UCHAR Action,
  70. IN PIRP pIrp,
  71. IN PCSTR pFileName,
  72. IN USHORT LineNumber
  73. )
  74. {
  75. IRP_TRACE_LOG_ENTRY entry;
  76. USHORT irpSize;
  77. //
  78. // Initialize the entry.
  79. //
  80. RtlGetCallersAddress( &entry.pCaller, &entry.pCallersCaller );
  81. entry.Action = Action;
  82. entry.pIrp = pIrp;
  83. entry.pFileName = pFileName;
  84. entry.LineNumber = LineNumber;
  85. entry.Processor = (UCHAR)KeGetCurrentProcessorNumber();
  86. entry.pProcess = PsGetCurrentProcess();
  87. entry.pThread = PsGetCurrentThread();
  88. #if ENABLE_IRP_CAPTURE
  89. irpSize = pIrp->Size;
  90. if (irpSize > sizeof(entry.CapturedIrp))
  91. {
  92. irpSize = sizeof(entry.CapturedIrp);
  93. }
  94. RtlCopyMemory( entry.CapturedIrp, pIrp, irpSize );
  95. #endif
  96. //
  97. // Write it to the logs.
  98. //
  99. WriteTraceLog( pLog, &entry );
  100. } // WriteIrpTraceLog
  101. #endif // ENABLE_IRP_TRACE