Description
There are two additional attributes that would be useful to expose to the user in SysProcAttr: PROC_THREAD_ATTRIBUTE_HANDLE_LIST (via SysProcAttr.AdditionalInheritedHandles
) and PROC_THREAD_ATTRIBUTE_PARENT_PROCESS (via SysProcAttr.ParentProcessHandle
), documented here:
Microsoft added these at a later point (Windows Vista) than the other attributes that we already support in StartProcess/SysProcAttr, so internally there's a slightly different way of passing these to CreateProcess, but that's just a weird implementation quirk that has no bearing on the Go user.
PROC_THREAD_ATTRIBUTE_HANDLE_LIST in particular has special significance in that we actually should already be using it unconditionally for basic reliability. Specifically, we should always use PROC_THREAD_ATTRIBUTE_HANDLE_LIST when launching processes, in order to prevent handle leaks and prevent races with functions like ShellExecute. And we might even be able to remove that global lock we're using now to hack around the absence of PROC_THREAD_ATTRIBUTE_HANDLE_LIST, which would be great.
To that end, I propose the following 3 steps:
- Always use PROC_THREAD_ATTRIBUTE_HANDLE_LIST for the handles we want to be inherited, automatically. No new API for this first point but rather making our existing logic more robust. This is an important reliability fix.
- Add
SysProcAttr.AdditionalInheritedHandles
which takes a list of handles to add to that list of point (1). - Add
SysProcAttr.ParentProcessHandle
that adds PROC_THREAD_ATTRIBUTE_PARENT_PROCESS with that value.
Point (1) is a bug/reliability fix that doesn't require the proposals process, so I'll submit a boring CL for that independent of this proposal. Therefore this proposal concerns adding:
SysProcAttr.AdditionalInheritedHandles
SysProcAttr.ParentProcessHandle
If you think there are additional attributes we should expose via SysProcAttr, I'm happy to add those to this proposal too.
This is an alternative to #44005, which in my opinion would be big mistake.