1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00
Ryujinx/Ryujinx.HLE/HOS/Kernel/Process/KTlsPageManager.cs
gdkchan 0039bb6394
Refactor SVC handler (#540)
* Refactor SVC handler

* Get rid of KernelErr

* Split kernel code files into multiple folders
2018-12-18 03:33:36 -02:00

61 lines
No EOL
1.3 KiB
C#

using Ryujinx.HLE.HOS.Kernel.Memory;
using System;
namespace Ryujinx.HLE.HOS.Kernel.Process
{
class KTlsPageManager
{
private const int TlsEntrySize = 0x200;
private long _pagePosition;
private int _usedSlots;
private bool[] _slots;
public bool IsEmpty => _usedSlots == 0;
public bool IsFull => _usedSlots == _slots.Length;
public KTlsPageManager(long pagePosition)
{
_pagePosition = pagePosition;
_slots = new bool[KMemoryManager.PageSize / TlsEntrySize];
}
public bool TryGetFreeTlsAddr(out long position)
{
position = _pagePosition;
for (int index = 0; index < _slots.Length; index++)
{
if (!_slots[index])
{
_slots[index] = true;
_usedSlots++;
return true;
}
position += TlsEntrySize;
}
position = 0;
return false;
}
public void FreeTlsSlot(int slot)
{
if ((uint)slot > _slots.Length)
{
throw new ArgumentOutOfRangeException(nameof(slot));
}
_slots[slot] = false;
_usedSlots--;
}
}
}