mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Rename procid package to hosttid.
"procid" implies "process ID", "processor (CPU?) ID", or "`runtime.p.id`". It is none of these things. Instead, `procid.Current()` returns the caller's host thread ID; almost every caller relies on this property. Rename the package accordingly. Nit: Replace "system thread identifier" with "host thread ID". "System" is needlessly vague in a setting where many callers will also have an unrelated application thread ID, and "identifier" is a guess at what is abbreviated by "thread ID" - but cf. gettid(2), "NAME: gettid - get thread identification". PiperOrigin-RevId: 507034135
This commit is contained in:
@@ -4,37 +4,37 @@ load("//tools/nogo:defs.bzl", "nogo_facts")
|
||||
package(licenses = ["notice"])
|
||||
|
||||
nogo_facts(
|
||||
name = "procid_impl",
|
||||
srcs = ["procid.go"],
|
||||
output = "procid_impl.s",
|
||||
name = "hosttid_impl",
|
||||
srcs = ["hosttid.go"],
|
||||
output = "hosttid_impl.s",
|
||||
template = select_arch(
|
||||
amd64 = "procid_amd64.s",
|
||||
arm64 = "procid_arm64.s",
|
||||
amd64 = "hosttid_amd64.s",
|
||||
arm64 = "hosttid_arm64.s",
|
||||
),
|
||||
)
|
||||
|
||||
arch_genrule(
|
||||
name = "procid_impl_arch",
|
||||
src = ":procid_impl",
|
||||
template = "procid_impl_%s.s",
|
||||
name = "hosttid_impl_arch",
|
||||
src = ":hosttid_impl",
|
||||
template = "hosttid_impl_%s.s",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "procid",
|
||||
name = "hosttid",
|
||||
srcs = [
|
||||
"procid.go",
|
||||
":procid_impl_arch",
|
||||
"hosttid.go",
|
||||
":hosttid_impl_arch",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "procid_test",
|
||||
name = "hosttid_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"procid_test.go",
|
||||
"hosttid_test.go",
|
||||
],
|
||||
library = ":procid",
|
||||
library = ":hosttid",
|
||||
deps = [
|
||||
"//pkg/sync",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
@@ -42,13 +42,13 @@ go_test(
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "procid_net_test",
|
||||
name = "hosttid_net_test",
|
||||
size = "small",
|
||||
srcs = [
|
||||
"procid_net_test.go",
|
||||
"procid_test.go",
|
||||
"hosttid_net_test.go",
|
||||
"hosttid_test.go",
|
||||
],
|
||||
library = ":procid",
|
||||
library = ":hosttid",
|
||||
deps = [
|
||||
"//pkg/sync",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
@@ -12,8 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package procid provides a way to get the current system thread identifier.
|
||||
package procid
|
||||
// Package hosttid provides the Current function.
|
||||
package hosttid
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
@@ -22,7 +22,9 @@ import (
|
||||
// Dummy references for facts.
|
||||
const _ = runtime.Compiler
|
||||
|
||||
// Current returns the current system thread identifier.
|
||||
// Current returns the caller's host thread ID. Unless runtime.LockOSThread()
|
||||
// is in effect, this function is inherently racy since the Go runtime may
|
||||
// migrate the calling goroutine to another thread at any time.
|
||||
//
|
||||
// Precondition: This should only be called with the runtime OS thread locked.
|
||||
// Current is equivalent to unix.Gettid(), but faster.
|
||||
func Current() uint64
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procid
|
||||
package hosttid
|
||||
|
||||
// This file is just to force the inclusion of the "net" package, which will
|
||||
// make the test binary a cgo one.
|
||||
@@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procid
|
||||
package hosttid
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -92,9 +92,9 @@ go_library(
|
||||
"//pkg/context",
|
||||
"//pkg/cpuid",
|
||||
"//pkg/hostarch",
|
||||
"//pkg/hosttid",
|
||||
"//pkg/log",
|
||||
"//pkg/metric",
|
||||
"//pkg/procid",
|
||||
"//pkg/ring0",
|
||||
"//pkg/ring0/pagetables",
|
||||
"//pkg/seccomp",
|
||||
|
||||
@@ -25,9 +25,9 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/atomicbitops"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
"gvisor.dev/gvisor/pkg/hosttid"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/metric"
|
||||
"gvisor.dev/gvisor/pkg/procid"
|
||||
"gvisor.dev/gvisor/pkg/ring0"
|
||||
"gvisor.dev/gvisor/pkg/ring0/pagetables"
|
||||
"gvisor.dev/gvisor/pkg/seccomp"
|
||||
@@ -447,7 +447,7 @@ func (m *machine) Destroy() {
|
||||
func (m *machine) Get() *vCPU {
|
||||
m.mu.RLock()
|
||||
runtime.LockOSThread()
|
||||
tid := procid.Current()
|
||||
tid := hosttid.Current()
|
||||
|
||||
// Check for an exact match.
|
||||
if c := m.vCPUsByTID[tid]; c != nil {
|
||||
@@ -467,7 +467,7 @@ func (m *machine) Get() *vCPU {
|
||||
runtime.UnlockOSThread()
|
||||
m.mu.Lock()
|
||||
runtime.LockOSThread()
|
||||
tid = procid.Current()
|
||||
tid = hosttid.Current()
|
||||
|
||||
// Recheck for an exact match.
|
||||
if c := m.vCPUsByTID[tid]; c != nil {
|
||||
|
||||
@@ -27,8 +27,8 @@ go_library(
|
||||
"//pkg/context",
|
||||
"//pkg/cpuid",
|
||||
"//pkg/hostarch",
|
||||
"//pkg/hosttid",
|
||||
"//pkg/log",
|
||||
"//pkg/procid",
|
||||
"//pkg/safecopy",
|
||||
"//pkg/seccomp",
|
||||
"//pkg/sentry/arch",
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/hostarch"
|
||||
"gvisor.dev/gvisor/pkg/hosttid"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/procid"
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
"gvisor.dev/gvisor/pkg/sentry/memmap"
|
||||
"gvisor.dev/gvisor/pkg/sentry/platform"
|
||||
@@ -518,7 +518,7 @@ func (s *subprocess) switchToApp(c *context, ac *arch.Context64) bool {
|
||||
fpState := ac.FloatingPointData()
|
||||
|
||||
// Grab our thread from the pool.
|
||||
currentTID := int32(procid.Current())
|
||||
currentTID := int32(hosttid.Current())
|
||||
t := s.sysemuThreads.lookupOrCreate(currentTID, s.newThread)
|
||||
|
||||
// Reset necessary registers.
|
||||
@@ -627,7 +627,7 @@ func (s *subprocess) syscall(sysno uintptr, args ...arch.SyscallArgument) (uintp
|
||||
// Grab a thread.
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
currentTID := int32(procid.Current())
|
||||
currentTID := int32(hosttid.Current())
|
||||
t := s.syscallThreads.lookupOrCreate(currentTID, s.newThread)
|
||||
|
||||
return t.syscallIgnoreInterrupt(&t.initRegs, sysno, args...)
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
"gvisor.dev/gvisor/pkg/abi/linux"
|
||||
"gvisor.dev/gvisor/pkg/hosttid"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/procid"
|
||||
"gvisor.dev/gvisor/pkg/seccomp"
|
||||
"gvisor.dev/gvisor/pkg/sentry/arch"
|
||||
)
|
||||
@@ -210,7 +210,7 @@ func forkStub(flags uintptr, instrs []linux.BPFInstruction) (*thread, error) {
|
||||
func (s *subprocess) createStub() (*thread, error) {
|
||||
// There's no need to lock the runtime thread here, as this can only be
|
||||
// called from a context that is already locked.
|
||||
currentTID := int32(procid.Current())
|
||||
currentTID := int32(hosttid.Current())
|
||||
t := s.syscallThreads.lookupOrCreate(currentTID, s.newThread)
|
||||
|
||||
// Pass the expected PPID to the child via R15.
|
||||
|
||||
Reference in New Issue
Block a user