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.

1002 lines
25 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. pdhidef.h
  5. Abstract:
  6. function definitions used internally by the performance data helper
  7. functions
  8. --*/
  9. #ifndef _PDHI_DEFS_H_
  10. #define _PDHI_DEFS_H_
  11. #pragma warning ( disable : 4115 )
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #ifndef _DEBUG_MUTEXES
  16. #define _DEBUG_MUTEXES 0 // for debugging
  17. #endif
  18. #include <locale.h>
  19. #include "pdhitype.h"
  20. #if DBG
  21. VOID
  22. __cdecl
  23. PdhDebugPrint(
  24. ULONG DebugPrintLevel,
  25. char * DebugMessage,
  26. ...
  27. );
  28. #define DebugPrint(x) PdhDebugPrint x
  29. #else
  30. #define DebugPrint(x)
  31. #endif
  32. #define STATIC_PDH_FUNCTION PDH_STATUS __stdcall
  33. #define STATIC_BOOL BOOL __stdcall
  34. #define STATIC_DWORD DWORD __stdcall
  35. #define PDH_PLA_MUTEX L"__PDH_PLA_MUTEX__"
  36. // global variable declarations
  37. extern HANDLE ThisDLLHandle;
  38. extern WCHAR szStaticLocalMachineName[];
  39. extern HANDLE hPdhDataMutex;
  40. extern HANDLE hPdhContextMutex;
  41. extern HANDLE hPdhPlaMutex;
  42. extern HANDLE hPdhHeap;
  43. extern HANDLE hEventLog;
  44. extern LONGLONG llRemoteRetryTime;
  45. extern BOOL bEnableRemotePdhAccess;
  46. extern DWORD dwPdhiLocalDefaultDataSource;
  47. extern LONG dwCurrentRealTimeDataSource;
  48. extern ULONGLONG ulPdhCollectTimeout;
  49. extern BOOL bProcessIsDetaching;
  50. // (assumes dword is 4 bytes)
  51. #define ALIGN_ON_DWORD(x) ((VOID *) (((DWORD_PTR) (x) & 3) ? (((DWORD_PTR) (x) & ~3) + 4 ) : ((DWORD_PTR)(x))))
  52. #define DWORD_MULTIPLE(x) ((((x) + sizeof(DWORD) - 1) / sizeof(DWORD)) * sizeof(DWORD))
  53. #define CLEAR_FIRST_FOUR_BYTES(x) * (DWORD *)(x) = 0L
  54. // (assumes QuadWORD is 8 bytes)
  55. #define ALIGN_ON_QWORD(x) ((VOID *)(((DWORD_PTR)(x) & 7) ? (((DWORD_PTR)(x) & ~7) + 8) : ((DWORD_PTR)(x))))
  56. #define QWORD_MULTIPLE(x) ((((x) + sizeof(LONGLONG) - 1) / sizeof(LONGLONG)) * sizeof(LONGLONG))
  57. #define CLEAR_FIRST_EIGHT_BYTES(x) * (LONGLONG *)(x) = 0L
  58. #if _DEBUG_MUTEXES
  59. __inline
  60. DWORD
  61. PdhiLocalWaitForMutex(
  62. LPCSTR szSourceFileName,
  63. DWORD dwLineNo,
  64. HANDLE hMutex
  65. )
  66. {
  67. DWORD dwReturnValue = PDH_INVALID_PARAMETER;
  68. if (hMutex != NULL) {
  69. FILETIME ft;
  70. GetSystemTimeAsFileTime(& ft);
  71. dwReturnValue = WaitForSingleObject(hMutex, 60000);
  72. DebugPrint((4, "\n[%8.8x] Mutex [%8.8x] %s by (%d) at: %s (%d)",
  73. ft.dwLowDateTime,
  74. (DWORD) hMutex,
  75. (dwReturnValue == 0 ? "Locked" : "Lock Failed"),
  76. GetCurrentThreadId(),
  77. szSourceFileName,
  78. dwLineNo));
  79. }
  80. else {
  81. DebugPrint((4, "\nLock of NULL Mutex attmpted at: %s (%d)", szSourceFileName, dwLineNo));
  82. dwReturnValue = PDH_INVALID_PARAMETER;
  83. }
  84. return dwReturnValue;
  85. }
  86. #define WAIT_FOR_AND_LOCK_MUTEX(h) PdhiLocalWaitForMutex (__FILE__, __LINE__, h);
  87. __inline
  88. void
  89. PdhiLocalReleaseMutex(
  90. LPCSTR szSourceFileName,
  91. DWORD dwLineNo,
  92. HANDLE hMutex
  93. )
  94. {
  95. BOOL bSuccess;
  96. LONG lPrevCount = 0;
  97. FILETIME ft;
  98. if (hMutex != NULL) {
  99. GetSystemTimeAsFileTime(& ft);
  100. bSuccess = ReleaseMutex(hMutex);
  101. DebugPrint((4, "\n[%8.8x] Mutex [%8.8x] %s by (%d) at: %s (%d)",
  102. ft.dwLowDateTime,
  103. (DWORD) hMutex,
  104. (bSuccess ? "Released" : "Release Failed"),
  105. GetCurrentThreadId(),
  106. szSourceFileName,
  107. dwLineNo));
  108. }
  109. else {
  110. DebugPrint((4, "\nRelease of NULL Mutex attempted at: %s (%d)", szSourceFileName, dwLineNo));
  111. }
  112. }
  113. #define RELEASE_MUTEX(h) PdhiLocalReleaseMutex (__FILE__, __LINE__, h);
  114. #else
  115. #define WAIT_FOR_AND_LOCK_MUTEX(h) (h != NULL ? WaitForSingleObject(h, 60000) : WAIT_TIMEOUT)
  116. #define RELEASE_MUTEX(h) (h != NULL ? ReleaseMutex(h) : FALSE)
  117. #endif
  118. #define LODWORD(ll) ((DWORD)((LONGLONG)ll & 0x00000000FFFFFFFF))
  119. #define HIDWORD(ll) ((DWORD)(((LONGLONG)ll >> 32) & 0x00000000FFFFFFFF))
  120. #define MAKELONGLONG(low, high) \
  121. ((LONGLONG) (((DWORD) (low)) | ((LONGLONG) ((DWORD) (high))) << 32))
  122. #define MAX_BTREE_DEPTH 40
  123. #define PDH_SQL_STRING_SIZE 1024
  124. #define SMALL_BUFFER_SIZE 4096
  125. #define MEDIUM_BUFFER_SIZE 16384
  126. #define LARGE_BUFFER_SIZE 65536
  127. // set this to 1 to report code errors (i.e. debugging information)
  128. // to the event log.
  129. #define PDHI_REPORT_CODE_ERRORS 0
  130. // set this to 1 to report user errors (i.e. things the normal user
  131. // would care about) to the event log.
  132. #define PDHI_REPORT_USER_ERRORS 1
  133. // USER category errors are typically configuration, schema or access
  134. // access errors, errors the user can usually do something about
  135. #define PDH_EVENT_CATEGORY_USER 100
  136. // COUNTER category errors are errors returned do to valid data returning
  137. // invalid results. These are a special subset of USER Category errors.
  138. #define PDH_EVENT_CATEGORY_COUNTER 110
  139. // DEBUG category errors are of interest only to PDH developers as they
  140. // indicate problems that can normally only be fixed by modifying the
  141. // program code.
  142. #define PDH_EVENT_CATEGORY_DEBUG 200
  143. #define REPORT_EVENT(t,c,id) ReportEvent (hEventLog, t, c, id, NULL, 0, 0, NULL, NULL)
  144. __inline
  145. BOOL
  146. CounterIsOkToUse(void * pCounterArg)
  147. {
  148. BOOL bReturn = FALSE;
  149. PPDHI_COUNTER pCounter = (PPDHI_COUNTER) pCounterArg;
  150. if (pCounter != NULL) {
  151. if (! (pCounter->dwFlags & PDHIC_COUNTER_UNUSABLE)) {
  152. bReturn = TRUE;
  153. }
  154. }
  155. return bReturn;
  156. }
  157. DWORD
  158. DataSourceTypeH(
  159. PDH_HLOG hDataSource
  160. );
  161. DWORD
  162. DataSourceTypeW(
  163. LPCWSTR szDataSource
  164. );
  165. DWORD
  166. DataSourceTypeA(
  167. LPCSTR szDataSource
  168. );
  169. LPWSTR
  170. GetStringResource(
  171. DWORD dwResId
  172. );
  173. //
  174. // Log file entries
  175. //
  176. extern LPCSTR szTsvLogFileHeader;
  177. extern LPCSTR szCsvLogFileHeader;
  178. extern LPCSTR szBinLogFileHeader;
  179. extern LPCSTR szTsvType;
  180. extern LPCSTR szCsvType;
  181. extern LPCSTR szBinaryType;
  182. extern const DWORD dwFileHeaderLength;
  183. extern const DWORD dwTypeLoc;
  184. extern const DWORD dwVersionLoc;
  185. extern const DWORD dwFieldLength;
  186. DWORD
  187. UnmapReadonlyMappedFile(
  188. LPVOID pMemoryBase,
  189. BOOL * bNeedToCloseHandles
  190. );
  191. PDH_FUNCTION
  192. PdhiGetLogCounterInfo(
  193. PDH_HLOG hLog,
  194. PPDHI_COUNTER pCounter
  195. );
  196. PDH_FUNCTION
  197. PdhiEnumLoggedMachines(
  198. PDH_HLOG hDataSource,
  199. LPVOID mszMachineList,
  200. LPDWORD pcchBufferSize,
  201. BOOL bUnicode
  202. );
  203. PDH_FUNCTION
  204. PdhiEnumLoggedObjects(
  205. PDH_HLOG hDataSource,
  206. LPCWSTR szMachineName,
  207. LPVOID mszObjectList,
  208. LPDWORD pcchBufferSize,
  209. DWORD dwDetailLevel,
  210. BOOL bRefresh,
  211. BOOL bUnicode
  212. );
  213. PDH_FUNCTION
  214. PdhiEnumLoggedObjectItems(
  215. PDH_HLOG hDataSource,
  216. LPCWSTR szMachineName,
  217. LPCWSTR szObjectName,
  218. LPVOID mszCounterList,
  219. LPDWORD pdwCounterListLength,
  220. LPVOID mszInstanceList,
  221. LPDWORD pdwInstanceListLength,
  222. DWORD dwDetailLevel,
  223. DWORD dwFlags,
  224. BOOL bUnicode
  225. );
  226. BOOL
  227. PdhiDataSourceHasDetailLevelsH(
  228. PDH_HLOG hDataSource
  229. );
  230. BOOL
  231. PdhiDataSourceHasDetailLevels(
  232. LPWSTR szDataSource
  233. );
  234. PDH_FUNCTION
  235. PdhiGetMatchingLogRecord(
  236. PDH_HLOG hLog,
  237. LONGLONG * pStartTime,
  238. LPDWORD pdwIndex
  239. );
  240. PDH_FUNCTION
  241. PdhiGetCounterValueFromLogFile(
  242. PDH_HLOG hLog,
  243. DWORD dwIndex,
  244. PDHI_COUNTER * pCounter
  245. );
  246. STATIC_PDH_FUNCTION
  247. PdhiGetCounterInfo(
  248. HCOUNTER hCounter,
  249. BOOLEAN bRetrieveExplainText,
  250. LPDWORD pdwBufferSize,
  251. PPDH_COUNTER_INFO_W lpBuffer,
  252. BOOL bUnicode
  253. );
  254. // log.c
  255. BOOL
  256. PdhiCloseAllLoggers();
  257. ULONG HashCounter(
  258. LPWSTR szCounterName
  259. );
  260. void
  261. PdhiInitCounterHashTable(
  262. PDHI_COUNTER_TABLE pTable
  263. );
  264. void
  265. PdhiResetInstanceCount(
  266. PDHI_COUNTER_TABLE pTable
  267. );
  268. PDH_FUNCTION
  269. PdhiFindCounterInstList(
  270. PDHI_COUNTER_TABLE pHeadList,
  271. LPWSTR szCounter,
  272. PPDHI_INST_LIST * pInstList
  273. );
  274. PDH_FUNCTION
  275. PdhiFindInstance(
  276. PLIST_ENTRY pHeadInst,
  277. LPWSTR szInstance,
  278. BOOLEAN bUpdateCount,
  279. PPDHI_INSTANCE * pInstance
  280. );
  281. DWORD
  282. AddStringToMultiSz(
  283. LPVOID mszDest,
  284. LPWSTR szSource,
  285. BOOL bUnicodeDest
  286. );
  287. // query.c
  288. PDH_FUNCTION
  289. PdhiCollectQueryData(
  290. PPDHI_QUERY pQuery,
  291. LONGLONG *pllTimeStamp
  292. );
  293. BOOL
  294. PdhiQueryCleanup(
  295. );
  296. PDH_FUNCTION
  297. PdhiConvertUnicodeToAnsi(
  298. UINT uCodePage,
  299. LPWSTR wszSrc,
  300. LPSTR aszDest,
  301. LPDWORD pdwSize
  302. );
  303. // qutils.c
  304. DWORD
  305. WINAPI
  306. PdhiAsyncTimerThreadProc(
  307. LPVOID pArg
  308. );
  309. BOOL
  310. IsValidQuery(
  311. HQUERY hQuery
  312. );
  313. BOOL
  314. IsValidCounter(
  315. HCOUNTER hCounter
  316. );
  317. BOOL
  318. InitCounter(
  319. PPDHI_COUNTER pCounter
  320. );
  321. BOOL
  322. ParseFullPathNameW(
  323. LPCWSTR szFullCounterPath,
  324. PDWORD pdwBufferLength,
  325. PPDHI_COUNTER_PATH pCounter,
  326. BOOL bWbemSyntax
  327. );
  328. BOOL
  329. ParseInstanceName(
  330. LPCWSTR szInstanceString,
  331. LPWSTR szInstanceName,
  332. LPWSTR szParentName,
  333. DWORD dwName,
  334. LPDWORD lpIndex
  335. );
  336. BOOL
  337. FreeCounter(
  338. PPDHI_COUNTER pThisCounter
  339. );
  340. BOOL
  341. InitPerflibCounterInfo(
  342. PPDHI_COUNTER pCounter
  343. );
  344. BOOL
  345. AddMachineToQueryLists(
  346. PPERF_MACHINE pMachine,
  347. PPDHI_COUNTER pNewCounter
  348. );
  349. BOOL
  350. UpdateRealTimeCounterValue(
  351. PPDHI_COUNTER pCounter
  352. );
  353. BOOL
  354. UpdateRealTimeMultiInstanceCounterValue(
  355. PPDHI_COUNTER pCounter
  356. );
  357. BOOL
  358. UpdateCounterValue(
  359. PPDHI_COUNTER pCounter,
  360. PPERF_DATA_BLOCK pPerfData
  361. );
  362. BOOL
  363. UpdateMultiInstanceCounterValue(
  364. PPDHI_COUNTER pCounter,
  365. PPERF_DATA_BLOCK pPerfData,
  366. LONGLONG TimeStamp
  367. );
  368. BOOL
  369. UpdateCounterObject(
  370. PPDHI_COUNTER pCounter
  371. );
  372. #define GPCDP_GET_BASE_DATA 0x00000001
  373. PVOID
  374. GetPerfCounterDataPtr(
  375. PPERF_DATA_BLOCK pPerfData,
  376. PPDHI_COUNTER_PATH pPath,
  377. PPERFLIB_COUNTER pplCtr,
  378. DWORD dwFlags,
  379. PPERF_OBJECT_TYPE *pPerfObject,
  380. PDWORD pStatus
  381. );
  382. LONG
  383. GetQueryPerfData(
  384. PPDHI_QUERY pQuery,
  385. LONGLONG * pTimeStamp
  386. );
  387. BOOL
  388. GetInstanceByNameMatch(
  389. PPERF_MACHINE pMachine,
  390. PPDHI_COUNTER pCounter
  391. );
  392. PDH_FUNCTION
  393. PdhiResetLogBuffers(
  394. PDH_HLOG hLog
  395. );
  396. PDH_FUNCTION
  397. AddUniqueWideStringToMultiSz(
  398. LPVOID mszDest,
  399. LPWSTR szSource,
  400. DWORD dwSizeLeft,
  401. LPDWORD pdwSize,
  402. BOOL bUnicodeDest
  403. );
  404. BOOL
  405. PdhiBrowseDataSource(
  406. HWND hWndParent,
  407. LPVOID szFileName,
  408. LPDWORD pcchFileNameSize,
  409. BOOL bUnicodeString
  410. );
  411. LPWSTR
  412. PdhiGetExplainText(
  413. LPCWSTR szMachineName,
  414. LPCWSTR szObjectName,
  415. LPCWSTR szCounterName
  416. );
  417. LONG
  418. GetCurrentServiceState(
  419. SC_HANDLE hService,
  420. BOOL * bStopped,
  421. BOOL * bPaused
  422. );
  423. // wbem.cpp
  424. BOOL
  425. IsWbemDataSource(
  426. LPCWSTR szDataSource
  427. );
  428. PDH_FUNCTION
  429. PdhiFreeAllWbemServers(
  430. );
  431. PDH_FUNCTION
  432. PdhiGetWbemExplainText(
  433. LPCWSTR szMachineName,
  434. LPCWSTR szObjectName,
  435. LPCWSTR szCounterName,
  436. LPWSTR szExplain,
  437. LPDWORD pdwExplain
  438. );
  439. PDH_FUNCTION
  440. PdhiEnumWbemMachines(
  441. LPVOID pMachineList,
  442. LPDWORD pcchBufferSize,
  443. BOOL bUnicode
  444. );
  445. PDH_FUNCTION
  446. PdhiEnumWbemObjects(
  447. LPCWSTR szWideMachineName,
  448. LPVOID mszObjectList,
  449. LPDWORD pcchBufferSize,
  450. DWORD dwDetailLevel,
  451. BOOL bRefresh,
  452. BOOL bUnicode
  453. );
  454. PDH_FUNCTION
  455. PdhiGetDefaultWbemObject(
  456. LPCWSTR szMachineName,
  457. LPVOID szDefaultObjectName,
  458. LPDWORD pcchBufferSize,
  459. BOOL bUnicode
  460. );
  461. PDH_FUNCTION
  462. PdhiEnumWbemObjectItems(
  463. LPCWSTR szWideMachineName,
  464. LPCWSTR szWideObjectName,
  465. LPVOID mszCounterList,
  466. LPDWORD pcchCounterListLength,
  467. LPVOID mszInstanceList,
  468. LPDWORD pcchInstanceListLength,
  469. DWORD dwDetailLevel,
  470. DWORD dwFlags,
  471. BOOL bUnicode
  472. );
  473. PDH_FUNCTION
  474. PdhiGetDefaultWbemProperty(
  475. LPCWSTR szMachineName,
  476. LPCWSTR szObjectName,
  477. LPVOID szDefaultCounterName,
  478. LPDWORD pcchBufferSize,
  479. BOOL bUnicode
  480. );
  481. PDH_FUNCTION
  482. PdhiEncodeWbemPathW(
  483. PPDH_COUNTER_PATH_ELEMENTS_W pCounterPathElements,
  484. LPWSTR szFullPathBuffer,
  485. LPDWORD pcchBufferSize,
  486. LANGID LangId,
  487. DWORD dwFlags
  488. );
  489. PDH_FUNCTION
  490. PdhiDecodeWbemPathA(
  491. LPCSTR szFullPathBuffer,
  492. PPDH_COUNTER_PATH_ELEMENTS_A pCounterPathElements,
  493. LPDWORD pcchBufferSize,
  494. LANGID LangId,
  495. DWORD dwFlags
  496. );
  497. PDH_FUNCTION
  498. PdhiDecodeWbemPathW(
  499. LPCWSTR szFullPathBuffer,
  500. PPDH_COUNTER_PATH_ELEMENTS_W pCounterPathElements,
  501. LPDWORD pcchBufferSize,
  502. LANGID LangId,
  503. DWORD dwFlags
  504. );
  505. PDH_FUNCTION
  506. PdhiEncodeWbemPathA(
  507. PPDH_COUNTER_PATH_ELEMENTS_A pCounterPathElements,
  508. LPSTR szFullPathBuffer,
  509. LPDWORD pcchBufferSize,
  510. LANGID LangId,
  511. DWORD dwFlags
  512. );
  513. BOOL
  514. WbemInitCounter(
  515. PPDHI_COUNTER pCounter
  516. );
  517. LONG
  518. GetQueryWbemData(
  519. PPDHI_QUERY pQuery,
  520. LONGLONG * pllTimeStamp
  521. );
  522. PDH_FUNCTION
  523. PdhiCloseWbemCounter(
  524. PPDHI_COUNTER pCounter
  525. );
  526. PDH_FUNCTION
  527. PdhiFreeWbemQuery(
  528. PPDHI_QUERY pThisQuery
  529. );
  530. // routinues for cached machine/Object/Counter/Instance structure for counter logs.
  531. int
  532. PdhiCompareLogCounterInstance(
  533. PPDHI_LOG_COUNTER pCounter,
  534. LPWSTR szCounter,
  535. LPWSTR szInstance,
  536. DWORD dwInstance,
  537. LPWSTR szParent
  538. );
  539. void
  540. PdhiFreeLogMachineTable(
  541. PPDHI_LOG_MACHINE * MachineTable
  542. );
  543. PPDHI_LOG_MACHINE
  544. PdhiFindLogMachine(
  545. PPDHI_LOG_MACHINE * MachineTable,
  546. LPWSTR szMachine,
  547. BOOL bInsert
  548. );
  549. PPDHI_LOG_OBJECT
  550. PdhiFindLogObject(
  551. PPDHI_LOG_MACHINE pMachine,
  552. PPDHI_LOG_OBJECT * ObjectTable,
  553. LPWSTR szObject,
  554. BOOL bInsert
  555. );
  556. PPDHI_LOG_COUNTER
  557. PdhiFindLogCounter(
  558. PPDHI_LOG pLog,
  559. PPDHI_LOG_MACHINE * MachineTable,
  560. LPWSTR szMachine,
  561. LPWSTR szObject,
  562. LPWSTR szCounter,
  563. DWORD dwCounterType,
  564. DWORD dwDefaultScale,
  565. LPWSTR szInstance,
  566. DWORD dwInstance,
  567. LPWSTR szParent,
  568. DWORD dwParent,
  569. LPDWORD pdwIndex,
  570. BOOL bInsert
  571. );
  572. PPDHI_LOG_COUNTER
  573. PdhiFindObjectCounter(
  574. PPDHI_LOG pLog,
  575. PPDHI_LOG_OBJECT pObject,
  576. LPWSTR szCounter,
  577. DWORD dwCounterType,
  578. DWORD dwDefaultScale,
  579. LPWSTR szInstance,
  580. DWORD dwInstance,
  581. LPWSTR szParent,
  582. DWORD dwParent,
  583. LPDWORD pdwIndex,
  584. BOOL bInsert
  585. );
  586. PDH_FUNCTION
  587. PdhiEnumCachedMachines(
  588. PPDHI_LOG_MACHINE MachineList,
  589. LPVOID pBuffer,
  590. LPDWORD lpdwBufferSize,
  591. BOOL bUnicodeDest
  592. );
  593. PDH_FUNCTION
  594. PdhiEnumCachedObjects(
  595. PPDHI_LOG_MACHINE MachineList,
  596. LPCWSTR szMachineName,
  597. LPVOID pBuffer,
  598. LPDWORD pcchBufferSize,
  599. DWORD dwDetailLevel,
  600. BOOL bUnicodeDest
  601. );
  602. PDH_FUNCTION
  603. PdhiEnumCachedObjectItems(
  604. PPDHI_LOG_MACHINE MachineList,
  605. LPCWSTR szMachineName,
  606. LPCWSTR szObjectName,
  607. PDHI_COUNTER_TABLE CounterTable,
  608. DWORD dwDetailLevel,
  609. DWORD dwFlags
  610. );
  611. // Debug event tracing facility
  612. //
  613. #define PDH_DBG_TRACE_NONE 0 // no trace
  614. #define PDH_DBG_TRACE_FATAL 1 // Print fatal error traces only
  615. #define PDH_DBG_TRACE_ERROR 2 // All errors
  616. #define PDH_DBG_TRACE_WARNING 3 // Warnings as well
  617. #define PDH_DBG_TRACE_INFO 4 // Informational traces as well
  618. #define PDH_DBG_TRACE_ALL 255 // All traces
  619. #define ARG_TYPE_ULONG 0
  620. #define ARG_TYPE_WSTR 1
  621. #define ARG_TYPE_STR 2
  622. #define ARG_TYPE_ULONG64 3
  623. #define ARG_TYPE_ULONGX 4
  624. #define ARG_TYPE_ULONG64X 5
  625. #ifdef _WIN64
  626. #define ARG_TYPE_PTR ARG_TYPE_ULONG64X
  627. #else
  628. #define ARG_TYPE_PTR ARG_TYPE_ULONGX
  629. #endif
  630. #define PDH_CALCFUNS 10
  631. #define PDH_STATFUNS 11
  632. #define PDH_COUNTER 20
  633. #define PDH_CUTILS 21
  634. #define PDH_DLLINIT 22
  635. #define PDH_PERFDATA 23
  636. #define PDH_PERFNAME 24
  637. #define PDH_PERFUTIL 25
  638. #define PDH_QUERY 26
  639. #define PDH_QUTILS 27
  640. #define PDH_STRINGS 28
  641. #define PDH_VBFUNCS 29
  642. #define PDH_LOG 40
  643. #define PDH_LOGBIN 41
  644. #define PDH_LOGCTRL 42
  645. #define PDH_LOGPM 43
  646. #define PDH_LOGSQL 44
  647. #define PDH_LOGTEXT 45
  648. #define PDH_LOGWMI 46
  649. #define PDH_RELOG 47
  650. #define PDH_PLOGMAN 50
  651. #define PDH_REGUTIL 51
  652. #define PDH_WMIUTIL 52
  653. #define PDH_BROWSDLG 60
  654. #define PDH_BROWSER 61
  655. #define PDH_DATASRC 62
  656. #define PDH_EXPLDLG 63
  657. #define PDH_WILDCARD 64
  658. #define PDH_WBEM 70
  659. #define PDH_GALLOC 80
  660. #define PDH_GREALLOC 81
  661. #define PDH_GFREE 82
  662. // n must be 1 through 8. x is the one of above types
  663. #define ARG_DEF(x, n) (x << ((n-1) * 4))
  664. #define TRACE_WSTR(str) str, (sizeof(WCHAR) * (lstrlenW(str) + 1))
  665. #define TRACE_STR(str) str, (sizeof(CHAR) * (lstrlenA(str) + 1))
  666. #define TRACE_DWORD(dwValue) & dwValue, sizeof(LONG)
  667. #define TRACE_LONG64(llValue) & llValue, sizeof(LONGLONG)
  668. #ifdef _WIN64
  669. #define TRACE_PTR(ptr) TRACE_LONG64(ptr)
  670. #else
  671. #define TRACE_PTR(ptr) TRACE_DWORD(ptr)
  672. #endif
  673. #ifdef _INIT_PDH_DEBUGTRACE
  674. DWORD g_dwDebugTraceLevel = PDH_DBG_TRACE_NONE;
  675. #else
  676. extern DWORD g_dwDebugTraceLevel;
  677. #endif
  678. PDH_FUNCTION
  679. PdhDebugStartTrace();
  680. VOID
  681. PdhDbgTrace(
  682. ULONG LineNumber,
  683. ULONG ModuleNumber,
  684. ULONG OptArgs,
  685. ULONG Status,
  686. ...
  687. );
  688. #define TRACE(L, X) if (g_dwDebugTraceLevel >= L) PdhDbgTrace X
  689. #define _SHOW_PDH_MEM_ALLOCS 1
  690. //#define _VALIDATE_PDH_MEM_ALLOCS 1
  691. #ifndef _SHOW_PDH_MEM_ALLOCS
  692. #define G_ALLOC(s) HeapAlloc(hPdhHeap, (HEAP_ZERO_MEMORY), s)
  693. #define G_REALLOC(h,s) HeapReAlloc(hPdhHeap, (HEAP_ZERO_MEMORY), h, s)
  694. #define G_FREE(h) if (h != NULL) HeapFree(hPdhHeap, 0, h)
  695. #define G_SIZE(h) (h != NULL ? HeapSize(hPdhHeap, 0, h) : 0)
  696. #else
  697. #ifdef _VALIDATE_PDH_MEM_ALLOCS
  698. __inline
  699. LPVOID
  700. PdhiHeapAlloc(DWORD s)
  701. {
  702. LPVOID lpRetVal;
  703. HeapValidate(hPdhHeap, 0, NULL);
  704. lpRetVal = HeapAlloc (hPdhHeap, HEAP_ZERO_MEMORY, s);
  705. return lpRetVal;
  706. }
  707. __inline
  708. LPVOID
  709. PdhiHeapReAlloc(LPVOID h, DWORD s)
  710. {
  711. LPVOID lpRetVal;
  712. HeapValidate(hPdhHeap, 0, NULL);
  713. lpRetVal = HeapReAlloc (hPdhHeap, HEAP_ZERO_MEMORY, h, s);
  714. return lpRetVal;
  715. }
  716. __inline
  717. BOOL
  718. PdhiHeapFree(LPVOID h)
  719. {
  720. BOOL bRetVal;
  721. if (h == NULL) return TRUE;
  722. HeapValidate(hPdhHeap, 0, NULL);
  723. bRetVal = HeapFree (hPdhHeap, 0, h);
  724. return bRetVal;
  725. }
  726. #define G_ALLOC(s) PdhiHeapAlloc(s)
  727. #define G_REALLOC(h,s) PdhiHeapReAlloc(h, s)
  728. #define G_FREE(h) PdhiHeapFree(h)
  729. #define G_SIZE(h) (h != NULL ? HeapSize(hPdhHeap, 0, h) : 0)
  730. #else
  731. __inline
  732. LPVOID
  733. PdhiHeapAlloc(LPSTR szSourceFileName, DWORD dwLineNo, SIZE_T s)
  734. {
  735. LPVOID lpRetVal = NULL;
  736. LONGLONG dwSize = (LONGLONG) s;
  737. if (hPdhHeap != NULL) {
  738. lpRetVal = HeapAlloc(hPdhHeap, HEAP_ZERO_MEMORY, s);
  739. TRACE((PDH_DBG_TRACE_INFO),
  740. (dwLineNo,
  741. PDH_GALLOC,
  742. ARG_DEF(ARG_TYPE_PTR, 1) | ARG_DEF(ARG_TYPE_STR, 2) | ARG_DEF(ARG_TYPE_ULONG64, 3),
  743. ERROR_SUCCESS,
  744. TRACE_PTR(lpRetVal),
  745. TRACE_STR(szSourceFileName),
  746. TRACE_LONG64(dwSize),
  747. NULL));
  748. }
  749. return lpRetVal;
  750. }
  751. __inline
  752. LPVOID
  753. PdhiHeapReAlloc(LPSTR szSourceFileName, DWORD dwLineNo, LPVOID h, SIZE_T s)
  754. {
  755. LPVOID lpRetVal = NULL;
  756. SIZE_T dwBeforeSize;
  757. LONGLONG lBeforeSize;
  758. LONGLONG lAfterSize;
  759. if (hPdhHeap != NULL) {
  760. dwBeforeSize = HeapSize(hPdhHeap, 0, h);
  761. lpRetVal = HeapReAlloc(hPdhHeap, HEAP_ZERO_MEMORY, h, s);
  762. lBeforeSize = (LONGLONG) dwBeforeSize;
  763. lAfterSize = (LONGLONG) s;
  764. TRACE((PDH_DBG_TRACE_INFO),
  765. (dwLineNo,
  766. PDH_GREALLOC,
  767. ARG_DEF(ARG_TYPE_PTR, 1) | ARG_DEF(ARG_TYPE_PTR, 2) | ARG_DEF(ARG_TYPE_STR, 3)
  768. | ARG_DEF(ARG_TYPE_ULONG64, 4) | ARG_DEF(ARG_TYPE_ULONG64, 5),
  769. ERROR_SUCCESS,
  770. TRACE_PTR(lpRetVal),
  771. TRACE_PTR(h),
  772. TRACE_STR(szSourceFileName),
  773. TRACE_LONG64(lAfterSize),
  774. TRACE_LONG64(lBeforeSize),
  775. NULL));
  776. }
  777. return lpRetVal;
  778. }
  779. __inline
  780. BOOL
  781. PdhiHeapFree(LPSTR szSourceFileName, DWORD dwLineNo, LPVOID h)
  782. {
  783. BOOL bRetVal = TRUE;
  784. SIZE_T dwBlockSize;
  785. LONGLONG lBlockSize;
  786. if (h != NULL) {
  787. dwBlockSize = HeapSize(hPdhHeap, 0, h);
  788. lBlockSize = (LONGLONG) dwBlockSize;
  789. TRACE((PDH_DBG_TRACE_INFO),
  790. (dwLineNo,
  791. PDH_GFREE,
  792. ARG_DEF(ARG_TYPE_PTR, 1) | ARG_DEF(ARG_TYPE_STR, 2) | ARG_DEF(ARG_TYPE_ULONG64, 3),
  793. ERROR_SUCCESS,
  794. TRACE_PTR(h),
  795. TRACE_STR(szSourceFileName),
  796. TRACE_LONG64(lBlockSize),
  797. NULL));
  798. bRetVal = HeapFree(hPdhHeap, 0, h);
  799. }
  800. return bRetVal;
  801. }
  802. #define G_ALLOC(s) PdhiHeapAlloc(__FILE__, __LINE__, s)
  803. #define G_REALLOC(h,s) PdhiHeapReAlloc(__FILE__, __LINE__, h, s)
  804. #define G_FREE(h) PdhiHeapFree(__FILE__, __LINE__, h)
  805. #define G_SIZE(h) (h != NULL ? HeapSize(hPdhHeap, 0, h) : 0)
  806. #endif
  807. #endif
  808. LPSTR
  809. PdhiWideCharToMultiByte(
  810. UINT CodePage,
  811. LPWSTR wszString
  812. );
  813. LPWSTR
  814. PdhiMultiByteToWideChar(
  815. UINT CodePage,
  816. LPSTR aszString
  817. );
  818. // Doubly-linked list manipulation routines. Implemented as macros
  819. // but logically these are procedures.
  820. //
  821. #define InitializeListHead(ListHead) ((ListHead)->Flink = (ListHead)->Blink = (ListHead))
  822. #define IsListEmpty(ListHead) ((ListHead)->Flink == (ListHead))
  823. #define RemoveHeadList(ListHead) (ListHead)->Flink; \
  824. { RemoveEntryList((ListHead)->Flink) }
  825. #define RemoveTailList(ListHead) (ListHead)->Blink; \
  826. { RemoveEntryList((ListHead)->Blink) }
  827. #define RemoveEntryList(Entry) { PLIST_ENTRY _EX_Blink; \
  828. PLIST_ENTRY _EX_Flink; \
  829. _EX_Flink = (Entry)->Flink; \
  830. _EX_Blink = (Entry)->Blink; \
  831. _EX_Blink->Flink = _EX_Flink; \
  832. _EX_Flink->Blink = _EX_Blink; \
  833. }
  834. #define InsertTailList(ListHead,Entry) { PLIST_ENTRY _EX_Blink; \
  835. PLIST_ENTRY _EX_ListHead; \
  836. _EX_ListHead = (ListHead); \
  837. _EX_Blink = _EX_ListHead->Blink; \
  838. (Entry)->Flink = _EX_ListHead; \
  839. (Entry)->Blink = _EX_Blink; \
  840. _EX_Blink->Flink = (Entry); \
  841. _EX_ListHead->Blink = (Entry); \
  842. }
  843. #define InsertHeadList(ListHead,Entry) { PLIST_ENTRY _EX_Flink; \
  844. PLIST_ENTRY _EX_ListHead; \
  845. _EX_ListHead = (ListHead); \
  846. _EX_Flink = _EX_ListHead->Flink; \
  847. (Entry)->Flink = _EX_Flink; \
  848. (Entry)->Blink = _EX_ListHead; \
  849. _EX_Flink->Blink = (Entry); \
  850. _EX_ListHead->Flink = (Entry); \
  851. }
  852. #define PopEntryList(ListHead) (ListHead)->Next; \
  853. { PSINGLE_LIST_ENTRY FirstEntry; \
  854. FirstEntry = (ListHead)->Next;\
  855. if (FirstEntry != NULL) { \
  856. (ListHead)->Next = FirstEntry->Next; \
  857. } \
  858. }
  859. #define PushEntryList(ListHead,Entry) (Entry)->Next = (ListHead)->Next; \
  860. (ListHead)->Next = (Entry)
  861. #ifdef __cplusplus
  862. }
  863. #endif
  864. #endif // _PDHI_DEFS_H_