Use XXHash128, for Ptc.Load & Ptc.Save, x10 faster than Md5.
This commit is contained in:
parent
b6f9659d08
commit
0566987e6c
2 changed files with 113 additions and 107 deletions
|
@ -3,6 +3,7 @@ using ARMeilleure.CodeGen.Unwinding;
|
||||||
using ARMeilleure.CodeGen.X86;
|
using ARMeilleure.CodeGen.X86;
|
||||||
using ARMeilleure.Memory;
|
using ARMeilleure.Memory;
|
||||||
using ARMeilleure.Translation.Cache;
|
using ARMeilleure.Translation.Cache;
|
||||||
|
using Ryujinx.Common;
|
||||||
using Ryujinx.Common.Configuration;
|
using Ryujinx.Common.Configuration;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using System;
|
using System;
|
||||||
|
@ -13,8 +14,8 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Runtime;
|
using System.Runtime;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace ARMeilleure.Translation.PTC
|
namespace ARMeilleure.Translation.PTC
|
||||||
|
@ -69,14 +70,9 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
static Ptc()
|
static Ptc()
|
||||||
{
|
{
|
||||||
_infosStream = new MemoryStream();
|
InitializeMemoryStreams();
|
||||||
_codesStream = new MemoryStream();
|
|
||||||
_relocsStream = new MemoryStream();
|
|
||||||
_unwindInfosStream = new MemoryStream();
|
|
||||||
|
|
||||||
_infosWriter = new BinaryWriter(_infosStream, EncodingCache.UTF8NoBOM, true);
|
_headerMagic = BinaryPrimitives.ReadUInt64LittleEndian(EncodingCache.UTF8NoBOM.GetBytes(HeaderMagicString).AsSpan());
|
||||||
|
|
||||||
_headerMagic = BitConverter.ToUInt64(EncodingCache.UTF8NoBOM.GetBytes(HeaderMagicString), 0);
|
|
||||||
|
|
||||||
_waitEvent = new ManualResetEvent(true);
|
_waitEvent = new ManualResetEvent(true);
|
||||||
|
|
||||||
|
@ -106,7 +102,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
Logger.Info?.Print(LogClass.Ptc, $"Initializing Profiled Persistent Translation Cache (enabled: {enabled}).");
|
Logger.Info?.Print(LogClass.Ptc, $"Initializing Profiled Persistent Translation Cache (enabled: {enabled}).");
|
||||||
|
|
||||||
if (!enabled || String.IsNullOrEmpty(titleIdText) || titleIdText == TitleIdTextDefault)
|
if (!enabled || string.IsNullOrEmpty(titleIdText) || titleIdText == TitleIdTextDefault)
|
||||||
{
|
{
|
||||||
TitleIdText = TitleIdTextDefault;
|
TitleIdText = TitleIdTextDefault;
|
||||||
DisplayVersion = DisplayVersionDefault;
|
DisplayVersion = DisplayVersionDefault;
|
||||||
|
@ -120,7 +116,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
}
|
}
|
||||||
|
|
||||||
TitleIdText = titleIdText;
|
TitleIdText = titleIdText;
|
||||||
DisplayVersion = !String.IsNullOrEmpty(displayVersion) ? displayVersion : DisplayVersionDefault;
|
DisplayVersion = !string.IsNullOrEmpty(displayVersion) ? displayVersion : DisplayVersionDefault;
|
||||||
|
|
||||||
string workPathActual = Path.Combine(AppDataManager.GamesDirPath, TitleIdText, "cache", "cpu", ActualDir);
|
string workPathActual = Path.Combine(AppDataManager.GamesDirPath, TitleIdText, "cache", "cpu", ActualDir);
|
||||||
string workPathBackup = Path.Combine(AppDataManager.GamesDirPath, TitleIdText, "cache", "cpu", BackupDir);
|
string workPathBackup = Path.Combine(AppDataManager.GamesDirPath, TitleIdText, "cache", "cpu", BackupDir);
|
||||||
|
@ -144,23 +140,8 @@ namespace ARMeilleure.Translation.PTC
|
||||||
Enable();
|
Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ResetMemoryStreamsIfNeeded()
|
private static void InitializeMemoryStreams()
|
||||||
{
|
{
|
||||||
if (_infosStream.Length == 0L &&
|
|
||||||
_codesStream.Length == 0L &&
|
|
||||||
_relocsStream.Length == 0L &&
|
|
||||||
_unwindInfosStream.Length == 0L)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_infosWriter.Dispose();
|
|
||||||
|
|
||||||
_infosStream.Dispose();
|
|
||||||
_codesStream.Dispose();
|
|
||||||
_relocsStream.Dispose();
|
|
||||||
_unwindInfosStream.Dispose();
|
|
||||||
|
|
||||||
_infosStream = new MemoryStream();
|
_infosStream = new MemoryStream();
|
||||||
_codesStream = new MemoryStream();
|
_codesStream = new MemoryStream();
|
||||||
_relocsStream = new MemoryStream();
|
_relocsStream = new MemoryStream();
|
||||||
|
@ -169,10 +150,37 @@ namespace ARMeilleure.Translation.PTC
|
||||||
_infosWriter = new BinaryWriter(_infosStream, EncodingCache.UTF8NoBOM, true);
|
_infosWriter = new BinaryWriter(_infosStream, EncodingCache.UTF8NoBOM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void DisposeMemoryStreams()
|
||||||
|
{
|
||||||
|
_infosWriter.Dispose();
|
||||||
|
|
||||||
|
_infosStream.Dispose();
|
||||||
|
_codesStream.Dispose();
|
||||||
|
_relocsStream.Dispose();
|
||||||
|
_unwindInfosStream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool AreMemoryStreamsEmpty()
|
||||||
|
{
|
||||||
|
return _infosStream.Length == 0L && _codesStream.Length == 0L && _relocsStream.Length == 0L && _unwindInfosStream.Length == 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ResetMemoryStreamsIfNeeded()
|
||||||
|
{
|
||||||
|
if (AreMemoryStreamsEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DisposeMemoryStreams();
|
||||||
|
|
||||||
|
InitializeMemoryStreams();
|
||||||
|
}
|
||||||
|
|
||||||
private static void PreLoad()
|
private static void PreLoad()
|
||||||
{
|
{
|
||||||
string fileNameActual = String.Concat(CachePathActual, ".cache");
|
string fileNameActual = string.Concat(CachePathActual, ".cache");
|
||||||
string fileNameBackup = String.Concat(CachePathBackup, ".cache");
|
string fileNameBackup = string.Concat(CachePathBackup, ".cache");
|
||||||
|
|
||||||
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
||||||
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
|
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
|
||||||
|
@ -195,29 +203,27 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
private static unsafe bool Load(string fileName, bool isBackup)
|
private static unsafe bool Load(string fileName, bool isBackup)
|
||||||
{
|
{
|
||||||
using (FileStream compressedStream = new FileStream(fileName, FileMode.Open))
|
using (FileStream compressedStream = new(fileName, FileMode.Open))
|
||||||
using (DeflateStream deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress, true))
|
using (DeflateStream deflateStream = new(compressedStream, CompressionMode.Decompress, true))
|
||||||
{
|
{
|
||||||
using MD5 md5 = MD5.Create();
|
int hashSize = Unsafe.SizeOf<Hash128>();
|
||||||
|
|
||||||
int hashSize = md5.HashSize / 8;
|
Span<byte> currentSizeHashBytes = new byte[hashSize];
|
||||||
|
compressedStream.Read(currentSizeHashBytes);
|
||||||
|
Hash128 currentSizeHash = MemoryMarshal.Read<Hash128>(currentSizeHashBytes);
|
||||||
|
|
||||||
byte[] currentSizeHash = new byte[hashSize];
|
Span<byte> sizeBytes = new byte[sizeof(int)];
|
||||||
compressedStream.Read(currentSizeHash, 0, hashSize);
|
compressedStream.Read(sizeBytes);
|
||||||
|
Hash128 expectedSizeHash = XXHash128.ComputeHash(sizeBytes);
|
||||||
|
|
||||||
byte[] sizeBytes = new byte[sizeof(int)];
|
if (currentSizeHash != expectedSizeHash)
|
||||||
compressedStream.Read(sizeBytes, 0, sizeBytes.Length);
|
|
||||||
|
|
||||||
byte[] expectedSizeHash = md5.ComputeHash(sizeBytes);
|
|
||||||
|
|
||||||
if (!CompareHash(currentSizeHash, expectedSizeHash))
|
|
||||||
{
|
{
|
||||||
InvalidateCompressedStream(compressedStream);
|
InvalidateCompressedStream(compressedStream);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = BitConverter.ToInt32(sizeBytes, 0);
|
int size = BinaryPrimitives.ReadInt32LittleEndian(sizeBytes);
|
||||||
|
|
||||||
IntPtr intPtr = IntPtr.Zero;
|
IntPtr intPtr = IntPtr.Zero;
|
||||||
|
|
||||||
|
@ -225,7 +231,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
{
|
{
|
||||||
intPtr = Marshal.AllocHGlobal(size);
|
intPtr = Marshal.AllocHGlobal(size);
|
||||||
|
|
||||||
using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte*)intPtr.ToPointer(), size, size, FileAccess.ReadWrite))
|
using (UnmanagedMemoryStream stream = new((byte*)intPtr.ToPointer(), size, size, FileAccess.ReadWrite))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -240,12 +246,14 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
stream.Seek(0L, SeekOrigin.Begin);
|
stream.Seek(0L, SeekOrigin.Begin);
|
||||||
|
|
||||||
byte[] currentHash = new byte[hashSize];
|
Span<byte> currentHashBytes = new byte[hashSize];
|
||||||
stream.Read(currentHash, 0, hashSize);
|
stream.Read(currentHashBytes);
|
||||||
|
Hash128 currentHash = MemoryMarshal.Read<Hash128>(currentHashBytes);
|
||||||
|
|
||||||
byte[] expectedHash = md5.ComputeHash(stream);
|
ReadOnlySpan<byte> streamBytes = new(stream.PositionPointer, (int)(stream.Length - stream.Position));
|
||||||
|
Hash128 expectedHash = XXHash128.ComputeHash(streamBytes);
|
||||||
|
|
||||||
if (!CompareHash(currentHash, expectedHash))
|
if (currentHash != expectedHash)
|
||||||
{
|
{
|
||||||
InvalidateCompressedStream(compressedStream);
|
InvalidateCompressedStream(compressedStream);
|
||||||
|
|
||||||
|
@ -270,6 +278,13 @@ namespace ARMeilleure.Translation.PTC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (header.Endianness != GetEndianness())
|
||||||
|
{
|
||||||
|
InvalidateCompressedStream(compressedStream);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (header.FeatureInfo != GetFeatureInfo())
|
if (header.FeatureInfo != GetFeatureInfo())
|
||||||
{
|
{
|
||||||
InvalidateCompressedStream(compressedStream);
|
InvalidateCompressedStream(compressedStream);
|
||||||
|
@ -291,9 +306,17 @@ namespace ARMeilleure.Translation.PTC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
long here = stream.Position;
|
ReadOnlySpan<byte> infosBuf = new(stream.PositionPointer, header.InfosLen);
|
||||||
|
stream.Seek(header.InfosLen, SeekOrigin.Current);
|
||||||
|
|
||||||
stream.Seek(header.InfosLen + header.CodesLen + header.RelocsLen + header.UnwindInfosLen, SeekOrigin.Current);
|
ReadOnlySpan<byte> codesBuf = new(stream.PositionPointer, header.CodesLen);
|
||||||
|
stream.Seek(header.CodesLen, SeekOrigin.Current);
|
||||||
|
|
||||||
|
ReadOnlySpan<byte> relocsBuf = new(stream.PositionPointer, header.RelocsLen);
|
||||||
|
stream.Seek(header.RelocsLen, SeekOrigin.Current);
|
||||||
|
|
||||||
|
ReadOnlySpan<byte> unwindInfosBuf = new(stream.PositionPointer, header.UnwindInfosLen);
|
||||||
|
stream.Seek(header.UnwindInfosLen, SeekOrigin.Current);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -308,26 +331,9 @@ namespace ARMeilleure.Translation.PTC
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.Seek(here, SeekOrigin.Begin);
|
|
||||||
|
|
||||||
int maxLength = Math.Max(Math.Max(header.InfosLen, header.CodesLen), Math.Max(header.RelocsLen, header.UnwindInfosLen));
|
|
||||||
|
|
||||||
Span<byte> buffer = new byte[maxLength];
|
|
||||||
|
|
||||||
Span<byte> infosBuf = buffer.Slice(0, header.InfosLen);
|
|
||||||
stream.Read(infosBuf);
|
|
||||||
_infosStream.Write(infosBuf);
|
_infosStream.Write(infosBuf);
|
||||||
|
|
||||||
Span<byte> codesBuf = buffer.Slice(0, header.CodesLen);
|
|
||||||
stream.Read(codesBuf);
|
|
||||||
_codesStream.Write(codesBuf);
|
_codesStream.Write(codesBuf);
|
||||||
|
|
||||||
Span<byte> relocsBuf = buffer.Slice(0, header.RelocsLen);
|
|
||||||
stream.Read(relocsBuf);
|
|
||||||
_relocsStream.Write(relocsBuf);
|
_relocsStream.Write(relocsBuf);
|
||||||
|
|
||||||
Span<byte> unwindInfosBuf = buffer.Slice(0, header.UnwindInfosLen);
|
|
||||||
stream.Read(unwindInfosBuf);
|
|
||||||
_unwindInfosStream.Write(unwindInfosBuf);
|
_unwindInfosStream.Write(unwindInfosBuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -347,20 +353,16 @@ namespace ARMeilleure.Translation.PTC
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool CompareHash(ReadOnlySpan<byte> currentHash, ReadOnlySpan<byte> expectedHash)
|
|
||||||
{
|
|
||||||
return currentHash.SequenceEqual(expectedHash);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Header ReadHeader(Stream stream)
|
private static Header ReadHeader(Stream stream)
|
||||||
{
|
{
|
||||||
using (BinaryReader headerReader = new BinaryReader(stream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryReader headerReader = new(stream, EncodingCache.UTF8NoBOM, true))
|
||||||
{
|
{
|
||||||
Header header = new Header();
|
Header header = new Header();
|
||||||
|
|
||||||
header.Magic = headerReader.ReadUInt64();
|
header.Magic = headerReader.ReadUInt64();
|
||||||
|
|
||||||
header.CacheFileVersion = headerReader.ReadUInt32();
|
header.CacheFileVersion = headerReader.ReadUInt32();
|
||||||
|
header.Endianness = headerReader.ReadBoolean();
|
||||||
header.FeatureInfo = headerReader.ReadUInt64();
|
header.FeatureInfo = headerReader.ReadUInt64();
|
||||||
header.OSPlatform = headerReader.ReadUInt32();
|
header.OSPlatform = headerReader.ReadUInt32();
|
||||||
|
|
||||||
|
@ -384,8 +386,8 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string fileNameActual = String.Concat(CachePathActual, ".cache");
|
string fileNameActual = string.Concat(CachePathActual, ".cache");
|
||||||
string fileNameBackup = String.Concat(CachePathBackup, ".cache");
|
string fileNameBackup = string.Concat(CachePathBackup, ".cache");
|
||||||
|
|
||||||
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
||||||
|
|
||||||
|
@ -411,15 +413,16 @@ namespace ARMeilleure.Translation.PTC
|
||||||
{
|
{
|
||||||
int translatedFuncsCount;
|
int translatedFuncsCount;
|
||||||
|
|
||||||
using MD5 md5 = MD5.Create();
|
int hashSize = Unsafe.SizeOf<Hash128>();
|
||||||
|
|
||||||
int hashSize = md5.HashSize / 8;
|
|
||||||
|
|
||||||
int size = hashSize + Header.Size + GetMemoryStreamsLength() + PtcJumpTable.GetSerializeSize(PtcJumpTable);
|
int size = hashSize + Header.Size + GetMemoryStreamsLength() + PtcJumpTable.GetSerializeSize(PtcJumpTable);
|
||||||
|
|
||||||
byte[] sizeBytes = BitConverter.GetBytes(size);
|
Span<byte> sizeBytes = new byte[sizeof(int)];
|
||||||
Debug.Assert(sizeBytes.Length == sizeof(int));
|
BinaryPrimitives.WriteInt32LittleEndian(sizeBytes, size);
|
||||||
byte[] sizeHash = md5.ComputeHash(sizeBytes);
|
Hash128 sizeHash = XXHash128.ComputeHash(sizeBytes);
|
||||||
|
|
||||||
|
Span<byte> sizeHashBytes = new byte[hashSize];
|
||||||
|
MemoryMarshal.Write<Hash128>(sizeHashBytes, ref sizeHash);
|
||||||
|
|
||||||
IntPtr intPtr = IntPtr.Zero;
|
IntPtr intPtr = IntPtr.Zero;
|
||||||
|
|
||||||
|
@ -427,7 +430,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
{
|
{
|
||||||
intPtr = Marshal.AllocHGlobal(size);
|
intPtr = Marshal.AllocHGlobal(size);
|
||||||
|
|
||||||
using (UnmanagedMemoryStream stream = new UnmanagedMemoryStream((byte*)intPtr.ToPointer(), size, size, FileAccess.ReadWrite))
|
using (UnmanagedMemoryStream stream = new((byte*)intPtr.ToPointer(), size, size, FileAccess.ReadWrite))
|
||||||
{
|
{
|
||||||
stream.Seek((long)hashSize, SeekOrigin.Begin);
|
stream.Seek((long)hashSize, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
@ -441,24 +444,28 @@ namespace ARMeilleure.Translation.PTC
|
||||||
PtcJumpTable.Serialize(stream, PtcJumpTable);
|
PtcJumpTable.Serialize(stream, PtcJumpTable);
|
||||||
|
|
||||||
stream.Seek((long)hashSize, SeekOrigin.Begin);
|
stream.Seek((long)hashSize, SeekOrigin.Begin);
|
||||||
byte[] hash = md5.ComputeHash(stream);
|
ReadOnlySpan<byte> streamBytes = new(stream.PositionPointer, (int)(stream.Length - stream.Position));
|
||||||
|
Hash128 hash = XXHash128.ComputeHash(streamBytes);
|
||||||
|
|
||||||
|
Span<byte> hashBytes = new byte[hashSize];
|
||||||
|
MemoryMarshal.Write<Hash128>(hashBytes, ref hash);
|
||||||
|
|
||||||
stream.Seek(0L, SeekOrigin.Begin);
|
stream.Seek(0L, SeekOrigin.Begin);
|
||||||
stream.Write(hash, 0, hashSize);
|
stream.Write(hashBytes);
|
||||||
|
|
||||||
translatedFuncsCount = GetInfosEntriesCount();
|
translatedFuncsCount = GetInfosEntriesCount();
|
||||||
|
|
||||||
ResetMemoryStreamsIfNeeded();
|
ResetMemoryStreamsIfNeeded();
|
||||||
PtcJumpTable.ClearIfNeeded();
|
PtcJumpTable.ClearIfNeeded();
|
||||||
|
|
||||||
using (FileStream compressedStream = new FileStream(fileName, FileMode.OpenOrCreate))
|
using (FileStream compressedStream = new(fileName, FileMode.OpenOrCreate))
|
||||||
using (DeflateStream deflateStream = new DeflateStream(compressedStream, SaveCompressionLevel, true))
|
using (DeflateStream deflateStream = new(compressedStream, SaveCompressionLevel, true))
|
||||||
{
|
{
|
||||||
compressedStream.Write(sizeHash, 0, hashSize);
|
|
||||||
compressedStream.Write(sizeBytes, 0, sizeBytes.Length);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
compressedStream.Write(sizeHashBytes);
|
||||||
|
compressedStream.Write(sizeBytes);
|
||||||
|
|
||||||
stream.Seek(0L, SeekOrigin.Begin);
|
stream.Seek(0L, SeekOrigin.Begin);
|
||||||
stream.CopyTo(deflateStream);
|
stream.CopyTo(deflateStream);
|
||||||
}
|
}
|
||||||
|
@ -497,11 +504,12 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
private static void WriteHeader(Stream stream)
|
private static void WriteHeader(Stream stream)
|
||||||
{
|
{
|
||||||
using (BinaryWriter headerWriter = new BinaryWriter(stream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryWriter headerWriter = new(stream, EncodingCache.UTF8NoBOM, true))
|
||||||
{
|
{
|
||||||
headerWriter.Write((ulong)_headerMagic); // Header.Magic
|
headerWriter.Write((ulong)_headerMagic); // Header.Magic
|
||||||
|
|
||||||
headerWriter.Write((uint)InternalVersion); // Header.CacheFileVersion
|
headerWriter.Write((uint)InternalVersion); // Header.CacheFileVersion
|
||||||
|
headerWriter.Write((bool)GetEndianness()); // Header.Endianness
|
||||||
headerWriter.Write((ulong)GetFeatureInfo()); // Header.FeatureInfo
|
headerWriter.Write((ulong)GetFeatureInfo()); // Header.FeatureInfo
|
||||||
headerWriter.Write((uint)GetOSPlatform()); // Header.OSPlatform
|
headerWriter.Write((uint)GetOSPlatform()); // Header.OSPlatform
|
||||||
|
|
||||||
|
@ -514,10 +522,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
internal static void LoadTranslations(ConcurrentDictionary<ulong, TranslatedFunction> funcs, IMemoryManager memory, JumpTable jumpTable)
|
internal static void LoadTranslations(ConcurrentDictionary<ulong, TranslatedFunction> funcs, IMemoryManager memory, JumpTable jumpTable)
|
||||||
{
|
{
|
||||||
if (_infosStream.Length == 0L &&
|
if (AreMemoryStreamsEmpty())
|
||||||
_codesStream.Length == 0L &&
|
|
||||||
_relocsStream.Length == 0L &&
|
|
||||||
_unwindInfosStream.Length == 0L)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -529,10 +534,10 @@ namespace ARMeilleure.Translation.PTC
|
||||||
_relocsStream.Seek(0L, SeekOrigin.Begin);
|
_relocsStream.Seek(0L, SeekOrigin.Begin);
|
||||||
_unwindInfosStream.Seek(0L, SeekOrigin.Begin);
|
_unwindInfosStream.Seek(0L, SeekOrigin.Begin);
|
||||||
|
|
||||||
using (BinaryReader infosReader = new BinaryReader(_infosStream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryReader infosReader = new(_infosStream, EncodingCache.UTF8NoBOM, true))
|
||||||
using (BinaryReader codesReader = new BinaryReader(_codesStream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryReader codesReader = new(_codesStream, EncodingCache.UTF8NoBOM, true))
|
||||||
using (BinaryReader relocsReader = new BinaryReader(_relocsStream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryReader relocsReader = new(_relocsStream, EncodingCache.UTF8NoBOM, true))
|
||||||
using (BinaryReader unwindInfosReader = new BinaryReader(_unwindInfosStream, EncodingCache.UTF8NoBOM, true))
|
using (BinaryReader unwindInfosReader = new(_unwindInfosStream, EncodingCache.UTF8NoBOM, true))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < GetInfosEntriesCount(); i++)
|
for (int i = 0; i < GetInfosEntriesCount(); i++)
|
||||||
{
|
{
|
||||||
|
@ -870,6 +875,11 @@ namespace ARMeilleure.Translation.PTC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool GetEndianness()
|
||||||
|
{
|
||||||
|
return BitConverter.IsLittleEndian;
|
||||||
|
}
|
||||||
|
|
||||||
private static ulong GetFeatureInfo()
|
private static ulong GetFeatureInfo()
|
||||||
{
|
{
|
||||||
return (ulong)HardwareCapabilities.FeatureInfoEdx << 32 | (uint)HardwareCapabilities.FeatureInfoEcx;
|
return (ulong)HardwareCapabilities.FeatureInfoEdx << 32 | (uint)HardwareCapabilities.FeatureInfoEcx;
|
||||||
|
@ -889,11 +899,12 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
private struct Header
|
private struct Header
|
||||||
{
|
{
|
||||||
public const int Size = 40; // Bytes.
|
public const int Size = 41; // Bytes.
|
||||||
|
|
||||||
public ulong Magic;
|
public ulong Magic;
|
||||||
|
|
||||||
public uint CacheFileVersion;
|
public uint CacheFileVersion;
|
||||||
|
public bool Endianness;
|
||||||
public ulong FeatureInfo;
|
public ulong FeatureInfo;
|
||||||
public uint OSPlatform;
|
public uint OSPlatform;
|
||||||
|
|
||||||
|
@ -958,12 +969,7 @@ namespace ARMeilleure.Translation.PTC
|
||||||
|
|
||||||
_loggerEvent.Dispose();
|
_loggerEvent.Dispose();
|
||||||
|
|
||||||
_infosWriter.Dispose();
|
DisposeMemoryStreams();
|
||||||
|
|
||||||
_infosStream.Dispose();
|
|
||||||
_codesStream.Dispose();
|
|
||||||
_relocsStream.Dispose();
|
|
||||||
_unwindInfosStream.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,8 +114,8 @@ namespace ARMeilleure.Translation.PTC
|
||||||
{
|
{
|
||||||
_lastHash = Array.Empty<byte>();
|
_lastHash = Array.Empty<byte>();
|
||||||
|
|
||||||
string fileNameActual = String.Concat(Ptc.CachePathActual, ".info");
|
string fileNameActual = string.Concat(Ptc.CachePathActual, ".info");
|
||||||
string fileNameBackup = String.Concat(Ptc.CachePathBackup, ".info");
|
string fileNameBackup = string.Concat(Ptc.CachePathBackup, ".info");
|
||||||
|
|
||||||
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
||||||
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
|
FileInfo fileInfoBackup = new FileInfo(fileNameBackup);
|
||||||
|
@ -261,8 +261,8 @@ namespace ARMeilleure.Translation.PTC
|
||||||
{
|
{
|
||||||
_waitEvent.Reset();
|
_waitEvent.Reset();
|
||||||
|
|
||||||
string fileNameActual = String.Concat(Ptc.CachePathActual, ".info");
|
string fileNameActual = string.Concat(Ptc.CachePathActual, ".info");
|
||||||
string fileNameBackup = String.Concat(Ptc.CachePathBackup, ".info");
|
string fileNameBackup = string.Concat(Ptc.CachePathBackup, ".info");
|
||||||
|
|
||||||
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
FileInfo fileInfoActual = new FileInfo(fileNameActual);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue