diff options
author | Jing Chen <chjing@google.com> | 2021-02-25 12:54:36 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-25 12:57:01 -0800 |
commit | e50ee26207a99930be966bd48e04f5bccd85cc05 (patch) | |
tree | 33961a0d07df93ee592c9a84d021d75cb2058a35 /pkg/sentry/syscalls/linux/sys_sem.go | |
parent | 56053f084f06e61e963b0007e7bf99e69a0f9144 (diff) |
Implement SEM_STAT_ANY cmd of semctl.
PiperOrigin-RevId: 359591577
Diffstat (limited to 'pkg/sentry/syscalls/linux/sys_sem.go')
-rw-r--r-- | pkg/sentry/syscalls/linux/sys_sem.go | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/pkg/sentry/syscalls/linux/sys_sem.go b/pkg/sentry/syscalls/linux/sys_sem.go index 55287f147..f0570d927 100644 --- a/pkg/sentry/syscalls/linux/sys_sem.go +++ b/pkg/sentry/syscalls/linux/sys_sem.go @@ -220,8 +220,16 @@ func Semctl(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.Syscal return uintptr(semid), nil, err case linux.SEM_STAT_ANY: - t.Kernel().EmitUnimplementedEvent(t) - fallthrough + arg := args[3].Pointer() + // id is an index in SEM_STAT. + semid, ds, err := semStatAny(t, id) + if err != nil { + return 0, nil, err + } + if _, err := ds.CopyOut(t, arg); err != nil { + return 0, nil, err + } + return uintptr(semid), nil, err default: return 0, nil, syserror.EINVAL @@ -272,7 +280,23 @@ func semStat(t *kernel.Task, index int32) (int32, *linux.SemidDS, error) { } creds := auth.CredentialsFromContext(t) ds, err := set.GetStat(creds) - return set.ID, ds, err + if err != nil { + return 0, ds, err + } + return set.ID, ds, nil +} + +func semStatAny(t *kernel.Task, index int32) (int32, *linux.SemidDS, error) { + set := t.IPCNamespace().SemaphoreRegistry().FindByIndex(index) + if set == nil { + return 0, nil, syserror.EINVAL + } + creds := auth.CredentialsFromContext(t) + ds, err := set.GetStatAny(creds) + if err != nil { + return 0, ds, err + } + return set.ID, ds, nil } func setVal(t *kernel.Task, id int32, num int32, val int16) error { |