public int sceKernelPollEventFlag([HleInvalidAsNull] HleEventFlag EventFlag, uint Bits,
                                          EventFlagWaitTypeSet WaitType, uint *OutBits)
        {
            if ((WaitType & ~EventFlagWaitTypeSet.MaskValidBits) != 0)
            {
                throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE);
            }

            // Poll seems to also fail when CLEAR and CLEARALL are used together, but not wait.
            if ((WaitType & (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll)) ==
                (EventFlagWaitTypeSet.Clear | EventFlagWaitTypeSet.ClearAll))
            {
                throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MODE);
            }

            // Can't wait on 0, it never matches.
            if (Bits == 0)
            {
                throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN);
            }

            if (EventFlag == null)
            {
                throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_NOT_FOUND_EVENT_FLAG);
            }

            bool Matched = EventFlag.Poll(Bits, WaitType, OutBits);

            if (!Matched)
            {
                throw new SceKernelException(SceKernelErrors.ERROR_KERNEL_EVENT_FLAG_POLL_FAILED);
            }

            return(0);
        }