Team Fortress 2 Source Code as on 22/4/2020
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.

457 lines
8.2 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. evntprov.h
  5. Abstract:
  6. This defines the unified provider side user mode API.
  7. Revision History:
  8. --*/
  9. #ifndef _EVNTPROV_H_
  10. #define _EVNTPROV_H_
  11. #pragma once
  12. #ifndef EVNTAPI
  13. #ifndef MIDL_PASS
  14. #ifdef _EVNT_SOURCE_
  15. #define EVNTAPI __stdcall
  16. #else
  17. #define EVNTAPI DECLSPEC_IMPORT __stdcall
  18. #endif // _EVNT_SOURCE_
  19. #endif // MIDL_PASS
  20. #endif // EVNTAPI
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #define EVENT_MIN_LEVEL (0)
  25. #define EVENT_MAX_LEVEL (0xff)
  26. #define EVENT_ACTIVITY_CTRL_GET_ID (1)
  27. #define EVENT_ACTIVITY_CTRL_SET_ID (2)
  28. #define EVENT_ACTIVITY_CTRL_CREATE_ID (3)
  29. #define EVENT_ACTIVITY_CTRL_GET_SET_ID (4)
  30. #define EVENT_ACTIVITY_CTRL_CREATE_SET_ID (5)
  31. typedef ULONGLONG REGHANDLE, *PREGHANDLE;
  32. #define MAX_EVENT_DATA_DESCRIPTORS (128)
  33. #define MAX_EVENT_FILTER_DATA_SIZE (1024)
  34. #define EVENT_FILTER_TYPE_SCHEMATIZED (0x80000000)
  35. //
  36. // EVENT_DATA_DESCRIPTOR is used to pass in user data items
  37. // in events.
  38. //
  39. typedef struct _EVENT_DATA_DESCRIPTOR {
  40. ULONGLONG Ptr; // Pointer to data
  41. ULONG Size; // Size of data in bytes
  42. ULONG Reserved;
  43. } EVENT_DATA_DESCRIPTOR, *PEVENT_DATA_DESCRIPTOR;
  44. //
  45. // EVENT_DESCRIPTOR describes and categorizes an event.
  46. //
  47. typedef struct _EVENT_DESCRIPTOR {
  48. USHORT Id;
  49. UCHAR Version;
  50. UCHAR Channel;
  51. UCHAR Level;
  52. UCHAR Opcode;
  53. USHORT Task;
  54. ULONGLONG Keyword;
  55. } EVENT_DESCRIPTOR, *PEVENT_DESCRIPTOR;
  56. typedef const EVENT_DESCRIPTOR *PCEVENT_DESCRIPTOR;
  57. //
  58. // EVENT_FILTER_DESCRIPTOR is used to pass in enable filter
  59. // data item to a user callback function.
  60. //
  61. typedef struct _EVENT_FILTER_DESCRIPTOR {
  62. ULONGLONG Ptr;
  63. ULONG Size;
  64. ULONG Type;
  65. } EVENT_FILTER_DESCRIPTOR, *PEVENT_FILTER_DESCRIPTOR;
  66. typedef struct _EVENT_FILTER_HEADER {
  67. USHORT Id;
  68. UCHAR Version;
  69. UCHAR Reserved[5];
  70. ULONGLONG InstanceId;
  71. ULONG Size;
  72. ULONG NextOffset;
  73. } EVENT_FILTER_HEADER, *PEVENT_FILTER_HEADER;
  74. #ifndef _ETW_KM_
  75. //
  76. // Optional callback function that users provide
  77. //
  78. typedef
  79. VOID
  80. (NTAPI *PENABLECALLBACK) (
  81. __in LPCGUID SourceId,
  82. __in ULONG IsEnabled,
  83. __in UCHAR Level,
  84. __in ULONGLONG MatchAnyKeyword,
  85. __in ULONGLONG MatchAllKeyword,
  86. __in_opt PEVENT_FILTER_DESCRIPTOR FilterData,
  87. __inout_opt PVOID CallbackContext
  88. );
  89. //
  90. // Registration APIs
  91. //
  92. #if (WINVER >= _WIN32_WINNT_VISTA)
  93. ULONG
  94. EVNTAPI
  95. EventRegister(
  96. __in LPCGUID ProviderId,
  97. __in_opt PENABLECALLBACK EnableCallback,
  98. __in_opt PVOID CallbackContext,
  99. __out PREGHANDLE RegHandle
  100. );
  101. #endif
  102. #if (WINVER >= _WIN32_WINNT_VISTA)
  103. ULONG
  104. EVNTAPI
  105. EventUnregister(
  106. __in REGHANDLE RegHandle
  107. );
  108. #endif
  109. //
  110. // Control (Is Enabled) APIs
  111. //
  112. #if (WINVER >= _WIN32_WINNT_VISTA)
  113. BOOLEAN
  114. EVNTAPI
  115. EventEnabled(
  116. __in REGHANDLE RegHandle,
  117. __in PCEVENT_DESCRIPTOR EventDescriptor
  118. );
  119. #endif
  120. #if (WINVER >= _WIN32_WINNT_VISTA)
  121. BOOLEAN
  122. EVNTAPI
  123. EventProviderEnabled(
  124. __in REGHANDLE RegHandle,
  125. __in UCHAR Level,
  126. __in ULONGLONG Keyword
  127. );
  128. #endif
  129. //
  130. // Writing (Publishing/Logging) APIs
  131. //
  132. #if (WINVER >= _WIN32_WINNT_VISTA)
  133. ULONG
  134. EVNTAPI
  135. EventWrite(
  136. __in REGHANDLE RegHandle,
  137. __in PCEVENT_DESCRIPTOR EventDescriptor,
  138. __in ULONG UserDataCount,
  139. __in_ecount_opt(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData
  140. );
  141. #endif
  142. #if (WINVER >= _WIN32_WINNT_VISTA)
  143. ULONG
  144. EVNTAPI
  145. EventWriteTransfer(
  146. __in REGHANDLE RegHandle,
  147. __in PCEVENT_DESCRIPTOR EventDescriptor,
  148. __in_opt LPCGUID ActivityId,
  149. __in_opt LPCGUID RelatedActivityId,
  150. __in ULONG UserDataCount,
  151. __in_ecount_opt(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData
  152. );
  153. #endif
  154. #if (WINVER >= _WIN32_WINNT_WIN7)
  155. ULONG
  156. EVNTAPI
  157. EventWriteEx(
  158. __in REGHANDLE RegHandle,
  159. __in PCEVENT_DESCRIPTOR EventDescriptor,
  160. __in ULONG64 Filter,
  161. __in ULONG Flags,
  162. __in_opt LPCGUID ActivityId,
  163. __in_opt LPCGUID RelatedActivityId,
  164. __in ULONG UserDataCount,
  165. __in_ecount_opt(UserDataCount) PEVENT_DATA_DESCRIPTOR UserData
  166. );
  167. #endif
  168. #if (WINVER >= _WIN32_WINNT_VISTA)
  169. ULONG
  170. EVNTAPI
  171. EventWriteString(
  172. __in REGHANDLE RegHandle,
  173. __in UCHAR Level,
  174. __in ULONGLONG Keyword,
  175. __in PCWSTR String
  176. );
  177. #endif
  178. //
  179. // ActivityId Control APIs
  180. //
  181. #if (WINVER >= _WIN32_WINNT_VISTA)
  182. ULONG
  183. EVNTAPI
  184. EventActivityIdControl(
  185. __in ULONG ControlCode,
  186. __inout LPGUID ActivityId
  187. );
  188. #endif
  189. #endif // _ETW_KM_
  190. //
  191. // Macros to create Event and Event Data Descriptors
  192. //
  193. FORCEINLINE
  194. VOID
  195. EventDataDescCreate(
  196. __out PEVENT_DATA_DESCRIPTOR EventDataDescriptor,
  197. __in const VOID* DataPtr,
  198. __in ULONG DataSize
  199. )
  200. {
  201. EventDataDescriptor->Ptr = (ULONGLONG)(ULONG_PTR)DataPtr;
  202. EventDataDescriptor->Size = DataSize;
  203. EventDataDescriptor->Reserved = 0;
  204. return;
  205. }
  206. FORCEINLINE
  207. VOID
  208. EventDescCreate(
  209. __out PEVENT_DESCRIPTOR EventDescriptor,
  210. __in USHORT Id,
  211. __in UCHAR Version,
  212. __in UCHAR Channel,
  213. __in UCHAR Level,
  214. __in USHORT Task,
  215. __in UCHAR Opcode,
  216. __in ULONGLONG Keyword
  217. )
  218. {
  219. EventDescriptor->Id = Id;
  220. EventDescriptor->Version = Version;
  221. EventDescriptor->Channel = Channel;
  222. EventDescriptor->Level = Level;
  223. EventDescriptor->Task = Task;
  224. EventDescriptor->Opcode = Opcode;
  225. EventDescriptor->Keyword = Keyword;
  226. return;
  227. }
  228. FORCEINLINE
  229. VOID
  230. EventDescZero(
  231. __out PEVENT_DESCRIPTOR EventDescriptor
  232. )
  233. {
  234. memset(EventDescriptor, 0, sizeof(EVENT_DESCRIPTOR));
  235. return;
  236. }
  237. //
  238. // Macros to extract info from an Event Descriptor
  239. //
  240. FORCEINLINE
  241. USHORT
  242. EventDescGetId(
  243. __in PCEVENT_DESCRIPTOR EventDescriptor
  244. )
  245. {
  246. return (EventDescriptor->Id);
  247. }
  248. FORCEINLINE
  249. UCHAR
  250. EventDescGetVersion(
  251. __in PCEVENT_DESCRIPTOR EventDescriptor
  252. )
  253. {
  254. return (EventDescriptor->Version);
  255. }
  256. FORCEINLINE
  257. USHORT
  258. EventDescGetTask(
  259. __in PCEVENT_DESCRIPTOR EventDescriptor
  260. )
  261. {
  262. return (EventDescriptor->Task);
  263. }
  264. FORCEINLINE
  265. UCHAR
  266. EventDescGetOpcode(
  267. __in PCEVENT_DESCRIPTOR EventDescriptor
  268. )
  269. {
  270. return (EventDescriptor->Opcode);
  271. }
  272. FORCEINLINE
  273. UCHAR
  274. EventDescGetChannel(
  275. __in PCEVENT_DESCRIPTOR EventDescriptor
  276. )
  277. {
  278. return (EventDescriptor->Channel);
  279. }
  280. FORCEINLINE
  281. UCHAR
  282. EventDescGetLevel(
  283. __in PCEVENT_DESCRIPTOR EventDescriptor
  284. )
  285. {
  286. return (EventDescriptor->Level);
  287. }
  288. FORCEINLINE
  289. ULONGLONG
  290. EventDescGetKeyword(
  291. __in PCEVENT_DESCRIPTOR EventDescriptor
  292. )
  293. {
  294. return (EventDescriptor->Keyword);
  295. }
  296. //
  297. // Macros to set info into an Event Descriptor
  298. //
  299. FORCEINLINE
  300. PEVENT_DESCRIPTOR
  301. EventDescSetId(
  302. __in PEVENT_DESCRIPTOR EventDescriptor,
  303. __in USHORT Id
  304. )
  305. {
  306. EventDescriptor->Id = Id;
  307. return (EventDescriptor);
  308. }
  309. FORCEINLINE
  310. PEVENT_DESCRIPTOR
  311. EventDescSetVersion(
  312. __in PEVENT_DESCRIPTOR EventDescriptor,
  313. __in UCHAR Version
  314. )
  315. {
  316. EventDescriptor->Version = Version;
  317. return (EventDescriptor);
  318. }
  319. FORCEINLINE
  320. PEVENT_DESCRIPTOR
  321. EventDescSetTask(
  322. __in PEVENT_DESCRIPTOR EventDescriptor,
  323. __in USHORT Task
  324. )
  325. {
  326. EventDescriptor->Task = Task;
  327. return (EventDescriptor);
  328. }
  329. FORCEINLINE
  330. PEVENT_DESCRIPTOR
  331. EventDescSetOpcode(
  332. __in PEVENT_DESCRIPTOR EventDescriptor,
  333. __in UCHAR Opcode
  334. )
  335. {
  336. EventDescriptor->Opcode = Opcode;
  337. return (EventDescriptor);
  338. }
  339. FORCEINLINE
  340. PEVENT_DESCRIPTOR
  341. EventDescSetLevel(
  342. __in PEVENT_DESCRIPTOR EventDescriptor,
  343. __in UCHAR Level
  344. )
  345. {
  346. EventDescriptor->Level = Level;
  347. return (EventDescriptor);
  348. }
  349. FORCEINLINE
  350. PEVENT_DESCRIPTOR
  351. EventDescSetChannel(
  352. __in PEVENT_DESCRIPTOR EventDescriptor,
  353. __in UCHAR Channel
  354. )
  355. {
  356. EventDescriptor->Channel = Channel;
  357. return (EventDescriptor);
  358. }
  359. FORCEINLINE
  360. PEVENT_DESCRIPTOR
  361. EventDescSetKeyword(
  362. __in PEVENT_DESCRIPTOR EventDescriptor,
  363. __in ULONGLONG Keyword
  364. )
  365. {
  366. EventDescriptor->Keyword = Keyword;
  367. return (EventDescriptor);
  368. }
  369. FORCEINLINE
  370. PEVENT_DESCRIPTOR
  371. EventDescOrKeyword(
  372. __in PEVENT_DESCRIPTOR EventDescriptor,
  373. __in ULONGLONG Keyword
  374. )
  375. {
  376. EventDescriptor->Keyword |= Keyword;
  377. return (EventDescriptor);
  378. }
  379. #ifdef __cplusplus
  380. }
  381. #endif
  382. #endif