[lldb][Windows] Translate file descriptors between CRT instances (#217126)
The official LLVM and lldb builds use `LLVM_ENABLE_RPMALLOC`. This changes the default CRT allocator to rpmalloc for performance reasons. In doing so, it also changes the CRT linkage from dynamic (`/MD`) to static (`/MT`). Since the CRT is the one managing file descriptors on Windows, its universe is now scoped to a module. For lldb, this means we have three fd-spaces: the driver (lldb/lldb-dap), liblldb, and Python. We usually pass files around as file descriptors. This breaks when we do it between modules. Fortunately, the C runtime provides us with helpers to translate between the process scoped HANDLEs and file descriptors. This way, we can allocate an fd for a handle passed across modules. For Python, there's the [`msvcrt`](https://docs.python.org/3/library/msvcrt.html) library we can use to translate. Fixes #216679. (cherry picked from commit 1ca6698be7708121f987d0acf896c7dc4cf63a51)
This commit is contained in:
1 parent
e24fcb6944
commit
28a01b03e1
6 files changed
+105
-6
No files matched your search
@@ -1088,8 +1088,10 @@ bool ScriptInterpreterPythonImpl::RedirectTerminalHandleThroughLock(
|
||||
// terminal) promptly: the pipe descriptor is not a tty, so the default
|
||||
// buffering would hold output back until the buffer filled.
|
||||
PyObject *pipe_file = PyFile_FromFd(
|
||||
redirect->GetWriteDescriptor(), nullptr, mode, /*buffering=*/1,
|
||||
/*encoding=*/nullptr, /*errors=*/"ignore", /*newline=*/nullptr,
|
||||
PythonFile::TranslateFdToPython(redirect->GetWriteDescriptor()), nullptr,
|
||||
mode, /*buffering=*/1,
|
||||
/*encoding=*/nullptr, /*errors=*/"ignore",
|
||||
/*newline=*/nullptr,
|
||||
/*closefd=*/0);
|
||||
if (!pipe_file) {
|
||||
// Fall back to the raw descriptor. That reopens the statusline race, so
|
||||
|
||||
Reference in new issue
Block a user