diff options
author | gdkchan <gab.dark.100@gmail.com> | 2023-01-10 19:16:59 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-10 19:16:59 -0300 |
commit | 5e0f8e873857ce3ca3f532aff0936beb28e412c8 (patch) | |
tree | 576e5110c076b7d1f4d94e608ee21493f5b48879 /ARMeilleure/Translation/Cache/JitCache.cs | |
parent | d16288a2a87f0979df30ba69d4fe10660177b6ac (diff) |
Implement JIT Arm64 backend (#4114)1.1.536
* Implement JIT Arm64 backend
* PPTC version bump
* Address some feedback from Arm64 JIT PR
* Address even more PR feedback
* Remove unused IsPageAligned function
* Sync Qc flag before calls
* Fix comment and remove unused enum
* Address riperiperi PR feedback
* Delete Breakpoint IR instruction that was only implemented for Arm64
Diffstat (limited to 'ARMeilleure/Translation/Cache/JitCache.cs')
-rw-r--r-- | ARMeilleure/Translation/Cache/JitCache.cs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/ARMeilleure/Translation/Cache/JitCache.cs b/ARMeilleure/Translation/Cache/JitCache.cs index 24affa34..f496a8e9 100644 --- a/ARMeilleure/Translation/Cache/JitCache.cs +++ b/ARMeilleure/Translation/Cache/JitCache.cs @@ -1,6 +1,7 @@ using ARMeilleure.CodeGen; using ARMeilleure.CodeGen.Unwinding; using ARMeilleure.Memory; +using ARMeilleure.Native; using System; using System.Collections.Generic; using System.Diagnostics; @@ -17,6 +18,7 @@ namespace ARMeilleure.Translation.Cache private const int CacheSize = 2047 * 1024 * 1024; private static ReservedRegion _jitRegion; + private static JitCacheInvalidation _jitCacheInvalidator; private static CacheMemoryAllocator _cacheAllocator; @@ -25,8 +27,6 @@ namespace ARMeilleure.Translation.Cache private static readonly object _lock = new object(); private static bool _initialized; - public static IntPtr Base => _jitRegion.Pointer; - public static void Initialize(IJitMemoryAllocator allocator) { if (_initialized) return; @@ -36,6 +36,7 @@ namespace ARMeilleure.Translation.Cache if (_initialized) return; _jitRegion = new ReservedRegion(allocator, CacheSize); + _jitCacheInvalidator = new JitCacheInvalidation(allocator); _cacheAllocator = new CacheMemoryAllocator(CacheSize); @@ -60,11 +61,24 @@ namespace ARMeilleure.Translation.Cache IntPtr funcPtr = _jitRegion.Pointer + funcOffset; - ReprotectAsWritable(funcOffset, code.Length); - - Marshal.Copy(code, 0, funcPtr, code.Length); + if (OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + unsafe + { + fixed (byte *codePtr = code) + { + JitSupportDarwin.Copy(funcPtr, (IntPtr)codePtr, (ulong)code.Length); + } + } + } + else + { + ReprotectAsWritable(funcOffset, code.Length); + Marshal.Copy(code, 0, funcPtr, code.Length); + ReprotectAsExecutable(funcOffset, code.Length); - ReprotectAsExecutable(funcOffset, code.Length); + _jitCacheInvalidator.Invalidate(funcPtr, (ulong)code.Length); + } Add(funcOffset, code.Length, func.UnwindInfo); |