rjx-mirror/Ryujinx.Cpu/AppleHv/HvIpaAllocator.cs
gdkchan a53cfdab78
Initial Apple Hypervisor based CPU emulation (#4332)
* Initial Apple Hypervisor based CPU emulation implementation

* Add UseHypervisor Setting

* Add basic MacOS support to Avalonia

* Fix initialization

* Fix GTK build

* Fix/silence warnings

* Change exceptions to asserts on HvAddressSpaceRange

* Replace DllImport with LibraryImport

* Fix LibraryImport

* Remove unneeded usings

* Revert outdated change

* Set DiskCacheLoadState when using hypervisor too

* Fix HvExecutionContext PC value

* Address PR feedback

* Use existing entitlements.xml file on distribution folder

---------

Co-authored-by: riperiperi <rhy3756547@hotmail.com>
2023-01-29 08:37:52 -03:00

34 lines
No EOL
928 B
C#

using System;
namespace Ryujinx.Cpu.AppleHv
{
class HvIpaAllocator
{
private const ulong AllocationGranule = 1UL << 14;
private const ulong IpaRegionSize = 1UL << 35;
private readonly PrivateMemoryAllocator.Block _block;
public HvIpaAllocator()
{
_block = new PrivateMemoryAllocator.Block(null, IpaRegionSize);
}
public ulong Allocate(ulong size, ulong alignment = AllocationGranule)
{
ulong offset = _block.Allocate(size, alignment);
if (offset == PrivateMemoryAllocator.InvalidOffset)
{
throw new InvalidOperationException($"No enough free IPA memory to allocate 0x{size:X} bytes with alignment 0x{alignment:X}.");
}
return offset;
}
public void Free(ulong offset, ulong size)
{
_block.Free(offset, size);
}
}
}