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.

155 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. ptrmap.hxx
  5. Abstract:
  6. A helper class for mapping ID to 32 or 64 bit ptr
  7. Author:
  8. Kestutis Patiejunas (kestutip) 08-Dec-1998
  9. Revision History:
  10. Notes:
  11. --*/
  12. #ifndef PTRMAP_HXX
  13. #define PTRMAP_HXX
  14. #define DEFAULT_START_NUMBER_OF_MAPS 4096
  15. #define DEFAULT_INCREASE_NUMBER_OF_MAPS 4096
  16. // for 32 bit DWORD only. intentionally the same for 32 and 64 bits
  17. #define MAPPING_NO_EMPTY_PLACE_IDX ((DWORD)0xffffffff)
  18. typedef struct
  19. {
  20. BOOL fInUse;
  21. //
  22. // The pData member is valid when fInUse is true, otherwise the dwIndex
  23. // member is valid
  24. //
  25. union
  26. {
  27. PVOID pData;
  28. DWORD dwIndex;
  29. };
  30. } MapperElement;
  31. class CIdToPointerMapper
  32. {
  33. public:
  34. /*++
  35. Routine Description:
  36. Constructor
  37. Arguments:
  38. nStartMaps - initial nubmer of possible mappings in table
  39. nIncreaseMaps - number of increase for table when there is not enought space
  40. Return Value:
  41. sucess is tored in m_fInitialized
  42. --*/
  43. CIdToPointerMapper(DWORD nStartMaps,DWORD nIncreaseMaps);
  44. ~CIdToPointerMapper();
  45. /*++
  46. Routine Description:
  47. Takes a PVOID pointer and returns a DWORD ID associated,which should be used
  48. in mapping it back to ptr
  49. Arguments:
  50. PVOID ptr - a pointer of 32/64 bits which should be mapped into dword
  51. Return Value:
  52. DWORD - an ID associated with a given pointer . Starts from 1.
  53. Zero indicates a failure to create mapping.
  54. --*/
  55. DWORD AddMapping(PVOID ptr);
  56. /*++
  57. Routine Description:
  58. Deletes a mapping from mapping table between dword ID and PTR
  59. Arguments:
  60. DWORD ID - and ID to which mapping should be deleted.
  61. Return Value:
  62. BOOL TRUE is succeded
  63. --*/
  64. BOOL DeleteMapping(DWORD id);
  65. /*++
  66. Routine Description:
  67. Finds a mapping in mapping table between DWORD ID and pointer associated
  68. Arguments:
  69. DWORD ID - and ID to which mapping should be deleted.
  70. Return Value:
  71. DWORD - an ID associated with a given pointer . Starts from 1.
  72. Zero indicates a failure to craete mapping.
  73. --*/
  74. PVOID FindMapping(DWORD id);
  75. VOID VerifyOutstandinMappings();
  76. #ifndef _X86_
  77. private:
  78. // size in sizeof(pvoid) of memory allocated for mapper
  79. // later can be increased where reallocating
  80. DWORD m_nStartMaps;
  81. // the increment for mapper for reallocation
  82. DWORD m_nIncreaseMaps;
  83. // was it initialized succesfully
  84. BOOL m_fInitialized;
  85. // an array of pointers what are mapped
  86. // an element contains a pointer of right size for a given platform
  87. // if is not used then it contains the index to the next element
  88. // in free element list.
  89. MapperElement *m_Map;
  90. BUFFER *m_pBufferObj;
  91. // first element in fre element list
  92. DWORD m_EmptyPlace;
  93. // counter for number of mappings
  94. DWORD m_nMappings;
  95. #endif
  96. };
  97. #endif PTRMAP_HXX