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.

156 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. spnlckdb.c
  5. Abstract:
  6. This module contains code which allows debugging of spinlock related NBF
  7. problems. Most of this code is conditional on the manifest constant
  8. NBF_LOCKS.
  9. Author:
  10. David Beaver 13-Feb-1991
  11. (From Chuck Lenzmeier, Jan 1991)
  12. Environment:
  13. Kernel mode
  14. Revision History:
  15. --*/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #ifdef NBF_LOCKS
  19. KSPIN_LOCK NbfGlobalLock = NULL;
  20. PKTHREAD NbfGlobalLockOwner = NULL;
  21. ULONG NbfGlobalLockRecursionCount = 0;
  22. ULONG NbfGlobalLockMaxRecursionCount = 0;
  23. KIRQL NbfGlobalLockPreviousIrql = (KIRQL)-1;
  24. BOOLEAN NbfGlobalLockPrint = 1;
  25. #define PRINT_ERR if ( (NbfGlobalLockPrint & 1) != 0 ) DbgPrint
  26. #define PRINT_INFO if ( (NbfGlobalLockPrint & 2) != 0 ) DbgPrint
  27. VOID
  28. NbfAcquireSpinLock(
  29. IN PKSPIN_LOCK Lock,
  30. OUT PKIRQL OldIrql,
  31. IN PSZ LockName,
  32. IN PSZ FileName,
  33. IN ULONG LineNumber
  34. )
  35. {
  36. KIRQL previousIrql;
  37. PKTHREAD currentThread = KeGetCurrentThread( );
  38. if ( NbfGlobalLockOwner == currentThread ) {
  39. ASSERT( Lock != NULL ); // else entering NBF with lock held
  40. ASSERT( NbfGlobalLockRecursionCount != 0 );
  41. NbfGlobalLockRecursionCount++;
  42. if ( NbfGlobalLockRecursionCount > NbfGlobalLockMaxRecursionCount ) {
  43. NbfGlobalLockMaxRecursionCount = NbfGlobalLockRecursionCount;
  44. }
  45. PRINT_INFO( "NBF reentered from %s/%ld, new count %ld\n",
  46. FileName, LineNumber, NbfGlobalLockRecursionCount );
  47. } else {
  48. ASSERT( Lock == NULL ); // else missing an ENTER_NBF call
  49. KeAcquireSpinLock( &NbfGlobalLock, &previousIrql );
  50. ASSERT( NbfGlobalLockRecursionCount == 0 );
  51. NbfGlobalLockOwner = currentThread;
  52. NbfGlobalLockPreviousIrql = previousIrql;
  53. NbfGlobalLockRecursionCount = 1;
  54. PRINT_INFO( "NBF entered from %s/%ld\n", FileName, LineNumber );
  55. }
  56. ASSERT( KeGetCurrentIrql() == DISPATCH_LEVEL );
  57. return;
  58. } // NbfAcquireSpinLock
  59. VOID
  60. NbfReleaseSpinLock(
  61. IN PKSPIN_LOCK Lock,
  62. IN KIRQL OldIrql,
  63. IN PSZ LockName,
  64. IN PSZ FileName,
  65. IN ULONG LineNumber
  66. )
  67. {
  68. PKTHREAD currentThread = KeGetCurrentThread( );
  69. KIRQL previousIrql;
  70. ASSERT( NbfGlobalLockOwner == currentThread );
  71. ASSERT( NbfGlobalLockRecursionCount != 0 );
  72. ASSERT( KeGetCurrentIrql() == DISPATCH_LEVEL );
  73. if ( --NbfGlobalLockRecursionCount == 0 ) {
  74. ASSERT( Lock == NULL ); // else not exiting NBF, but releasing lock
  75. NbfGlobalLockOwner = NULL;
  76. previousIrql = NbfGlobalLockPreviousIrql;
  77. NbfGlobalLockPreviousIrql = (KIRQL)-1;
  78. PRINT_INFO( "NBF exited from %s/%ld\n", FileName, LineNumber );
  79. KeReleaseSpinLock( &NbfGlobalLock, previousIrql );
  80. } else {
  81. ASSERT( Lock != NULL ); // else exiting NBF with lock held
  82. PRINT_INFO( "NBF semiexited from %s/%ld, new count %ld\n",
  83. FileName, LineNumber, NbfGlobalLockRecursionCount );
  84. }
  85. return;
  86. } // NbfReleaseSpinLock
  87. VOID
  88. NbfFakeSendCompletionHandler(
  89. IN NDIS_HANDLE ProtocolBindingContext,
  90. IN PNDIS_PACKET NdisPacket,
  91. IN NDIS_STATUS NdisStatus
  92. )
  93. {
  94. ENTER_NBF;
  95. NbfSendCompletionHandler (ProtocolBindingContext, NdisPacket, NdisStatus);
  96. LEAVE_NBF;
  97. }
  98. VOID
  99. NbfFakeTransferDataComplete (
  100. IN NDIS_HANDLE BindingContext,
  101. IN PNDIS_PACKET NdisPacket,
  102. IN NDIS_STATUS NdisStatus,
  103. IN UINT BytesTransferred
  104. )
  105. {
  106. ENTER_NBF;
  107. NbfTransferDataComplete (BindingContext, NdisPacket, NdisStatus, BytesTransferred);
  108. LEAVE_NBF;
  109. }
  110. #endif // def NBF_LOCKS