diff options
author | Jing Chen <chjing@google.com> | 2020-11-02 23:56:29 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-02 23:58:45 -0800 |
commit | 1a3f417f4a329339d89fcf89262bd08c18c1f27e (patch) | |
tree | 54d28b81f22b29ac979308b3cf7e642145916d2e /pkg/sentry/kernel/semaphore | |
parent | 1321f837bd9f082e3c1b0a37831453b3637202c3 (diff) |
Implement command GETZCNT for semctl.
PiperOrigin-RevId: 340389884
Diffstat (limited to 'pkg/sentry/kernel/semaphore')
-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. // |