Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Armeilleure: Fix support for Windows on ARM64 #5202

Merged
merged 2 commits into from Jun 3, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/ARMeilleure/Translation/Cache/JitCache.cs
Expand Up @@ -6,10 +6,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

namespace ARMeilleure.Translation.Cache
{
static class JitCache
static partial class JitCache
{
private const int PageSize = 4 * 1024;
private const int PageMask = PageSize - 1;
Expand All @@ -27,6 +28,10 @@ static class JitCache
private static readonly object _lock = new object();
private static bool _initialized;

[SupportedOSPlatform("windows")]
[LibraryImport("kernel32.dll", SetLastError = true)]
public static partial IntPtr FlushInstructionCache(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize);

public static void Initialize(IJitMemoryAllocator allocator)
{
if (_initialized) return;
Expand Down Expand Up @@ -77,7 +82,14 @@ public static IntPtr Map(CompiledFunction func)
Marshal.Copy(code, 0, funcPtr, code.Length);
ReprotectAsExecutable(funcOffset, code.Length);

_jitCacheInvalidator.Invalidate(funcPtr, (ulong)code.Length);
if (OperatingSystem.IsWindows() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
FlushInstructionCache(Process.GetCurrentProcess().Handle, funcPtr, (UIntPtr)code.Length);
}
else
{
_jitCacheInvalidator.Invalidate(funcPtr, (ulong)code.Length);
marysaka marked this conversation as resolved.
Show resolved Hide resolved
}
}

Add(funcOffset, code.Length, func.UnwindInfo);
Expand Down