aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Tests.Unicorn/Native/Interface.cs
diff options
context:
space:
mode:
authorMerry <MerryMage@users.noreply.github.com>2018-09-01 15:24:05 +0100
committergdkchan <gab.dark.100@gmail.com>2018-09-01 11:24:05 -0300
commit326777ca4a68b38c7a5e44c76291f09f07ddcf2e (patch)
tree4049b9229ed326c9bb809a93778e6377d51ce209 /Ryujinx.Tests.Unicorn/Native/Interface.cs
parent42dc925c3da59bf8801b14779482ee5bd9c25dc0 (diff)
Ryujinx.Tests: Add unicorn to test framework (#389)
* Ryujinx.Tests: Add unicorn to test framework * CpuTestSimdArithmetic: Comment out inaccurate results
Diffstat (limited to 'Ryujinx.Tests.Unicorn/Native/Interface.cs')
-rw-r--r--Ryujinx.Tests.Unicorn/Native/Interface.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/Ryujinx.Tests.Unicorn/Native/Interface.cs b/Ryujinx.Tests.Unicorn/Native/Interface.cs
new file mode 100644
index 00000000..a6563220
--- /dev/null
+++ b/Ryujinx.Tests.Unicorn/Native/Interface.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Runtime.InteropServices;
+using Ryujinx.Tests.Unicorn;
+
+namespace Ryujinx.Tests.Unicorn.Native
+{
+ public class Interface
+ {
+ public static void Checked(UnicornError error)
+ {
+ if (error != UnicornError.UC_ERR_OK)
+ {
+ throw new UnicornException(error);
+ }
+ }
+
+ public static void MarshalArrayOf<T>(IntPtr input, int length, out T[] output)
+ {
+ var size = Marshal.SizeOf(typeof(T));
+ output = new T[length];
+
+ for (int i = 0; i < length; i++)
+ {
+ IntPtr item = new IntPtr(input.ToInt64() + i * size);
+ output[i] = Marshal.PtrToStructure<T>(item);
+ }
+ }
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern uint uc_version(out uint major, out uint minor);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError uc_open(uint arch, uint mode, out IntPtr uc);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError uc_close(IntPtr uc);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern IntPtr uc_strerror(UnicornError err);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError 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);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError 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);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError 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);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError 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);
+
+ [DllImport("unicorn", CallingConvention = CallingConvention.Cdecl)]
+ public static extern UnicornError uc_mem_regions(IntPtr uc, out IntPtr regions, out uint count);
+ }
+}