diff options
author | Adin Scannell <ascannell@google.com> | 2021-11-01 16:05:18 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-11-01 16:07:40 -0700 |
commit | 9776edb3fa9e67a28182aedc9342ef9c1b556d7c (patch) | |
tree | b62780ff71219f1257e359b43ab33592f0ca7a03 /pkg/sentry/kernel/auth/context.go | |
parent | df6043afa02208bf9a6c2ac7986096869e9e2907 (diff) |
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
Diffstat (limited to 'pkg/sentry/kernel/auth/context.go')
-rw-r--r-- | pkg/sentry/kernel/auth/context.go | 13 |
1 files changed, 13 insertions, 0 deletions
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} |