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.

185 lines
5.0 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // bpool.h
  4. // RAS L2TP WAN mini-port/call-manager driver
  5. // Buffer pool management header
  6. //
  7. // 01/07/97 Steve Cobb, adapted from Gurdeep's WANARP code.
  8. #ifndef _BPOOL_H_
  9. #define _BPOOL_H_
  10. //-----------------------------------------------------------------------------
  11. // Data structures
  12. //-----------------------------------------------------------------------------
  13. // Buffer pool control block. A buffer pool prevents fragmentation of the
  14. // non-paged memory pool by allocating the memory for a group of buffers in a
  15. // single contiguous block. At user's option, the buffer pool routines may
  16. // allocate a pool of NDIS_BUFFER buffer descriptors and associate each with
  17. // the memory buffers sliced from the contiguous block. This allows the
  18. // buffer to be reused while the virtual->physical memory mapping is performed
  19. // only once. All necessary pool growth and shrinkage is handled internally.
  20. //
  21. typedef struct
  22. _BUFFERPOOL
  23. {
  24. // Size in bytes of an individual buffer in the pool.
  25. //
  26. ULONG ulBufferSize;
  27. // The optimal number of buffers to allocate in each buffer block.
  28. //
  29. ULONG ulBuffersPerBlock;
  30. // Maximum number of individual buffers that may be allocated in the
  31. // entire pool or 0 for unlimited.
  32. //
  33. ULONG ulMaxBuffers;
  34. // Current number of individual buffers allocated in the entire pool.
  35. //
  36. ULONG ulCurBuffers;
  37. // Garbage collection occurs after this many calls to FreeBufferToPool.
  38. //
  39. ULONG ulFreesPerCollection;
  40. // Number of calls to FreeBufferToPool since a garbage collection.
  41. //
  42. ULONG ulFreesSinceCollection;
  43. // Indicates an NDIS_BUFFER is to be associated with each individual
  44. // buffer in the pool.
  45. //
  46. BOOLEAN fAssociateNdisBuffer;
  47. // Memory identification tag for allocated blocks.
  48. //
  49. ULONG ulTag;
  50. // Head of the double linked list of BUFFERBLOCKHEADs. Access to the list
  51. // is protected with 'lock' in this structure.
  52. //
  53. LIST_ENTRY listBlocks;
  54. // Head of the double linked list of free BUFFERHEADs. Each BUFFERHEAD in
  55. // the list is ready to go, i.e. it preceeds it's already allocated memory
  56. // buffer and, if appropriate, has an NDIS_BUFFER associated with it.
  57. // Access to the list is protected by 'lock' in this structure.
  58. // Interlocked push/pop is not used because (a) the list of blocks and the
  59. // list of buffers must lock each other and (b) double links are necessary
  60. // for garbage collection.
  61. //
  62. LIST_ENTRY listFreeBuffers;
  63. // This lock protects this structure and both the list of blocks and the
  64. // list of buffers.
  65. //
  66. NDIS_SPIN_LOCK lock;
  67. }
  68. BUFFERPOOL;
  69. // Header of a single block of buffers from a buffer pool. The BUFFERHEAD of
  70. // the first buffer immediately follows.
  71. //
  72. typedef struct
  73. _BUFFERBLOCKHEAD
  74. {
  75. // Link to the prev/next buffer block header in the buffer pool's list.
  76. //
  77. LIST_ENTRY linkBlocks;
  78. // NDIS's handle of the pool of NDIS_BUFFER descriptors associated with
  79. // this block, or NULL if none. (Note: With the current NT implementation
  80. // of NDIS_BUFFER as MDL this is always NULL).
  81. //
  82. NDIS_HANDLE hNdisPool;
  83. // Back pointer to the buffer pool.
  84. //
  85. BUFFERPOOL* pPool;
  86. // Number of individual buffers in this block.
  87. //
  88. ULONG ulBuffers;
  89. // Number of individual buffers in this block on the free list.
  90. //
  91. ULONG ulFreeBuffers;
  92. }
  93. BUFFERBLOCKHEAD;
  94. // Header of an individual buffer. The buffer memory itself immediately
  95. // follows.
  96. //
  97. typedef struct
  98. _BUFFERHEAD
  99. {
  100. // Links to prev/next buffer header in the buffer pool's free list.
  101. //
  102. LIST_ENTRY linkFreeBuffers;
  103. // Back link to owning buffer block header.
  104. //
  105. BUFFERBLOCKHEAD* pBlock;
  106. // NDIS buffer descriptor of this buffer. This is NULL unless the pool is
  107. // initialized with the 'fAssociateNdisBuffer' option.
  108. //
  109. NDIS_BUFFER* pNdisBuffer;
  110. }
  111. BUFFERHEAD;
  112. //-----------------------------------------------------------------------------
  113. // Interface prototypes and inline definitions
  114. //-----------------------------------------------------------------------------
  115. VOID
  116. InitBufferPool(
  117. OUT BUFFERPOOL* pPool,
  118. IN ULONG ulBufferSize,
  119. IN ULONG ulMaxBuffers,
  120. IN ULONG ulBuffersPerBlock,
  121. IN ULONG ulFreesPerCollection,
  122. IN BOOLEAN fAssociateNdisBuffer,
  123. IN ULONG ulTag );
  124. BOOLEAN
  125. FreeBufferPool(
  126. IN BUFFERPOOL* pPool );
  127. CHAR*
  128. GetBufferFromPool(
  129. IN BUFFERPOOL* pPool );
  130. VOID
  131. FreeBufferToPool(
  132. IN BUFFERPOOL* pPool,
  133. IN CHAR* pBuffer,
  134. IN BOOLEAN fGarbageCollection );
  135. NDIS_BUFFER*
  136. NdisBufferFromBuffer(
  137. IN CHAR* pBuffer );
  138. ULONG
  139. BufferSizeFromBuffer(
  140. IN CHAR* pBuffer );
  141. NDIS_BUFFER*
  142. PoolHandleForNdisCopyBufferFromBuffer(
  143. IN CHAR* pBuffer );
  144. VOID
  145. CollectBufferPoolGarbage(
  146. BUFFERPOOL* pPool );
  147. #endif // BPOOL_H_