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.

181 lines
5.0 KiB

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