2018-08-15 18:59:51 +00:00
|
|
|
using System;
|
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
|
|
|
class KTlsPageManager
|
|
|
|
{
|
|
|
|
private const int TlsEntrySize = 0x200;
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private long PagePosition;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private int UsedSlots;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
private bool[] Slots;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public bool IsEmpty => UsedSlots == 0;
|
|
|
|
public bool IsFull => UsedSlots == Slots.Length;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public KTlsPageManager(long PagePosition)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
this.PagePosition = PagePosition;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Slots = new bool[KMemoryManager.PageSize / TlsEntrySize];
|
2018-08-15 18:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public bool TryGetFreeTlsAddr(out long Position)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Position = PagePosition;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
for (int Index = 0; Index < Slots.Length; Index++)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if (!Slots[Index])
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
Slots[Index] = true;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
UsedSlots++;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Position += TlsEntrySize;
|
2018-08-15 18:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Position = 0;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
public void FreeTlsSlot(int Slot)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
if ((uint)Slot > Slots.Length)
|
2018-08-15 18:59:51 +00:00
|
|
|
{
|
2018-12-05 00:52:39 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(Slot));
|
2018-08-15 18:59:51 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
Slots[Slot] = false;
|
2018-08-15 18:59:51 +00:00
|
|
|
|
2018-12-05 00:52:39 +00:00
|
|
|
UsedSlots--;
|
2018-08-15 18:59:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|