From a5903828501ce21c81d49d49f80704b714a8bffc Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 22 May 2024 14:00:04 -0400 Subject: [PATCH] libuv: win/spawn: disable extra-file-descriptor support not needed by CMake Upstream libuv supports passing file descriptors >= 3 to child processes via `STARTUPINFOW` members reserved by the MSVC C run-time. However, some programs use `GetStartupInfoW` to initialize a `STARTUPINFOW` structure to pass to `CreateProcessW` without clearing the reserved members. If we launch such programs with non-zero values in the reserved members, the MSVC C run-time in *their* children may not correctly associate the stdin/stdout/stderr streams' file descriptors with the corresponding `HANDLE`s. Patch our copy of libuv to avoid using the reserved members. This restores `execute_process` support for the above-described programs as we had prior to commit 5420639a8d (cmExecuteProcessCommand: Replace cmsysProcess with cmUVProcessChain, 2023-06-01, v3.28.0-rc1~138^2~8). It also enables support for such programs when launched by `ctest`. Fixes: #25996 Fixes: #25889 --- Utilities/cmlibuv/src/win/process.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Utilities/cmlibuv/src/win/process.c b/Utilities/cmlibuv/src/win/process.c index 11cf5b2837..5cf9fb8066 100644 --- a/Utilities/cmlibuv/src/win/process.c +++ b/Utilities/cmlibuv/src/win/process.c @@ -1083,8 +1083,15 @@ int uv_spawn(uv_loop_t* loop, startup.lpTitle = NULL; startup.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; +#if 1 + /* cmake does not need libuv's support for passing file descriptors >= 3 + to the MSVC C run-time in the child. Avoid using reserved members. */ + startup.cbReserved2 = 0; + startup.lpReserved2 = NULL; +#else startup.cbReserved2 = uv__stdio_size(process->child_stdio_buffer); startup.lpReserved2 = (BYTE*) process->child_stdio_buffer; +#endif startup.hStdInput = uv__stdio_handle(process->child_stdio_buffer, 0); startup.hStdOutput = uv__stdio_handle(process->child_stdio_buffer, 1);