From 23070b2e5fab3c777dfd6389b80472ba9d58572e Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 21 Aug 2020 16:18:31 -0700 Subject: Internal change. PiperOrigin-RevId: 327892274 --- pkg/sentry/limits/context.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pkg/sentry/limits') diff --git a/pkg/sentry/limits/context.go b/pkg/sentry/limits/context.go index 77e1fe217..0bade6e57 100644 --- a/pkg/sentry/limits/context.go +++ b/pkg/sentry/limits/context.go @@ -33,3 +33,12 @@ func FromContext(ctx context.Context) *LimitSet { } return nil } + +// FromContextOrDie returns FromContext(ctx) if the latter is not nil. +// Otherwise, panic is triggered. +func FromContextOrDie(ctx context.Context) *LimitSet { + if v := ctx.Value(CtxLimits); v != nil { + return v.(*LimitSet) + } + panic("failed to create limit set from context") +} -- cgit v1.2.3