summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry
diff options
context:
space:
mode:
authorRahat Mahmood <rahat@google.com>2019-04-02 16:45:27 -0700
committerShentubot <shentubot@google.com>2019-04-02 16:46:32 -0700
commitd14a7de65865e14383e3c4e68400446189b2e5e8 (patch)
tree2c73b3764d62c2358a7cdba9da24c55cafed9ae4 /pkg/sentry
parent1fcd40719dd89d92213c6ba5b4872b79198c309f (diff)
Fix more data races in shm debug messages.
PiperOrigin-RevId: 241630409 Change-Id: Ie0df5f5a2f20c2d32e615f16e2ba43c88f963181
Diffstat (limited to 'pkg/sentry')
-rw-r--r--pkg/sentry/kernel/shm/shm.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/sentry/kernel/shm/shm.go b/pkg/sentry/kernel/shm/shm.go
index 2b291e4f8..349f2a26e 100644
--- a/pkg/sentry/kernel/shm/shm.go
+++ b/pkg/sentry/kernel/shm/shm.go
@@ -286,7 +286,7 @@ func (r *Registry) remove(s *Shm) {
defer s.mu.Unlock()
if s.key != linux.IPC_PRIVATE {
- panic(fmt.Sprintf("Attempted to remove shm segment %d (key=%d) from the registry whose key is still associated", s.ID, s.key))
+ panic(fmt.Sprintf("Attempted to remove %s from the registry whose key is still associated", s.debugLocked()))
}
delete(r.shms, s.ID)
@@ -370,6 +370,12 @@ type Shm struct {
pendingDestruction bool
}
+// Precondition: Caller must hold s.mu.
+func (s *Shm) debugLocked() string {
+ return fmt.Sprintf("Shm{id: %d, key: %d, size: %d bytes, refs: %d, destroyed: %v}",
+ s.ID, s.key, s.size, s.ReadRefs(), s.pendingDestruction)
+}
+
// MappedName implements memmap.MappingIdentity.MappedName.
func (s *Shm) MappedName(ctx context.Context) string {
s.mu.Lock()
@@ -412,7 +418,7 @@ func (s *Shm) AddMapping(ctx context.Context, _ memmap.MappingSpace, _ usermem.A
} else {
// AddMapping is called during a syscall, so ctx should always be a task
// context.
- log.Warningf("Adding mapping to shm %+v but couldn't get the current pid; not updating the last attach pid", s)
+ log.Warningf("Adding mapping to %s but couldn't get the current pid; not updating the last attach pid", s.debugLocked())
}
return nil
}
@@ -434,7 +440,7 @@ func (s *Shm) RemoveMapping(ctx context.Context, _ memmap.MappingSpace, _ userme
if pid, ok := context.ThreadGroupIDFromContext(ctx); ok {
s.lastAttachDetachPID = pid
} else {
- log.Debugf("Couldn't obtain pid when removing mapping to shm %+v, not updating the last detach pid.", s)
+ log.Debugf("Couldn't obtain pid when removing mapping to %s, not updating the last detach pid.", s.debugLocked())
}
}