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.

246 lines
6.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: class.hxx
  7. //
  8. //--------------------------------------------------------------------------
  9. #ifndef __CLASS_HXX__
  10. #define __CLASS_HXX__
  11. //--------------------------------------------------------------------------
  12. // There are two kinds of out-of-proc servers
  13. // 1. Traditional local servers that use CoRegisterClassObject and have entries
  14. // for individual CLSIDs each with its own server list.
  15. //
  16. // 2. COM+ surrogate processes that use the IMachineActivatorControl interface
  17. // for registration/revocation, and have a server-list per process GUID.
  18. //
  19. // There are two tables, one for each kind of server.
  20. //
  21. //--------------------------------------------------------------------------
  22. class CServerTable;
  23. class CServerTableEntry;
  24. extern CServerTable * gpClassTable;
  25. extern CServerTable * gpProcessTable;
  26. extern CSharedLock * gpClassLock;
  27. extern CSharedLock * gpProcessLock;
  28. extern CInterlockedInteger gRegisterKey;
  29. typedef enum {ENTRY_TYPE_CLASS, ENTRY_TYPE_PROCESS} EnumEntryType;
  30. //
  31. // CServerTable
  32. //
  33. class CServerTable : public CGuidTable
  34. {
  35. friend class CServerTableEntry;
  36. public:
  37. CServerTable(
  38. OUT LONG& Status,
  39. IN EnumEntryType EntryType
  40. ) : CGuidTable( Status ), _EntryType(EntryType)
  41. {
  42. _pServerTableLock = (_EntryType == ENTRY_TYPE_CLASS)
  43. ? gpClassLock
  44. : gpProcessLock;
  45. }
  46. ~CServerTable() {}
  47. CServerTableEntry *
  48. Create(
  49. IN GUID & ServerGuid
  50. );
  51. CServerTableEntry *
  52. Lookup(
  53. IN GUID & ServerGuid
  54. );
  55. CServerTableEntry *
  56. GetOrCreate(
  57. IN GUID & ServerGuid
  58. );
  59. private:
  60. EnumEntryType _EntryType;
  61. CSharedLock * _pServerTableLock;
  62. };
  63. //+-------------------------------------------------------------------------
  64. //
  65. // CServerTableEntry
  66. //
  67. //--------------------------------------------------------------------------
  68. class CServerTableEntry : public CGuidTableEntry
  69. {
  70. public:
  71. CServerTableEntry(
  72. OUT LONG& Status,
  73. IN GUID * pServerGUID,
  74. IN EnumEntryType EntryType
  75. );
  76. ~CServerTableEntry();
  77. DWORD
  78. Release();
  79. HRESULT
  80. RegisterServer(
  81. IN CProcess * pServerProcess,
  82. IN IPID ipid,
  83. IN CClsidData * pClsidData, // NULL for ComPlus Surrogate
  84. IN CAppidData * pAppidData,
  85. IN UCHAR ServerState,
  86. OUT DWORD * pRegistrationKey
  87. );
  88. void
  89. RevokeServer(
  90. IN CProcess * pServerProcess,
  91. IN DWORD RegistrationKey
  92. );
  93. void
  94. RevokeServer(
  95. IN ScmProcessReg * pScmProcessReg
  96. );
  97. void
  98. UnsuspendServer(
  99. IN DWORD RegistrationKey
  100. );
  101. BOOL
  102. LookupServer(
  103. IN CToken * pClientToken,
  104. IN BOOL bRemoteActivation,
  105. IN BOOL bClientImpersonating,
  106. IN WCHAR * pwszWinstaDesktop,
  107. IN DWORD dwFlags,
  108. IN LONG lThreadToken,
  109. IN LONG lSessionID,
  110. IN DWORD pid,
  111. IN DWORD dwProcessReqType,
  112. OUT CServerListEntry ** ppServerListEntry
  113. );
  114. HRESULT ServerExists(
  115. IN ACTIVATION_PARAMS * pActParams, BOOL *pfExist
  116. );
  117. BOOL
  118. LookupServer(
  119. IN DWORD RegistrationKey,
  120. OUT CServerListEntry ** ppServerListEntry
  121. );
  122. BOOL
  123. CallRunningServer(
  124. IN ACTIVATION_PARAMS * pActParams,
  125. IN DWORD dwFlags,
  126. IN LONG lThreadToken,
  127. IN CClsidData * pClsidData, OPTIONAL
  128. OUT HRESULT * phr
  129. );
  130. BOOL RegisterHandles(IN CServerListEntry * pEntry,
  131. IN CProcess *pServerProcess);
  132. BOOL
  133. WaitForLocalServer(
  134. IN HANDLE hRegisterEvent,
  135. IN ULONG &winerr
  136. );
  137. BOOL
  138. WaitForDllhostServer(
  139. IN HANDLE hRegisterEvent,
  140. IN ACTIVATION_PARAMS * pActParams,
  141. IN ULONG &winerr,
  142. IN LONG lThreadToken
  143. );
  144. BOOL
  145. WaitForService(
  146. IN SC_HANDLE hService,
  147. IN HANDLE hRegisterEvent,
  148. IN BOOL bServiceAlreadyRunning
  149. );
  150. HRESULT
  151. WaitForInitCompleted(
  152. IN CServerListEntry *pEntry,
  153. IN CClsidData *pClsidData
  154. );
  155. HRESULT
  156. StartServerAndWait(
  157. IN ACTIVATION_PARAMS * pActParams,
  158. IN CClsidData * pClsidData,
  159. IN LONG &lThreadToken
  160. );
  161. //
  162. // The following methods are for supporting custom activatorss
  163. //
  164. CServerList* GetServerListWithSharedLock();
  165. void ReleaseSharedListLock();
  166. void SuspendClass();
  167. void UnsuspendClass();
  168. void RetireClass();
  169. void SuspendApplication();
  170. void UnsuspendApplication();
  171. void RetireApplication();
  172. BOOL IsSuspended();
  173. void SetSuspendedFlagOnNewServer(CProcess* pprocess);
  174. private:
  175. inline CSharedLock* ServerLock()
  176. {
  177. return &_ServerLock;
  178. }
  179. void SetSuspendOnAllServers(BOOL bSuspended);
  180. void RetireAllServers();
  181. EnumEntryType _EntryType;
  182. CSharedLock * _pParentTableLock;
  183. CServerTable * _pParentTable;
  184. LONG _lThreadToken;
  185. DWORD _dwProcessId;
  186. HANDLE _hProcess;
  187. CProcess* _pProcess;
  188. void * _pvRunAsHandle;
  189. BOOL _bSuspendedClsid;
  190. BOOL _bSuspendedApplication;
  191. // the _bRetired flag exists per-running process/application
  192. CServerList _ServerList;
  193. CSharedLock _ServerLock;
  194. };
  195. #endif // __CLASS_HXX__