diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-05-30 12:01:41 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-05-30 12:09:39 -0700 |
commit | 38de91b028639ef5f4a4c8874b3ee23503fd2f3a (patch) | |
tree | 8d58a49107c491688a89c805336690ca493bf008 | |
parent | e3c5fa3345139a38b380e14067640931ce885288 (diff) |
Add build guard to files using go:linkname
Funcion signatures are not validated during compilation. Since
they are not exported, they can change at any time. The guard
ensures that they are verified at least on every version upgrade.
PiperOrigin-RevId: 250733742
-rw-r--r-- | pkg/sentry/platform/kvm/bluepill_unsafe.go | 5 | ||||
-rw-r--r-- | pkg/sentry/platform/kvm/machine_unsafe.go | 5 | ||||
-rw-r--r-- | pkg/sentry/platform/ptrace/subprocess_unsafe.go | 5 | ||||
-rw-r--r-- | pkg/sleep/sleep_unsafe.go | 4 | ||||
-rw-r--r-- | pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go | 5 | ||||
-rw-r--r-- | pkg/tcpip/time_unsafe.go | 4 | ||||
-rw-r--r-- | third_party/gvsync/BUILD | 4 | ||||
-rw-r--r-- | third_party/gvsync/downgradable_rwmutex_1_12_unsafe.go | 21 | ||||
-rw-r--r-- | third_party/gvsync/downgradable_rwmutex_1_13_unsafe.go | 16 | ||||
-rw-r--r-- | third_party/gvsync/downgradable_rwmutex_unsafe.go | 20 | ||||
-rw-r--r-- | third_party/gvsync/memmove_unsafe.go | 13 |
11 files changed, 85 insertions, 17 deletions
diff --git a/pkg/sentry/platform/kvm/bluepill_unsafe.go b/pkg/sentry/platform/kvm/bluepill_unsafe.go index 4184939e5..7e8e9f42a 100644 --- a/pkg/sentry/platform/kvm/bluepill_unsafe.go +++ b/pkg/sentry/platform/kvm/bluepill_unsafe.go @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build go1.12 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + package kvm import ( diff --git a/pkg/sentry/platform/kvm/machine_unsafe.go b/pkg/sentry/platform/kvm/machine_unsafe.go index 452d88d7f..1d3c6d2d6 100644 --- a/pkg/sentry/platform/kvm/machine_unsafe.go +++ b/pkg/sentry/platform/kvm/machine_unsafe.go @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build go1.12 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + package kvm import ( diff --git a/pkg/sentry/platform/ptrace/subprocess_unsafe.go b/pkg/sentry/platform/ptrace/subprocess_unsafe.go index 17736b05b..b80a3604d 100644 --- a/pkg/sentry/platform/ptrace/subprocess_unsafe.go +++ b/pkg/sentry/platform/ptrace/subprocess_unsafe.go @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +// +build go1.12 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + package ptrace import ( diff --git a/pkg/sleep/sleep_unsafe.go b/pkg/sleep/sleep_unsafe.go index 0526f52de..8f5e60a25 100644 --- a/pkg/sleep/sleep_unsafe.go +++ b/pkg/sleep/sleep_unsafe.go @@ -13,7 +13,9 @@ // limitations under the License. // +build go1.11 -// +build !go1.13 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. // Package sleep allows goroutines to efficiently sleep on multiple sources of // notifications (wakers). It offers O(1) complexity, which is different from diff --git a/pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go b/pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go index 0b51982c6..c87268610 100644 --- a/pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go +++ b/pkg/tcpip/link/rawfile/blockingpoll_amd64_unsafe.go @@ -13,9 +13,10 @@ // limitations under the License. // +build linux,amd64 -// +build !go1.13 +// +build go1.12 +// +build !go1.14 -// This must be validated with Go 1.13 and future releases. +// Check go:linkname function signatures when updating Go version. package rawfile diff --git a/pkg/tcpip/time_unsafe.go b/pkg/tcpip/time_unsafe.go index 1a307483b..a52262e87 100644 --- a/pkg/tcpip/time_unsafe.go +++ b/pkg/tcpip/time_unsafe.go @@ -13,7 +13,9 @@ // limitations under the License. // +build go1.9 -// +build !go1.13 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. package tcpip diff --git a/third_party/gvsync/BUILD b/third_party/gvsync/BUILD index 4764eaa83..04a1fbeba 100644 --- a/third_party/gvsync/BUILD +++ b/third_party/gvsync/BUILD @@ -5,6 +5,8 @@ package( licenses = ["notice"], ) +exports_files(["LICENSE"]) + load("//tools/go_generics:defs.bzl", "go_template") go_template( @@ -29,6 +31,8 @@ go_template( go_library( name = "gvsync", srcs = [ + "downgradable_rwmutex_1_12_unsafe.go", + "downgradable_rwmutex_1_13_unsafe.go", "downgradable_rwmutex_unsafe.go", "gvsync.go", "memmove_unsafe.go", diff --git a/third_party/gvsync/downgradable_rwmutex_1_12_unsafe.go b/third_party/gvsync/downgradable_rwmutex_1_12_unsafe.go new file mode 100644 index 000000000..855b2a2b1 --- /dev/null +++ b/third_party/gvsync/downgradable_rwmutex_1_12_unsafe.go @@ -0,0 +1,21 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2019 The gVisor Authors. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.12 +// +build !go1.13 + +// TODO(b/133868570): Delete once Go 1.12 is no longer supported. + +package gvsync + +import _ "unsafe" + +//go:linkname runtimeSemrelease112 sync.runtime_Semrelease +func runtimeSemrelease112(s *uint32, handoff bool) + +func runtimeSemrelease(s *uint32, handoff bool, skipframes int) { + // 'skipframes' is only available starting from 1.13. + runtimeSemrelease112(s, handoff) +} diff --git a/third_party/gvsync/downgradable_rwmutex_1_13_unsafe.go b/third_party/gvsync/downgradable_rwmutex_1_13_unsafe.go new file mode 100644 index 000000000..8baec5458 --- /dev/null +++ b/third_party/gvsync/downgradable_rwmutex_1_13_unsafe.go @@ -0,0 +1,16 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2019 The gVisor Authors. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build go1.13 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + +package gvsync + +import _ "unsafe" + +//go:linkname runtimeSemrelease sync.runtime_Semrelease +func runtimeSemrelease(s *uint32, handoff bool, skipframes int) diff --git a/third_party/gvsync/downgradable_rwmutex_unsafe.go b/third_party/gvsync/downgradable_rwmutex_unsafe.go index 4d43eb765..069939033 100644 --- a/third_party/gvsync/downgradable_rwmutex_unsafe.go +++ b/third_party/gvsync/downgradable_rwmutex_unsafe.go @@ -3,6 +3,11 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build go1.12 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + // This is mostly copied from the standard library's sync/rwmutex.go. // // Happens-before relationships indicated to the race detector: @@ -19,6 +24,9 @@ import ( "unsafe" ) +//go:linkname runtimeSemacquire sync.runtime_Semacquire +func runtimeSemacquire(s *uint32) + // DowngradableRWMutex is identical to sync.RWMutex, but adds the DowngradeLock // method. type DowngradableRWMutex struct { @@ -62,7 +70,7 @@ func (rw *DowngradableRWMutex) RUnlock() { // A writer is pending. if atomic.AddInt32(&rw.readerWait, -1) == 0 { // The last reader unblocks the writer. - runtimeSemrelease(&rw.writerSem, false) + runtimeSemrelease(&rw.writerSem, false, 0) } } if RaceEnabled { @@ -103,7 +111,7 @@ func (rw *DowngradableRWMutex) Unlock() { } // Unblock blocked readers, if any. for i := 0; i < int(r); i++ { - runtimeSemrelease(&rw.readerSem, false) + runtimeSemrelease(&rw.readerSem, false, 0) } // Allow other writers to proceed. rw.w.Unlock() @@ -126,7 +134,7 @@ func (rw *DowngradableRWMutex) DowngradeLock() { // Unblock blocked readers, if any. Note that this loop starts as 1 since r // includes this goroutine. for i := 1; i < int(r); i++ { - runtimeSemrelease(&rw.readerSem, false) + runtimeSemrelease(&rw.readerSem, false, 0) } // Allow other writers to proceed to rw.w.Lock(). Note that they will still // block on rw.writerSem since at least this reader exists, such that @@ -136,9 +144,3 @@ func (rw *DowngradableRWMutex) DowngradeLock() { RaceEnable() } } - -//go:linkname runtimeSemacquire sync.runtime_Semacquire -func runtimeSemacquire(s *uint32) - -//go:linkname runtimeSemrelease sync.runtime_Semrelease -func runtimeSemrelease(s *uint32, handoff bool) diff --git a/third_party/gvsync/memmove_unsafe.go b/third_party/gvsync/memmove_unsafe.go index 4c8aa9ab6..84b69f215 100644 --- a/third_party/gvsync/memmove_unsafe.go +++ b/third_party/gvsync/memmove_unsafe.go @@ -3,12 +3,21 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build go1.12 +// +build !go1.14 + +// Check go:linkname function signatures when updating Go version. + package gvsync import ( "unsafe" ) +//go:linkname memmove runtime.memmove +//go:noescape +func memmove(to, from unsafe.Pointer, n uintptr) + // Memmove is exported for SeqAtomicLoad/SeqAtomicTryLoad<T>, which can't // define it because go_generics can't update the go:linkname annotation. // Furthermore, go:linkname silently doesn't work if the local name is exported @@ -17,7 +26,3 @@ import ( func Memmove(to, from unsafe.Pointer, n uintptr) { memmove(to, from, n) } - -//go:linkname memmove runtime.memmove -//go:noescape -func memmove(to, from unsafe.Pointer, n uintptr) |