コード例 #1
0
        public virtual int hleKernelWaitSema(SceKernelSemaInfo sema, int signal, TPointer32 timeoutAddr, bool doCallbacks)
        {
            if (!tryWaitSemaphore(sema, signal))
            {
                // Failed, but it's ok, just wait a little
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelWaitSema {0} fast check failed", sema));
                }
                ThreadManForUser    threadMan     = Modules.ThreadManForUserModule;
                SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                sema.threadWaitingList.addWaitingThread(currentThread);
                // Wait on a specific semaphore
                currentThread.wait.Semaphore_id     = sema.uid;
                currentThread.wait.Semaphore_signal = signal;
                threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_SEMA, sema.uid, semaWaitStateChecker, timeoutAddr.Address, doCallbacks);
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelWaitSema {0} fast check succeeded", sema));
                }
            }

            return(0);
        }
コード例 #2
0
        private int hleKernelAllocateFpl(int uid, TPointer32 dataAddr, TPointer32 timeoutAddr, bool wait, bool doCallbacks)
        {
            SceKernelFplInfo fpl       = fplMap[uid];
            int addr                   = tryAllocateFpl(fpl);
            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (addr == 0)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelAllocateFpl {0} fast check failed", fpl));
                }
                if (!wait)
                {
                    return(ERROR_KERNEL_WAIT_CAN_NOT_WAIT);
                }
                // Go to wait state
                SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                fpl.threadWaitingList.addWaitingThread(currentThread);
                currentThread.wait.Fpl_id       = uid;
                currentThread.wait.Fpl_dataAddr = dataAddr;
                threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_FPL, uid, fplWaitStateChecker, timeoutAddr.Address, doCallbacks);
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelAllocateFpl {0} fast check succeeded", fpl));
                }
                dataAddr.setValue(addr);
            }

            return(0);
        }
コード例 #3
0
        private int hleKernelReceiveMsgPipe(int uid, TPointer msgAddr, int size, int waitMode, TPointer32 resultSizeAddr, TPointer32 timeoutAddr, bool doCallbacks, bool poll)
        {
            SceKernelMppInfo info = msgMap[uid];

            if (info.bufSize != 0 && size > info.bufSize)
            {
                Console.WriteLine(string.Format("hleKernelReceiveMsgPipe illegal size 0x{0:X}, max 0x{1:X}", size, info.bufSize));
                return(ERROR_KERNEL_ILLEGAL_SIZE);
            }

            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (!tryReceiveMsgPipe(info, msgAddr, size, waitMode, resultSizeAddr))
            {
                if (!poll)
                {
                    // Failed, but it's ok, just wait a little
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("hleKernelReceiveMsgPipe {0} waiting for 0x{1:X} bytes to become available", info, size));
                    }
                    SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                    info.receiveThreadWaitingList.addWaitingThread(currentThread);
                    // Wait on a specific MsgPipe.
                    currentThread.wait.MsgPipe_isSend          = false;
                    currentThread.wait.MsgPipe_id              = uid;
                    currentThread.wait.MsgPipe_address         = msgAddr;
                    currentThread.wait.MsgPipe_size            = size;
                    currentThread.wait.MsgPipe_resultSize_addr = resultSizeAddr;
                    threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_MSGPIPE, uid, msgPipeReceiveWaitStateChecker, timeoutAddr.Address, doCallbacks);
                }
                else
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("hleKernelReceiveMsgPipe trying to read more than is available size 0x{0:X}, available 0x{1:X}", size, info.bufSize - info.freeSize));
                    }
                    return(ERROR_KERNEL_MESSAGE_PIPE_EMPTY);
                }
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelReceiveMsgPipe {0} fast check succeeded", info));
                }
                onMsgPipeSendModified(info);
            }

            return(0);
        }
コード例 #4
0
        public virtual int hleKernelWaitEventFlag(int uid, int bits, int wait, TPointer32 outBitsAddr, TPointer32 timeoutAddr, bool doCallbacks)
        {
            if ((wait & ~(PSP_EVENT_WAITOR | PSP_EVENT_WAITCLEAR | PSP_EVENT_WAITCLEARALL)) != 0 || (wait & (PSP_EVENT_WAITCLEAR | PSP_EVENT_WAITCLEARALL)) == (PSP_EVENT_WAITCLEAR | PSP_EVENT_WAITCLEARALL))
            {
                return(ERROR_KERNEL_ILLEGAL_MODE);
            }
            if (bits == 0)
            {
                return(ERROR_KERNEL_EVENT_FLAG_ILLEGAL_WAIT_PATTERN);
            }
            if (!Modules.ThreadManForUserModule.DispatchThreadEnabled)
            {
                return(ERROR_KERNEL_WAIT_CAN_NOT_WAIT);
            }

            SceKernelEventFlagInfo @event = eventMap[uid];

            if (@event.NumWaitThreads >= 1 && (@event.attr & PSP_EVENT_WAITMULTIPLE) != PSP_EVENT_WAITMULTIPLE)
            {
                Console.WriteLine("hleKernelWaitEventFlag already another thread waiting on it");
                return(ERROR_KERNEL_EVENT_FLAG_NO_MULTI_PERM);
            }

            if (!checkEventFlag(@event, bits, wait, outBitsAddr))
            {
                // Failed, but it's ok, just wait a little
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelWaitEventFlag - {0} fast check failed", @event));
                }
                ThreadManForUser    threadMan     = Modules.ThreadManForUserModule;
                SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                @event.threadWaitingList.addWaitingThread(currentThread);
                // Wait on a specific event flag
                currentThread.wait.EventFlag_id           = uid;
                currentThread.wait.EventFlag_bits         = bits;
                currentThread.wait.EventFlag_wait         = wait;
                currentThread.wait.EventFlag_outBits_addr = outBitsAddr;

                threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_EVENTFLAG, uid, eventFlagWaitStateChecker, timeoutAddr.Address, doCallbacks);
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelWaitEventFlag - {0} fast check succeeded", @event));
                }
            }

            return(0);
        }
コード例 #5
0
        protected internal virtual int hleUmdWaitDriveStat(int wantedStat, bool doCallbacks, bool doTimeout, int timeout)
        {
            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (!checkDriveStat(wantedStat))
            {
                SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                // Wait on a specific umdStat.
                currentThread.wait.wantedUmdStat = wantedStat;
                waitingThreads.Add(currentThread);
                threadMan.hleKernelThreadEnterWaitState(currentThread, JPCSP_WAIT_UMD, -1, umdWaitStateChecker, timeout, !doTimeout, doCallbacks);
            }
            threadMan.hleRescheduleCurrentThread(doCallbacks);

            return(0);
        }
コード例 #6
0
        private int hleKernelAllocateVpl(int uid, int size, TPointer32 dataAddr, TPointer32 timeoutAddr, bool wait, bool doCallbacks)
        {
            SceKernelVplInfo vpl = vplMap[uid];

            if (size <= 0 || size > vpl.poolSize)
            {
                return(ERROR_KERNEL_ILLEGAL_MEMSIZE);
            }

            int addr = tryAllocateVpl(vpl, size);
            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (addr == 0)
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelAllocateVpl {0} fast check failed", vpl));
                }
                if (!wait)
                {
                    return(ERROR_KERNEL_WAIT_CAN_NOT_WAIT);
                }
                // Go to wait state
                SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                vpl.threadWaitingList.addWaitingThread(currentThread);
                // Wait on a specific fpl
                currentThread.wait.Vpl_id       = uid;
                currentThread.wait.Vpl_size     = size;
                currentThread.wait.Vpl_dataAddr = dataAddr;
                threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_VPL, uid, vplWaitStateChecker, timeoutAddr.Address, doCallbacks);
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelAllocateVpl {0} fast check succeeded, allocated addr=0x{1:X8}", vpl, addr));
                }
                dataAddr.setValue(addr);
            }

            return(0);
        }
コード例 #7
0
        private int hleKernelReceiveMbx(int uid, TPointer32 addrMsgAddr, TPointer32 timeoutAddr, bool doCallbacks, bool poll)
        {
            SceKernelMbxInfo info      = mbxMap[uid];
            ThreadManForUser threadMan = Modules.ThreadManForUserModule;

            if (!info.hasMessage())
            {
                if (!poll)
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("hleKernelReceiveMbx - {0} (waiting)", info));
                    }
                    SceKernelThreadInfo currentThread = threadMan.CurrentThread;
                    info.threadWaitingList.addWaitingThread(currentThread);
                    currentThread.wait.Mbx_id         = uid;
                    currentThread.wait.Mbx_resultAddr = addrMsgAddr;
                    threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_MBX, uid, mbxWaitStateChecker, timeoutAddr.Address, doCallbacks);
                }
                else
                {
                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine("hleKernelReceiveMbx has no messages.");
                    }
                    return(ERROR_KERNEL_MESSAGEBOX_NO_MESSAGE);
                }
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("hleKernelReceiveMbx - {0} fast check succeeded", info));
                }
                int msgAddr = info.removeMsg(Memory.Instance);
                addrMsgAddr.setValue(msgAddr);
            }

            return(0);
        }
コード例 #8
0
        private int hleKernelLockLwMutex(int uid, int count, TPointer32 timeoutAddr, bool wait, bool doCallbacks)
        {
            SceKernelLwMutexInfo info = lwMutexMap[uid];

            if (info == null)
            {
                if (uid == 0)
                {
                    // Avoid spamming messages for uid==0
                    //if (log.DebugEnabled)
                    {
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: Console.WriteLine(String.format("hleKernelLockLwMutex uid=%d, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b -  - unknown UID", uid, count, timeoutAddr, wait, doCallbacks));
                        Console.WriteLine(string.Format("hleKernelLockLwMutex uid=%d, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b -  - unknown UID", uid, count, timeoutAddr, wait, doCallbacks));
                    }
                }
                else
                {
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: Console.WriteLine(String.format("hleKernelLockLwMutex uid=%d, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b -  - unknown UID", uid, count, timeoutAddr, wait, doCallbacks));
                    Console.WriteLine(string.Format("hleKernelLockLwMutex uid=%d, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b -  - unknown UID", uid, count, timeoutAddr, wait, doCallbacks));
                }
                return(ERROR_KERNEL_LWMUTEX_NOT_FOUND);
            }

            ThreadManForUser    threadMan     = Modules.ThreadManForUserModule;
            SceKernelThreadInfo currentThread = threadMan.CurrentThread;

            if (!tryLockLwMutex(info, count, currentThread))
            {
                //if (log.DebugEnabled)
                {
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: Console.WriteLine(String.format("hleKernelLockLwMutex %s, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b - fast check failed", info.toString(), count, timeoutAddr, wait, doCallbacks));
                    Console.WriteLine(string.Format("hleKernelLockLwMutex %s, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b - fast check failed", info.ToString(), count, timeoutAddr, wait, doCallbacks));
                }
                if (wait && info.threadid != currentThread.uid)
                {
                    // Failed, but it's ok, just wait a little
                    info.threadWaitingList.addWaitingThread(currentThread);
                    // Wait on a specific lwmutex
                    currentThread.wait.LwMutex_id    = uid;
                    currentThread.wait.LwMutex_count = count;
                    threadMan.hleKernelThreadEnterWaitState(PSP_WAIT_LWMUTEX, uid, lwMutexWaitStateChecker, timeoutAddr.Address, doCallbacks);
                }
                else
                {
                    if ((info.attr & PSP_LWMUTEX_ATTR_ALLOW_RECURSIVE) != PSP_LWMUTEX_ATTR_ALLOW_RECURSIVE)
                    {
                        return(ERROR_KERNEL_LWMUTEX_RECURSIVE_NOT_ALLOWED);
                    }
                    return(ERROR_KERNEL_LWMUTEX_LOCKED);
                }
            }
            else
            {
                // Success, do not reschedule the current thread.
                //if (log.DebugEnabled)
                {
//JAVA TO C# CONVERTER TODO TASK: The following line has a Java format specifier which cannot be directly translated to .NET:
//ORIGINAL LINE: Console.WriteLine(String.format("hleKernelLockLwMutex %s, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b - fast check succeeded", info.toString(), count, timeoutAddr, wait, doCallbacks));
                    Console.WriteLine(string.Format("hleKernelLockLwMutex %s, count=%d, timeout_addr=%s, wait=%b, doCallbacks=%b - fast check succeeded", info.ToString(), count, timeoutAddr, wait, doCallbacks));
                }
            }

            return(0);
        }