From 59fc42b230671d083feb68925d9cadc1da1d2616 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 1 Apr 2016 15:06:25 -0700 Subject: [PATCH] runtime: allocate mp.cgocallers earlier Fixes #15061. Change-Id: I71f69f398d1c5f3a884bbd044786f1a5600d0fae Reviewed-on: https://go-review.googlesource.com/21398 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/cgocall.go | 5 ----- src/runtime/proc.go | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index 7cffa83617..d5248803a4 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -113,11 +113,6 @@ func cgocall(fn, arg unsafe.Pointer) int32 { mp.ncgo++ defer endcgo(mp) - // Allocate memory to hold a cgo traceback if the cgo call crashes. - if mp.cgoCallers == nil { - mp.cgoCallers = new(cgoCallers) - } - // Reset traceback. mp.cgoCallers[0] = 0 diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 27e61bd3e2..1e1987ff9e 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -510,6 +510,11 @@ func mcommoninit(mp *m) { // so we need to publish it safely. atomicstorep(unsafe.Pointer(&allm), unsafe.Pointer(mp)) unlock(&sched.lock) + + // Allocate memory to hold a cgo traceback if the cgo call crashes. + if iscgo || GOOS == "solaris" || GOOS == "windows" { + mp.cgoCallers = new(cgoCallers) + } } // Mark gp ready to run. -- 2.48.1