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.

101 lines
4.6 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: ExternalProcess.h
  3. //
  4. // Copyright (c) 1999-2000, Microsoft Corporation
  5. //
  6. // Class to handle premature termination of external processes or signaling
  7. // of termination of an external process.
  8. //
  9. // History: 1999-09-20 vtan created
  10. // 2000-02-01 vtan moved from Neptune to Whistler
  11. // --------------------------------------------------------------------------
  12. #ifndef _ExternalProcess_
  13. #define _ExternalProcess_
  14. #include "CountedObject.h"
  15. #include "KernelResources.h"
  16. // --------------------------------------------------------------------------
  17. // IExternalProcess
  18. //
  19. // Purpose: This interface defines functions that clients of
  20. // CExternalProcess must implement.
  21. //
  22. // History: 1999-09-14 vtan created
  23. // 2000-02-01 vtan moved from Neptune to Whistler
  24. // 2000-06-21 vtan added RemoveTokenSIDsAndPrivileges
  25. // --------------------------------------------------------------------------
  26. class IExternalProcess : public CCountedObject
  27. {
  28. public:
  29. virtual NTSTATUS Start (const TCHAR *pszCommandLine,
  30. DWORD dwCreateFlags,
  31. const STARTUPINFO& startupInfo,
  32. PROCESS_INFORMATION& processInformation);
  33. virtual bool AllowTermination (DWORD dwExitCode) = 0;
  34. virtual NTSTATUS SignalTermination (void);
  35. virtual NTSTATUS SignalAbnormalTermination (void);
  36. virtual NTSTATUS SignalRestart (void);
  37. private:
  38. NTSTATUS RemoveTokenSIDsAndPrivileges (HANDLE hTokenIn, HANDLE& hTokenOut);
  39. };
  40. // --------------------------------------------------------------------------
  41. // CExternalProcess
  42. //
  43. // Purpose: This class handles the starting and monitoring the termination
  44. // of an external process.
  45. //
  46. // History: 1999-09-14 vtan created
  47. // 2000-02-01 vtan moved from Neptune to Whistler
  48. // --------------------------------------------------------------------------
  49. class CJobCompletionWatcher;
  50. class CExternalProcess : public CCountedObject
  51. {
  52. private:
  53. CExternalProcess (const CExternalProcess& copyObject);
  54. const CExternalProcess& operator = (const CExternalProcess& assignObject);
  55. protected:
  56. CExternalProcess (void);
  57. ~CExternalProcess (void);
  58. public:
  59. void SetInterface (IExternalProcess *pIExternalProcess);
  60. IExternalProcess* GetInterface (void) const;
  61. void SetParameter (const TCHAR* pszParameter);
  62. NTSTATUS Start (void);
  63. NTSTATUS End (void);
  64. NTSTATUS Terminate (void);
  65. bool HandleNoProcess (void);
  66. void HandleNewProcess (DWORD dwProcessID);
  67. void HandleTermination (DWORD dwProcessID);
  68. bool IsStarted (void) const;
  69. protected:
  70. virtual void NotifyNoProcess (void);
  71. void AdjustForDebugging (void);
  72. bool IsBeingDebugged (void) const;
  73. private:
  74. bool IsPrefixedWithNTSD (void) const;
  75. bool IsImageFileExecutionDebugging (void) const;
  76. protected:
  77. HANDLE _hProcess;
  78. DWORD _dwProcessID,
  79. _dwProcessExitCode,
  80. _dwCreateFlags,
  81. _dwStartFlags;
  82. WORD _wShowFlags;
  83. int _iRestartCount;
  84. TCHAR _szCommandLine[MAX_PATH],
  85. _szParameter[MAX_PATH];
  86. CJob _job;
  87. private:
  88. IExternalProcess *_pIExternalProcess;
  89. CJobCompletionWatcher *_jobCompletionWatcher;
  90. };
  91. #endif /* _ExternalProcess_ */