1
0
mirror of https://github.com/golang/go synced 2024-11-17 10:04:43 -07:00

runtime: don't use systemstack for BeforeFork/AfterFork

In https://golang.org/cl/140930043 syscall.BeforeFork was changed to
call beforefork via onM. This was done because at the time BeforeFork
was written in C but was called from Go. While the runtime was being
converted to Go, calls to complex C functions used onM to ensure that
enough stack space was available.

In https://golang.org/cl/172260043 the syscall.BeforeFork and
beforefork functions were rewritten into Go. In this rewrite
syscall.BeforeFork continue to call beforefork via onM, although
because both functions were now in Go that was no longer necessary.

In https://golang.org/cl/174950043 onM was renamed to systemstack,
producing essentially the code we have today.

Therefore, the use of systemstack in syscall.BeforeFork (and
syscall.AfterFork) is a historical relic.  Remove it.

Change-Id: Ia570f556b20e8405afa6c5e707bd6f4ad18fd7ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/341335
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Ian Lance Taylor 2021-08-11 15:34:29 -07:00
parent bad1fc1265
commit 2eb4d68833

View File

@ -4104,7 +4104,10 @@ func exitsyscall0(gp *g) {
schedule() // Never returns. schedule() // Never returns.
} }
func beforefork() { // Called from syscall package before fork.
//go:linkname syscall_runtime_BeforeFork syscall.runtime_BeforeFork
//go:nosplit
func syscall_runtime_BeforeFork() {
gp := getg().m.curg gp := getg().m.curg
// Block signals during a fork, so that the child does not run // Block signals during a fork, so that the child does not run
@ -4121,14 +4124,10 @@ func beforefork() {
gp.stackguard0 = stackFork gp.stackguard0 = stackFork
} }
// Called from syscall package before fork. // Called from syscall package after fork in parent.
//go:linkname syscall_runtime_BeforeFork syscall.runtime_BeforeFork //go:linkname syscall_runtime_AfterFork syscall.runtime_AfterFork
//go:nosplit //go:nosplit
func syscall_runtime_BeforeFork() { func syscall_runtime_AfterFork() {
systemstack(beforefork)
}
func afterfork() {
gp := getg().m.curg gp := getg().m.curg
// See the comments in beforefork. // See the comments in beforefork.
@ -4139,13 +4138,6 @@ func afterfork() {
gp.m.locks-- gp.m.locks--
} }
// Called from syscall package after fork in parent.
//go:linkname syscall_runtime_AfterFork syscall.runtime_AfterFork
//go:nosplit
func syscall_runtime_AfterFork() {
systemstack(afterfork)
}
// inForkedChild is true while manipulating signals in the child process. // inForkedChild is true while manipulating signals in the child process.
// This is used to avoid calling libc functions in case we are using vfork. // This is used to avoid calling libc functions in case we are using vfork.
var inForkedChild bool var inForkedChild bool