stackwalker_imports.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. // This file is part of BOINC.
  2. // http://boinc.berkeley.edu
  3. // Copyright (C) 2008 University of California
  4. //
  5. // BOINC is free software; you can redistribute it and/or modify it
  6. // under the terms of the GNU Lesser General Public License
  7. // as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // BOINC is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. // See the GNU Lesser General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Lesser General Public License
  16. // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef BOINC_STACKWALKER_IMPORTS_H
  18. #define BOINC_STACKWALKER_IMPORTS_H
  19. #define gle (GetLastError())
  20. #define TTBUFLEN 8096 // for a temp buffer (2^13)
  21. #if (defined(__CYGWIN32__) || defined(__MINGW32__)) && !defined(__MINGW64_VERSION_MAJOR)
  22. #define MAX_SYM_NAME 2000
  23. #define SYMOPT_LOAD_ANYTHING 0x00000040
  24. #define SYMOPT_IGNORE_CVREC 0x00000080
  25. #define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100
  26. #define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200
  27. #define SYMOPT_EXACT_SYMBOLS 0x00000400
  28. #define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800
  29. #define SYMOPT_IGNORE_NT_SYMPATH 0x00001000
  30. #define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000
  31. #define SYMOPT_PUBLICS_ONLY 0x00004000
  32. #define SYMOPT_NO_PUBLICS 0x00008000
  33. #define SYMOPT_AUTO_PUBLICS 0x00010000
  34. #define SYMOPT_NO_IMAGE_SEARCH 0x00020000
  35. #define SYMOPT_SECURE 0x00040000
  36. #define SYMOPT_NO_PROMPTS 0x00080000
  37. #define SYMOPT_DEBUG 0x80000000
  38. #define SSRVOPT_CALLBACK 0x0001
  39. #define SSRVOPT_DWORD 0x0002
  40. #define SSRVOPT_DWORDPTR 0x0004
  41. #define SSRVOPT_GUIDPTR 0x0008
  42. #define SSRVOPT_OLDGUIDPTR 0x0010
  43. #define SSRVOPT_UNATTENDED 0x0020
  44. #define SSRVOPT_NOCOPY 0x0040
  45. #define SSRVOPT_PARENTWIN 0x0080
  46. #define SSRVOPT_PARAMTYPE 0x0100
  47. #define SSRVOPT_SECURE 0x0200
  48. #define SSRVOPT_TRACE 0x0400
  49. #define SSRVOPT_SETCONTEXT 0x0800
  50. #define SSRVOPT_PROXY 0x1000
  51. #define SSRVOPT_DOWNSTREAM_STORE 0x2000
  52. #define SSRVOPT_RESET ((ULONG_PTR)-1)
  53. #define SSRVACTION_TRACE 1
  54. #define SSRVACTION_QUERYCANCEL 2
  55. #define SSRVACTION_EVENT 3
  56. #define CBA_READ_MEMORY 0x00000006
  57. #define CBA_DEFERRED_SYMBOL_LOAD_CANCEL 0x00000007
  58. #define CBA_SET_OPTIONS 0x00000008
  59. #define CBA_EVENT 0x00000010
  60. #define CBA_DEFERRED_SYMBOL_LOAD_PARTIAL 0x00000020
  61. #define CBA_DEBUG_INFO 0x10000000
  62. enum {
  63. sevInfo = 0,
  64. sevProblem,
  65. sevAttn,
  66. sevFatal,
  67. sevMax
  68. };
  69. typedef enum {
  70. SymDia = 7,
  71. SymVirtual,
  72. NumSymTypes
  73. } SYM_TYPE_EX;
  74. typedef PCSTR PCTSTR;
  75. typedef struct _IMAGEHLP_CBA_EVENT {
  76. DWORD severity;
  77. DWORD code;
  78. PCHAR desc;
  79. PVOID object;
  80. } IMAGEHLP_CBA_EVENT, *PIMAGEHLP_CBA_EVENT;
  81. typedef struct _ADDRESS64 {
  82. DWORD64 Offset;
  83. WORD Segment;
  84. ADDRESS_MODE Mode;
  85. } ADDRESS64, *LPADDRESS64;
  86. typedef struct _KDHELP64 {
  87. DWORD64 Thread;
  88. DWORD ThCallbackStack;
  89. DWORD ThCallbackBStore;
  90. DWORD NextCallback;
  91. DWORD FramePointer;
  92. DWORD64 KiCallUserMode;
  93. DWORD64 KeUserCallbackDispatcher;
  94. DWORD64 SystemRangeStart;
  95. DWORD64 Reserved[8];
  96. } KDHELP64, *PKDHELP64;
  97. typedef struct _IMAGEHLP_LINE64 {
  98. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE64)
  99. PVOID Key; // internal
  100. DWORD LineNumber; // line number in file
  101. PCHAR FileName; // full filename
  102. DWORD64 Address; // first instruction of line
  103. } IMAGEHLP_LINE64, *PIMAGEHLP_LINE64;
  104. typedef struct _IMAGEHLP_MODULE64 {
  105. DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64)
  106. DWORD64 BaseOfImage; // base load address of module
  107. DWORD ImageSize; // virtual size of the loaded module
  108. DWORD TimeDateStamp; // date/time stamp from pe header
  109. DWORD CheckSum; // checksum from the pe header
  110. DWORD NumSyms; // number of symbols in the symbol table
  111. SYM_TYPE SymType; // type of symbols loaded
  112. CHAR ModuleName[32]; // module name
  113. CHAR ImageName[256]; // image name
  114. CHAR LoadedImageName[256]; // symbol file name
  115. } IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64;
  116. typedef struct _SYMBOL_INFO {
  117. ULONG SizeOfStruct;
  118. ULONG TypeIndex; // Type Index of symbol
  119. ULONG64 Reserved[2];
  120. ULONG info;
  121. ULONG Size;
  122. ULONG64 ModBase; // Base Address of module comtaining this symbol
  123. ULONG Flags;
  124. ULONG64 Value; // Value of symbol, ValuePresent should be 1
  125. ULONG64 Address; // Address of symbol including base address of module
  126. ULONG Register; // register holding value or pointer to value
  127. ULONG Scope; // scope of the symbol
  128. ULONG Tag; // pdb classification
  129. ULONG NameLen; // Actual length of name
  130. ULONG MaxNameLen;
  131. CHAR Name[1]; // Name of symbol
  132. } SYMBOL_INFO, *PSYMBOL_INFO;
  133. typedef struct _STACKFRAME64 {
  134. ADDRESS64 AddrPC; // program counter
  135. ADDRESS64 AddrReturn; // return address
  136. ADDRESS64 AddrFrame; // frame pointer
  137. ADDRESS64 AddrStack; // stack pointer
  138. ADDRESS64 AddrBStore; // backing store pointer
  139. PVOID FuncTableEntry; // pointer to pdata/fpo or NULL
  140. DWORD64 Params[4]; // possible arguments to the function
  141. BOOL Far; // WOW far call
  142. BOOL Virtual; // is this a virtual frame?
  143. DWORD64 Reserved[3];
  144. KDHELP64 KdHelp;
  145. } STACKFRAME64, *LPSTACKFRAME64;
  146. typedef BOOL
  147. (CALLBACK *PSYM_ENUMMODULES_CALLBACK64)(
  148. LPCSTR ModuleName,
  149. DWORD64 BaseOfDll,
  150. PVOID UserContext
  151. );
  152. typedef BOOL
  153. (CALLBACK *PSYMBOL_REGISTERED_CALLBACK64)(
  154. HANDLE hProcess,
  155. ULONG ActionCode,
  156. ULONG64 CallbackData,
  157. ULONG64 UserContext
  158. );
  159. typedef
  160. BOOL
  161. (CALLBACK *PREAD_PROCESS_MEMORY_ROUTINE64)(
  162. HANDLE hProcess,
  163. DWORD64 qwBaseAddress,
  164. PVOID lpBuffer,
  165. DWORD nSize,
  166. LPDWORD lpNumberOfBytesRead
  167. );
  168. typedef
  169. PVOID
  170. (CALLBACK *PFUNCTION_TABLE_ACCESS_ROUTINE64)(
  171. HANDLE hProcess,
  172. DWORD64 AddrBase
  173. );
  174. typedef
  175. DWORD64
  176. (CALLBACK *PGET_MODULE_BASE_ROUTINE64)(
  177. HANDLE hProcess,
  178. DWORD64 Address
  179. );
  180. typedef
  181. DWORD64
  182. (CALLBACK *PTRANSLATE_ADDRESS_ROUTINE64)(
  183. HANDLE hProcess,
  184. HANDLE hThread,
  185. LPADDRESS64 lpaddr
  186. );
  187. #endif
  188. // ImagehlpApiVersion()
  189. typedef LPAPI_VERSION (__stdcall *tIAV)(
  190. VOID
  191. );
  192. // SymCleanup()
  193. typedef BOOL (__stdcall *tSC)(
  194. IN HANDLE hProcess
  195. );
  196. // SymEnumerateModules64()
  197. typedef BOOL (__stdcall *tSEM)(
  198. IN HANDLE hProcess,
  199. IN PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
  200. IN PVOID UserContext
  201. );
  202. // SymFunctionTableAccess64()
  203. typedef PVOID (__stdcall *tSFTA)(
  204. IN HANDLE hProcess,
  205. IN DWORD64 AddrBase
  206. );
  207. // SymGetLineFromAddr64()
  208. typedef BOOL (__stdcall *tSGLFA)(
  209. IN HANDLE hProcess,
  210. IN DWORD64 dwAddr,
  211. OUT PDWORD pdwDisplacement,
  212. OUT PIMAGEHLP_LINE64 Line
  213. );
  214. // SymGetModuleBase64()
  215. typedef DWORD64 (__stdcall *tSGMB)(
  216. IN HANDLE hProcess,
  217. IN DWORD64 dwAddr
  218. );
  219. // SymGetModuleInfo64()
  220. typedef BOOL (__stdcall *tSGMI)(
  221. IN HANDLE hProcess,
  222. IN DWORD64 dwAddr,
  223. OUT PIMAGEHLP_MODULE64 ModuleInfo
  224. );
  225. // SymGetOptions()
  226. typedef DWORD (__stdcall *tSGO)(
  227. VOID
  228. );
  229. // SymGetSearchPath()
  230. typedef BOOL (__stdcall *tSGSP)(
  231. IN HANDLE hProcess,
  232. OUT PTSTR SearchPath,
  233. IN DWORD SearchPathLength
  234. );
  235. // SymFromAddr()
  236. typedef BOOL (__stdcall *tSFA)(
  237. IN HANDLE hProcess,
  238. IN DWORD64 dwAddr,
  239. OUT PDWORD64 pdwDisplacement,
  240. OUT PSYMBOL_INFO Symbol
  241. );
  242. // SymInitialize()
  243. typedef BOOL (__stdcall *tSI)(
  244. IN HANDLE hProcess,
  245. IN PCSTR UserSearchPath,
  246. IN BOOL fInvadeProcess
  247. );
  248. // SymLoadModuleEx()
  249. typedef DWORD64 (__stdcall *tSLM)(
  250. IN HANDLE hProcess,
  251. IN HANDLE hFile,
  252. IN PCSTR ImageName,
  253. IN PCSTR ModuleName,
  254. IN DWORD64 BaseOfDll,
  255. IN DWORD SizeOfDll
  256. );
  257. // SymRegisterCallback64()
  258. typedef BOOL (__stdcall *tSRC)(
  259. IN HANDLE hProcess,
  260. PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
  261. ULONG64 UserContext
  262. );
  263. // SymSetOptions()
  264. typedef DWORD (__stdcall *tSSO)(
  265. IN DWORD SymOptions
  266. );
  267. // StackWalk()
  268. typedef BOOL (__stdcall *tSW)(
  269. DWORD MachineType,
  270. HANDLE hProcess,
  271. HANDLE hThread,
  272. LPSTACKFRAME64 StackFrame,
  273. PVOID ContextRecord,
  274. PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
  275. PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
  276. PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine,
  277. PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress
  278. );
  279. // UnDecorateSymbolName()
  280. typedef DWORD (__stdcall *tUDSN)(
  281. PCSTR DecoratedName,
  282. PSTR UnDecoratedName,
  283. DWORD UndecoratedLength,
  284. DWORD Flags
  285. );
  286. // SymbolServerSetOptions
  287. typedef BOOL (__stdcall *tSSSO)(
  288. UINT_PTR options,
  289. ULONG64 data
  290. );
  291. // SetDllDirectory
  292. typedef BOOL (__stdcall *tSDD)(
  293. LPCSTR lpPathName
  294. );
  295. // GetFileVersionInfoSize
  296. typedef BOOL (__stdcall *tGFVIS)(
  297. LPCSTR lptstrFilename,
  298. LPDWORD lpdwHandle
  299. );
  300. // GetFileVersionInfo
  301. typedef BOOL (__stdcall *tGFVI)(
  302. LPCSTR lptstrFilename,
  303. DWORD dwHandle,
  304. DWORD dwLen,
  305. LPVOID lpData
  306. );
  307. // VerQueryValue
  308. typedef BOOL (__stdcall *tVQV)(
  309. const LPVOID pBlock,
  310. LPCSTR lpSubBlock,
  311. LPVOID *lplpBuffer,
  312. PUINT puLen
  313. );
  314. #ifndef SYMOPT_NO_PROMPTS
  315. #define SYMOPT_NO_PROMPTS 0x00080000
  316. #endif
  317. #ifndef SSRVACTION_EVENT
  318. #define SSRVACTION_EVENT 3
  319. #endif
  320. #ifndef SSRVOPT_PROXY
  321. #define SSRVOPT_PROXY 0x00001000
  322. #endif
  323. #endif