2018-11-28 22:18:09 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
|
|
|
{
|
|
|
|
class KTlsPageInfo
|
|
|
|
{
|
|
|
|
public const int TlsEntrySize = 0x200;
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public ulong PageAddr { get; private set; }
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private bool[] IsSlotFree;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public KTlsPageInfo(ulong PageAddress)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
this.PageAddr = PageAddress;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
IsSlotFree = new bool[KMemoryManager.PageSize / TlsEntrySize];
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < IsSlotFree.Length; Index++)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
IsSlotFree[Index] = true;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public bool TryGetFreePage(out ulong Address)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Address = PageAddr;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < IsSlotFree.Length; Index++)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if (IsSlotFree[Index])
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
IsSlotFree[Index] = false;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Address += TlsEntrySize;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Address = 0;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsFull()
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
bool HasFree = false;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < IsSlotFree.Length; Index++)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
HasFree |= IsSlotFree[Index];
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
return !HasFree;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsEmpty()
|
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
bool AllFree = true;
|
2018-11-28 22:18:09 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < IsSlotFree.Length; Index++)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
AllFree &= IsSlotFree[Index];
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
return AllFree;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void FreeTlsSlot(ulong Address)
|
2018-11-28 22:18:09 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
IsSlotFree[(Address - PageAddr) / TlsEntrySize] = true;
|
2018-11-28 22:18:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|