diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-11-03 08:02:44 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-03 08:02:44 +0000 |
commit | 0cbb9d78231f653e064c57544e6d479e2e958d53 (patch) | |
tree | c4c60d15a2c48276c3e9c1bb1e44876c4c0d54b2 /pkg/sentry/kernel | |
parent | 2a842882bf424c5fb8adfd04ff4489551b814cba (diff) | |
parent | 1a3f417f4a329339d89fcf89262bd08c18c1f27e (diff) |
Merge release-20201027.0-56-g1a3f417f4 (automated)
Diffstat (limited to 'pkg/sentry/kernel')
-rw-r--r-- | pkg/sentry/kernel/semaphore/semaphore.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/sentry/kernel/semaphore/semaphore.go b/pkg/sentry/kernel/semaphore/semaphore.go index c39ecfb8f..310762936 100644 --- a/pkg/sentry/kernel/semaphore/semaphore.go +++ b/pkg/sentry/kernel/semaphore/semaphore.go @@ -423,6 +423,29 @@ func (s *Set) GetPID(num int32, creds *auth.Credentials) (int32, error) { return sem.pid, nil } +// GetZeroWaiters returns number of waiters waiting for the sem to go to zero. +func (s *Set) GetZeroWaiters(num int32, creds *auth.Credentials) (uint16, error) { + s.mu.Lock() + defer s.mu.Unlock() + + // The calling process must have read permission on the semaphore set. + if !s.checkPerms(creds, fs.PermMask{Read: true}) { + return 0, syserror.EACCES + } + + sem := s.findSem(num) + if sem == nil { + return 0, syserror.ERANGE + } + var semzcnt uint16 + for w := sem.waiters.Front(); w != nil; w = w.Next() { + if w.value == 0 { + semzcnt++ + } + } + return semzcnt, nil +} + // ExecuteOps attempts to execute a list of operations to the set. It only // succeeds when all operations can be applied. No changes are made if it fails. // |