From 00579927e43bf55ee06ae02933c1e755fb4120eb Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 28 Nov 2018 20:18:09 -0200 Subject: Better process implementation (#491) * Initial implementation of KProcess * Some improvements to the memory manager, implement back guest stack trace printing * Better GetInfo implementation, improve checking in some places with information from process capabilities * Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary * Change long -> ulong for address/size on memory related methods to avoid unnecessary casts * Attempt at implementing ldr:ro with new KProcess * Allow BSS with size 0 on ldr:ro * Add checking for memory block slab heap usage, return errors if full, exit gracefully * Use KMemoryBlockSize const from KMemoryManager * Allow all methods to read from non-contiguous locations * Fix for TransactParcelAuto * Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort * Fix wrong check for source pages count from page list on MapPhysicalMemory * Fix some issues with UnloadNro on ldr:ro --- Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs | 183 -------------------------- 1 file changed, 183 deletions(-) delete mode 100644 Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs (limited to 'Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs') diff --git a/Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs b/Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs deleted file mode 100644 index 682f08d4..00000000 --- a/Ryujinx.HLE/HOS/Kernel/KProcessHandleTable.cs +++ /dev/null @@ -1,183 +0,0 @@ -using System; - -namespace Ryujinx.HLE.HOS.Kernel -{ - class KProcessHandleTable - { - private const int SelfThreadHandle = (0x1ffff << 15) | 0; - private const int SelfProcessHandle = (0x1ffff << 15) | 1; - - private Horizon System; - - private KHandleEntry[] Table; - - private KHandleEntry TableHead; - private KHandleEntry NextFreeEntry; - - private int ActiveSlotsCount; - - private int Size; - - private ushort IdCounter; - - private object LockObj; - - public KProcessHandleTable(Horizon System, int Size = 1024) - { - this.System = System; - this.Size = Size; - - IdCounter = 1; - - Table = new KHandleEntry[Size]; - - TableHead = new KHandleEntry(0); - - KHandleEntry Entry = TableHead; - - for (int Index = 0; Index < Size; Index++) - { - Table[Index] = Entry; - - Entry.Next = new KHandleEntry(Index + 1); - - Entry = Entry.Next; - } - - Table[Size - 1].Next = null; - - NextFreeEntry = TableHead; - - LockObj = new object(); - } - - public KernelResult GenerateHandle(object Obj, out int Handle) - { - Handle = 0; - - lock (LockObj) - { - if (ActiveSlotsCount >= Size) - { - return KernelResult.HandleTableFull; - } - - KHandleEntry Entry = NextFreeEntry; - - NextFreeEntry = Entry.Next; - - Entry.Obj = Obj; - Entry.HandleId = IdCounter; - - ActiveSlotsCount++; - - Handle = (int)((IdCounter << 15) & (uint)0xffff8000) | Entry.Index; - - if ((short)(IdCounter + 1) >= 0) - { - IdCounter++; - } - else - { - IdCounter = 1; - } - } - - return KernelResult.Success; - } - - public bool CloseHandle(int Handle) - { - if ((Handle >> 30) != 0 || - Handle == SelfThreadHandle || - Handle == SelfProcessHandle) - { - return false; - } - - int Index = (Handle >> 0) & 0x7fff; - int HandleId = (Handle >> 15); - - bool Result = false; - - lock (LockObj) - { - if (HandleId != 0 && Index < Size) - { - KHandleEntry Entry = Table[Index]; - - if (Entry.Obj != null && Entry.HandleId == HandleId) - { - Entry.Obj = null; - Entry.Next = NextFreeEntry; - - NextFreeEntry = Entry; - - ActiveSlotsCount--; - - Result = true; - } - } - } - - return Result; - } - - public T GetObject(int Handle) - { - int Index = (Handle >> 0) & 0x7fff; - int HandleId = (Handle >> 15); - - lock (LockObj) - { - if ((Handle >> 30) == 0 && HandleId != 0) - { - KHandleEntry Entry = Table[Index]; - - if (Entry.HandleId == HandleId && Entry.Obj is T Obj) - { - return Obj; - } - } - } - - return default(T); - } - - public KThread GetKThread(int Handle) - { - if (Handle == SelfThreadHandle) - { - return System.Scheduler.GetCurrentThread(); - } - else - { - return GetObject(Handle); - } - } - - public void Destroy() - { - lock (LockObj) - { - for (int Index = 0; Index < Size; Index++) - { - KHandleEntry Entry = Table[Index]; - - if (Entry.Obj != null) - { - if (Entry.Obj is IDisposable DisposableObj) - { - DisposableObj.Dispose(); - } - - Entry.Obj = null; - Entry.Next = NextFreeEntry; - - NextFreeEntry = Entry; - } - } - } - } - } -} \ No newline at end of file -- cgit v1.2.3