Skip to content

Commit 4b3a3bd

Browse files
runtime: don't issue cgocheck error for timer bucket source pointer
The cgo checker was issuing an error with cgocheck=2 when a timer bucket was stored in a pollDesc. The pollDesc values are allocated using persistentalloc, so they are not in the Go heap. The code is OK since timer bucket pointers point into a global array, and as such are never garbage collected or moved. Mark timersBucket notinheap to avoid the problem. timersBucket values only occur in the global timers array. Fixes #23435 Change-Id: I835f31caafd54cdacc692db5989de63bb49e7697 Reviewed-on: https://go-review.googlesource.com/87637 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
1 parent 3968705 commit 4b3a3bd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

misc/cgo/errors/ptr_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ var ptrTests = []ptrTest{
349349
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()`,
350350
fail: false,
351351
},
352+
{
353+
// Test poller deadline with cgocheck=2. Issue #23435.
354+
name: "deadline",
355+
c: `#define US 10`,
356+
imports: []string{"os", "time"},
357+
body: `r, _, _ := os.Pipe(); r.SetDeadline(time.Now().Add(C.US * time.Microsecond))`,
358+
fail: false,
359+
},
352360
}
353361

354362
func TestPointerChecks(t *testing.T) {

src/runtime/time.go

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (t *timer) assignBucket() *timersBucket {
5959
return t.tb
6060
}
6161

62+
//go:notinheap
6263
type timersBucket struct {
6364
lock mutex
6465
gp *g

0 commit comments

Comments
 (0)