diff options
Diffstat (limited to 'pkg/goid')
-rw-r--r-- | pkg/goid/BUILD | 22 | ||||
-rw-r--r-- | pkg/goid/goid.go | 72 | ||||
-rw-r--r-- | pkg/goid/goid_amd64.s | 21 | ||||
-rw-r--r-- | pkg/goid/goid_arm64.s | 21 | ||||
-rw-r--r-- | pkg/goid/goid_test.go | 81 |
5 files changed, 0 insertions, 217 deletions
diff --git a/pkg/goid/BUILD b/pkg/goid/BUILD deleted file mode 100644 index d855b702c..000000000 --- a/pkg/goid/BUILD +++ /dev/null @@ -1,22 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "goid", - srcs = [ - "goid.go", - "goid_amd64.s", - "goid_arm64.s", - ], - visibility = ["//visibility:public"], -) - -go_test( - name = "goid_test", - size = "small", - srcs = [ - "goid_test.go", - ], - library = ":goid", -) diff --git a/pkg/goid/goid.go b/pkg/goid/goid.go deleted file mode 100644 index 17c384cb0..000000000 --- a/pkg/goid/goid.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// +build go1.12 -// +build !go1.17 - -// Check type signatures when updating Go version. - -// Package goid provides the Get function. -package goid - -// Get returns the ID of the current goroutine. -func Get() int64 { - return getg().goid -} - -// Structs from Go runtime. These may change in the future and require -// updating. These structs are currently the same on both AMD64 and ARM64, -// but may diverge in the future. - -type stack struct { - lo uintptr - hi uintptr -} - -type gobuf struct { - sp uintptr - pc uintptr - g uintptr - ctxt uintptr - ret uint64 - lr uintptr - bp uintptr -} - -type g struct { - stack stack - stackguard0 uintptr - stackguard1 uintptr - - _panic uintptr - _defer uintptr - m uintptr - sched gobuf - syscallsp uintptr - syscallpc uintptr - stktopsp uintptr - param uintptr - atomicstatus uint32 - stackLock uint32 - goid int64 - - // More fields... - // - // We only use goid and the fields before it are only listed to - // calculate the correct offset. -} - -// Defined in assembly. This can't use go:linkname since runtime.getg() isn't a -// real function, it's a compiler intrinsic. -func getg() *g diff --git a/pkg/goid/goid_amd64.s b/pkg/goid/goid_amd64.s deleted file mode 100644 index d9f5cd2a3..000000000 --- a/pkg/goid/goid_amd64.s +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "textflag.h" - -// func getg() *g -TEXT ·getg(SB),NOSPLIT,$0-8 - MOVQ (TLS), R14 - MOVQ R14, ret+0(FP) - RET diff --git a/pkg/goid/goid_arm64.s b/pkg/goid/goid_arm64.s deleted file mode 100644 index a7465b75d..000000000 --- a/pkg/goid/goid_arm64.s +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "textflag.h" - -// func getg() *g -TEXT ·getg(SB),NOSPLIT,$0-8 - MOVD g, R0 // g - MOVD R0, ret+0(FP) - RET diff --git a/pkg/goid/goid_test.go b/pkg/goid/goid_test.go deleted file mode 100644 index 54be11d63..000000000 --- a/pkg/goid/goid_test.go +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package goid - -import ( - "runtime" - "sync" - "testing" - "time" -) - -func TestUniquenessAndConsistency(t *testing.T) { - const ( - numGoroutines = 5000 - - // maxID is not an intrinsic property of goroutine IDs; it is only a - // property of how the Go runtime currently assigns them. Future - // changes to the Go runtime may require that maxID be raised, or that - // assertions regarding it be removed entirely. - maxID = numGoroutines + 1000 - ) - - var ( - goidsMu sync.Mutex - goids = make(map[int64]struct{}) - checkedWG sync.WaitGroup - exitCh = make(chan struct{}) - ) - for i := 0; i < numGoroutines; i++ { - checkedWG.Add(1) - go func() { - id := Get() - if id > maxID { - t.Errorf("observed unexpectedly large goroutine ID %d", id) - } - goidsMu.Lock() - if _, dup := goids[id]; dup { - t.Errorf("observed duplicate goroutine ID %d", id) - } - goids[id] = struct{}{} - goidsMu.Unlock() - checkedWG.Done() - for { - if curID := Get(); curID != id { - t.Errorf("goroutine ID changed from %d to %d", id, curID) - // Don't spam logs by repeating the check; wait quietly for - // the test to finish. - <-exitCh - return - } - // Check if the test is over. - select { - case <-exitCh: - return - default: - } - // Yield to other goroutines, and possibly migrate to another P. - runtime.Gosched() - } - }() - } - // Wait for all goroutines to perform uniqueness checks. - checkedWG.Wait() - // Wait for an additional second to allow goroutines to spin checking for - // ID consistency. - time.Sleep(time.Second) - // Request that all goroutines exit. - close(exitCh) -} |