proc: unlock OS thread on exit from handlePtraceFuncs (#2972)

On FreeBSD and OpenBSD, the use of runtime.LockOSThread is resulting in segfaults
within the Go runtime (see https://github.com/golang/go/issues/52394) - while it
should not be necessary, calling runtime.UnlockOSThread upon exit from
handlePtraceFuncs avoids this issue and allows the tests to run correctly.
This commit is contained in:
Joel Sing 2022-04-27 07:33:16 +10:00 committed by GitHub
parent 7ab33ac92f
commit 5b16ddb7e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -271,6 +271,13 @@ func (dbp *nativeProcess) handlePtraceFuncs() {
// all commands after PTRACE_ATTACH to come from the same thread.
runtime.LockOSThread()
// Leaving the OS thread locked currently leads to segfaults in the
// Go runtime while running on FreeBSD and OpenBSD:
// https://github.com/golang/go/issues/52394
if runtime.GOOS == "freebsd" || runtime.GOOS == "openbsd" {
defer runtime.UnlockOSThread()
}
for fn := range dbp.ptraceChan {
fn()
dbp.ptraceDoneChan <- nil