diff options
| author | TSRBerry <20988865+TSRBerry@users.noreply.github.com> | 2022-11-20 20:18:21 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-20 20:18:21 +0100 |
| commit | 905a191e28fd9262d0fde97f3c2d100f74693c8d (patch) | |
| tree | e430239067d37d25aaf8d6f476b3b5d5aaab0858 /Ryujinx.Tests.Unicorn/Native/Interface.cs | |
| parent | ab0491817e87b9dd134c41764ba213f8c8559e9b (diff) | |
Use upstream unicorn for Ryujinx.Tests.Unicorn (#3771)
* unicorn: Add modified ver of unicorns const gen
* unicorn: Use upstream consts
These consts were generated from the dev branch of unicorn
* unicorn: Split common consts into multiple enums
* unicorn: Remove arch prefix from consts
* unicorn: Add new windows dll
Windows 10 - MSVC x64 shared build
* unicorn: Use absolute path for const generation
* unicorn: Remove fspcr patch
* unicorn: Fix using the wrong file extension
For some reason _NativeLibraryExtension evaluates to ".so" even on Windows.
* unicorn: Add linux shared object again
* unicron: Add DllImportResolver
* unicorn: Try to import unicorn using an absolute path
* unicorn: Add clean target
* unicorn: Replace IsUnicornAvailable() methods
* unicorn: Skip tests instead of silently passing them if unicorn is missing
* unicorn: Write error message to stderr
* unicorn: Make Interface static
* unicron: Include prefixed unicorn libs (libunicorn.so)
Co-authored-by: merry <git@mary.rs>
* unicorn: Add lib prefix to shared object for linux
Co-authored-by: merry <git@mary.rs>
Diffstat (limited to 'Ryujinx.Tests.Unicorn/Native/Interface.cs')
| -rw-r--r-- | Ryujinx.Tests.Unicorn/Native/Interface.cs | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/Ryujinx.Tests.Unicorn/Native/Interface.cs b/Ryujinx.Tests.Unicorn/Native/Interface.cs index 59b1da07..0ecda22e 100644 --- a/Ryujinx.Tests.Unicorn/Native/Interface.cs +++ b/Ryujinx.Tests.Unicorn/Native/Interface.cs @@ -1,13 +1,43 @@ +using Ryujinx.Tests.Unicorn.Native.Const; using System; +using System.IO; +using System.Reflection; using System.Runtime.InteropServices; namespace Ryujinx.Tests.Unicorn.Native { - public class Interface + public static class Interface { - public static void Checked(UnicornError error) + public static bool IsUnicornAvailable { get; private set; } = true; + + private static IntPtr ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) + { + if (libraryName == "unicorn") + { + string loadPath = $"{Path.GetDirectoryName(assembly.Location)}/"; + loadPath += OperatingSystem.IsWindows() ? $"{libraryName}.dll" : $"lib{libraryName}.so"; + + if (!NativeLibrary.TryLoad(loadPath, out IntPtr libraryPtr)) + { + IsUnicornAvailable = false; + Console.Error.WriteLine($"ERROR: Could not find unicorn at: {loadPath}"); + } + + return libraryPtr; + } + + // Otherwise, fallback to default import resolver. + return IntPtr.Zero; + } + + static Interface() + { + NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), ImportResolver); + } + + public static void Checked(Error error) { - if (error != UnicornError.UC_ERR_OK) + if (error != Error.OK) { throw new UnicornException(error); } @@ -31,39 +61,39 @@ namespace Ryujinx.Tests.Unicorn.Native public static extern uint uc_version(out uint major, out uint minor); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_open(UnicornArch arch, UnicornMode mode, out IntPtr uc); + public static extern Error uc_open(Arch arch, Mode mode, out IntPtr uc); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_close(IntPtr uc); + public static extern Error uc_close(IntPtr uc); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr uc_strerror(UnicornError err); + public static extern IntPtr uc_strerror(Error err); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_reg_write(IntPtr uc, int regid, byte[] value); + public static extern Error uc_reg_write(IntPtr uc, int regid, byte[] value); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_reg_read(IntPtr uc, int regid, byte[] value); + public static extern Error uc_reg_read(IntPtr uc, int regid, byte[] value); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size); + public static extern Error uc_mem_write(IntPtr uc, ulong address, byte[] bytes, ulong size); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size); + public static extern Error uc_mem_read(IntPtr uc, ulong address, byte[] bytes, ulong size); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count); + public static extern Error uc_emu_start(IntPtr uc, ulong begin, ulong until, ulong timeout, ulong count); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms); + public static extern Error uc_mem_map(IntPtr uc, ulong address, ulong size, uint perms); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_unmap(IntPtr uc, ulong address, ulong size); + public static extern Error uc_mem_unmap(IntPtr uc, ulong address, ulong size); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms); + public static extern Error uc_mem_protect(IntPtr uc, ulong address, ulong size, uint perms); [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)] - public static extern UnicornError uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count); + public static extern Error uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count); } -} +}
\ No newline at end of file |
