Exemple #1
0
        private KernelResult CreateThread(
            ulong entrypoint,
            ulong argsPtr,
            ulong stackTop,
            int priority,
            int cpuCore,
            out int handle)
        {
            handle = 0;

            KProcess currentProcess = _system.Scheduler.GetCurrentProcess();

            if (cpuCore == -2)
            {
                cpuCore = currentProcess.DefaultCpuCore;
            }

            if ((uint)cpuCore >= KScheduler.CpuCoresCount || !currentProcess.IsCpuCoreAllowed(cpuCore))
            {
                return(KernelResult.InvalidCpuCore);
            }

            if ((uint)priority >= KScheduler.PrioritiesCount || !currentProcess.IsPriorityAllowed(priority))
            {
                return(KernelResult.InvalidPriority);
            }

            long timeout = KTimeManager.ConvertMillisecondsToNanoseconds(100);

            if (currentProcess.ResourceLimit != null &&
                !currentProcess.ResourceLimit.Reserve(LimitableResource.Thread, 1, timeout))
            {
                return(KernelResult.ResLimitExceeded);
            }

            KThread thread = new KThread(_system);

            KernelResult result = currentProcess.InitializeThread(
                thread,
                entrypoint,
                argsPtr,
                stackTop,
                priority,
                cpuCore);

            if (result != KernelResult.Success)
            {
                currentProcess.ResourceLimit?.Release(LimitableResource.Thread, 1);

                return(result);
            }

            result = _process.HandleTable.GenerateHandle(thread, out handle);

            if (result != KernelResult.Success)
            {
                thread.Terminate();

                currentProcess.ResourceLimit?.Release(LimitableResource.Thread, 1);
            }

            return(result);
        }
Exemple #2
0
 public bool Reserve(LimitableResource Resource, long Amount)
 {
     return(Reserve(Resource, Amount, KTimeManager.ConvertMillisecondsToNanoseconds(Time10SecondsMs)));
 }
Exemple #3
0
        private KernelResult CreateThread(
            ulong Entrypoint,
            ulong ArgsPtr,
            ulong StackTop,
            int Priority,
            int CpuCore,
            out int Handle)
        {
            Handle = 0;

            KProcess CurrentProcess = System.Scheduler.GetCurrentProcess();

            if (CpuCore == -2)
            {
                CpuCore = CurrentProcess.DefaultCpuCore;
            }

            if ((uint)CpuCore >= KScheduler.CpuCoresCount || !CurrentProcess.IsCpuCoreAllowed(CpuCore))
            {
                return(KernelResult.InvalidCpuCore);
            }

            if ((uint)Priority >= KScheduler.PrioritiesCount || !CurrentProcess.IsPriorityAllowed(Priority))
            {
                return(KernelResult.InvalidPriority);
            }

            long Timeout = KTimeManager.ConvertMillisecondsToNanoseconds(100);

            if (CurrentProcess.ResourceLimit != null &&
                !CurrentProcess.ResourceLimit.Reserve(LimitableResource.Thread, 1, Timeout))
            {
                return(KernelResult.ResLimitExceeded);
            }

            KThread Thread = new KThread(System);

            KernelResult Result = CurrentProcess.InitializeThread(
                Thread,
                Entrypoint,
                ArgsPtr,
                StackTop,
                Priority,
                CpuCore);

            if (Result != KernelResult.Success)
            {
                CurrentProcess.ResourceLimit?.Release(LimitableResource.Thread, 1);

                return(Result);
            }

            Result = Process.HandleTable.GenerateHandle(Thread, out Handle);

            if (Result != KernelResult.Success)
            {
                Thread.Terminate();

                CurrentProcess.ResourceLimit?.Release(LimitableResource.Thread, 1);
            }

            return(Result);
        }