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.

173 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999.
  5. //
  6. // File: dmnslave.hxx
  7. //
  8. // History: 01-31-96 srikants Created
  9. // 01-06-97 srikants Renamed to dmnslave.hxx
  10. //
  11. //----------------------------------------------------------------------------
  12. #pragma once
  13. #include <dmnproxy.hxx>
  14. #include <proc32.hxx>
  15. #include "pdaemon.hxx"
  16. class CCiManager;
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Class: CSecurityAttributes
  20. //
  21. // Purpose: A wrapper class for SECURITY_ATTRIBUTES to initialize it for
  22. // automatic inheritance.
  23. //
  24. // History: 2-02-96 srikants Created
  25. //
  26. // Notes: The shared-memory, event classes, etc need a pointer to
  27. // SECURITY_ATTRIBUTES to the constructor. Since
  28. // SECURITY_ATTRIBUTES
  29. //
  30. //----------------------------------------------------------------------------
  31. class CSecurityAttributes : public SECURITY_ATTRIBUTES
  32. {
  33. public:
  34. CSecurityAttributes()
  35. {
  36. nLength = sizeof(SECURITY_ATTRIBUTES);
  37. lpSecurityDescriptor = NULL;
  38. bInheritHandle = TRUE;
  39. }
  40. private:
  41. };
  42. //+---------------------------------------------------------------------------
  43. //
  44. // Class: CDaemonSlave
  45. //
  46. // Purpose: Class that manages the slave thread that executes on behalf
  47. // of the downlevel DaemonProcess in the ContentIndex.
  48. //
  49. // History: 1-31-96 srikants Created
  50. //
  51. // Notes:
  52. //
  53. //----------------------------------------------------------------------------
  54. class CDaemonSlave : public PFilterDaemonControl
  55. {
  56. public:
  57. CDaemonSlave( CCiManager & ciManager,
  58. CCI * pCci,
  59. WCHAR const * pwcsCatRoot,
  60. CSharedNameGen & nameGen,
  61. const GUID & clsidDaemonClientMgr );
  62. virtual ~CDaemonSlave();
  63. //
  64. // PFilterDaemonControl methods.
  65. //
  66. virtual void InitiateShutdown();
  67. virtual void WaitForDeath()
  68. {
  69. _thrSlave.WaitForDeath();
  70. }
  71. virtual void StartFiltering( BYTE const * pbStartupData,
  72. ULONG cbStartupData );
  73. private:
  74. enum EState
  75. {
  76. eReadyToStart, // ready to startup daemon process
  77. eRunning, // Daemon process is running
  78. eDied, // Daemon process died and CiManager must be notified
  79. eDeathNotified // CiDaemon death has been notified to CiManager
  80. };
  81. static DWORD GetInheritableHandle( HANDLE & hTarget );
  82. static DWORD WINAPI SlaveThread( void * self );
  83. void DoWork();
  84. void KillProcess();
  85. void KillThread();
  86. void StartProcess();
  87. BOOL IsProcessLowOnResources() const;
  88. void RestartDaemon();
  89. void SaveDaemonExitCode();
  90. //
  91. // Slave work methods.
  92. //
  93. SCODE FilterReady();
  94. SCODE FilterMore();
  95. SCODE FilterDone();
  96. SCODE FilterDataReady();
  97. SCODE FilterStoreValue();
  98. SCODE FilterStoreSecurity();
  99. SCODE FPSToPROPID();
  100. SCODE GetClientStartupData();
  101. void DoSlaveWork();
  102. void DoStateMachineWork();
  103. BOOL IsScanNeeded( NTSTATUS status )
  104. {
  105. return FILTER_S_FULL_CONTENTSCAN_IMMEDIATE == status;
  106. }
  107. CCiManager & _ciManager; // Content Index Manager
  108. CCI* _pCci; // CCI
  109. BOOL _fAbort; // Set to TRUE if the thread should
  110. // abort.
  111. CThread _thrSlave; // The thread that does the work
  112. CSecurityAttributes _sa; // Security attributes for enabling
  113. // inheritance.
  114. CIPMutexSem _smemMutex; // Guard for the shared memory
  115. CLocalSystemSharedMemory _sharedMem; // Shared memory used by the two.
  116. CFilterSharedMemLayout * _pLayout;
  117. CEventSem _evtCi; // Event used to signal CI.
  118. CEventSem _evtDaemon; // Event used to signal Daemon.
  119. CProcess * _pProcess;
  120. XArray<WCHAR> _wszCatRoot;// Catalog root.
  121. HANDLE _hParent; // An inheritable handle of this
  122. // process.
  123. CMutexSem _mutex; // To guard this object
  124. //
  125. // Current state of the thread.
  126. //
  127. EState _state;
  128. //
  129. // Last exit code of the daemon process.
  130. //
  131. SCODE _daemonExitStatus;
  132. const GUID & _clsidDaemonClientMgr;
  133. //
  134. // Startup client data.
  135. //
  136. XArray<BYTE> _xbStartupData;
  137. ULONG _cbStartupData;
  138. };