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.

144 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1989-1993 Microsoft Corporation
  3. Module Name:
  4. spxmem.h
  5. Abstract:
  6. This module contains memory management routines.
  7. Author:
  8. Nikhil Kamkolkar (nikhilk) 17-November-1993
  9. Environment:
  10. Kernel mode
  11. Revision History:
  12. --*/
  13. #define QWORDSIZEBLOCK(Size) (((Size)+sizeof(LARGE_INTEGER)-1) & ~(sizeof(LARGE_INTEGER)-1))
  14. #define SPX_MEMORY_SIGNATURE *(PULONG)"SPXM"
  15. #define ZEROED_MEMORY_TAG 0xF0000000
  16. #define SPX_TAG *((PULONG)"SPX ")
  17. //
  18. // Definitions for the block management package
  19. //
  20. typedef UCHAR BLKID;
  21. // Add a BLKID_xxx and an entry to atalkBlkSize for every block client
  22. #define BLKID_TIMERLIST (BLKID)0
  23. #define BLKID_NDISSEND (BLKID)1
  24. #define BLKID_NDISRECV (BLKID)2
  25. #define NUM_BLKIDS (BLKID)3
  26. typedef struct _BLK_CHUNK
  27. {
  28. struct _BLK_CHUNK * bc_Next; // Pointer to next in the link
  29. SHORT bc_NumFrees; // Number of free blocks in the chunk
  30. UCHAR bc_Age; // Number of invocations since the chunk free
  31. BLKID bc_BlkId; // Id of the block
  32. struct _BLK_HDR * bc_FreeHead; // Head of the list of free blocks
  33. #ifndef SPX_OWN_PACKETS
  34. PVOID bc_ChunkCtx; // Used to store pool header if not own
  35. // packets
  36. #else
  37. PVOID bc_Padding; // Keep the header 16 bytes
  38. #endif
  39. // This is followed by an array of N blks of size M such that the block header
  40. // is exactly spxChunkSize[i]
  41. } BLK_CHUNK, *PBLK_CHUNK;
  42. typedef struct _BLK_HDR
  43. {
  44. union
  45. {
  46. struct _BLK_HDR * bh_Next; // Valid when it is free
  47. struct _BLK_CHUNK * bh_pChunk; // The parent chunk to which this blocks belong
  48. // valid when it is allocated
  49. };
  50. PVOID bh_Padding; // Make the header 8 bytes
  51. } BLK_HDR, *PBLK_HDR;
  52. #define BC_OVERHEAD (8+8) // LARGE_INTEGER for SpxAllocMemory() header and
  53. // POOL_HEADER for ExAllocatePool() header
  54. #define BLOCK_POOL_TIMER 1000 // Check interval (1 sec)
  55. #define MAX_BLOCK_POOL_AGE 3 // # of timer invocations before free
  56. ULONG
  57. spxBPAgePool(
  58. IN PVOID Context,
  59. IN BOOLEAN TimerShuttingDown);
  60. #ifdef TRACK_MEMORY_USAGE
  61. #define SpxAllocateMemory(Size) SpxAllocMem((Size), FILENUM | __LINE__)
  62. extern
  63. PVOID
  64. SpxAllocMem(
  65. IN ULONG Size,
  66. IN ULONG FileLine
  67. );
  68. extern
  69. VOID
  70. SpxTrackMemoryUsage(
  71. IN PVOID pMem,
  72. IN BOOLEAN Alloc,
  73. IN ULONG FileLine
  74. );
  75. #else
  76. #define SpxAllocateMemory(Size) SpxAllocMem(Size)
  77. #define SpxTrackMemoryUsage(pMem, Alloc, FileLine)
  78. extern
  79. PVOID
  80. SpxAllocMem(
  81. IN ULONG Size
  82. );
  83. #endif // TRACK_MEMORY_USAGE
  84. VOID
  85. SpxFreeMemory(
  86. IN PVOID pBuf);
  87. #define SpxAllocateZeroedMemory(Size) SpxAllocateMemory((Size) | ZEROED_MEMORY_TAG)
  88. extern
  89. NTSTATUS
  90. SpxInitMemorySystem(
  91. IN PDEVICE pSpxDevice);
  92. extern
  93. VOID
  94. SpxDeInitMemorySystem(
  95. IN PDEVICE pSpxDevice);
  96. PVOID
  97. SpxBPAllocBlock(
  98. IN BLKID BlockId);
  99. VOID
  100. SpxBPFreeBlock(
  101. IN PVOID pBlock,
  102. IN BLKID BlockId);
  103. PNDIS_PACKET
  104. GrowSPXPacketList(void);