KTlsPageManager.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. namespace Ryujinx.HLE.HOS.Kernel
  3. {
  4. class KTlsPageManager
  5. {
  6. private const int TlsEntrySize = 0x200;
  7. private long PagePosition;
  8. private int UsedSlots;
  9. private bool[] Slots;
  10. public bool IsEmpty => UsedSlots == 0;
  11. public bool IsFull => UsedSlots == Slots.Length;
  12. public KTlsPageManager(long PagePosition)
  13. {
  14. this.PagePosition = PagePosition;
  15. Slots = new bool[KMemoryManager.PageSize / TlsEntrySize];
  16. }
  17. public bool TryGetFreeTlsAddr(out long Position)
  18. {
  19. Position = PagePosition;
  20. for (int Index = 0; Index < Slots.Length; Index++)
  21. {
  22. if (!Slots[Index])
  23. {
  24. Slots[Index] = true;
  25. UsedSlots++;
  26. return true;
  27. }
  28. Position += TlsEntrySize;
  29. }
  30. Position = 0;
  31. return false;
  32. }
  33. public void FreeTlsSlot(int Slot)
  34. {
  35. if ((uint)Slot > Slots.Length)
  36. {
  37. throw new ArgumentOutOfRangeException(nameof(Slot));
  38. }
  39. Slots[Slot] = false;
  40. UsedSlots--;
  41. }
  42. }
  43. }