master
h 84 lines 2.03 KB
Raw
1 /*++
2
3 Copyright (c) Microsoft. All rights reserved.
4
5 Module Name:
6
7 Dmesg.h
8
9 Abstract:
10
11 This file contains declarations used to collect dmesg output
12
13 --*/
14
15 #pragma once
16
17 #include "relay.hpp"
18 #include "HandleIO.h"
19 #include "RingBuffer.h"
20
21 class DmesgCollector
22 {
23 public:
24 DmesgCollector() = delete;
25 ~DmesgCollector();
26
27 std::wstring EarlyConsoleName() const
28 {
29 return m_earlyConsoleName;
30 }
31
32 std::wstring VirtioConsoleName() const
33 {
34 return m_virtioConsoleName;
35 }
36
37 static std::shared_ptr<DmesgCollector> Create(
38 GUID VmId,
39 HANDLE ExitEvent,
40 bool EnableTelemetry,
41 bool EnableDebugConsole,
42 const std::wstring& Com1PipeName,
43 bool EnableEarlyBootConsole,
44 wil::unique_handle&& OutputHandle);
45
46 private:
47 enum InputSource
48 {
49 DmesgCollectorEarlyConsole,
50 DmesgCollectorConsole
51 };
52
53 DmesgCollector(GUID VmId, HANDLE ExitEvent, bool EnableTelemetry, bool EnableDebugConsole, const std::wstring& Com1PipeName, wil::unique_handle&& OutputHandle = {});
54
55 void Start(bool EnableEarlyBootConsole);
56
57 void Run();
58
59 static std::pair<std::wstring, wil::unique_hfile> CreateConsolePipe();
60
61 void ProcessInput(InputSource Source, const gsl::span<char>& Input);
62
63 std::wstring m_com1PipeName;
64 std::wstring m_earlyConsoleName;
65 std::wstring m_virtioConsoleName;
66 HANDLE m_vmExitEvent;
67 wil::unique_event m_threadExitEvent{wil::EventOptions::ManualReset};
68 wil::unique_hfile m_com1Pipe;
69 wil::unique_handle m_outputHandle;
70 wil::unique_hfile m_earlyConsolePipe;
71 wil::unique_hfile m_virtioConsolePipe;
72 GUID m_runtimeId{};
73 RingBuffer m_dmesgBuffer{LX_RELAY_BUFFER_SIZE};
74 RingBuffer m_dmesgEarlyBuffer{LX_RELAY_BUFFER_SIZE};
75 bool m_debugConsole;
76 bool m_telemetry;
77 bool m_earlyConsoleTransition = false;
78 bool m_pipeServer = false;
79
80 std::thread m_thread;
81
82 wsl::windows::common::io::WriteHandle* m_outputWrite = nullptr;
83 wsl::windows::common::io::WriteNamedPipe* m_com1Write = nullptr;
84 };