summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/kernel/auth/context.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-11-01 23:12:31 +0000
committergVisor bot <gvisor-bot@google.com>2021-11-01 23:12:31 +0000
commitaac9c42f3e58cced50246227469b3c4a300c5678 (patch)
treea57c86f5faf4db4705df8e6820f9d771ccd8eeb0 /pkg/sentry/kernel/auth/context.go
parent76d5839bc55623bce2cb80f4a1cf5cbed2a6a179 (diff)
parent9776edb3fa9e67a28182aedc9342ef9c1b556d7c (diff)
Merge release-20211026.0-19-g9776edb3f (automated)
Diffstat (limited to 'pkg/sentry/kernel/auth/context.go')
-rw-r--r--pkg/sentry/kernel/auth/context.go13
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}