| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCProcess.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Contains the definition for WSLCProcess |
| 12 | |
| 13 | --*/ |
| 14 | #pragma once |
| 15 | |
| 16 | #include "wslc.h" |
| 17 | #include "WSLCCompat.h" |
| 18 | #include "WSLCProcessControl.h" |
| 19 | #include "WSLCProcessIO.h" |
| 20 | |
| 21 | namespace wsl::windows::service::wslc { |
| 22 | |
| 23 | class WSLCVirtualMachine; |
| 24 | |
| 25 | class DECLSPEC_UUID("AFBEA6D6-D8A4-4F81-8FED-F947EB74B33B") WSLCProcess |
| 26 | : public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLCProcess, IWSLCCompatProcess, IFastRundown> |
| 27 | { |
| 28 | public: |
| 29 | WSLCProcess(std::shared_ptr<WSLCProcessControl> Control, std::unique_ptr<WSLCProcessIO>&& Io, WSLCProcessFlags Flags); |
| 30 | WSLCProcess(const WSLCProcess&) = delete; |
| 31 | WSLCProcess& operator=(const WSLCProcess&) = delete; |
| 32 | |
| 33 | IFACEMETHOD(Signal)(_In_ int Signal) override; |
| 34 | IFACEMETHOD(GetExitEvent)(_Out_ HANDLE* Event) override; |
| 35 | IFACEMETHOD(GetStdHandle)(_In_ WSLCFD Fd, _Out_ WSLCHandle* Handle) override; |
| 36 | IFACEMETHOD(GetFlags)(_Out_ WSLCProcessFlags* Flags) override; |
| 37 | IFACEMETHOD(GetPid)(_Out_ int* Pid) override; |
| 38 | IFACEMETHOD(GetState)(_Out_ WSLCProcessState* State, _Out_ int* Code) override; |
| 39 | IFACEMETHOD(ResizeTty)(_In_ ULONG Rows, _In_ ULONG Columns) override; |
| 40 | |
| 41 | // IWSLCCompatProcess - converts the WSLCCompat types to the wslc.idl types and forwards to the methods above. |
| 42 | IFACEMETHOD(GetStdHandle)(_In_ WSLCFD Fd, _Out_ WSLCCompatHandle* Handle) override; |
| 43 | |
| 44 | common::io::HandleWrapper GetStdHandle(int Index); |
| 45 | HANDLE GetExitEvent(); |
| 46 | int GetPid() const; |
| 47 | |
| 48 | // Attaches an opaque keep-alive token whose lifetime is bound to this process object. A |
| 49 | // root-namespace process is not tracked as a container, so it relies on this token to hold an |
| 50 | // activity reference on the owning session for as long as the client keeps the process alive, |
| 51 | // preventing the idle worker from tearing the VM down (and killing the process) underneath it. |
| 52 | void SetKeepAliveToken(Microsoft::WRL::ComPtr<IUnknown>&& Token) noexcept |
| 53 | { |
| 54 | m_keepAliveToken = std::move(Token); |
| 55 | } |
| 56 | |
| 57 | private: |
| 58 | WSLCProcessFlags m_flags; |
| 59 | std::shared_ptr<WSLCProcessControl> m_control; |
| 60 | std::unique_ptr<WSLCProcessIO> m_io; |
| 61 | Microsoft::WRL::ComPtr<IUnknown> m_keepAliveToken; |
| 62 | }; |
| 63 | } // namespace wsl::windows::service::wslc |