private KernelResult SetThreadCoreMask(int handle, int preferredCore, long affinityMask) { KProcess currentProcess = _system.Scheduler.GetCurrentProcess(); if (preferredCore == -2) { preferredCore = currentProcess.DefaultCpuCore; affinityMask = 1 << preferredCore; } else { if ((currentProcess.Capabilities.AllowedCpuCoresMask | affinityMask) != currentProcess.Capabilities.AllowedCpuCoresMask) { return(KernelResult.InvalidCpuCore); } if (affinityMask == 0) { return(KernelResult.InvalidCombination); } if ((uint)preferredCore > 3) { if ((preferredCore | 2) != -1) { return(KernelResult.InvalidCpuCore); } } else if ((affinityMask & (1 << preferredCore)) == 0) { return(KernelResult.InvalidCombination); } } KThread thread = _process.HandleTable.GetKThread(handle); if (thread == null) { return(KernelResult.InvalidHandle); } return(thread.SetCoreAndAffinityMask(preferredCore, affinityMask)); }
private KernelResult SetThreadCoreMask(int Handle, int PreferredCore, long AffinityMask) { KProcess CurrentProcess = System.Scheduler.GetCurrentProcess(); if (PreferredCore == -2) { PreferredCore = CurrentProcess.DefaultCpuCore; AffinityMask = 1 << PreferredCore; } else { if ((CurrentProcess.Capabilities.AllowedCpuCoresMask | AffinityMask) != CurrentProcess.Capabilities.AllowedCpuCoresMask) { return(KernelResult.InvalidCpuCore); } if (AffinityMask == 0) { return(KernelResult.InvalidCombination); } if ((uint)PreferredCore > 3) { if ((PreferredCore | 2) != -1) { return(KernelResult.InvalidCpuCore); } } else if ((AffinityMask & (1 << PreferredCore)) == 0) { return(KernelResult.InvalidCombination); } } KThread Thread = Process.HandleTable.GetKThread(Handle); if (Thread == null) { return(KernelResult.InvalidHandle); } return(Thread.SetCoreAndAffinityMask(PreferredCore, AffinityMask)); }
private void SvcSetThreadCoreMask(AThreadState ThreadState) { int Handle = (int)ThreadState.X0; int PrefferedCore = (int)ThreadState.X1; long AffinityMask = (long)ThreadState.X2; Device.Log.PrintDebug(LogClass.KernelSvc, "Handle = 0x" + Handle.ToString("x8") + ", " + "PrefferedCore = 0x" + PrefferedCore.ToString("x8") + ", " + "AffinityMask = 0x" + AffinityMask.ToString("x16")); if (PrefferedCore == -2) { //TODO: Get this value from the NPDM file. PrefferedCore = 0; AffinityMask = 1 << PrefferedCore; } else { //TODO: Check allowed cores from NPDM file. if ((uint)PrefferedCore > 3) { if ((PrefferedCore | 2) != -1) { Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid core id 0x{PrefferedCore:x8}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidCoreId); return; } } else if ((AffinityMask & (1 << PrefferedCore)) == 0) { Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid core mask 0x{AffinityMask:x8}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidMaskValue); return; } } KThread Thread = Process.HandleTable.GetKThread(Handle); if (Thread == null) { Device.Log.PrintWarning(LogClass.KernelSvc, $"Invalid thread handle 0x{Handle:x8}!"); ThreadState.X0 = MakeError(ErrorModule.Kernel, KernelErr.InvalidHandle); return; } long Result = Thread.SetCoreAndAffinityMask(PrefferedCore, AffinityMask); if (Result != 0) { Device.Log.PrintWarning(LogClass.KernelSvc, $"Operation failed with error 0x{Result:x}!"); } ThreadState.X0 = (ulong)Result; }