Exemplo n.º 1
0
        private KernelResult GetInfo(uint id, int handle, long subId, out long value)
        {
            value = 0;

            switch (id)
            {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 20:
            case 21:
            case 22:
            {
                if (subId != 0)
                {
                    return(KernelResult.InvalidCombination);
                }

                KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

                KProcess process = currentProcess.HandleTable.GetKProcess(handle);

                if (process == null)
                {
                    return(KernelResult.InvalidHandle);
                }

                switch (id)
                {
                case 0: value = process.Capabilities.AllowedCpuCoresMask;    break;

                case 1: value = process.Capabilities.AllowedThreadPriosMask; break;

                case 2: value = (long)process.MemoryManager.AliasRegionStart; break;

                case 3: value = (long)(process.MemoryManager.AliasRegionEnd -
                                       process.MemoryManager.AliasRegionStart); break;

                case 4: value = (long)process.MemoryManager.HeapRegionStart; break;

                case 5: value = (long)(process.MemoryManager.HeapRegionEnd -
                                       process.MemoryManager.HeapRegionStart); break;

                case 6: value = (long)process.GetMemoryCapacity(); break;

                case 7: value = (long)process.GetMemoryUsage(); break;

                case 12: value = (long)process.MemoryManager.GetAddrSpaceBaseAddr(); break;

                case 13: value = (long)process.MemoryManager.GetAddrSpaceSize(); break;

                case 14: value = (long)process.MemoryManager.StackRegionStart; break;

                case 15: value = (long)(process.MemoryManager.StackRegionEnd -
                                        process.MemoryManager.StackRegionStart); break;

                case 16: value = (long)process.PersonalMmHeapPagesCount * KMemoryManager.PageSize; break;

                case 17:
                    if (process.PersonalMmHeapPagesCount != 0)
                    {
                        value = process.MemoryManager.GetMmUsedPages() * KMemoryManager.PageSize;
                    }

                    break;

                case 18: value = process.TitleId; break;

                case 20: value = (long)process.UserExceptionContextAddress; break;

                case 21: value = (long)process.GetMemoryCapacityWithoutPersonalMmHeap(); break;

                case 22: value = (long)process.GetMemoryUsageWithoutPersonalMmHeap(); break;
                }

                break;
            }

            case 8:
            {
                if (handle != 0)
                {
                    return(KernelResult.InvalidHandle);
                }

                if (subId != 0)
                {
                    return(KernelResult.InvalidCombination);
                }

                value = _system.Scheduler.GetCurrentProcess().Debug ? 1 : 0;

                break;
            }

            case 9:
            {
                if (handle != 0)
                {
                    return(KernelResult.InvalidHandle);
                }

                if (subId != 0)
                {
                    return(KernelResult.InvalidCombination);
                }

                KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

                if (currentProcess.ResourceLimit != null)
                {
                    KHandleTable   handleTable   = currentProcess.HandleTable;
                    KResourceLimit resourceLimit = currentProcess.ResourceLimit;

                    KernelResult result = handleTable.GenerateHandle(resourceLimit, out int resLimHandle);

                    if (result != KernelResult.Success)
                    {
                        return(result);
                    }

                    value = (uint)resLimHandle;
                }

                break;
            }

            case 10:
            {
                if (handle != 0)
                {
                    return(KernelResult.InvalidHandle);
                }

                int currentCore = _system.Scheduler.GetCurrentThread().CurrentCore;

                if (subId != -1 && subId != currentCore)
                {
                    return(KernelResult.InvalidCombination);
                }

                value = _system.Scheduler.CoreContexts[currentCore].TotalIdleTimeTicks;

                break;
            }

            case 11:
            {
                if (handle != 0)
                {
                    return(KernelResult.InvalidHandle);
                }

                if ((ulong)subId > 3)
                {
                    return(KernelResult.InvalidCombination);
                }

                KProcess currentProcess = _system.Scheduler.GetCurrentProcess();


                value = currentProcess.RandomEntropy[subId];

                break;
            }

            case 0xf0000002u:
            {
                if (subId < -1 || subId > 3)
                {
                    return(KernelResult.InvalidCombination);
                }

                KThread thread = _system.Scheduler.GetCurrentProcess().HandleTable.GetKThread(handle);

                if (thread == null)
                {
                    return(KernelResult.InvalidHandle);
                }

                KThread currentThread = _system.Scheduler.GetCurrentThread();

                int currentCore = currentThread.CurrentCore;

                if (subId != -1 && subId != currentCore)
                {
                    return(KernelResult.Success);
                }

                KCoreContext coreContext = _system.Scheduler.CoreContexts[currentCore];

                long timeDelta = PerformanceCounter.ElapsedMilliseconds - coreContext.LastContextSwitchTime;

                if (subId != -1)
                {
                    value = KTimeManager.ConvertMillisecondsToTicks(timeDelta);
                }
                else
                {
                    long totalTimeRunning = thread.TotalTimeRunning;

                    if (thread == currentThread)
                    {
                        totalTimeRunning += timeDelta;
                    }

                    value = KTimeManager.ConvertMillisecondsToTicks(totalTimeRunning);
                }

                break;
            }

            default: return(KernelResult.InvalidEnumValue);
            }

            return(KernelResult.Success);
        }