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