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.

534 lines
16 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: scmrot.hxx
  7. //
  8. // Contents: Classes used in implementing the ROT in the SCM
  9. //
  10. // Functions:
  11. //
  12. // History: 20-Jan-95 Ricksa Created
  13. //
  14. //--------------------------------------------------------------------------
  15. #ifndef __SCMROT_HXX__
  16. #define __SCMROT_HXX__
  17. InterfaceData *AllocateAndCopy(InterfaceData *pifdIn);
  18. #define SCM_HASH_SIZE 251
  19. #define SCMROT_SIG 0x746f7263
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: CScmRotEntry (sre)
  23. //
  24. // Purpose: Entry in the SCM's ROT
  25. //
  26. // Interface: IsEqual - tells whether entry is equal to input key
  27. // GetPRocessID - accessor to process ID for entry
  28. // SetTime - set the time for the entry
  29. // GetTime - get the time for the entry
  30. // GetObject - get the marshaled object for the entry
  31. // GetMoniker - get marshaled moniker for the entry
  32. // IsValid - determines if signitures for entry are valid
  33. // Key - pointer to key for the entry
  34. // cKey - get count of bytes in the key
  35. //
  36. // History: 20-Jan-95 Ricksa Created
  37. //
  38. // Notes:
  39. //
  40. //--------------------------------------------------------------------------
  41. class CScmRotEntry : public CScmHashEntry
  42. {
  43. public:
  44. CScmRotEntry(
  45. DWORD dwScmRotId,
  46. MNKEQBUF *pmnkeqbuf,
  47. FILETIME *pfiletime,
  48. DWORD _dwProcessID,
  49. #if 1 // #ifndef _CHICAGO_
  50. CToken *pToken,
  51. #endif
  52. WCHAR *pwszWinstaDesktop,
  53. InterfaceData *pifdObject,
  54. InterfaceData *pifdObjectName);
  55. ~CScmRotEntry(void);
  56. BOOL IsEqual(LPVOID pKey, UINT cbKey);
  57. DWORD GetProcessID(void);
  58. void SetTime(FILETIME *pfiletime);
  59. void GetTime(FILETIME *pfiletime);
  60. InterfaceData * GetObject(void);
  61. InterfaceData * GetMoniker(void);
  62. #if 1 // #ifndef _CHICAGO_
  63. CToken * Token();
  64. #endif
  65. WCHAR * WinstaDesktop();
  66. BOOL IsValid(DWORD dwScmId);
  67. BYTE * Key(void);
  68. DWORD cKey(void);
  69. void SetScmRegKey(SCMREGKEY *psrkOut);
  70. // Real new for this object.
  71. void *operator new(
  72. size_t size,
  73. size_t sizeWinstaDesktop,
  74. size_t sizeObject,
  75. size_t sizeMnkEqBuf,
  76. size_t sizeObjectName );
  77. void operator delete(void *pvMem);
  78. private:
  79. #if DBG == 1
  80. // For debug builds we override this operator to
  81. // prevent its use by causing a run time error.
  82. //
  83. // We also make it private, to hopefully cause a
  84. // compile-time error.
  85. void *operator new(size_t size);
  86. #endif // DBG
  87. // Signiture for object in memory
  88. DWORD _dwSig;
  89. // SCM id for uniqueness
  90. DWORD _dwScmRotId;
  91. // Process ID for registered object. Used for
  92. // internal support of finding objects that
  93. // a process has registered.
  94. DWORD _dwProcessID;
  95. // Time of last change
  96. FILETIME _filetimeLastChange;
  97. // Object identifier used by client to get
  98. // actual object from the object server
  99. InterfaceData * _pifdObject;
  100. // Comparison buffer.
  101. MNKEQBUF * _pmkeqbufKey;
  102. // Object name (really only used for enumeration).
  103. InterfaceData * _pifdObjectName;
  104. #if 1 // #ifndef _CHICAGO_
  105. // Token object of the registering server.
  106. CToken * _pToken;
  107. #endif
  108. // Window station - desktop of server.
  109. WCHAR * _pwszWinstaDesktop;
  110. // Where the data for _pifdObject, _pmkeqbufKey,
  111. // _pifdObjectName, and _pwszWinstaDesktop are stored.
  112. BYTE _ab[1];
  113. };
  114. //+-------------------------------------------------------------------------
  115. //
  116. // Member: CScmRotEntry::~CScmRotEntry
  117. //
  118. // Synopsis: Clean up object and invalidate signitures
  119. //
  120. // History: 20-Jan-95 Ricksa Created
  121. //
  122. //--------------------------------------------------------------------------
  123. inline CScmRotEntry::~CScmRotEntry(void)
  124. {
  125. // Invalidate signiture identifiers.
  126. _dwSig = 0;
  127. _dwScmRotId = 0;
  128. #if 1 // #ifndef _CHICAGO_
  129. if ( _pToken )
  130. _pToken->Release();
  131. #endif
  132. // Remember that all the data allocated in pointers was allocated
  133. // when this object was created so the freeing of the object's memory
  134. // will free all the memory for this object.
  135. }
  136. //+-------------------------------------------------------------------------
  137. //
  138. // Member: CScmRotEntry::GetProcessID
  139. //
  140. // Synopsis: Get the process ID for the registration
  141. //
  142. // History: 20-Jan-95 Ricksa Created
  143. //
  144. //--------------------------------------------------------------------------
  145. inline DWORD CScmRotEntry::GetProcessID(void)
  146. {
  147. return _dwProcessID;
  148. }
  149. //+-------------------------------------------------------------------------
  150. //
  151. // Member: CScmRotEntry::SetTime
  152. //
  153. // Synopsis: Set the time for the entry
  154. //
  155. // History: 20-Jan-95 Ricksa Created
  156. //
  157. //--------------------------------------------------------------------------
  158. inline void CScmRotEntry::SetTime(FILETIME *pfiletime)
  159. {
  160. _filetimeLastChange = *pfiletime;
  161. }
  162. //+-------------------------------------------------------------------------
  163. //
  164. // Member: CScmRotEntry::GetTime
  165. //
  166. // Synopsis: Get the time for an entry
  167. //
  168. // History: 20-Jan-95 Ricksa Created
  169. //
  170. //--------------------------------------------------------------------------
  171. inline void CScmRotEntry::GetTime(FILETIME *pfiletime)
  172. {
  173. *pfiletime = _filetimeLastChange;
  174. }
  175. //+-------------------------------------------------------------------------
  176. //
  177. // Member: CScmRotEntry::GetObject
  178. //
  179. // Synopsis: Return the marshaled interface for the object
  180. //
  181. // History: 20-Jan-95 Ricksa Created
  182. //
  183. //--------------------------------------------------------------------------
  184. inline InterfaceData *CScmRotEntry::GetObject(void)
  185. {
  186. return _pifdObject;
  187. }
  188. //+-------------------------------------------------------------------------
  189. //
  190. // Member: CScmRotEntry::GetMoniker
  191. //
  192. // Synopsis: Return the marshaled moniker
  193. //
  194. // History: 20-Jan-95 Ricksa Created
  195. //
  196. //--------------------------------------------------------------------------
  197. inline InterfaceData *CScmRotEntry::GetMoniker(void)
  198. {
  199. return _pifdObjectName;
  200. }
  201. #if 1 // #ifndef _CHICAGO_
  202. //+-------------------------------------------------------------------------
  203. //
  204. // Member: CScmRotEntry::Token
  205. //
  206. // Synopsis: Return the CToken.
  207. //
  208. //--------------------------------------------------------------------------
  209. inline CToken * CScmRotEntry::Token()
  210. {
  211. return _pToken;
  212. }
  213. #endif // _CHICAGO_
  214. //+-------------------------------------------------------------------------
  215. //
  216. // Member: CScmRotEntry::WinstaDesktop
  217. //
  218. // Synopsis: Return the winsta\desktop string.
  219. //
  220. //--------------------------------------------------------------------------
  221. inline WCHAR * CScmRotEntry::WinstaDesktop()
  222. {
  223. return _pwszWinstaDesktop;
  224. }
  225. //+-------------------------------------------------------------------------
  226. //
  227. // Member: CScmRotEntry::IsValid
  228. //
  229. // Synopsis: Validate signitures for the object
  230. //
  231. // History: 20-Jan-95 Ricksa Created
  232. //
  233. //--------------------------------------------------------------------------
  234. inline BOOL CScmRotEntry::IsValid(DWORD dwScmId)
  235. {
  236. return (SCMROT_SIG == _dwSig) && (_dwScmRotId == dwScmId);
  237. }
  238. //+-------------------------------------------------------------------------
  239. //
  240. // Member: CScmRotEntry::Key
  241. //
  242. // Synopsis: Get the buffer for the marshaled data
  243. //
  244. // History: 20-Jan-95 Ricksa Created
  245. //
  246. //--------------------------------------------------------------------------
  247. inline BYTE *CScmRotEntry::Key(void)
  248. {
  249. return &_pmkeqbufKey->abEqData[0];
  250. }
  251. //+-------------------------------------------------------------------------
  252. //
  253. // Member: CScmRotEntry::cKey
  254. //
  255. // Synopsis: Get count of bytes in the marshaled buffer
  256. //
  257. // History: 20-Jan-95 Ricksa Created
  258. //
  259. //--------------------------------------------------------------------------
  260. inline DWORD CScmRotEntry::cKey(void)
  261. {
  262. return _pmkeqbufKey->cdwSize;
  263. }
  264. //+-------------------------------------------------------------------------
  265. //
  266. // Member: CScmRotEntry::SetScmRegKey
  267. //
  268. // Synopsis: Copy out the registration key
  269. //
  270. // History: 23-Feb-95 Ricksa Created
  271. //
  272. //--------------------------------------------------------------------------
  273. inline void CScmRotEntry::SetScmRegKey(SCMREGKEY *psrkOut)
  274. {
  275. psrkOut->dwEntryLoc = (ULONG64) this;
  276. psrkOut->dwScmId = _dwScmRotId;
  277. }
  278. //+-------------------------------------------------------------------------
  279. //
  280. // Member: CScmRotEntry::operator new
  281. //
  282. // Synopsis: Stop this class being allocated by wrong new
  283. //
  284. // History: 20-Jan-95 Ricksa Created
  285. //
  286. //--------------------------------------------------------------------------
  287. #if DBG == 1
  288. inline void *CScmRotEntry::operator new(size_t size)
  289. {
  290. Win4Assert(0 && "Called regular new on CScmRotEntry");
  291. return NULL;
  292. }
  293. #endif // DBG
  294. //+-------------------------------------------------------------------------
  295. //
  296. // Member: CScmRotEntry::operator new
  297. //
  298. // Synopsis: Force contiguous allocation of data in entry
  299. //
  300. // History: 20-Jan-95 Ricksa Created
  301. //
  302. //--------------------------------------------------------------------------
  303. inline void *CScmRotEntry::operator new(
  304. size_t size,
  305. size_t sizeWinstaDesktop,
  306. size_t sizeObject,
  307. size_t sizeMnkEqBuf,
  308. size_t sizeObjectName)
  309. {
  310. return PrivMemAlloc((ULONG)(size + sizeWinstaDesktop + sizeObject + sizeMnkEqBuf + sizeObjectName) );
  311. }
  312. //+-------------------------------------------------------------------------
  313. //
  314. // Member: CScmRotEntry::operator delete
  315. //
  316. // Synopsis: Make sure the proper allocator is always used for this
  317. // class.
  318. //
  319. // History: 04-Oct-2000 JohnDoty Created
  320. //
  321. //--------------------------------------------------------------------------
  322. inline void CScmRotEntry::operator delete(void *pvMem)
  323. {
  324. PrivMemFree(pvMem);
  325. }
  326. //+-------------------------------------------------------------------------
  327. //
  328. // Class: CScmRot (sr)
  329. //
  330. // Purpose: Provide implementation of the ROT in the SCM
  331. //
  332. // Interface: Register - register a new entry in the ROT.
  333. // Revoke - remove an entry from the ROT
  334. // IsRunning - determine if an entry is in the ROT
  335. // NoteChangeTime - set time last changed in the ROT
  336. // GetTimeOfLastChange - get time of change in the ROT
  337. // EnumRunning - get all running monikers
  338. //
  339. // History: 20-Jan-95 Ricksa Created
  340. //
  341. // Notes:
  342. //
  343. //--------------------------------------------------------------------------
  344. class CScmRot : public CPrivAlloc
  345. {
  346. public:
  347. CScmRot(
  348. HRESULT& hr,
  349. WCHAR *pwszNameHintTable);
  350. HRESULT Register(
  351. #if 1 // #ifndef _CHICAGO_
  352. CProcess *pProcess,
  353. #endif
  354. WCHAR *pwszWinstaDesktop,
  355. MNKEQBUF *pmnkeqbuf,
  356. InterfaceData *pifdObject,
  357. InterfaceData *pifdObjectName,
  358. FILETIME *pfiletime,
  359. DWORD dwProcessID,
  360. WCHAR *pwszServerExe,
  361. SCMREGKEY *pdwRegister);
  362. HRESULT Revoke(
  363. SCMREGKEY *psrkRegister,
  364. BOOL fServer,
  365. InterfaceData **pifdObject,
  366. InterfaceData **pifdName);
  367. HRESULT IsRunning(
  368. #if 1 // #ifndef _CHICAGO_
  369. CToken *pToken,
  370. #endif
  371. WCHAR *pwszWinstaDesktop,
  372. MNKEQBUF *pmnkeqbuf);
  373. HRESULT GetObject(
  374. #if 1 // #ifndef _CHICAGO_
  375. CToken *pToken,
  376. #endif
  377. WCHAR *pwszWinstaDesktop,
  378. DWORD dwProcessID,
  379. MNKEQBUF *pmnkeqbuf,
  380. SCMREGKEY *psrkRegister,
  381. InterfaceData **ppifdObject);
  382. HRESULT NoteChangeTime(
  383. SCMREGKEY *psrkRegister,
  384. FILETIME *pfiletime);
  385. HRESULT GetTimeOfLastChange(
  386. #if 1 // #ifndef _CHICAGO_
  387. CToken *pToken,
  388. #endif
  389. WCHAR *pwszWinstaDesktop,
  390. MNKEQBUF *pmnkeqbuf,
  391. FILETIME *pfiletime);
  392. HRESULT EnumRunning(
  393. #if 1 // #ifndef _CHICAGO_
  394. CToken *pToken,
  395. #endif
  396. WCHAR *pwszWinstaDesktop,
  397. MkInterfaceList **ppMkIFList);
  398. private:
  399. // This is a friend for Chicago initialization purposes.
  400. friend HRESULT StartSCM(VOID);
  401. CScmRotEntry * GetRotEntry(
  402. #if 1 // #ifndef _CHICAGO_
  403. CToken *pToken,
  404. #endif
  405. WCHAR *pwszWinstaDesktop,
  406. MNKEQBUF *pmnkeqbuf);
  407. // Mutex to protect from multithreaded update
  408. // This mutex must be static so we can initialize
  409. // it per process in Chicago.
  410. #if 0 // #ifdef _CHICAGO_
  411. static CStaticPortableMutex _mxs;
  412. #else
  413. CDynamicPortableMutex _mxs;
  414. #endif // _CHICAGO_
  415. // ID Counter to make entries unique
  416. DWORD _dwIdCntr;
  417. #if 1 // #ifndef _CHICAGO_
  418. // Table that tells clients whether they need to
  419. // contact the SCM for accurate information.
  420. CScmRotHintTable _rht;
  421. #endif // !_CHICAGO_
  422. // Scm Hash Table
  423. CScmHashTable _sht;
  424. };
  425. //+-------------------------------------------------------------------------
  426. //
  427. // Member: CScmRot::CScmRot
  428. //
  429. // Synopsis: Initialize the SCM ROT
  430. //
  431. // History: 20-Jan-95 Ricksa Created
  432. //
  433. //--------------------------------------------------------------------------
  434. inline CScmRot::CScmRot(HRESULT& hr, WCHAR *pwszNameHintTable)
  435. : _dwIdCntr(0),
  436. #if 1 // #ifndef _CHICAGO_
  437. _rht(pwszNameHintTable),
  438. #endif // _CHICAGO_
  439. _sht(SCM_HASH_SIZE)
  440. {
  441. #if 0 // #ifdef _CHICAGO_
  442. hr = _sht.InitOK() ? S_OK : E_OUTOFMEMORY;
  443. #else // ! _CHICAGO_
  444. hr = (_sht.InitOK() && _rht.InitOK()) ? S_OK : E_OUTOFMEMORY;
  445. if (hr == S_OK)
  446. {
  447. if (_mxs.FInit() == FALSE)
  448. {
  449. ASSERT(FALSE);
  450. hr = E_OUTOFMEMORY;
  451. }
  452. }
  453. #endif // !_CHICAGO_
  454. }
  455. #endif __SCMROT_HXX__