From 00acb429a178b034da73db102bc83d486124a197 Mon Sep 17 00:00:00 2001
From: Johan Knutzen
Date: Tue, 13 Oct 2020 10:40:42 -0700
Subject: [PATCH 1/5] syscall: expose bInheritHandles of CreateProcess
Certain use cases require this parameter to be false. This includes
spawning a child process in a different windows session than session 0.
Docs regarding the behavior of this parameter to CreateProcess:
https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa
---
src/syscall/exec_windows.go | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
index 4a1d74ba3f3721..820ddde606ca56 100644
--- a/src/syscall/exec_windows.go
+++ b/src/syscall/exec_windows.go
@@ -235,12 +235,13 @@ type ProcAttr struct {
}
type SysProcAttr struct {
- HideWindow bool
- CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
- CreationFlags uint32
- Token Token // if set, runs new process in the security context represented by the token
- ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
- ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
+ HideWindow bool
+ CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
+ CreationFlags uint32
+ Token Token // if set, runs new process in the security context represented by the token
+ ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
+ ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
+ DontInheritHandles bool
}
var zeroProcAttr ProcAttr
@@ -341,9 +342,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
if sys.Token != 0 {
- err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
+ err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
} else {
- err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
+ err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
}
if err != nil {
return 0, 0, err
From 3ec87999a5d3990657fd735a5f9b8891ed301619 Mon Sep 17 00:00:00 2001
From: Johan Knutzen
Date: Tue, 13 Oct 2020 11:48:44 -0700
Subject: [PATCH 2/5] add comment for DontInheritHandles in SysProcAttr
---
src/syscall/exec_windows.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
index 820ddde606ca56..9f827c53f83b33 100644
--- a/src/syscall/exec_windows.go
+++ b/src/syscall/exec_windows.go
@@ -241,7 +241,7 @@ type SysProcAttr struct {
Token Token // if set, runs new process in the security context represented by the token
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
- DontInheritHandles bool
+ DontInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
}
var zeroProcAttr ProcAttr
From ad8e36df66d27aae8df013892afeffedc3b80732 Mon Sep 17 00:00:00 2001
From: Johan Knutzen
Date: Tue, 20 Oct 2020 10:37:35 -0700
Subject: [PATCH 3/5] doc/go1.16: documented SysProcAttr.DontInheritHandles in
release notes
---
doc/go1.16.html | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/doc/go1.16.html b/doc/go1.16.html
index 509956fbf2f87f..4b49edafd2364e 100644
--- a/doc/go1.16.html
+++ b/doc/go1.16.html
@@ -309,3 +309,13 @@ Minor changes to the library
+
+- syscall
+ -
+
+ The new DontInheritHandles field in SysProcAttr
+ has been introduced for Windows, exposing configurability of handle inheritence when creating
+ new processes.
+
+
+
From f5ee7abb4ca92bba07550597f4cc99d7cda251bb Mon Sep 17 00:00:00 2001
From: Johan Knutzen
Date: Tue, 20 Oct 2020 15:02:46 -0700
Subject: [PATCH 4/5] doc/go1.16: refactored wording of
SysProcAttr.DontInheritHandles
---
doc/go1.16.html | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/doc/go1.16.html b/doc/go1.16.html
index 88772a177c16aa..f179c1448d2633 100644
--- a/doc/go1.16.html
+++ b/doc/go1.16.html
@@ -328,9 +328,7 @@ Minor changes to the library
- syscall
-
- The new DontInheritHandles field in SysProcAttr
- has been introduced for Windows, exposing configurability of handle inheritence when creating
- new processes.
+ SysProcAttr
on Windows has a new DontInheritHandles field that disables inheriting handles when creating a new process.
From 584eb13e36a3ef7e0cd959295e92fb129f21d1f8 Mon Sep 17 00:00:00 2001
From: Johan Knutzen
Date: Wed, 21 Oct 2020 10:54:11 -0700
Subject: [PATCH 5/5] syscall: rename variable DontInheritHandles to
NoInheritHandles
Fixes #42098
---
doc/go1.16.html | 2 +-
src/syscall/exec_windows.go | 18 +++++++++---------
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/doc/go1.16.html b/doc/go1.16.html
index 74d31cc9809d22..4ba9d6785c8bc2 100644
--- a/doc/go1.16.html
+++ b/doc/go1.16.html
@@ -334,7 +334,7 @@ Minor changes to the library
- syscall
-
- SysProcAttr
on Windows has a new DontInheritHandles field that disables inheriting handles when creating a new process.
+ SysProcAttr
on Windows has a new NoInheritHandles field that disables inheriting handles when creating a new process.
diff --git a/src/syscall/exec_windows.go b/src/syscall/exec_windows.go
index 9f827c53f83b33..46cbd7567dd560 100644
--- a/src/syscall/exec_windows.go
+++ b/src/syscall/exec_windows.go
@@ -235,13 +235,13 @@ type ProcAttr struct {
}
type SysProcAttr struct {
- HideWindow bool
- CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
- CreationFlags uint32
- Token Token // if set, runs new process in the security context represented by the token
- ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
- ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
- DontInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
+ HideWindow bool
+ CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
+ CreationFlags uint32
+ Token Token // if set, runs new process in the security context represented by the token
+ ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
+ ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
+ NoInheritHandles bool // if set, each inheritable handle in the calling process is not inherited by the new process
}
var zeroProcAttr ProcAttr
@@ -342,9 +342,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
if sys.Token != 0 {
- err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
+ err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
} else {
- err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.DontInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
+ err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, !sys.NoInheritHandles, flags, createEnvBlock(attr.Env), dirp, si, pi)
}
if err != nil {
return 0, 0, err