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.

219 lines
5.5 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Main
  6. File: perfdata.cpp
  7. Owner: DmitryR
  8. PERFMON related data in asp.dll -- source file
  9. ===================================================================*/
  10. #include "denpre.h"
  11. #pragma hdrstop
  12. #include "perfdata.h"
  13. #include "memchk.h"
  14. // to access metabase
  15. #include <iiscnfg.h>
  16. #include <iwamreg.h>
  17. #ifndef PERF_DISABLE
  18. BOOL g_fPerfInited = FALSE;
  19. CPerfMainBlock g_PerfMain;
  20. CPerfData g_PerfData;
  21. /*===================================================================
  22. GetCurrentClsId
  23. Static function to find the current WAM CLSID in the metabase
  24. Parameters
  25. pIReq to retrieve WAM CLSID from the metabase
  26. pClsId [out] CLSID
  27. Returns:
  28. HRESULT
  29. ===================================================================*/
  30. static HRESULT GetCurrentClsId
  31. (
  32. CIsapiReqInfo *pIReq,
  33. CLSID *pClsId
  34. )
  35. {
  36. HRESULT hr = S_OK;
  37. Assert(pClsId);
  38. TCHAR *szMDPath = pIReq->QueryPszApplnMDPath();
  39. if (!szMDPath)
  40. {
  41. *pClsId = CLSID_NULL;
  42. return E_FAIL;
  43. }
  44. CLSID ClsId = CLSID_NULL;
  45. WCHAR wszClsBuffer[80];
  46. DWORD dwRequiredLen, dwAppMode;
  47. // Find the application mode, inproc, out-of-proc, or pooled OOP
  48. hr = pIReq->GetAspMDData(szMDPath,
  49. MD_APP_ISOLATED,
  50. METADATA_INHERIT,
  51. IIS_MD_UT_WAM,
  52. DWORD_METADATA,
  53. sizeof(DWORD),
  54. 0,
  55. (unsigned char*) &dwAppMode,
  56. &dwRequiredLen);
  57. if (SUCCEEDED(hr))
  58. {
  59. switch (dwAppMode)
  60. {
  61. case eAppRunInProc:
  62. // preconfigured WAM CLSID for all inproc apps
  63. wcscpy(wszClsBuffer,
  64. L"{99169CB0-A707-11d0-989D-00C04FD919C1}");
  65. break;
  66. case eAppRunOutProcIsolated:
  67. // custom WAM CLSID for non-pooled OOP apps
  68. hr = pIReq->GetAspMDData(szMDPath,
  69. MD_APP_WAM_CLSID,
  70. METADATA_INHERIT,
  71. IIS_MD_UT_WAM,
  72. STRING_METADATA,
  73. sizeof(wszClsBuffer) / sizeof(WCHAR),
  74. 0,
  75. (unsigned char *)wszClsBuffer,
  76. &dwRequiredLen);
  77. break;
  78. case eAppRunOutProcInDefaultPool:
  79. // preconfigured WAM CLSID for the pooled OOP apps
  80. wcscpy(wszClsBuffer,
  81. L"{3D14228D-FBE1-11d0-995D-00C04FD919C1}");
  82. break;
  83. default:
  84. Assert(!"unknown AppMode");
  85. hr = E_FAIL;
  86. break;
  87. }
  88. }
  89. if (SUCCEEDED(hr))
  90. {
  91. // Convert string to CLSID
  92. hr = CLSIDFromString(wszClsBuffer, &ClsId);
  93. }
  94. if (SUCCEEDED(hr) && g_fOOP) // always CLSID_NULL if inproc
  95. *pClsId = ClsId;
  96. else
  97. *pClsId = CLSID_NULL;
  98. return hr;
  99. }
  100. /*===================================================================
  101. PreInitPerfData
  102. Initialize from DllInit
  103. Creates critical sections
  104. Parameters
  105. Returns:
  106. HRESULT
  107. ===================================================================*/
  108. HRESULT PreInitPerfData()
  109. {
  110. HRESULT hr = S_OK;
  111. hr = g_PerfData.InitCriticalSections();
  112. return hr;
  113. }
  114. /*===================================================================
  115. InitPerfDataOnFirstRequest
  116. Initialize PERFMON related ASP data from first request
  117. Parameters
  118. pIReq to retrieve WAM CLSID from the metabase
  119. Returns:
  120. HRESULT
  121. ===================================================================*/
  122. HRESULT InitPerfDataOnFirstRequest
  123. (
  124. CIsapiReqInfo *pIReq
  125. )
  126. {
  127. // access main shared memory
  128. HRESULT hr = g_PerfMain.Init();
  129. // access shared memory of this process
  130. if (SUCCEEDED(hr))
  131. hr = g_PerfData.Init(GetCurrentProcessId());
  132. // add this process data to main shared memory
  133. if (SUCCEEDED(hr))
  134. hr = g_PerfMain.AddProcess(GetCurrentProcessId());
  135. if (FAILED(hr))
  136. {
  137. g_PerfData.UnInit();
  138. g_PerfMain.UnInit();
  139. }
  140. return hr;
  141. }
  142. /*===================================================================
  143. UnInitPerfData
  144. UnInitialize PERFMON related ASP data
  145. Returns:
  146. HRESULT
  147. ===================================================================*/
  148. HRESULT UnInitPerfData()
  149. {
  150. // stop accessing process shared memory
  151. g_PerfData.UnInit();
  152. // stop accessing main shared memory
  153. g_PerfMain.UnInit();
  154. return S_OK;
  155. }
  156. /*===================================================================
  157. UnPreInitPerfData
  158. Un-Initialize from DllInit
  159. Creates critical sections
  160. Parameters
  161. Returns:
  162. HRESULT
  163. ===================================================================*/
  164. HRESULT UnPreInitPerfData()
  165. {
  166. HRESULT hr = S_OK;
  167. hr = g_PerfData.UnInitCriticalSections();
  168. return hr;
  169. }
  170. #endif // PERF_DISABLE