ReadBytes function in AMemory, with cleaner range check. (#136)
This commit is contained in:
parent
f1027d5511
commit
81b59077f8
2 changed files with 20 additions and 12 deletions
|
@ -301,6 +301,15 @@ namespace ChocolArm64.Memory
|
||||||
return *((ulong*)(RamPtr + (uint)Position));
|
return *((ulong*)(RamPtr + (uint)Position));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] ReadBytes(long Position, long Size)
|
||||||
|
{
|
||||||
|
EnsureRangeIsValid(Position, Size, AMemoryPerm.Read);
|
||||||
|
|
||||||
|
byte[] Result = new byte[Size];
|
||||||
|
Marshal.Copy((IntPtr)(RamPtr + (uint)Position), Result, 0, (int)Size);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector128<float> ReadVector8Unchecked(long Position)
|
public Vector128<float> ReadVector8Unchecked(long Position)
|
||||||
{
|
{
|
||||||
if (Sse2.IsSupported)
|
if (Sse2.IsSupported)
|
||||||
|
@ -611,6 +620,17 @@ namespace ChocolArm64.Memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void EnsureRangeIsValid(long Position, long Size, AMemoryPerm Perm)
|
||||||
|
{
|
||||||
|
long EndPos = (Position + Size);
|
||||||
|
Position = Position & ~AMemoryMgr.PageMask; //check base of each page
|
||||||
|
while (Position < EndPos)
|
||||||
|
{
|
||||||
|
EnsureAccessIsValid(Position, Perm);
|
||||||
|
Position += AMemoryMgr.PageSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
Dispose(true);
|
||||||
|
|
|
@ -22,18 +22,6 @@ namespace ChocolArm64.Memory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] ReadBytes(AMemory Memory, long Position, long Size)
|
|
||||||
{
|
|
||||||
byte[] Data = new byte[Size];
|
|
||||||
|
|
||||||
for (long Offs = 0; Offs < Size; Offs++)
|
|
||||||
{
|
|
||||||
Data[Offs] = (byte)Memory.ReadByte(Position + Offs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void WriteBytes(AMemory Memory, long Position, byte[] Data)
|
public static void WriteBytes(AMemory Memory, long Position, byte[] Data)
|
||||||
{
|
{
|
||||||
for (int Offs = 0; Offs < Data.Length; Offs++)
|
for (int Offs = 0; Offs < Data.Length; Offs++)
|
||||||
|
|
Loading…
Reference in a new issue