LLDB mainline
ProcessLauncherWindows.h
Go to the documentation of this file.
1//===-- ProcessLauncherWindows.h --------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef lldb_Host_windows_ProcessLauncherWindows_h_
10#define lldb_Host_windows_ProcessLauncherWindows_h_
11
14#include "llvm/Support/Error.h"
15
16namespace lldb_private {
17
19
20/// This class manages the lifetime of a PROC_THREAD_ATTRIBUTE_LIST, which is
21/// used with STARTUPINFOEX.
22///
23/// The attribute list is automatically cleaned up when this object is
24/// destroyed.
26public:
27 /// Allocate memory for the attribute list, initialize it, and sets the
28 /// lpAttributeList member of STARTUPINFOEXW structure.
29 ///
30 /// \param[in,out] startupinfoex
31 /// The STARTUPINFOEXW structure whose lpAttributeList member will be set
32 /// to point to the attribute list. The caller must ensure
33 /// this structure remains valid for the lifetime of the returned object.
34 ///
35 /// \return
36 /// A ProcThreadAttributeList object on success, or an error code on
37 /// failure.
38 static llvm::ErrorOr<ProcThreadAttributeList>
39 Create(STARTUPINFOEXW &startupinfoex);
40
41 /// Setup the PseudoConsole handle in the underlying
42 /// LPPROC_THREAD_ATTRIBUTE_LIST.
43 ///
44 /// \param hPC
45 /// The handle to the PseudoConsole.
46 llvm::Error SetupPseudoConsole(HPCON hPC);
47
49 if (lpAttributeList) {
50 DeleteProcThreadAttributeList(lpAttributeList);
51 free(lpAttributeList);
52 }
53 }
54
55 /// ProcThreadAttributeList is not copyable.
56 /// @{
59 /// @}
60
62 : lpAttributeList(other.lpAttributeList) {
63 other.lpAttributeList = nullptr;
64 }
65
66private:
67 explicit ProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST list)
68 : lpAttributeList(list) {}
69
70 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
71};
72
74public:
76 Status &error) override;
77
78protected:
79 HANDLE GetStdioHandle(const ProcessLaunchInfo &launch_info, int fd);
80
81 /// Get the list of Windows handles that should be inherited by the child
82 /// process and update `STARTUPINFOEXW` with the handle list.
83 ///
84 /// If no handles need to be inherited, an empty vector is returned.
85 ///
86 /// Otherwise, the function populates the
87 /// `PROC_THREAD_ATTRIBUTE_HANDLE_LIST` attribute in `startupinfoex` with the
88 /// collected handles using `UpdateProcThreadAttribute`. On success, the
89 /// vector of inherited handles is returned.
90 ///
91 /// \param launch_info
92 /// The process launch configuration.
93 ///
94 /// \param startupinfoex
95 /// The extended STARTUPINFO structure for the process being created.
96 ///
97 /// \param stdout_handle
98 /// \param stderr_handle
99 /// \param stdin_handle
100 /// Optional explicit standard stream handles to use for the child process.
101 ///
102 /// \returns
103 /// `std::vector<HANDLE>` containing all handles that the child must
104 /// inherit.
105 llvm::ErrorOr<std::vector<HANDLE>>
106 GetInheritedHandles(const ProcessLaunchInfo &launch_info,
107 STARTUPINFOEXW &startupinfoex,
108 HANDLE stdout_handle = NULL, HANDLE stderr_handle = NULL,
109 HANDLE stdin_handle = NULL);
110};
111}
112
113#endif
static llvm::raw_ostream & error(Stream &strm)
void * HPCON
void * HANDLE
ProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST list)
ProcThreadAttributeList(ProcThreadAttributeList &&other) noexcept
ProcThreadAttributeList & operator=(const ProcThreadAttributeList &)=delete
static llvm::ErrorOr< ProcThreadAttributeList > Create(STARTUPINFOEXW &startupinfoex)
Allocate memory for the attribute list, initialize it, and sets the lpAttributeList member of STARTUP...
llvm::Error SetupPseudoConsole(HPCON hPC)
Setup the PseudoConsole handle in the underlying LPPROC_THREAD_ATTRIBUTE_LIST.
LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList
ProcThreadAttributeList(const ProcThreadAttributeList &)=delete
ProcThreadAttributeList is not copyable.
HostProcess LaunchProcess(const ProcessLaunchInfo &launch_info, Status &error) override
llvm::ErrorOr< std::vector< HANDLE > > GetInheritedHandles(const ProcessLaunchInfo &launch_info, STARTUPINFOEXW &startupinfoex, HANDLE stdout_handle=NULL, HANDLE stderr_handle=NULL, HANDLE stdin_handle=NULL)
Get the list of Windows handles that should be inherited by the child process and update STARTUPINFOE...
HANDLE GetStdioHandle(const ProcessLaunchInfo &launch_info, int fd)
An error handling class.
Definition Status.h:118
A class that represents a running process on the host machine.