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.

189 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. lsamacro.hxx
  6. Abstract:
  7. LSA Library useful macros
  8. Author:
  9. Larry Zhu (Lzhu) May 1, 2001
  10. Revision History:
  11. --*/
  12. #ifndef _LSAGMACRO_HXX_
  13. #define _LSAGMACRO_HXX_
  14. namespace LSA_NS {
  15. //
  16. // General arrary count.
  17. //
  18. #ifndef COUNTOF
  19. #define COUNTOF(s) ( sizeof( (s) ) / sizeof( *(s) ) )
  20. #endif // COUNTOF
  21. //+------------------------------------------------------------------------
  22. //
  23. // NO_COPY *declares* the constructors and assignment operator for copying.
  24. // By not *defining* these functions, you can prevent your class from
  25. // accidentally being copied or assigned -- you will be notified by
  26. // a linkage error.
  27. //
  28. //-------------------------------------------------------------------------
  29. #ifndef NO_COPY
  30. #define NO_COPY(cls) \
  31. cls(const cls&); \
  32. cls& operator=(const cls&);
  33. #endif // NO_COPY
  34. //
  35. // This reverses a DWORD so that the bytes can be easily read
  36. // as characters ('prnt' can be read from debugger forward).
  37. //
  38. inline DWORD
  39. ByteSwapDword(
  40. IN DWORD val
  41. )
  42. {
  43. return (val & 0xff) << 24 |
  44. (val & 0xff00) << 8 |
  45. (val & 0xff0000) >> 8 |
  46. (val & 0xff000000) >> 24;
  47. }
  48. //
  49. // You must use this macro at the start of a class definition to place
  50. // a dword signature. The signature can be used to idendify the actual
  51. // class when the memory is dumped in the debugger. The bytes are reversed
  52. // so that the debugger 'dc' command displays the name correctly.
  53. // It also creates an inline function bSigCheck() that can be used to
  54. // ensures the object matches the signature.
  55. //
  56. // Example: Looking at signature in debugger.
  57. //
  58. // class TFoo
  59. // {
  60. // SIGNATURE('tfoo')
  61. //
  62. // public:
  63. // TFoo() {}
  64. // ~TFoo() {}
  65. //
  66. // private:
  67. // m_FooData;
  68. // };
  69. //
  70. // An example usage is as follows, in NTSD or CDB 'dc' an address that
  71. // you are not sure points to TFoo you should see something like this
  72. // if it is a TFoo object.
  73. //
  74. // 0:001> dc 75ffb8
  75. // 0075ffb8 6f6f6674 00000000 00000000 00000000 tfoo............
  76. // 0075ffc8 45434231 7ffdd000 00000000 0075ffc0 1BCE..........u.
  77. // 0075ffd8 00000000 ffffffff 77ee2c46 77e98ad8 ........F,.w...w
  78. //
  79. // Example: Checking if the object matches expected signature.
  80. //
  81. // TNotify *pNotify = reinterpret_cast<TNotify*>(pVoid);
  82. //
  83. // if(!pNotify->bSigCheck())
  84. // {
  85. // return FALSE; // Object is not a TNotify
  86. // }
  87. //
  88. // Note: We store the signature in a 4 byte character array rather
  89. // than a DWORD so the debugger dt command will the dump the signature
  90. // in a readable form.
  91. //
  92. #define SIGNATURE(sig) \
  93. public: \
  94. class TSignature \
  95. { \
  96. public: \
  97. BYTE m_Signature[4]; \
  98. \
  99. TSignature() \
  100. { \
  101. *reinterpret_cast<DWORD *>(m_Signature) = ByteSwapDword(sig); \
  102. } \
  103. }; \
  104. \
  105. TSignature m_Signature; \
  106. \
  107. BOOL \
  108. bSigCheck( \
  109. void \
  110. ) const \
  111. { \
  112. return *reinterpret_cast<const DWORD *>(m_Signature.m_Signature) == ByteSwapDword(sig); \
  113. } \
  114. private:
  115. ///////////////////////////////////////////////////////////////////////////
  116. #if defined(DBG)
  117. #define DBG_LOG(uLevel, Msg) do { if (g_Globals.uDebugMask & uLevel) { debugPrintLevel(uLevel); debugPrintf Msg;} } while (0)
  118. #define DBG_OPEN(pszPrompt, uMask) do { g_Globals.uDebugMask = uMask; g_Globals.pszDbgPrompt = pszPrompt; } while (0)
  119. #define DBG_CLOSE() do { g_Globals.uDebugMask = 0; g_Globals.pszDbgPrompt = NULL; } while (0)
  120. #else
  121. #define DBG_LOG(uLevel, Msg) // Empty
  122. #define DBG_OPEN(pszPrompt, uMask)
  123. #define DBG_CLOSE()
  124. #endif // DBG
  125. // #define InitTypeRead(Addr, Type) GetShortField(Addr, #Type, 1)
  126. #define LsaInitTypeRead(Addr, TypeName) ReadShortField(Addr, #TypeName, 1)
  127. #define LsaReadUCHARField(Field) (static_cast<UCHAR> (ReadShortField(0, #Field, 0)))
  128. #define LsaReadUSHORTField(Field) (static_cast<USHORT>(ReadShortField(0, #Field, 0)))
  129. #define LsaReadULONGField(Field) (static_cast<ULONG> (ReadShortField(0, #Field, 0)))
  130. #define LsaReadULONG64Field(Field) (ReadShortField(0, #Field, 0))
  131. #define LsaReadPtrField(Field) toPtr(ReadShortField(0, #Field, 0))
  132. //
  133. // Handle all execptions raised by lsaexts.dll
  134. //
  135. #define CATCH_LSAEXTS_EXCEPTIONS(pszMessage, pszSymHint) \
  136. \
  137. catch (PCSTR error) { \
  138. \
  139. DBG_LOG(LSA_ERROR, (kstrStrLn, EasyStr(error))); \
  140. \
  141. if (error) { \
  142. dprintf("\n%s\n", error); \
  143. } \
  144. \
  145. if (pszMessage) { \
  146. \
  147. dprintf(kstrNewLine); \
  148. dprintf(kstrStrLn, pszMessage); \
  149. } \
  150. \
  151. hRetval = E_FAIL; \
  152. \
  153. } catch (ELsaExceptionCode eExceptionCode) { \
  154. \
  155. handleLsaException(eExceptionCode, pszMessage, pszSymHint); \
  156. \
  157. hRetval = E_FAIL; \
  158. }
  159. } // LSA_NS
  160. #endif // _LSAMACRO_HXX