| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using Ryujinx.HLE.HOS.Kernel.Common;
- using Ryujinx.HLE.HOS.Kernel.Memory;
- using Ryujinx.HLE.HOS.Kernel.Process;
- using Ryujinx.HLE.HOS.Kernel.SupervisorCall;
- using Ryujinx.HLE.HOS.Kernel.Threading;
- using Ryujinx.Memory;
- using System;
- using System.Collections.Concurrent;
- using System.Threading;
- namespace Ryujinx.HLE.HOS.Kernel
- {
- class KernelContext : IDisposable
- {
- public long PrivilegedProcessLowestId { get; set; } = 1;
- public long PrivilegedProcessHighestId { get; set; } = 8;
- public bool EnableVersionChecks { get; set; }
- public bool KernelInitialized { get; }
- public bool Running { get; private set; }
- public Switch Device { get; }
- public MemoryBlock Memory { get; }
- public Syscall Syscall { get; }
- public SyscallHandler SyscallHandler { get; }
- public KResourceLimit ResourceLimit { get; }
- public KMemoryRegionManager[] MemoryRegions { get; }
- public KMemoryBlockAllocator LargeMemoryBlockAllocator { get; }
- public KMemoryBlockAllocator SmallMemoryBlockAllocator { get; }
- public KSlabHeap UserSlabHeapPages { get; }
- public KCriticalSection CriticalSection { get; }
- public KScheduler[] Schedulers { get; }
- public KPriorityQueue PriorityQueue { get; }
- public KTimeManager TimeManager { get; }
- public KSynchronization Synchronization { get; }
- public KContextIdManager ContextIdManager { get; }
- public ConcurrentDictionary<long, KProcess> Processes { get; }
- public ConcurrentDictionary<string, KAutoObject> AutoObjectNames { get; }
- public bool ThreadReselectionRequested { get; set; }
- private long _kipId;
- private long _processId;
- private long _threadUid;
- public KernelContext(Switch device, MemoryBlock memory)
- {
- Device = device;
- Memory = memory;
- Running = true;
- Syscall = new Syscall(this);
- SyscallHandler = new SyscallHandler(this);
- ResourceLimit = new KResourceLimit(this);
- KernelInit.InitializeResourceLimit(ResourceLimit);
- MemoryRegions = KernelInit.GetMemoryRegions();
- LargeMemoryBlockAllocator = new KMemoryBlockAllocator(KernelConstants.MemoryBlockAllocatorSize * 2);
- SmallMemoryBlockAllocator = new KMemoryBlockAllocator(KernelConstants.MemoryBlockAllocatorSize);
- UserSlabHeapPages = new KSlabHeap(
- KernelConstants.UserSlabHeapBase,
- KernelConstants.UserSlabHeapItemSize,
- KernelConstants.UserSlabHeapSize);
- CriticalSection = new KCriticalSection(this);
- Schedulers = new KScheduler[KScheduler.CpuCoresCount];
- PriorityQueue = new KPriorityQueue();
- TimeManager = new KTimeManager(this);
- Synchronization = new KSynchronization(this);
- ContextIdManager = new KContextIdManager();
- for (int core = 0; core < KScheduler.CpuCoresCount; core++)
- {
- Schedulers[core] = new KScheduler(this, core);
- }
- StartPreemptionThread();
- KernelInitialized = true;
- Processes = new ConcurrentDictionary<long, KProcess>();
- AutoObjectNames = new ConcurrentDictionary<string, KAutoObject>();
- _kipId = KernelConstants.InitialKipId;
- _processId = KernelConstants.InitialProcessId;
- }
- private void StartPreemptionThread()
- {
- void PreemptionThreadStart()
- {
- KScheduler.PreemptionThreadLoop(this);
- }
- new Thread(PreemptionThreadStart) { Name = "HLE.PreemptionThread" }.Start();
- }
- public long NewThreadUid()
- {
- return Interlocked.Increment(ref _threadUid) - 1;
- }
- public long NewKipId()
- {
- return Interlocked.Increment(ref _kipId) - 1;
- }
- public long NewProcessId()
- {
- return Interlocked.Increment(ref _processId) - 1;
- }
- public void Dispose()
- {
- Running = false;
- for (int i = 0; i < KScheduler.CpuCoresCount; i++)
- {
- Schedulers[i].Dispose();
- }
- TimeManager.Dispose();
- }
- }
- }
|