Author: Charles Zablit
Date: 2026-01-28T13:32:37Z
New Revision: f44ecfd0702518ad2cfaec1c13549ef9c0aa2f73

URL: 
https://github.com/llvm/llvm-project/commit/f44ecfd0702518ad2cfaec1c13549ef9c0aa2f73
DIFF: 
https://github.com/llvm/llvm-project/commit/f44ecfd0702518ad2cfaec1c13549ef9c0aa2f73.diff

LOG: [lldb][windows] fix an invalid cast from a file descriptor to a HANDLE 
(#178238)

Added: 
    

Modified: 
    lldb/include/lldb/Host/FileAction.h
    lldb/source/Host/common/FileAction.cpp
    lldb/source/Host/windows/ProcessLauncherWindows.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Host/FileAction.h 
b/lldb/include/lldb/Host/FileAction.h
index b2cc8be32d296..4a064c1e5ec08 100644
--- a/lldb/include/lldb/Host/FileAction.h
+++ b/lldb/include/lldb/Host/FileAction.h
@@ -35,6 +35,10 @@ class FileAction {
 
   int GetFD() const { return m_fd; }
 
+#ifdef _WIN32
+  void *GetHandle() const;
+#endif
+
   Action GetAction() const { return m_action; }
 
   int GetActionArgument() const { return m_arg; }

diff  --git a/lldb/source/Host/common/FileAction.cpp 
b/lldb/source/Host/common/FileAction.cpp
index ec271f7b920d8..7bae82cada32d 100644
--- a/lldb/source/Host/common/FileAction.cpp
+++ b/lldb/source/Host/common/FileAction.cpp
@@ -12,12 +12,24 @@
 #include "lldb/Host/PosixApi.h"
 #include "lldb/Utility/Stream.h"
 
+#ifdef _WIN32
+#include "lldb/Host/windows/windows.h"
+#endif
+
 using namespace lldb_private;
 
 // FileAction member functions
 
 FileAction::FileAction() : m_file_spec() {}
 
+#ifdef _WIN32
+HANDLE FileAction::GetHandle() const {
+  if (m_fd == -1)
+    return INVALID_HANDLE_VALUE;
+  return reinterpret_cast<HANDLE>(_get_osfhandle(m_fd));
+}
+#endif
+
 void FileAction::Clear() {
   m_action = eFileActionNone;
   m_fd = -1;

diff  --git a/lldb/source/Host/windows/ProcessLauncherWindows.cpp 
b/lldb/source/Host/windows/ProcessLauncherWindows.cpp
index ec1a20ebb2200..0ee71ea17fd50 100644
--- a/lldb/source/Host/windows/ProcessLauncherWindows.cpp
+++ b/lldb/source/Host/windows/ProcessLauncherWindows.cpp
@@ -242,8 +242,9 @@ llvm::ErrorOr<std::vector<HANDLE>> 
ProcessLauncherWindows::GetInheritedHandles(
   for (size_t i = 0; i < launch_info.GetNumFileActions(); ++i) {
     const FileAction *act = launch_info.GetFileActionAtIndex(i);
     if (act->GetAction() == FileAction::eFileActionDuplicate &&
-        act->GetFD() == act->GetActionArgument())
-      inherited_handles.push_back(reinterpret_cast<HANDLE>(act->GetFD()));
+        act->GetFD() == act->GetActionArgument()) {
+      inherited_handles.push_back(act->GetHandle());
+    }
   }
 
   if (inherited_handles.empty())


        
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to