1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-30 22:52:03 +00:00
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 20:01:59 +00:00
private bool[] _isSlotFree;
2018-12-01 20:01:59 +00:00
public KTlsPageInfo(ulong pageAddress)
{
2018-12-01 20:24:37 +00:00
PageAddr = pageAddress;
2018-12-01 20:01:59 +00:00
_isSlotFree = new bool[KMemoryManager.PageSize / TlsEntrySize];
2018-12-01 20:01:59 +00:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 20:01:59 +00:00
_isSlotFree[index] = true;
}
}
2018-12-01 20:01:59 +00:00
public bool TryGetFreePage(out ulong address)
{
2018-12-01 20:01:59 +00:00
address = PageAddr;
2018-12-01 20:01:59 +00:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 20:01:59 +00:00
if (_isSlotFree[index])
{
2018-12-01 20:01:59 +00:00
_isSlotFree[index] = false;
return true;
}
2018-12-01 20:01:59 +00:00
address += TlsEntrySize;
}
2018-12-01 20:01:59 +00:00
address = 0;
return false;
}
public bool IsFull()
{
2018-12-01 20:01:59 +00:00
bool hasFree = false;
2018-12-01 20:01:59 +00:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 20:01:59 +00:00
hasFree |= _isSlotFree[index];
}
2018-12-01 20:01:59 +00:00
return !hasFree;
}
public bool IsEmpty()
{
2018-12-01 20:01:59 +00:00
bool allFree = true;
2018-12-01 20:01:59 +00:00
for (int index = 0; index < _isSlotFree.Length; index++)
{
2018-12-01 20:01:59 +00:00
allFree &= _isSlotFree[index];
}
2018-12-01 20:01:59 +00:00
return allFree;
}
2018-12-01 20:01:59 +00:00
public void FreeTlsSlot(ulong address)
{
2018-12-01 20:01:59 +00:00
_isSlotFree[(address - PageAddr) / TlsEntrySize] = true;
}
}
}