Source code of Windows XP (NT5)
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.

128 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. memlog.c
  5. Abstract:
  6. general purpose in-memory logging facility
  7. Author:
  8. Charlie Wickham (charlwi) 31-May-1997
  9. Environment:
  10. Kernel Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. /* External */
  16. /* Static */
  17. /* Forward */
  18. /* End Forward */
  19. #ifdef MEMLOGGING
  20. //
  21. // in-memory event logging facility. This is used to determine
  22. // subtle timing problems that can't be observed via printfs.
  23. //
  24. #define MAX_MEMLOG_ENTRIES 2000
  25. ULONG MemLogEntries = MAX_MEMLOG_ENTRIES;
  26. ULONG MemLogNextLogEntry = 0;
  27. PMEMLOG_ENTRY MemLog;
  28. KSPIN_LOCK MemLogLock;
  29. VOID
  30. CnInitializeMemoryLog(
  31. VOID
  32. )
  33. {
  34. KeInitializeSpinLock( &MemLogLock );
  35. if ( MemLogEntries > 0 ) {
  36. MemLog = CnAllocatePool( MemLogEntries * sizeof( MEMLOG_ENTRY ));
  37. if ( MemLog == NULL ) {
  38. MemLogEntries = 0;
  39. }
  40. MEMLOG( MemLogInitLog, 0, 0 );
  41. }
  42. }
  43. NTSTATUS
  44. CnSetMemLogging(
  45. PCLUSNET_SET_MEM_LOGGING_REQUEST request
  46. )
  47. {
  48. KIRQL OldIrql;
  49. NTSTATUS Status = STATUS_SUCCESS;
  50. if ( request->NumberOfEntries != MemLogEntries ) {
  51. KeAcquireSpinLock( &MemLogLock, &OldIrql );
  52. if ( MemLog != NULL ) {
  53. CnFreePool( MemLog );
  54. MemLogEntries = 0;
  55. MemLog = NULL;
  56. }
  57. if ( request->NumberOfEntries != 0 ) {
  58. MemLogEntries = request->NumberOfEntries;
  59. MemLog = CnAllocatePool( MemLogEntries * sizeof( MEMLOG_ENTRY ));
  60. if ( MemLog == NULL ) {
  61. MemLogEntries = 0;
  62. Status = STATUS_INSUFFICIENT_RESOURCES;
  63. } else {
  64. MemLogNextLogEntry = 0;
  65. }
  66. }
  67. KeReleaseSpinLock( &MemLogLock, OldIrql );
  68. }
  69. return Status;
  70. }
  71. VOID
  72. CnFreeMemoryLog(
  73. VOID
  74. )
  75. {
  76. if ( MemLog )
  77. CnFreePool( MemLog );
  78. }
  79. #else // MEMLOGGING
  80. NTSTATUS
  81. CnSetMemLogging(
  82. PCLUSNET_SET_MEM_LOGGING_REQUEST request
  83. )
  84. {
  85. return STATUS_INVALID_DEVICE_REQUEST;
  86. }
  87. #endif // MEMLOGGING
  88. /* end memlog.c */