10
10
#include " lldb/Host/HostProcess.h"
11
11
#include " lldb/Host/ProcessLaunchInfo.h"
12
12
13
- #include " llvm/ADT/ScopeExit.h"
14
13
#include " llvm/ADT/SmallVector.h"
15
14
#include " llvm/Support/ConvertUTF.h"
16
15
#include " llvm/Support/Program.h"
@@ -66,23 +65,14 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
66
65
67
66
std::string executable;
68
67
std::vector<char > environment;
69
- STARTUPINFOEX startupinfoex = {};
70
- STARTUPINFO &startupinfo = startupinfoex.StartupInfo ;
68
+ STARTUPINFO startupinfo = {};
71
69
PROCESS_INFORMATION pi = {};
72
70
73
71
HANDLE stdin_handle = GetStdioHandle (launch_info, STDIN_FILENO);
74
72
HANDLE stdout_handle = GetStdioHandle (launch_info, STDOUT_FILENO);
75
73
HANDLE stderr_handle = GetStdioHandle (launch_info, STDERR_FILENO);
76
- auto close_handles = llvm::make_scope_exit ([&] {
77
- if (stdin_handle)
78
- ::CloseHandle (stdin_handle);
79
- if (stdout_handle)
80
- ::CloseHandle (stdout_handle);
81
- if (stderr_handle)
82
- ::CloseHandle (stderr_handle);
83
- });
84
-
85
- startupinfo.cb = sizeof (startupinfoex);
74
+
75
+ startupinfo.cb = sizeof (startupinfo);
86
76
startupinfo.dwFlags |= STARTF_USESTDHANDLES;
87
77
startupinfo.hStdError =
88
78
stderr_handle ? stderr_handle : ::GetStdHandle (STD_ERROR_HANDLE);
@@ -91,48 +81,6 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
91
81
startupinfo.hStdOutput =
92
82
stdout_handle ? stdout_handle : ::GetStdHandle (STD_OUTPUT_HANDLE);
93
83
94
- std::vector<HANDLE> inherited_handles;
95
- if (startupinfo.hStdError )
96
- inherited_handles.push_back (startupinfo.hStdError );
97
- if (startupinfo.hStdInput )
98
- inherited_handles.push_back (startupinfo.hStdInput );
99
- if (startupinfo.hStdOutput )
100
- inherited_handles.push_back (startupinfo.hStdOutput );
101
-
102
- size_t attributelist_size = 0 ;
103
- InitializeProcThreadAttributeList (/* lpAttributeList=*/ nullptr ,
104
- /* dwAttributeCount=*/ 1 , /* dwFlags=*/ 0 ,
105
- &attributelist_size);
106
-
107
- startupinfoex.lpAttributeList =
108
- static_cast <LPPROC_THREAD_ATTRIBUTE_LIST>(malloc (attributelist_size));
109
- auto free_attributelist =
110
- llvm::make_scope_exit ([&] { free (startupinfoex.lpAttributeList ); });
111
- if (!InitializeProcThreadAttributeList (startupinfoex.lpAttributeList ,
112
- /* dwAttributeCount=*/ 1 , /* dwFlags=*/ 0 ,
113
- &attributelist_size)) {
114
- error = Status (::GetLastError (), eErrorTypeWin32);
115
- return HostProcess ();
116
- }
117
- auto delete_attributelist = llvm::make_scope_exit (
118
- [&] { DeleteProcThreadAttributeList (startupinfoex.lpAttributeList ); });
119
- for (size_t i = 0 ; i < launch_info.GetNumFileActions (); ++i) {
120
- const FileAction *act = launch_info.GetFileActionAtIndex (i);
121
- if (act->GetAction () == FileAction::eFileActionDuplicate &&
122
- act->GetFD () == act->GetActionArgument ())
123
- inherited_handles.push_back (reinterpret_cast <HANDLE>(act->GetFD ()));
124
- }
125
- if (!inherited_handles.empty ()) {
126
- if (!UpdateProcThreadAttribute (
127
- startupinfoex.lpAttributeList , /* dwFlags=*/ 0 ,
128
- PROC_THREAD_ATTRIBUTE_HANDLE_LIST, inherited_handles.data (),
129
- inherited_handles.size () * sizeof (HANDLE),
130
- /* lpPreviousValue=*/ nullptr , /* lpReturnSize=*/ nullptr )) {
131
- error = Status (::GetLastError (), eErrorTypeWin32);
132
- return HostProcess ();
133
- }
134
- }
135
-
136
84
const char *hide_console_var =
137
85
getenv (" LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE" );
138
86
if (hide_console_var &&
@@ -141,8 +89,7 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
141
89
startupinfo.wShowWindow = SW_HIDE;
142
90
}
143
91
144
- DWORD flags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT |
145
- EXTENDED_STARTUPINFO_PRESENT;
92
+ DWORD flags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
146
93
if (launch_info.GetFlags ().Test (eLaunchFlagDebug))
147
94
flags |= DEBUG_ONLY_THIS_PROCESS;
148
95
@@ -167,10 +114,9 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
167
114
WCHAR *pwcommandLine = wcommandLine.empty () ? nullptr : &wcommandLine[0 ];
168
115
169
116
BOOL result = ::CreateProcessW (
170
- wexecutable.c_str (), pwcommandLine, NULL , NULL ,
171
- /* bInheritHandles=*/ !inherited_handles.empty (), flags, env_block,
117
+ wexecutable.c_str (), pwcommandLine, NULL , NULL , TRUE , flags, env_block,
172
118
wworkingDirectory.size () == 0 ? NULL : wworkingDirectory.c_str (),
173
- reinterpret_cast <STARTUPINFO *>(&startupinfoex) , &pi );
119
+ &startupinfo , &pi );
174
120
175
121
if (!result) {
176
122
// Call GetLastError before we make any other system calls.
@@ -185,6 +131,13 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
185
131
::CloseHandle (pi .hThread);
186
132
}
187
133
134
+ if (stdin_handle)
135
+ ::CloseHandle (stdin_handle);
136
+ if (stdout_handle)
137
+ ::CloseHandle (stdout_handle);
138
+ if (stderr_handle)
139
+ ::CloseHandle (stderr_handle);
140
+
188
141
if (!result)
189
142
return HostProcess ();
190
143
0 commit comments