HvIpaAllocator.cs 928 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. namespace Ryujinx.Cpu.AppleHv
  3. {
  4. class HvIpaAllocator
  5. {
  6. private const ulong AllocationGranule = 1UL << 14;
  7. private const ulong IpaRegionSize = 1UL << 35;
  8. private readonly PrivateMemoryAllocator.Block _block;
  9. public HvIpaAllocator()
  10. {
  11. _block = new PrivateMemoryAllocator.Block(null, IpaRegionSize);
  12. }
  13. public ulong Allocate(ulong size, ulong alignment = AllocationGranule)
  14. {
  15. ulong offset = _block.Allocate(size, alignment);
  16. if (offset == PrivateMemoryAllocator.InvalidOffset)
  17. {
  18. throw new InvalidOperationException($"No enough free IPA memory to allocate 0x{size:X} bytes with alignment 0x{alignment:X}.");
  19. }
  20. return offset;
  21. }
  22. public void Free(ulong offset, ulong size)
  23. {
  24. _block.Free(offset, size);
  25. }
  26. }
  27. }