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; private set; }
  7. private bool[] IsSlotFree;
  8. public KTlsPageInfo(ulong PageAddress)
  9. {
  10. this.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. }