Skip to content

Commit 3146166

Browse files
committed
syscall: introduce SysProcAttr.AdditionalInheritedHandles on Windows
This allows users to specify handles that they explicitly want to be inherited by the new process. These handles must already be marked as inheritable. Updates #44011. Updates #21085. Change-Id: Ib18322e7dc2909e68c4209e80385492804fa15d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/288298 Trust: Jason A. Donenfeld <[email protected]> Reviewed-by: Alex Brainman <[email protected]>
1 parent 2d76081 commit 3146166

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/syscall/exec_windows.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,14 @@ type ProcAttr struct {
235235
}
236236

237237
type SysProcAttr struct {
238-
HideWindow bool
239-
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
240-
CreationFlags uint32
241-
Token Token // if set, runs new process in the security context represented by the token
242-
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
243-
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
244-
NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
238+
HideWindow bool
239+
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
240+
CreationFlags uint32
241+
Token Token // if set, runs new process in the security context represented by the token
242+
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
243+
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
244+
NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
245+
AdditionalInheritedHandles []Handle // a list of additional handles, already marked as inheritable, that will be inherited by the new process
245246
}
246247

247248
var zeroProcAttr ProcAttr
@@ -337,6 +338,7 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
337338
si.StdOutput = fd[1]
338339
si.StdErr = fd[2]
339340

341+
fd = append(fd, sys.AdditionalInheritedHandles...)
340342
// Do not accidentally inherit more than these handles.
341343
err = updateProcThreadAttribute(si.ProcThreadAttributeList, 0, _PROC_THREAD_ATTRIBUTE_HANDLE_LIST, uintptr(unsafe.Pointer(&fd[0])), uintptr(len(fd))*unsafe.Sizeof(fd[0]), 0, nil)
342344
if err != nil {

0 commit comments

Comments
 (0)