KTlsPageInfo.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. namespace Ryujinx.HLE.HOS.Kernel
  2. {
  3. class KTlsPageInfo
  4. {
  5. public const int TlsEntrySize = 0x200;
  6. public ulong PageAddr { get; }
  7. private bool[] _isSlotFree;
  8. public KTlsPageInfo(ulong pageAddress)
  9. {
  10. PageAddr = pageAddress;
  11. _isSlotFree = new bool[KMemoryManager.PageSize / TlsEntrySize];
  12. for (int index = 0; index < _isSlotFree.Length; index++)
  13. {
  14. _isSlotFree[index] = true;
  15. }
  16. }
  17. public bool TryGetFreePage(out ulong address)
  18. {
  19. address = PageAddr;
  20. for (int index = 0; index < _isSlotFree.Length; index++)
  21. {
  22. if (_isSlotFree[index])
  23. {
  24. _isSlotFree[index] = false;
  25. return true;
  26. }
  27. address += TlsEntrySize;
  28. }
  29. address = 0;
  30. return false;
  31. }
  32. public bool IsFull()
  33. {
  34. bool hasFree = false;
  35. for (int index = 0; index < _isSlotFree.Length; index++)
  36. {
  37. hasFree |= _isSlotFree[index];
  38. }
  39. return !hasFree;
  40. }
  41. public bool IsEmpty()
  42. {
  43. bool allFree = true;
  44. for (int index = 0; index < _isSlotFree.Length; index++)
  45. {
  46. allFree &= _isSlotFree[index];
  47. }
  48. return allFree;
  49. }
  50. public void FreeTlsSlot(ulong address)
  51. {
  52. _isSlotFree[(address - PageAddr) / TlsEntrySize] = true;
  53. }
  54. }
  55. }