KMemoryRegionBlock.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace Ryujinx.HLE.HOS.Kernel.Memory
  2. {
  3. class KMemoryRegionBlock
  4. {
  5. public long[][] Masks;
  6. public ulong FreeCount;
  7. public int MaxLevel;
  8. public ulong StartAligned;
  9. public ulong SizeInBlocksTruncated;
  10. public ulong SizeInBlocksRounded;
  11. public int Order;
  12. public int NextOrder;
  13. public bool TryCoalesce(int index, int size)
  14. {
  15. long mask = ((1L << size) - 1) << (index & 63);
  16. index /= 64;
  17. if ((mask & ~Masks[MaxLevel - 1][index]) != 0)
  18. {
  19. return false;
  20. }
  21. Masks[MaxLevel - 1][index] &= ~mask;
  22. for (int level = MaxLevel - 2; level >= 0; level--, index /= 64)
  23. {
  24. Masks[level][index / 64] &= ~(1L << (index & 63));
  25. if (Masks[level][index / 64] != 0)
  26. {
  27. break;
  28. }
  29. }
  30. FreeCount -= (ulong)size;
  31. return true;
  32. }
  33. }
  34. }