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.

207 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. wmiexts.h
  5. Author:
  6. Ivan Brugiolo
  7. Revision History:
  8. --*/
  9. # ifndef _ELFMAIN_H_
  10. # define _ELFMAIN_H_
  11. #ifdef _WIN64
  12. #define KDEXT_64BIT
  13. #else
  14. #define KDEXT_32BIT
  15. #endif
  16. #ifdef KDEXT_64BIT
  17. #define MEMORY_ADDRESS ULONG64
  18. #else
  19. #define MEMORY_ADDRESS ULONG_PTR
  20. #endif
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. #include <ntexapi.h>
  25. #ifdef PowerSystemMaximum
  26. #undef PowerSystemMaximum
  27. #endif
  28. #include <windows.h>
  29. #include <wdbgexts.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <wchar.h>
  34. #include <stdlib.h>
  35. //
  36. // To obtain the private & protected members of C++ class,
  37. // let me fake the "private" keyword
  38. //
  39. # define private public
  40. # define protected public
  41. //
  42. // Turn off dllexp et al so this DLL won't export tons of unnecessary garbage.
  43. //
  44. /************************************************************
  45. * Macro Definitions
  46. ************************************************************/
  47. extern WINDBG_EXTENSION_APIS ExtensionApis;
  48. extern HANDLE ExtensionCurrentProcess;
  49. extern USHORT g_MajorVersion;
  50. extern USHORT g_MinorVersion;
  51. #define moveBlock(dst, src, size)\
  52. __try {\
  53. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), (size), NULL);\
  54. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  55. return;\
  56. }
  57. #define MoveWithRet(dst, src, retVal)\
  58. __try {\
  59. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), sizeof(dst), NULL);\
  60. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  61. return retVal;\
  62. }
  63. #define MoveBlockWithRet(dst, src, size, retVal)\
  64. __try {\
  65. ReadMemory( (ULONG_PTR)(src), (PVOID)&(dst), (size), NULL);\
  66. } __except (EXCEPTION_EXECUTE_HANDLER) {\
  67. return retVal;\
  68. }
  69. #ifdef _WIN64
  70. #define INIT_API() \
  71. LPSTR lpArgumentString = (LPSTR)args; \
  72. ExtensionCurrentProcess = hCurrentProcess;
  73. #else
  74. #define INIT_API() \
  75. LPSTR lpArgumentString = (LPSTR)args; \
  76. ExtensionCurrentProcess = hCurrentProcess; \
  77. if (ExtensionApis.nSize != sizeof(WINDBG_EXTENSION_APIS)){ \
  78. WINDBG_OLD_EXTENSION_APIS * pOld = (WINDBG_OLD_EXTENSION_APIS *)&ExtensionApis; \
  79. *pOld = *((WINDBG_OLD_EXTENSION_APIS *)dwProcessor); \
  80. }
  81. #endif
  82. # define BoolValue( b) ((b) ? " TRUE" : " FALSE")
  83. #define DumpDword( symbol ) \
  84. { \
  85. ULONG_PTR dw = 0; \
  86. if (ExtensionApis.nSize != sizeof(WINDBG_EXTENSION_APIS)){ \
  87. dw = GetExpression( "&" symbol ); \
  88. } else { \
  89. dw = GetExpression( symbol ); \
  90. }; \
  91. \
  92. ULONG_PTR dwValue = 0; \
  93. if ( dw ) \
  94. { \
  95. if ( ReadMemory( (ULONG_PTR) dw, \
  96. &dwValue, \
  97. sizeof(dwValue), \
  98. NULL )) \
  99. { \
  100. dprintf( "\t" symbol " = %8d (0x%p)\n", \
  101. dwValue, \
  102. dwValue ); \
  103. } \
  104. } \
  105. }
  106. //
  107. // C++ Structures typically require the constructors and most times
  108. // we may not have default constructors
  109. // => trouble in defining a copy of these struct/class inside the
  110. // Debugger extension DLL for debugger process
  111. // So we will define them as CHARACTER arrays with appropriate sizes.
  112. // This is okay, since we are not really interested in structure as is,
  113. // however, we will copy over data block from the debuggee process to
  114. // these structure variables in the debugger process.
  115. //
  116. # define DEFINE_CPP_VAR( className, classVar) \
  117. CHAR classVar[sizeof(className)]
  118. # define GET_CPP_VAR_PTR( className, classVar) \
  119. (className * ) &classVar
  120. #ifndef KDEXT_64BIT
  121. /**
  122. Routine to get offset of a "Field" of "Type" on a debugee machine. This uses
  123. Ioctl call for type info.
  124. Returns 0 on success, Ioctl error value otherwise.
  125. **/
  126. __inline
  127. ULONG
  128. GetFieldOffset (
  129. IN LPCSTR Type,
  130. IN LPCSTR Field,
  131. OUT PULONG pOffset
  132. )
  133. {
  134. FIELD_INFO flds = {
  135. (PUCHAR)Field,
  136. (PUCHAR)"",
  137. 0,
  138. DBG_DUMP_FIELD_FULL_NAME | DBG_DUMP_FIELD_RETURN_ADDRESS,
  139. 0,
  140. NULL};
  141. SYM_DUMP_PARAM Sym = {
  142. sizeof (SYM_DUMP_PARAM),
  143. (PUCHAR)Type,
  144. DBG_DUMP_NO_PRINT,
  145. 0,
  146. NULL,
  147. NULL,
  148. NULL,
  149. 1,
  150. &flds
  151. };
  152. ULONG Err;
  153. Sym.nFields = 1;
  154. Err = Ioctl( IG_DUMP_SYMBOL_INFO, &Sym, Sym.size );
  155. *pOffset = (ULONG) (flds.address - Sym.addr);
  156. return Err;
  157. }
  158. #endif /* KDEXT_64BIT */
  159. #endif // _ELFMAIN_H_