diff options
author | Jing Chen <chjing@google.com> | 2020-11-06 18:36:03 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-06 18:38:13 -0800 |
commit | 3ac00fe9c3396f07a1416ff7fc855f6f9a3c4304 (patch) | |
tree | df9b44695e70a06e9c568406489281ccaefd8b37 /pkg/sentry/syscalls/linux/sys_sem.go | |
parent | 5288e194156a72a3efae7794e46e44f1dd0d7427 (diff) |
Implement command GETNCNT for semctl.
PiperOrigin-RevId: 341154192
Diffstat (limited to 'pkg/sentry/syscalls/linux/sys_sem.go')
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_sem.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_sem.go b/pkg/sentry/syscalls/linux/sys_sem.go index 067f6be6d..e383a0a87 100644 --- a/pkg/sentry/syscalls/linux/sys_sem.go +++ b/pkg/sentry/syscalls/linux/sys_sem.go @@ -139,14 +139,17 @@ func Semctl(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscal return 0, nil, err case linux.GETZCNT: - v, err := getSemzcnt(t, id, num) + v, err := getZCnt(t, id, num) + return uintptr(v), nil, err + + case linux.GETNCNT: + v, err := getNCnt(t, id, num) return uintptr(v), nil, err case linux.IPC_INFO, linux.SEM_INFO, linux.SEM_STAT, - linux.SEM_STAT_ANY, - linux.GETNCNT: + linux.SEM_STAT_ANY: t.Kernel().EmitUnimplementedEvent(t) fallthrough @@ -262,12 +265,22 @@ func getPID(t *kernel.Task, id int32, num int32) (int32, error) { return int32(tg.ID()), nil } -func getSemzcnt(t *kernel.Task, id int32, num int32) (uint16, error) { +func getZCnt(t *kernel.Task, id int32, num int32) (uint16, error) { + r := t.IPCNamespace().SemaphoreRegistry() + set := r.FindByID(id) + if set == nil { + return 0, syserror.EINVAL + } + creds := auth.CredentialsFromContext(t) + return set.CountZeroWaiters(num, creds) +} + +func getNCnt(t *kernel.Task, id int32, num int32) (uint16, error) { r := t.IPCNamespace().SemaphoreRegistry() set := r.FindByID(id) if set == nil { return 0, syserror.EINVAL } creds := auth.CredentialsFromContext(t) - return set.GetZeroWaiters(num, creds) + return set.CountNegativeWaiters(num, creds) } |