From 9776edb3fa9e67a28182aedc9342ef9c1b556d7c Mon Sep 17 00:00:00 2001 From: Adin Scannell Date: Mon, 1 Nov 2021 16:05:18 -0700 Subject: Move ThreadGroupIDFromContext to kernel/auth. This function doesn't belong in the global context package. Move to a more suitable package to break the dependency cycle. PiperOrigin-RevId: 406942122 --- pkg/sentry/kernel/auth/context.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pkg/sentry/kernel/auth/context.go') diff --git a/pkg/sentry/kernel/auth/context.go b/pkg/sentry/kernel/auth/context.go index c08d47787..2039a96ad 100644 --- a/pkg/sentry/kernel/auth/context.go +++ b/pkg/sentry/kernel/auth/context.go @@ -24,6 +24,10 @@ type contextID int const ( // CtxCredentials is a Context.Value key for Credentials. CtxCredentials contextID = iota + + // CtxThreadGroupID is the current thread group ID when a context represents + // a task context. The value is represented as an int32. + CtxThreadGroupID contextID = iota ) // CredentialsFromContext returns a copy of the Credentials used by ctx, or a @@ -35,6 +39,15 @@ func CredentialsFromContext(ctx context.Context) *Credentials { return NewAnonymousCredentials() } +// ThreadGroupIDFromContext returns the current thread group ID when ctx +// represents a task context. +func ThreadGroupIDFromContext(ctx context.Context) (tgid int32, ok bool) { + if tgid := ctx.Value(CtxThreadGroupID); tgid != nil { + return tgid.(int32), true + } + return 0, false +} + // ContextWithCredentials returns a copy of ctx carrying creds. func ContextWithCredentials(ctx context.Context, creds *Credentials) context.Context { return &authContext{ctx, creds} -- cgit v1.2.3