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.

136 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. mmfile.hxx
  5. Abstract:
  6. This file contains definitions for mmfile.cxx
  7. Generic shared memory allocator.
  8. Author:
  9. Adriaan Canter (adriaanc) 01-Aug-1998
  10. --*/
  11. #ifndef MMFILE_HXX
  12. #define MMFILE_HXX
  13. #define MAKE_MUTEX_NAME 0
  14. #define MAKE_MAP_NAME 1
  15. // BUGBUG dynamic map name.
  16. #define SZ_MAPNAME "SSPIDIGESTMAP:"
  17. #define SIG_CMMF 'FMMC'
  18. #define MMF_SIG_SZ "Digest Cred Cache Ver 0.9"
  19. #define MMF_SIG_SIZE sizeof(MMF_SIG_SZ)
  20. #define PAGE_SIZE 4096
  21. // BUGBUG reverse sigs or make up new ones.
  22. #define SIG_FREE 0xbadf00d
  23. #define SIG_ALLOC 0xdeadbeef
  24. #define NUM_BITS_IN_BYTE 8
  25. #define NUM_BITS_IN_DWORD (sizeof(DWORD) * NUM_BITS_IN_BYTE)
  26. #define MAX_ENTRY_SIZE PAGE_SIZE
  27. #define MAX_HEADER_ARRAY_SIZE 8
  28. // Useful macros.
  29. // BUGBUG - precedence, parens.
  30. #define ROUNDUPTOPOWEROF2(bytesize, powerof2)(((bytesize) + (powerof2) - 1) & ~((powerof2) - 1))
  31. #define ROUNDUPBLOCKS(bytesize) ((bytesize + _cbEntry-1) & ~(_cbEntry-1))
  32. #define ROUNDUPDWORD(bytesize) ((bytesize + sizeof(DWORD)-1) & ~(sizeof(DWORD)-1))
  33. #define ROUNDUPPAGE(bytesize) ((bytesize + PAGE_SIZE-1) & ~(PAGE_SIZE-1))
  34. #define NUMBLOCKS(bytesize, blocksize) (bytesize / blocksize)
  35. //--------------------------------------------------------------------
  36. // struct MEMMAP_HEADER
  37. //--------------------------------------------------------------------
  38. typedef struct MEMMAP_HEADER
  39. {
  40. TCHAR szSig[MMF_SIG_SIZE];
  41. DWORD nEntries;
  42. DWORD dwHeaderData[MAX_HEADER_ARRAY_SIZE * sizeof(DWORD)];
  43. } *LPMEMMAP_HEADER;
  44. //--------------------------------------------------------------------
  45. // struct MAP_ENTRY
  46. //--------------------------------------------------------------------
  47. typedef struct MAP_ENTRY
  48. {
  49. DWORD dwSig;
  50. DWORD nBlocks;
  51. } *LPMAP_ENTRY;
  52. //--------------------------------------------------------------------
  53. // class CMMFile
  54. //--------------------------------------------------------------------
  55. class CMMFile
  56. {
  57. protected:
  58. DWORD _dwSig;
  59. DWORD _dwStatus;
  60. LPMEMMAP_HEADER _pHeader;
  61. LPDWORD _pBitMap;
  62. LPBYTE _pHeap;
  63. DWORD _cbHeap;
  64. DWORD _cbEntry;
  65. DWORD _cbBitMap;
  66. DWORD _cbTotal;
  67. DWORD _nBitMapDwords;
  68. DWORD _nMaxEntries;
  69. HANDLE _hFile;
  70. BOOL CheckNextNBits(DWORD& nArrayIndex, DWORD& dwStartMask,
  71. DWORD nBitsRequired, DWORD& nBitsFound);
  72. BOOL SetNextNBits(DWORD nIdx, DWORD dwMask,
  73. DWORD nBitsRequired);
  74. DWORD GetAndSetNextFreeEntry(DWORD nBitsRequired);
  75. VOID ResetEntryData(LPMAP_ENTRY Entry,
  76. DWORD dwResetValue, DWORD nBlocks);
  77. public:
  78. CMMFile(DWORD cbHeap, DWORD cbEntry);
  79. ~CMMFile();
  80. DWORD Init();
  81. DWORD DeInit();
  82. LPDWORD GetHeaderData(DWORD dwHeaderIndex);
  83. VOID SetHeaderData(DWORD dwHeaderIndex, DWORD dwHeaderValue);
  84. LPMAP_ENTRY AllocateEntry(DWORD cbBytes);
  85. BOOL ReAllocateEntry(LPMAP_ENTRY pEntry, DWORD cbBytes);
  86. BOOL FreeEntry(LPMAP_ENTRY Entry);
  87. DWORD_PTR GetMapPtr();
  88. DWORD GetStatus();
  89. static DWORD MakeUserObjectName(LPSTR szName, LPDWORD pcbName, DWORD dwFlags);
  90. };
  91. #endif
  92.