Ryujinx/Ryujinx.HLE/HOS/Kernel/KTlsPageInfo.cs

73 lines
1.6 KiB
C#
Raw Normal View History

namespace Ryujinx.HLE.HOS.Kernel
{
class KTlsPageInfo
{
public const int TlsEntrySize = 0x200;
public ulong PageAddr { get; private set; }
2018-12-01 21:01:59 +01:00
private bool[] _isSlotFree;
2018-12-01 21:01:59 +01:00
public KTlsPageInfo(ulong pageAddress)
{
2018-12-01 21:24:37 +01:00
PageAddr = pageAddress;
2018-12-01 21:01:59 +01:00
_isSlotFree = new bool[KMemoryManager.PageSize / TlsEntrySize];
2018-12-01 21:01:59 +01:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 21:01:59 +01:00
_isSlotFree[index] = true;
}
}
2018-12-01 21:01:59 +01:00
public bool TryGetFreePage(out ulong address)
{
2018-12-01 21:01:59 +01:00
address = PageAddr;
2018-12-01 21:01:59 +01:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 21:01:59 +01:00
if (_isSlotFree[index])
{
2018-12-01 21:01:59 +01:00
_isSlotFree[index] = false;
return true;
}
2018-12-01 21:01:59 +01:00
address += TlsEntrySize;
}
2018-12-01 21:01:59 +01:00
address = 0;
return false;
}
public bool IsFull()
{
2018-12-01 21:01:59 +01:00
bool hasFree = false;
2018-12-01 21:01:59 +01:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 21:01:59 +01:00
hasFree |= _isSlotFree[index];
}
2018-12-01 21:01:59 +01:00
return !hasFree;
}
public bool IsEmpty()
{
2018-12-01 21:01:59 +01:00
bool allFree = true;
2018-12-01 21:01:59 +01:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 21:01:59 +01:00
allFree &= _isSlotFree[index];
}
2018-12-01 21:01:59 +01:00
return allFree;
}
2018-12-01 21:01:59 +01:00
public void FreeTlsSlot(ulong address)
{
2018-12-01 21:01:59 +01:00
_isSlotFree[(address - PageAddr) / TlsEntrySize] = true;
}
}
}