Source code of Windows XP (NT5)
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.

512 lines
12 KiB

  1. #ifndef _TRACEP_H
  2. #define _TRACEP_H
  3. /*++
  4. Copyright (c) 1998 Microsoft Corporation
  5. Module Name:
  6. tracep.h
  7. Abstract:
  8. Private header for trace component
  9. Author:
  10. JeePang
  11. Environment:
  12. Revision History:
  13. --*/
  14. #define MAX_WMI_BUFFER_SIZE 1024 // in KBytes
  15. #define MAX_FILE_TABLE_SIZE 64
  16. #define KERNEL_LOGGER (0)
  17. // NOTE: Consider allowing user to change the two values below
  18. #define TRACE_MAXIMUM_NP_POOL_USAGE 10 // maximum per cent of NP used
  19. #define BYTES_PER_MB 1048576 // Conversion for FileSizeLimit
  20. #define REQUEST_FLAG_NEW_FILE 0x00000001 // request for new file
  21. #define REQUEST_FLAG_FLUSH_BUFFERS 0x00000002 // request for flush
  22. #define REQUEST_FLAG_CIRCULAR_PERSIST 0x00010000
  23. #define REQUEST_FLAG_CIRCULAR_TRANSITION 0x00020000
  24. #define TRACEPOOLTAG 'timW'
  25. //
  26. // Increase refcount on a logger context
  27. #define WmipReferenceLogger(Id) InterlockedIncrement(&WmipRefCount[Id])
  28. // Decrease refcount on a logger context
  29. #define WmipDereferenceLogger(Id) InterlockedDecrement(&WmipRefCount[Id])
  30. // Macro to retrieve Logger Context from LoggerId as index
  31. //
  32. #define WmipGetLoggerContext(LoggerId) \
  33. (LoggerId < MAXLOGGERS) ? \
  34. WmipLoggerContext[LoggerId] : NULL
  35. #define WmipIsValidLogger(L) \
  36. (((L) != NULL) && ((L) != (PWMI_LOGGER_CONTEXT) &WmipLoggerContext[0])\
  37. ? TRUE : FALSE)
  38. #define WmipInitializeMutex(x) KeInitializeMutex((x), 0)
  39. #define WmipAcquireMutex(x) KeWaitForSingleObject((x), Executive, KernelMode,\
  40. FALSE, NULL)
  41. #define WmipReleaseMutex(x) KeReleaseMutex((x), FALSE)
  42. //
  43. // Wmi Buffer states
  44. //
  45. #define BUFFER_STATE_UNUSED 0 // Buffer is empty, not used
  46. #define BUFFER_STATE_DIRTY 1 // Buffer is being used
  47. #define BUFFER_STATE_FULL 2 // Buffer is filled up
  48. #define BUFFER_STATE_FLUSH 4 // Buffer ready for flush
  49. //
  50. // Context Swap Trace Constants
  51. //
  52. #define WMI_CTXSWAP_EVENTSIZE_ALIGNMENT 8
  53. //
  54. // Private local data structures used
  55. //
  56. __inline
  57. __int64
  58. WmipGetSystemTime(
  59. VOID
  60. )
  61. {
  62. LARGE_INTEGER Time;
  63. KiQuerySystemTime(&Time);
  64. return Time.QuadPart;
  65. }
  66. __inline
  67. __int64
  68. WmipGetPerfCounter(
  69. VOID
  70. )
  71. {
  72. LARGE_INTEGER Time;
  73. Time = KeQueryPerformanceCounter(NULL);
  74. return Time.QuadPart;
  75. }
  76. #if _MSC_VER >= 1200
  77. #pragma warning( push )
  78. #endif
  79. #pragma warning( disable:4214 )
  80. #pragma warning( disable:4201 )
  81. //
  82. // Perf logging states
  83. //
  84. #define PERF_LOG_NO_TRANSITION 0 // No Perf Logging transition
  85. #define PERF_LOG_START_TRANSITION 1 // Perf Logging is starting
  86. #define PERF_LOG_STOP_TRANSITION 2 // Perf logging is ending
  87. typedef struct _WMI_LOGGER_MODE {
  88. ULONG SequentialFile:1;
  89. ULONG CircularFile:1;
  90. ULONG AppendFile:1;
  91. ULONG Unused1:5;
  92. ULONG RealTime:1;
  93. ULONG DelayOpenFile:1;
  94. ULONG BufferOnly:1;
  95. ULONG PrivateLogger:1;
  96. ULONG AddHeader:1;
  97. ULONG UseExisting:1;
  98. ULONG UseGlobalSequence:1;
  99. ULONG UseLocalSequence:1;
  100. ULONG Unused2:16;
  101. } WMI_LOGGER_MODE, *PWMI_LOGGER_MODE;
  102. typedef struct _WMI_LOGGER_CONTEXT {
  103. //
  104. // the following are private context used by the buffer manager
  105. //
  106. KSPIN_LOCK BufferSpinLock;
  107. LARGE_INTEGER StartTime;
  108. HANDLE LogFileHandle;
  109. KSEMAPHORE LoggerSemaphore;
  110. PETHREAD LoggerThread;
  111. KEVENT LoggerEvent;
  112. KEVENT FlushEvent;
  113. NTSTATUS LoggerStatus;
  114. ULONG LoggerId;
  115. LONG BuffersAvailable;
  116. ULONG UsePerfClock;
  117. ULONG WriteFailureLimit;
  118. #ifdef WMI_NON_BLOCKING
  119. ULONG BuffersDirty;
  120. ULONG BuffersInUse;
  121. ULONG SwitchingInProgress;
  122. SLIST_HEADER FreeList;
  123. SLIST_HEADER FlushList;
  124. SLIST_HEADER GlobalList;
  125. SLIST_HEADER* ProcessorBuffers; // Per Processor Buffer
  126. #else
  127. LIST_ENTRY FreeList;
  128. LIST_ENTRY FlushList;
  129. PLIST_ENTRY TransitionBuffer; // Used to find Buffer
  130. PWMI_BUFFER_HEADER* ProcessorBuffers; // Per Processor Buffer
  131. #endif //WMI_NON_BLOCKING
  132. UNICODE_STRING LoggerName; // points to paged pool
  133. UNICODE_STRING LogFileName;
  134. UNICODE_STRING LogFilePattern;
  135. UNICODE_STRING NewLogFileName; // for updating log file name
  136. PUCHAR EndPageMarker;
  137. LONG CollectionOn;
  138. ULONG KernelTraceOn;
  139. LONG PerfLogInTransition; // perf logging transition status
  140. ULONG RequestFlag;
  141. ULONG EnableFlags;
  142. ULONG MaximumFileSize;
  143. union {
  144. ULONG LoggerMode;
  145. WMI_LOGGER_MODE LoggerModeFlags;
  146. };
  147. ULONG LastFlushedBuffer;
  148. ULONG RefCount;
  149. #ifdef WMI_NON_BLOCKING
  150. ULONG FlushTimer;
  151. #else
  152. LARGE_INTEGER FlushTimer;
  153. #endif //WMI_NON_BLOCKING
  154. LARGE_INTEGER FirstBufferOffset;
  155. LARGE_INTEGER ByteOffset;
  156. LARGE_INTEGER BufferAgeLimit;
  157. // the following are attributes available for query
  158. ULONG MaximumBuffers;
  159. ULONG MinimumBuffers;
  160. ULONG EventsLost;
  161. ULONG BuffersWritten;
  162. ULONG LogBuffersLost;
  163. ULONG RealTimeBuffersLost;
  164. ULONG BufferSize;
  165. LONG NumberOfBuffers;
  166. PLONG SequencePtr;
  167. GUID InstanceGuid;
  168. PVOID LoggerHeader;
  169. WMI_GET_CPUCLOCK_ROUTINE GetCpuClock;
  170. SECURITY_CLIENT_CONTEXT ClientSecurityContext;
  171. // logger specific extension to context
  172. PVOID LoggerExtension;
  173. LONG ReleaseQueue;
  174. TRACE_ENABLE_FLAG_EXTENSION EnableFlagExtension;
  175. ULONG LocalSequence;
  176. ULONG MaximumIrql;
  177. PULONG EnableFlagArray;
  178. #ifndef WMI_MUTEX_FREE
  179. KMUTEX LoggerMutex;
  180. LONG MutexCount;
  181. #endif
  182. ULONG FileCounter;
  183. WMI_TRACE_BUFFER_CALLBACK BufferCallback;
  184. PVOID CallbackContext;
  185. POOL_TYPE PoolType;
  186. LARGE_INTEGER ReferenceSystemTime; // always in SystemTime
  187. LARGE_INTEGER ReferenceTimeStamp; // by specified clocktype
  188. } WMI_LOGGER_CONTEXT, *PWMI_LOGGER_CONTEXT;
  189. #if _MSC_VER >= 1200
  190. #pragma warning( pop )
  191. #endif
  192. extern LONG WmipRefCount[MAXLOGGERS]; // Global refcount on loggercontext
  193. extern PWMI_LOGGER_CONTEXT WmipLoggerContext[MAXLOGGERS];
  194. extern PWMI_BUFFER_HEADER WmipContextSwapProcessorBuffers[MAXIMUM_PROCESSORS];
  195. extern PFILE_OBJECT* WmipFileTable; // Filename hashing table
  196. #ifdef WMI_NON_BLOCKING
  197. extern KSPIN_LOCK WmiSlistLock;
  198. #endif //WMI_NON_BLOCKING
  199. extern ULONG WmipGlobalSequence;
  200. extern ULONG WmipPtrSize; // temporary for wmikd to work
  201. extern ULONG WmipKernelLogger;
  202. extern ULONG WmipEventLogger;
  203. extern ULONG WmiUsePerfClock;
  204. extern ULONG WmiTraceAlignment;
  205. extern ULONG WmiWriteFailureLimit;
  206. extern FAST_MUTEX WmipTraceFastMutex;
  207. extern WMI_TRACE_BUFFER_CALLBACK WmipGlobalBufferCallback;
  208. //
  209. // Private routines for tracing support
  210. //
  211. //
  212. // from tracelog.c
  213. //
  214. NTSTATUS
  215. WmipFlushBuffer(
  216. IN PWMI_LOGGER_CONTEXT LoggerContext,
  217. IN PWMI_BUFFER_HEADER Buffer
  218. );
  219. NTSTATUS
  220. WmipStartLogger(
  221. IN OUT PWMI_LOGGER_INFORMATION LoggerInfo
  222. );
  223. NTSTATUS
  224. WmipQueryLogger(
  225. IN OUT PWMI_LOGGER_INFORMATION LoggerInfo,
  226. IN PWMI_LOGGER_CONTEXT LoggerContext
  227. );
  228. #if DBG
  229. NTSTATUS
  230. WmipVerifyLoggerInfo(
  231. IN PWMI_LOGGER_INFORMATION LoggerInfo,
  232. OUT PWMI_LOGGER_CONTEXT *LoggerContext,
  233. LPSTR Caller
  234. );
  235. #else
  236. NTSTATUS
  237. WmipVerifyLoggerInfo(
  238. IN PWMI_LOGGER_INFORMATION LoggerInfo,
  239. OUT PWMI_LOGGER_CONTEXT *LoggerContext
  240. );
  241. #endif
  242. VOID
  243. WmipFreeLoggerContext(
  244. IN PWMI_LOGGER_CONTEXT LoggerContext
  245. );
  246. NTSTATUS
  247. WmipStopLoggerInstance(
  248. IN PWMI_LOGGER_CONTEXT LoggerContext
  249. );
  250. NTSTATUS
  251. WmipFlushActiveBuffers(
  252. IN PWMI_LOGGER_CONTEXT,
  253. IN ULONG FlushAll
  254. );
  255. PSYSTEM_TRACE_HEADER
  256. FASTCALL
  257. WmiReserveWithSystemHeader(
  258. IN ULONG LoggerId,
  259. IN ULONG AuxSize,
  260. IN PETHREAD Thread,
  261. OUT PVOID *BufferResource
  262. );
  263. PVOID
  264. FASTCALL
  265. WmipReserveTraceBuffer(
  266. IN PWMI_LOGGER_CONTEXT LoggerContext,
  267. IN ULONG RequiredSize,
  268. OUT PWMI_BUFFER_HEADER *BufferResource
  269. );
  270. ULONG
  271. FASTCALL
  272. WmipReleaseTraceBuffer(
  273. IN PWMI_BUFFER_HEADER Buffer,
  274. IN PWMI_LOGGER_CONTEXT LoggerContext
  275. );
  276. PWMI_BUFFER_HEADER
  277. WmipGetFreeBuffer(
  278. IN PWMI_LOGGER_CONTEXT LoggerContext
  279. );
  280. #ifdef WMI_NON_BLOCKING
  281. ULONG
  282. WmipAllocateFreeBuffers(
  283. IN PWMI_LOGGER_CONTEXT LoggerContext,
  284. IN ULONG NumberOfBuffers
  285. );
  286. NTSTATUS
  287. WmipAdjustFreeBuffers(
  288. IN PWMI_LOGGER_CONTEXT LoggerContext
  289. );
  290. #endif //NWMI_NON_BLOCKING
  291. NTSTATUS
  292. WmipShutdown(
  293. IN PDEVICE_OBJECT DeviceObject,
  294. IN PIRP Irp
  295. );
  296. VOID
  297. WmipLogger(
  298. IN PWMI_LOGGER_CONTEXT LoggerContext
  299. );
  300. NTSTATUS
  301. WmipSendNotification(
  302. PWMI_LOGGER_CONTEXT LoggerContext,
  303. NTSTATUS Status,
  304. ULONG Flag
  305. );
  306. #if DBG
  307. VOID
  308. TraceDebugPrint(
  309. ULONG DebugPrintLevel,
  310. PCCHAR DebugMessage,
  311. ...
  312. );
  313. #define TraceDebug(x) TraceDebugPrint x
  314. #else
  315. #define TraceDebug(x)
  316. #endif
  317. PWMI_BUFFER_HEADER
  318. FASTCALL
  319. WmipPopFreeContextSwapBuffer
  320. (UCHAR CurrentProcessor
  321. );
  322. VOID
  323. FASTCALL
  324. WmipPushDirtyContextSwapBuffer
  325. (UCHAR CurrentProcessor,
  326. PWMI_BUFFER_HEADER Buffer
  327. );
  328. // from callouts.c
  329. VOID
  330. WmipSetTraceNotify(
  331. IN PDEVICE_OBJECT DeviceObject,
  332. IN ULONG TraceClass,
  333. IN ULONG Enable
  334. );
  335. VOID
  336. FASTCALL
  337. WmipEnableKernelTrace(
  338. IN ULONG EnableFlags
  339. );
  340. VOID
  341. FASTCALL
  342. WmipDisableKernelTrace(
  343. IN ULONG EnableFlags
  344. );
  345. NTSTATUS
  346. WmipDelayCreate(
  347. OUT PHANDLE FileHandle,
  348. IN OUT PUNICODE_STRING FileName,
  349. IN ULONG Append
  350. );
  351. PWMI_LOGGER_CONTEXT
  352. FASTCALL
  353. WmipIsLoggerOn(IN ULONG LoggerId);
  354. // from globalog.c
  355. VOID
  356. WmipStartGlobalLogger();
  357. NTSTATUS
  358. WmipQueryGLRegistryRoutine(
  359. IN PWSTR ValueName,
  360. IN ULONG ValueType,
  361. IN PVOID ValueData,
  362. IN ULONG ValueLength,
  363. IN PVOID Context,
  364. IN PVOID EntryContext
  365. );
  366. NTSTATUS
  367. WmipAddLogHeader(
  368. IN PWMI_LOGGER_CONTEXT LoggerContext,
  369. IN OUT PWMI_BUFFER_HEADER Buffer
  370. );
  371. NTSTATUS
  372. WmipCreateDirectoryFile(
  373. IN PWCHAR DirFileName,
  374. IN ULONG IsDirectory,
  375. OUT PHANDLE FileHandle,
  376. ULONG Append
  377. );
  378. NTSTATUS
  379. WmipCreateNtFileName(
  380. IN PWCHAR strFileName,
  381. OUT PWCHAR * strNtFileName
  382. );
  383. NTSTATUS
  384. WmipFlushLogger(
  385. IN OUT PWMI_LOGGER_CONTEXT LoggerContext,
  386. IN ULONG Wait
  387. );
  388. NTSTATUS
  389. FASTCALL
  390. WmipNotifyLogger(
  391. IN PWMI_LOGGER_CONTEXT LoggerContext
  392. );
  393. PVOID
  394. WmipExtendBase(
  395. IN PWMI_LOGGER_CONTEXT Base,
  396. IN ULONG Size
  397. );
  398. NTSTATUS
  399. WmipGenerateFileName(
  400. IN PUNICODE_STRING FilePattern,
  401. IN OUT PLONG FileCounter,
  402. OUT PUNICODE_STRING FileName
  403. );
  404. VOID
  405. WmipValidateClockType(
  406. IN OUT PWMI_LOGGER_INFORMATION LoggerInfo
  407. );
  408. ULONG
  409. WmipDumpGuidMaps(
  410. IN PWMI_LOGGER_CONTEXT LoggerContext,
  411. IN PLIST_ENTRY TraceGMHeadPtr
  412. );
  413. PVOID
  414. WmipGetTraceBuffer(
  415. IN PWMI_LOGGER_CONTEXT LoggerContext,
  416. IN HANDLE LogFileHandle,
  417. IN PWMI_BUFFER_HEADER Buffer,
  418. IN ULONG GroupType,
  419. IN ULONG RequiredSize,
  420. OUT PULONG GuidMapBuffers
  421. );
  422. #ifdef NTPERF
  423. NTSTATUS
  424. WmipSwitchPerfmemBuffer(
  425. PWMI_SWITCH_PERFMEM_BUFFER_INFORMATION SwitchBufferInfo
  426. );
  427. #endif //NTPERF
  428. NTSTATUS
  429. WmipNtDllLoggerInfo(
  430. PWMINTDLLLOGGERINFO Buffer
  431. );
  432. #endif // _TRACEP_H