KTlsPageInfo.cs 1.6 KB

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