Commit f096b5b3 authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: mark activeModules nosplit/nowritebarrier

The activeModules function is called by the cgo pointer checking code,
which is called by the write barrier (when GODEBUG=cgocheck=2), and as
such must be nosplit/nowritebarrier.

Fixes #21306

Change-Id: I57f2124f14de7f3872b2de9532abab15df95d45a
Reviewed-on: https://go-review.googlesource.com/53352Reviewed-by: default avatarAustin Clements <austin@google.com>
parent 3e3da546
...@@ -343,6 +343,14 @@ var ptrTests = []ptrTest{ ...@@ -343,6 +343,14 @@ var ptrTests = []ptrTest{
body: `var b C.char; p := &b; C.f((*C.u)(unsafe.Pointer(&p)))`, body: `var b C.char; p := &b; C.f((*C.u)(unsafe.Pointer(&p)))`,
fail: false, fail: false,
}, },
{
// Issue #21306.
name: "preempt-during-call",
c: `void f() {}`,
imports: []string{"runtime", "sync"},
body: `var wg sync.WaitGroup; wg.Add(100); for i := 0; i < 100; i++ { go func(i int) { for j := 0; j < 100; j++ { C.f(); runtime.GOMAXPROCS(i) }; wg.Done() }(i) }; wg.Wait()`,
fail: false,
},
} }
func main() { func main() {
......
...@@ -409,6 +409,11 @@ var modulesSlice unsafe.Pointer // see activeModules ...@@ -409,6 +409,11 @@ var modulesSlice unsafe.Pointer // see activeModules
// //
// A module is active once its gcdatamask and gcbssmask have been // A module is active once its gcdatamask and gcbssmask have been
// assembled and it is usable by the GC. // assembled and it is usable by the GC.
//
// This is nosplit/nowritebarrier because it is called by the
// cgo pointer checking code.
//go:nosplit
//go:nowritebarrier
func activeModules() []*moduledata { func activeModules() []*moduledata {
p := (*[]*moduledata)(atomic.Loadp(unsafe.Pointer(&modulesSlice))) p := (*[]*moduledata)(atomic.Loadp(unsafe.Pointer(&modulesSlice)))
if p == nil { if p == nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment