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.

122 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. clsmacro.hxx
  6. Abstract:
  7. useful macros
  8. Author:
  9. Larry Zhu (Lzhu) Janary 1, 2002
  10. Revision History:
  11. --*/
  12. #ifndef CLS_MACRO_HXX
  13. #define CLS_MACRO_HXX
  14. //+------------------------------------------------------------------------
  15. //
  16. // NO_COPY *declares* the constructors and assignment operator for copying.
  17. // By not *defining* these functions, you can prevent your class from
  18. // accidentally being copied or assigned -- you will be notified by
  19. // a linkage error.
  20. //
  21. //-------------------------------------------------------------------------
  22. #ifndef NO_COPY
  23. #define NO_COPY(cls) \
  24. cls(const cls&); \
  25. cls& operator=(const cls&);
  26. #endif // NO_COPY
  27. //
  28. // This reverses a DWORD so that the bytes can be easily read
  29. // as characters ('prnt' can be read from debugger forward).
  30. //
  31. inline DWORD
  32. ByteSwapDword(
  33. IN DWORD val
  34. )
  35. {
  36. return (val & 0xff) << 24 |
  37. (val & 0xff00) << 8 |
  38. (val & 0xff0000) >> 8 |
  39. (val & 0xff000000) >> 24;
  40. }
  41. //
  42. // You must use this macro at the start of a class definition to place
  43. // a dword signature. The signature can be used to idendify the actual
  44. // class when the memory is dumped in the debugger. The bytes are reversed
  45. // so that the debugger 'dc' command displays the name correctly.
  46. // It also creates an inline function bSigCheck() that can be used to
  47. // ensures the object matches the signature.
  48. //
  49. // Example: Looking at signature in debugger.
  50. //
  51. // class TFoo
  52. // {
  53. // SIGNATURE('tfoo')
  54. //
  55. // public:
  56. // TFoo() {}
  57. // ~TFoo() {}
  58. //
  59. // private:
  60. // m_FooData;
  61. // };
  62. //
  63. // An example usage is as follows, in NTSD or CDB 'dc' an address that
  64. // you are not sure points to TFoo you should see something like this
  65. // if it is a TFoo object.
  66. //
  67. // 0:001> dc 75ffb8
  68. // 0075ffb8 6f6f6674 00000000 00000000 00000000 tfoo............
  69. // 0075ffc8 45434231 7ffdd000 00000000 0075ffc0 1BCE..........u.
  70. // 0075ffd8 00000000 ffffffff 77ee2c46 77e98ad8 ........F,.w...w
  71. //
  72. // Example: Checking if the object matches expected signature.
  73. //
  74. // TNotify *pNotify = reinterpret_cast<TNotify*>(pVoid);
  75. //
  76. // if(!pNotify->bSigCheck())
  77. // {
  78. // return FALSE; // Object is not a TNotify
  79. // }
  80. //
  81. // Note: We store the signature in a 4 byte character array rather
  82. // than a DWORD so the debugger dt command will the dump the signature
  83. // in a readable form.
  84. //
  85. #define SIGNATURE(sig) \
  86. public: \
  87. class TSignature \
  88. { \
  89. public: \
  90. BYTE m_Signature[4]; \
  91. \
  92. TSignature() \
  93. { \
  94. *reinterpret_cast<DWORD *>(m_Signature) = ByteSwapDword(sig); \
  95. } \
  96. }; \
  97. \
  98. TSignature m_Signature; \
  99. \
  100. BOOL \
  101. bSigCheck( \
  102. void \
  103. ) const \
  104. { \
  105. return *reinterpret_cast<const DWORD *>(m_Signature.m_Signature) == ByteSwapDword(sig); \
  106. } \
  107. private:
  108. #endif // CLS_MACRO_HXX