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