func Shmctl(t *kernel.Task, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) {
	id := args[0].Int()
	cmd := args[1].Int()
	buf := args[2].Pointer()

	r := t.IPCNamespace().ShmRegistry()

	switch cmd {
	case linux.SHM_STAT:
		// Technically, we should be treating id as "an index into the kernel's
		// internal array that maintains information about all shared memory
		// segments on the system". Since we don't track segments in an array,
		// we'll just pretend the shmid is the index and do the same thing as
		// IPC_STAT. Linux also uses the index as the shmid.
		fallthrough
	case linux.IPC_STAT:
		segment, err := findSegment(t, id)
		if err != nil {
			return 0, nil, syserror.EINVAL
		}

		stat, err := segment.IPCStat(t)
		if err == nil {
			_, err = t.CopyOut(buf, stat)
		}
		return 0, nil, err

	case linux.IPC_INFO:
		params := r.IPCInfo()
		_, err := t.CopyOut(buf, params)
		return 0, nil, err

	case linux.SHM_INFO:
		info := r.ShmInfo()
		_, err := t.CopyOut(buf, info)
		return 0, nil, err
	}

	// Remaining commands refer to a specific segment.
	segment, err := findSegment(t, id)
	if err != nil {
		return 0, nil, syserror.EINVAL
	}

	switch cmd {
	case linux.IPC_SET:
		var ds linux.ShmidDS
		_, err = t.CopyIn(buf, &ds)
		if err != nil {
			return 0, nil, err
		}
		err = segment.Set(t, &ds)
		return 0, nil, err

	case linux.IPC_RMID:
		segment.MarkDestroyed()
		return 0, nil, nil

	case linux.SHM_LOCK, linux.SHM_UNLOCK:
		// We currently do not support memmory locking anywhere.
		// mlock(2)/munlock(2) are currently stubbed out as no-ops so do the
		// same here.
		t.Kernel().EmitUnimplementedEvent(t)
		return 0, nil, nil

	default:
		return 0, nil, syserror.EINVAL
	}
}