mirror of
https://github.com/GreemDev/Ryujinx.git
synced 2024-12-26 00:34:52 +01:00
ddc9ae2a83
* Add VTimer as alternative interrupt method on Apple Hypervisor * Fix naming violations on TimeApi * Fix timer interval (was 16us rather than 16ms) * Fix delta ticks calculation * Missing ThrowOnError call * Add SupportedOSPlatform attribute on AppleHv classes
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using Ryujinx.Memory;
|
|
using System.Runtime.Versioning;
|
|
|
|
namespace Ryujinx.Cpu.AppleHv
|
|
{
|
|
[SupportedOSPlatform("macos")]
|
|
class HvMemoryBlockAllocator : PrivateMemoryAllocatorImpl<HvMemoryBlockAllocator.Block>
|
|
{
|
|
public class Block : PrivateMemoryAllocator.Block
|
|
{
|
|
private readonly HvIpaAllocator _ipaAllocator;
|
|
public ulong Ipa { get; }
|
|
|
|
public Block(HvIpaAllocator ipaAllocator, MemoryBlock memory, ulong size) : base(memory, size)
|
|
{
|
|
_ipaAllocator = ipaAllocator;
|
|
|
|
lock (ipaAllocator)
|
|
{
|
|
Ipa = ipaAllocator.Allocate(size);
|
|
}
|
|
|
|
HvApi.hv_vm_map((ulong)Memory.Pointer, Ipa, size, HvMemoryFlags.Read | HvMemoryFlags.Write).ThrowOnError();
|
|
}
|
|
|
|
public override void Destroy()
|
|
{
|
|
HvApi.hv_vm_unmap(Ipa, Size).ThrowOnError();
|
|
|
|
lock (_ipaAllocator)
|
|
{
|
|
_ipaAllocator.Free(Ipa, Size);
|
|
}
|
|
|
|
base.Destroy();
|
|
}
|
|
}
|
|
|
|
private readonly HvIpaAllocator _ipaAllocator;
|
|
|
|
public HvMemoryBlockAllocator(HvIpaAllocator ipaAllocator, int blockAlignment) : base(blockAlignment, MemoryAllocationFlags.None)
|
|
{
|
|
_ipaAllocator = ipaAllocator;
|
|
}
|
|
|
|
public HvMemoryBlockAllocation Allocate(ulong size, ulong alignment)
|
|
{
|
|
var allocation = Allocate(size, alignment, CreateBlock);
|
|
|
|
return new HvMemoryBlockAllocation(this, allocation.Block, allocation.Offset, allocation.Size);
|
|
}
|
|
|
|
private Block CreateBlock(MemoryBlock memory, ulong size)
|
|
{
|
|
return new Block(_ipaAllocator, memory, size);
|
|
}
|
|
}
|
|
}
|