summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/platform/filemem
diff options
context:
space:
mode:
authorJamie Liu <jamieliu@google.com>2018-06-13 10:03:06 -0700
committerShentubot <shentubot@google.com>2018-06-13 10:03:54 -0700
commit55b905845650efc9a0a23066f8ffd25ce2565bbc (patch)
tree952c190a8f4550931f1516a323f81901b3f25211 /pkg/sentry/platform/filemem
parentba426f7782d35f971820a0193cfda58485b92cad (diff)
Log filemem state when panicing due to invalid refcount.
PiperOrigin-RevId: 200408305 Change-Id: I676ee49ec77697105723577928c7f82088cd378e
Diffstat (limited to 'pkg/sentry/platform/filemem')
-rw-r--r--pkg/sentry/platform/filemem/filemem.go18
1 files changed, 5 insertions, 13 deletions
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