From 4b3a3bd3aa7ff9f02d1f2dde0bcafc0110984c59 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 12 Jan 2018 16:29:48 -0800 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements Reviewed-by: Brad Fitzpatrick --- misc/cgo/errors/ptr_test.go | 8 ++++++++ src/runtime/time.go | 1 + 2 files changed, 9 insertions(+) diff --git a/misc/cgo/errors/ptr_test.go b/misc/cgo/errors/ptr_test.go index d295a5849dbfc..fe8dfff1d891b 100644 --- a/misc/cgo/errors/ptr_test.go +++ b/misc/cgo/errors/ptr_test.go @@ -349,6 +349,14 @@ var ptrTests = []ptrTest{ 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, }, + { + // Test poller deadline with cgocheck=2. Issue #23435. + name: "deadline", + c: `#define US 10`, + imports: []string{"os", "time"}, + body: `r, _, _ := os.Pipe(); r.SetDeadline(time.Now().Add(C.US * time.Microsecond))`, + fail: false, + }, } func TestPointerChecks(t *testing.T) { diff --git a/src/runtime/time.go b/src/runtime/time.go index 6c349c8461bc7..3ac60f3aecedb 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -59,6 +59,7 @@ func (t *timer) assignBucket() *timersBucket { return t.tb } +//go:notinheap type timersBucket struct { lock mutex gp *g