From 55b905845650efc9a0a23066f8ffd25ce2565bbc Mon Sep 17 00:00:00 2001 From: Jamie Liu Date: Wed, 13 Jun 2018 10:03:06 -0700 Subject: Log filemem state when panicing due to invalid refcount. PiperOrigin-RevId: 200408305 Change-Id: I676ee49ec77697105723577928c7f82088cd378e --- pkg/sentry/platform/filemem/filemem.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'pkg/sentry/platform') diff --git a/pkg/sentry/platform/filemem/filemem.go b/pkg/sentry/platform/filemem/filemem.go index d79c3c7f1..45ef98eb0 100644 --- a/pkg/sentry/platform/filemem/filemem.go +++ b/pkg/sentry/platform/filemem/filemem.go @@ -156,17 +156,6 @@ type usageInfo struct { refs uint64 } -func (u *usageInfo) incRef() { - u.refs++ -} - -func (u *usageInfo) decRef() { - if u.refs == 0 { - panic("DecRef at 0 refs!") - } - u.refs-- -} - const ( chunkShift = 24 chunkSize = 1 << chunkShift // 16 MB @@ -506,7 +495,7 @@ func (f *FileMem) IncRef(fr platform.FileRange) { defer f.mu.Unlock() gap := f.usage.ApplyContiguous(fr, func(seg usageIterator) { - seg.ValuePtr().incRef() + seg.ValuePtr().refs++ }) if gap.Ok() { panic(fmt.Sprintf("IncRef(%v): attempted to IncRef on unallocated pages %v:\n%v", fr, gap.Range(), &f.usage)) @@ -527,7 +516,10 @@ func (f *FileMem) DecRef(fr platform.FileRange) { for seg := f.usage.FindSegment(fr.Start); seg.Ok() && seg.Start() < fr.End; seg = seg.NextSegment() { seg = f.usage.Isolate(seg, fr) val := seg.ValuePtr() - val.decRef() + if val.refs == 0 { + panic(fmt.Sprintf("DecRef(%v): 0 existing references on %v:\n%v", fr, seg.Range(), &f.usage)) + } + val.refs-- if val.refs == 0 { freed = true // Reclassify memory as System, until it's freed by the reclaim -- cgit v1.2.3