KTlsPageManager.cs 1.3 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. _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. }