Skip to content

Commit f096b5b

Browse files
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/53352 Reviewed-by: Austin Clements <[email protected]>
1 parent 3e3da54 commit f096b5b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

misc/cgo/errors/ptr.go

+8
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,14 @@ var ptrTests = []ptrTest{
343343
body: `var b C.char; p := &b; C.f((*C.u)(unsafe.Pointer(&p)))`,
344344
fail: false,
345345
},
346+
{
347+
// Issue #21306.
348+
name: "preempt-during-call",
349+
c: `void f() {}`,
350+
imports: []string{"runtime", "sync"},
351+
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()`,
352+
fail: false,
353+
},
346354
}
347355

348356
func main() {

src/runtime/symtab.go

+5
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ var modulesSlice unsafe.Pointer // see activeModules
409409
//
410410
// A module is active once its gcdatamask and gcbssmask have been
411411
// assembled and it is usable by the GC.
412+
//
413+
// This is nosplit/nowritebarrier because it is called by the
414+
// cgo pointer checking code.
415+
//go:nosplit
416+
//go:nowritebarrier
412417
func activeModules() []*moduledata {
413418
p := (*[]*moduledata)(atomic.Loadp(unsafe.Pointer(&modulesSlice)))
414419
if p == nil {

0 commit comments

Comments
 (0)