Skip to content

Conversation

@lb90
Copy link

@lb90 lb90 commented Oct 27, 2025

CreateProcess fails with ERROR_INVALID_PARAMETER when duplicate HANDLEs are passed via PROC_THREAD_ATTRIBUTE_HANDLE_LIST. This can happen, for example, if stdout and stdin are the same device (e.g. a bidirectional named pipe), or if stdout and stderr are the same device.

Fixes msys2/MINGW-packages#26030

@lb90 lb90 requested a review from JDevlieghere as a code owner October 27, 2025 17:18
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added the lldb label Oct 27, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-lldb

Author: None (lb90)

Changes

Fixes msys2/MINGW-packages#26030


Full diff: https://github.com/llvm/llvm-project/pull/165281.diff

1 Files Affected:

  • (modified) lldb/source/Host/windows/ProcessLauncherWindows.cpp (+6)
diff --git a/lldb/source/Host/windows/ProcessLauncherWindows.cpp b/lldb/source/Host/windows/ProcessLauncherWindows.cpp
index f5adadaf061bf..ab151f1a9a0ac 100644
--- a/lldb/source/Host/windows/ProcessLauncherWindows.cpp
+++ b/lldb/source/Host/windows/ProcessLauncherWindows.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/Program.h"
 
+#include <algorithm>
 #include <string>
 #include <vector>
 
@@ -122,6 +123,11 @@ ProcessLauncherWindows::LaunchProcess(const ProcessLaunchInfo &launch_info,
         act->GetFD() == act->GetActionArgument())
       inherited_handles.push_back(reinterpret_cast<HANDLE>(act->GetFD()));
   }
+  // Remove duplicate HANDLEs
+  std::sort(inherited_handles.begin(), inherited_handles.end());
+  inherited_handles.erase(
+      std::unique(inherited_handles.begin(), inherited_handles.end()),
+      inherited_handles.end());
   if (!inherited_handles.empty()) {
     if (!UpdateProcThreadAttribute(
             startupinfoex.lpAttributeList, /*dwFlags=*/0,

@charles-zablit
Copy link
Contributor

Thanks for submitting this patch!

This looks good to me, I just wonder if it would make sense to convert this inherited_handles vector to an std::unordered_set?

I think It would make it clearer that we should only have unique handles in this data structure. What do you think?

@lb90 lb90 force-pushed the lldb-remove-duplicated-handles branch from 65250c7 to 76cf6d1 Compare October 28, 2025 09:47
@lb90
Copy link
Author

lb90 commented Oct 28, 2025

Nice idea! Changed :)

Copy link
Contributor

@charles-zablit charles-zablit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lldb can't run commands depending on output device type

3 participants