diff options
author | gdkchan <gab.dark.100@gmail.com> | 2023-01-23 19:37:53 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-23 22:37:53 +0000 |
commit | a1a4771ac1de95f2410c7fb8dfaf4a5986e5ebc6 (patch) | |
tree | b79abb40024184b18b2ff821490de4ad5e7b9683 | |
parent | 2fd819613ffcede43562b333602d17fa79c9751d (diff) |
Remove use of GetFunctionPointerForDelegate to get JIT cache function pointer (#4337)1.1.594
* Remove use of GetFunctionPointerForDelegate to get JIT cache function pointer
* Rename FuncPtr to FuncPointer
-rw-r--r-- | ARMeilleure/CodeGen/CompiledFunction.cs | 16 | ||||
-rw-r--r-- | ARMeilleure/Instructions/NativeInterface.cs | 2 | ||||
-rw-r--r-- | ARMeilleure/Translation/PTC/Ptc.cs | 4 | ||||
-rw-r--r-- | ARMeilleure/Translation/TranslatedFunction.cs | 7 | ||||
-rw-r--r-- | ARMeilleure/Translation/Translator.cs | 12 |
5 files changed, 26 insertions, 15 deletions
diff --git a/ARMeilleure/CodeGen/CompiledFunction.cs b/ARMeilleure/CodeGen/CompiledFunction.cs index ab5e88ebb..0560bf2e9 100644 --- a/ARMeilleure/CodeGen/CompiledFunction.cs +++ b/ARMeilleure/CodeGen/CompiledFunction.cs | |||
@@ -48,9 +48,21 @@ namespace ARMeilleure.CodeGen | |||
48 | /// <returns>A delegate of type <typeparamref name="T"/> pointing to the mapped function</returns> | 48 | /// <returns>A delegate of type <typeparamref name="T"/> pointing to the mapped function</returns> |
49 | public T Map<T>() | 49 | public T Map<T>() |
50 | { | 50 | { |
51 | IntPtr codePtr = JitCache.Map(this); | 51 | return MapWithPointer<T>(out _); |
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Maps the <see cref="CompiledFunction"/> onto the <see cref="JitCache"/> and returns a delegate of type | ||
56 | /// <typeparamref name="T"/> pointing to the mapped function. | ||
57 | /// </summary> | ||
58 | /// <typeparam name="T">Type of delegate</typeparam> | ||
59 | /// <param name="codePointer">Pointer to the function code in memory</param> | ||
60 | /// <returns>A delegate of type <typeparamref name="T"/> pointing to the mapped function</returns> | ||
61 | public T MapWithPointer<T>(out IntPtr codePointer) | ||
62 | { | ||
63 | codePointer = JitCache.Map(this); | ||
52 | 64 | ||
53 | return Marshal.GetDelegateForFunctionPointer<T>(codePtr); | 65 | return Marshal.GetDelegateForFunctionPointer<T>(codePointer); |
54 | } | 66 | } |
55 | } | 67 | } |
56 | } \ No newline at end of file | 68 | } \ No newline at end of file |
diff --git a/ARMeilleure/Instructions/NativeInterface.cs b/ARMeilleure/Instructions/NativeInterface.cs index 2ac748a9a..57964cc8d 100644 --- a/ARMeilleure/Instructions/NativeInterface.cs +++ b/ARMeilleure/Instructions/NativeInterface.cs | |||
@@ -191,7 +191,7 @@ namespace ARMeilleure.Instructions | |||
191 | { | 191 | { |
192 | TranslatedFunction function = Context.Translator.GetOrTranslate(address, GetContext().ExecutionMode); | 192 | TranslatedFunction function = Context.Translator.GetOrTranslate(address, GetContext().ExecutionMode); |
193 | 193 | ||
194 | return (ulong)function.FuncPtr.ToInt64(); | 194 | return (ulong)function.FuncPointer.ToInt64(); |
195 | } | 195 | } |
196 | 196 | ||
197 | public static void InvalidateCacheLine(ulong address) | 197 | public static void InvalidateCacheLine(ulong address) |
diff --git a/ARMeilleure/Translation/PTC/Ptc.cs b/ARMeilleure/Translation/PTC/Ptc.cs index aeb5868c9..de2294b24 100644 --- a/ARMeilleure/Translation/PTC/Ptc.cs +++ b/ARMeilleure/Translation/PTC/Ptc.cs | |||
@@ -745,9 +745,9 @@ namespace ARMeilleure.Translation.PTC | |||
745 | bool highCq) | 745 | bool highCq) |
746 | { | 746 | { |
747 | var cFunc = new CompiledFunction(code, unwindInfo, RelocInfo.Empty); | 747 | var cFunc = new CompiledFunction(code, unwindInfo, RelocInfo.Empty); |
748 | var gFunc = cFunc.Map<GuestFunction>(); | 748 | var gFunc = cFunc.MapWithPointer<GuestFunction>(out IntPtr gFuncPointer); |
749 | 749 | ||
750 | return new TranslatedFunction(gFunc, callCounter, guestSize, highCq); | 750 | return new TranslatedFunction(gFunc, gFuncPointer, callCounter, guestSize, highCq); |
751 | } | 751 | } |
752 | 752 | ||
753 | private void UpdateInfo(InfoEntry infoEntry) | 753 | private void UpdateInfo(InfoEntry infoEntry) |
diff --git a/ARMeilleure/Translation/TranslatedFunction.cs b/ARMeilleure/Translation/TranslatedFunction.cs index 04dd769c1..71eec08ac 100644 --- a/ARMeilleure/Translation/TranslatedFunction.cs +++ b/ARMeilleure/Translation/TranslatedFunction.cs | |||
@@ -1,6 +1,5 @@ | |||
1 | using ARMeilleure.Common; | 1 | using ARMeilleure.Common; |
2 | using System; | 2 | using System; |
3 | using System.Runtime.InteropServices; | ||
4 | 3 | ||
5 | namespace ARMeilleure.Translation | 4 | namespace ARMeilleure.Translation |
6 | { | 5 | { |
@@ -8,18 +7,18 @@ namespace ARMeilleure.Translation | |||
8 | { | 7 | { |
9 | private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected. | 8 | private readonly GuestFunction _func; // Ensure that this delegate will not be garbage collected. |
10 | 9 | ||
10 | public IntPtr FuncPointer { get; } | ||
11 | public Counter<uint> CallCounter { get; } | 11 | public Counter<uint> CallCounter { get; } |
12 | public ulong GuestSize { get; } | 12 | public ulong GuestSize { get; } |
13 | public bool HighCq { get; } | 13 | public bool HighCq { get; } |
14 | public IntPtr FuncPtr { get; } | ||
15 | 14 | ||
16 | public TranslatedFunction(GuestFunction func, Counter<uint> callCounter, ulong guestSize, bool highCq) | 15 | public TranslatedFunction(GuestFunction func, IntPtr funcPointer, Counter<uint> callCounter, ulong guestSize, bool highCq) |
17 | { | 16 | { |
18 | _func = func; | 17 | _func = func; |
18 | FuncPointer = funcPointer; | ||
19 | CallCounter = callCounter; | 19 | CallCounter = callCounter; |
20 | GuestSize = guestSize; | 20 | GuestSize = guestSize; |
21 | HighCq = highCq; | 21 | HighCq = highCq; |
22 | FuncPtr = Marshal.GetFunctionPointerForDelegate(func); | ||
23 | } | 22 | } |
24 | 23 | ||
25 | public ulong Execute(State.ExecutionContext context) | 24 | public ulong Execute(State.ExecutionContext context) |
diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index cbf6baa00..0c05b2b49 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs | |||
@@ -211,7 +211,7 @@ namespace ARMeilleure.Translation | |||
211 | 211 | ||
212 | if (oldFunc != func) | 212 | if (oldFunc != func) |
213 | { | 213 | { |
214 | JitCache.Unmap(func.FuncPtr); | 214 | JitCache.Unmap(func.FuncPointer); |
215 | func = oldFunc; | 215 | func = oldFunc; |
216 | } | 216 | } |
217 | 217 | ||
@@ -230,7 +230,7 @@ namespace ARMeilleure.Translation | |||
230 | { | 230 | { |
231 | if (FunctionTable.IsValid(guestAddress) && (Optimizations.AllowLcqInFunctionTable || func.HighCq)) | 231 | if (FunctionTable.IsValid(guestAddress) && (Optimizations.AllowLcqInFunctionTable || func.HighCq)) |
232 | { | 232 | { |
233 | Volatile.Write(ref FunctionTable.GetValue(guestAddress), (ulong)func.FuncPtr); | 233 | Volatile.Write(ref FunctionTable.GetValue(guestAddress), (ulong)func.FuncPointer); |
234 | } | 234 | } |
235 | } | 235 | } |
236 | 236 | ||
@@ -292,11 +292,11 @@ namespace ARMeilleure.Translation | |||
292 | _ptc.WriteCompiledFunction(address, funcSize, hash, highCq, compiledFunc); | 292 | _ptc.WriteCompiledFunction(address, funcSize, hash, highCq, compiledFunc); |
293 | } | 293 | } |
294 | 294 | ||
295 | GuestFunction func = compiledFunc.Map<GuestFunction>(); | 295 | GuestFunction func = compiledFunc.MapWithPointer<GuestFunction>(out IntPtr funcPointer); |
296 | 296 | ||
297 | Allocators.ResetAll(); | 297 | Allocators.ResetAll(); |
298 | 298 | ||
299 | return new TranslatedFunction(func, counter, funcSize, highCq); | 299 | return new TranslatedFunction(func, funcPointer, counter, funcSize, highCq); |
300 | } | 300 | } |
301 | 301 | ||
302 | private void BackgroundTranslate() | 302 | private void BackgroundTranslate() |
@@ -537,7 +537,7 @@ namespace ARMeilleure.Translation | |||
537 | 537 | ||
538 | foreach (var func in functions) | 538 | foreach (var func in functions) |
539 | { | 539 | { |
540 | JitCache.Unmap(func.FuncPtr); | 540 | JitCache.Unmap(func.FuncPointer); |
541 | 541 | ||
542 | func.CallCounter?.Dispose(); | 542 | func.CallCounter?.Dispose(); |
543 | } | 543 | } |
@@ -546,7 +546,7 @@ namespace ARMeilleure.Translation | |||
546 | 546 | ||
547 | while (_oldFuncs.TryDequeue(out var kv)) | 547 | while (_oldFuncs.TryDequeue(out var kv)) |
548 | { | 548 | { |
549 | JitCache.Unmap(kv.Value.FuncPtr); | 549 | JitCache.Unmap(kv.Value.FuncPointer); |
550 | 550 | ||
551 | kv.Value.CallCounter?.Dispose(); | 551 | kv.Value.CallCounter?.Dispose(); |
552 | } | 552 | } |