]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't issue cgocheck error for timer bucket source pointer
authorIan Lance Taylor <iant@golang.org>
Sat, 13 Jan 2018 00:29:48 +0000 (16:29 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 15 Jan 2018 22:18:55 +0000 (22:18 +0000)
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>
misc/cgo/errors/ptr_test.go
src/runtime/time.go

index d295a5849dbfcd94a4b14f597b86e8391670f754..fe8dfff1d891b76eea60b67d06f4c0b9441e8759 100644 (file)
@@ -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) {
index 6c349c8461bc7efc8304cc889228bba980ed5673..3ac60f3aecedb24da76b086676c03d6bfb402498 100644 (file)
@@ -59,6 +59,7 @@ func (t *timer) assignBucket() *timersBucket {
        return t.tb
 }
 
+//go:notinheap
 type timersBucket struct {
        lock         mutex
        gp           *g