]> Cypherpunks repositories - gostls13.git/commit
runtime: keep //go:cgo_unsafe_args arguments alive to prevent GC
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 29 Nov 2021 20:07:04 +0000 (15:07 -0500)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 30 Nov 2021 03:11:18 +0000 (03:11 +0000)
commitf463b20789c89f0d22e56663a34e57a942f945cf
tree1d673bad2a149f97ac45850e85b9d6cd45fa1612
parentf90a42b41080cf5a289f151f2166d0d0a795e836
runtime: keep //go:cgo_unsafe_args arguments alive to prevent GC

When syscall's DLL.FindProc calls into syscall_getprocaddress with a
byte slice pointer, we need to keep those bytes alive. Otherwise the GC
will collect the allocation, and we wind up calling `GetProcAddress` on
garbage, which showed up as various flakes in the builders. It turns out
that this problem extends to many uses of //go:cgo_unsafe_args
throughout, on all platforms. So this patch fixes the issue by keeping
non-integer pointer arguments alive through their invocation in
//go:cgo_unsafe_args functions.

Fixes #49731.

Change-Id: I93e4fbc2e8e210cb3fc53149708758bb33f2f9c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/367654
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Patrik Nyblom <pnyb@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
src/runtime/sys_darwin.go
src/runtime/sys_darwin_arm64.go
src/runtime/sys_openbsd.go
src/runtime/sys_openbsd1.go
src/runtime/sys_openbsd2.go
src/runtime/syscall_solaris.go
src/runtime/syscall_windows.go