| 1 | /*++ |
| 2 | |
| 3 | Copyright (c) Microsoft. All rights reserved. |
| 4 | |
| 5 | Module Name: |
| 6 | |
| 7 | WSLCProcessIO.h |
| 8 | |
| 9 | Abstract: |
| 10 | |
| 11 | Contains the different WSLCProcessIO definitions for process IO handling. |
| 12 | |
| 13 | --*/ |
| 14 | |
| 15 | #pragma once |
| 16 | #include "HandleIO.h" |
| 17 | #include "wslc.h" |
| 18 | |
| 19 | namespace wsl::windows::service::wslc { |
| 20 | |
| 21 | struct TypedHandle |
| 22 | { |
| 23 | common::io::HandleWrapper Handle; |
| 24 | WSLCHandleType Type = WSLCHandleTypeUnknown; |
| 25 | |
| 26 | TypedHandle() = default; |
| 27 | TypedHandle(common::io::HandleWrapper&& handle, WSLCHandleType type) : Handle(std::move(handle)), Type(type) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | bool is_valid() const noexcept |
| 32 | { |
| 33 | return Handle.IsValid(); |
| 34 | } |
| 35 | HANDLE get() const noexcept |
| 36 | { |
| 37 | return Handle.Get(); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | class WSLCProcessIO |
| 42 | { |
| 43 | public: |
| 44 | virtual ~WSLCProcessIO() = default; |
| 45 | virtual TypedHandle OpenFd(ULONG Fd) = 0; |
| 46 | }; |
| 47 | |
| 48 | class RelayedProcessIO : public WSLCProcessIO |
| 49 | { |
| 50 | public: |
| 51 | RelayedProcessIO(std::map<ULONG, TypedHandle>&& fds); |
| 52 | |
| 53 | TypedHandle OpenFd(ULONG Fd) override; |
| 54 | |
| 55 | private: |
| 56 | std::map<ULONG, TypedHandle> m_relayedHandles; |
| 57 | }; |
| 58 | |
| 59 | class TTYProcessIO : public WSLCProcessIO |
| 60 | { |
| 61 | public: |
| 62 | TTYProcessIO(TypedHandle&& IoStream); |
| 63 | |
| 64 | TypedHandle OpenFd(ULONG Fd) override; |
| 65 | |
| 66 | private: |
| 67 | TypedHandle m_ioStream; |
| 68 | }; |
| 69 | |
| 70 | class VMProcessIO : public WSLCProcessIO |
| 71 | { |
| 72 | public: |
| 73 | VMProcessIO(std::map<ULONG, TypedHandle>&& handles); |
| 74 | TypedHandle OpenFd(ULONG Fd) override; |
| 75 | |
| 76 | private: |
| 77 | std::map<ULONG, TypedHandle> m_handles; |
| 78 | }; |
| 79 | |
| 80 | } // namespace wsl::windows::service::wslc |