Skip to content

Commit a0260a9

Browse files
committed
Revert "[lldb] Inherit DuplicateFileAction(HANDLE, HANDLE) handles on windows (#137978)"
This reverts commit 7c5f5f3 due to failures on the lldb-remote-linux-win bot.
1 parent 93f61ce commit a0260a9

File tree

5 files changed

+21
-63
lines changed

5 files changed

+21
-63
lines changed

lldb/source/Host/windows/PipeWindows.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,8 @@ Status PipeWindows::CreateNew(llvm::StringRef name,
8888
std::string pipe_path = g_pipe_name_prefix.str();
8989
pipe_path.append(name.str());
9090

91-
// We always create inheritable handles, but we won't pass them to a child
92-
// process unless explicitly requested (cf. ProcessLauncherWindows.cpp).
93-
SECURITY_ATTRIBUTES sa{sizeof(SECURITY_ATTRIBUTES), 0, TRUE};
91+
SECURITY_ATTRIBUTES sa{sizeof(SECURITY_ATTRIBUTES), 0,
92+
child_process_inherit ? TRUE : FALSE};
9493

9594
// Always open for overlapped i/o. We implement blocking manually in Read
9695
// and Write.

lldb/source/Host/windows/ProcessLauncherWindows.cpp

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "lldb/Host/HostProcess.h"
1111
#include "lldb/Host/ProcessLaunchInfo.h"
1212

13-
#include "llvm/ADT/ScopeExit.h"
1413
#include "llvm/ADT/SmallVector.h"
1514
#include "llvm/Support/ConvertUTF.h"
1615
#include "llvm/Support/Program.h"
@@ -66,23 +65,14 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
6665

6766
std::string executable;
6867
std::vector<char> environment;
69-
STARTUPINFOEX startupinfoex = {};
70-
STARTUPINFO &startupinfo = startupinfoex.StartupInfo;
68+
STARTUPINFO startupinfo = {};
7169
PROCESS_INFORMATION pi = {};
7270

7371
HANDLE stdin_handle = GetStdioHandle(launch_info, STDIN_FILENO);
7472
HANDLE stdout_handle = GetStdioHandle(launch_info, STDOUT_FILENO);
7573
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);
8676
startupinfo.dwFlags |= STARTF_USESTDHANDLES;
8777
startupinfo.hStdError =
8878
stderr_handle ? stderr_handle : ::GetStdHandle(STD_ERROR_HANDLE);
@@ -91,48 +81,6 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
9181
startupinfo.hStdOutput =
9282
stdout_handle ? stdout_handle : ::GetStdHandle(STD_OUTPUT_HANDLE);
9383

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-
13684
const char *hide_console_var =
13785
getenv("LLDB_LAUNCH_INFERIORS_WITHOUT_CONSOLE");
13886
if (hide_console_var &&
@@ -141,8 +89,7 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
14189
startupinfo.wShowWindow = SW_HIDE;
14290
}
14391

144-
DWORD flags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT |
145-
EXTENDED_STARTUPINFO_PRESENT;
92+
DWORD flags = CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT;
14693
if (launch_info.GetFlags().Test(eLaunchFlagDebug))
14794
flags |= DEBUG_ONLY_THIS_PROCESS;
14895

@@ -167,10 +114,9 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
167114
WCHAR *pwcommandLine = wcommandLine.empty() ? nullptr : &wcommandLine[0];
168115

169116
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,
172118
wworkingDirectory.size() == 0 ? NULL : wworkingDirectory.c_str(),
173-
reinterpret_cast<STARTUPINFO *>(&startupinfoex), &pi);
119+
&startupinfo, &pi);
174120

175121
if (!result) {
176122
// Call GetLastError before we make any other system calls.
@@ -185,6 +131,13 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
185131
::CloseHandle(pi.hThread);
186132
}
187133

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+
188141
if (!result)
189142
return HostProcess();
190143

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ Status GDBRemoteCommunication::StartDebugserverProcess(
924924
debugserver_args.AppendArgument(fd_arg.GetString());
925925
// Send "pass_comm_fd" down to the inferior so it can use it to
926926
// communicate back with this process. Ignored on Windows.
927+
#ifndef _WIN32
927928
launch_info.AppendDuplicateFileAction((int)pass_comm_fd, (int)pass_comm_fd);
929+
#endif
928930
}
929931

930932
// use native registers, not the GDB registers

lldb/tools/lldb-server/lldb-platform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,10 @@ static Status spawn_process(const char *progname, const FileSpec &prog,
274274
self_args.AppendArgument(llvm::StringRef("platform"));
275275
self_args.AppendArgument(llvm::StringRef("--child-platform-fd"));
276276
self_args.AppendArgument(llvm::to_string(shared_socket.GetSendableFD()));
277+
#ifndef _WIN32
277278
launch_info.AppendDuplicateFileAction((int)shared_socket.GetSendableFD(),
278279
(int)shared_socket.GetSendableFD());
280+
#endif
279281
if (gdb_port) {
280282
self_args.AppendArgument(llvm::StringRef("--gdbserver-port"));
281283
self_args.AppendArgument(llvm::to_string(gdb_port));

lldb/unittests/Host/HostTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ TEST(Host, LaunchProcessSetsArgv0) {
9090
ASSERT_THAT(exit_status.get_future().get(), 0);
9191
}
9292

93+
#ifdef LLVM_ON_UNIX
9394
TEST(Host, LaunchProcessDuplicatesHandle) {
9495
static constexpr llvm::StringLiteral test_msg("Hello subprocess!");
9596

@@ -129,3 +130,4 @@ TEST(Host, LaunchProcessDuplicatesHandle) {
129130
ASSERT_THAT_EXPECTED(bytes_read, llvm::Succeeded());
130131
ASSERT_EQ(llvm::StringRef(msg, *bytes_read), test_msg);
131132
}
133+
#endif

0 commit comments

Comments
 (0)