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/ErrorOr.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
42 if (lpAttributeList) {
43 DeleteProcThreadAttributeList(lpAttributeList);
44 free(lpAttributeList);
45 }
46 }
47
48 /// ProcThreadAttributeList is not copyable.
49 /// @{
52 /// @}
53
55 : lpAttributeList(other.lpAttributeList) {
56 other.lpAttributeList = nullptr;
57 }
58
59private:
60 explicit ProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST list)
61 : lpAttributeList(list) {}
62
63 LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;
64};
65
67public:
69 Status &error) override;
70
71protected:
72 HANDLE GetStdioHandle(const ProcessLaunchInfo &launch_info, int fd);
73
74 /// Get the list of Windows handles that should be inherited by the child
75 /// process and update `STARTUPINFOEXW` with the handle list.
76 ///
77 /// If no handles need to be inherited, an empty vector is returned.
78 ///
79 /// Otherwise, the function populates the
80 /// `PROC_THREAD_ATTRIBUTE_HANDLE_LIST` attribute in `startupinfoex` with the
81 /// collected handles using `UpdateProcThreadAttribute`. On success, the
82 /// vector of inherited handles is returned.
83 ///
84 /// \param launch_info
85 /// The process launch configuration.
86 ///
87 /// \param startupinfoex
88 /// The extended STARTUPINFO structure for the process being created.
89 ///
90 /// \param stdout_handle
91 /// \param stderr_handle
92 /// \param stdin_handle
93 /// Optional explicit standard stream handles to use for the child process.
94 ///
95 /// \returns
96 /// `std::vector<HANDLE>` containing all handles that the child must
97 /// inherit.
98 llvm::ErrorOr<std::vector<HANDLE>>
99 GetInheritedHandles(const ProcessLaunchInfo &launch_info,
100 STARTUPINFOEXW &startupinfoex,
101 HANDLE stdout_handle = NULL, HANDLE stderr_handle = NULL,
102 HANDLE stdin_handle = NULL);
103};
104}
105
106#endif
static llvm::raw_ostream & error(Stream &strm)
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...
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.