From 19a0abc19b8fca323d76946debb42f9d7f965a7d Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Tue, 12 Nov 2019 03:13:47 -0500
Subject: [PATCH] arm_unicorn: Resolve sign conversion warnings

While we're at it, this also resolves a type truncation warning as well,
given the code was truncating from a 64-bit value to a 32-bit one.
---
 src/core/arm/dynarmic/arm_dynarmic.cpp |  2 +-
 src/core/arm/unicorn/arm_unicorn.cpp   | 14 ++++++++------
 src/core/arm/unicorn/arm_unicorn.h     |  2 +-
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp
index 700c4afff9..a0705b2b89 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp
@@ -67,7 +67,7 @@ public:
         ARM_Interface::ThreadContext ctx;
         parent.SaveContext(ctx);
         parent.inner_unicorn.LoadContext(ctx);
-        parent.inner_unicorn.ExecuteInstructions(static_cast<int>(num_instructions));
+        parent.inner_unicorn.ExecuteInstructions(num_instructions);
         parent.inner_unicorn.SaveContext(ctx);
         parent.LoadContext(ctx);
         num_interpreted_instructions += num_instructions;
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp
index d4f41bfc18..9698172dbf 100644
--- a/src/core/arm/unicorn/arm_unicorn.cpp
+++ b/src/core/arm/unicorn/arm_unicorn.cpp
@@ -67,10 +67,11 @@ ARM_Unicorn::ARM_Unicorn(System& system) : system{system} {
     CHECKED(uc_reg_write(uc, UC_ARM64_REG_CPACR_EL1, &fpv));
 
     uc_hook hook{};
-    CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, -1));
-    CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, &system, 0, -1));
+    CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, UINT64_MAX));
+    CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, &system, 0,
+                        UINT64_MAX));
     if (GDBStub::IsServerEnabled()) {
-        CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, -1));
+        CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, UINT64_MAX));
         last_bkpt_hit = false;
     }
 }
@@ -154,9 +155,10 @@ void ARM_Unicorn::SetTPIDR_EL0(u64 value) {
 
 void ARM_Unicorn::Run() {
     if (GDBStub::IsServerEnabled()) {
-        ExecuteInstructions(std::max(4000000, 0));
+        ExecuteInstructions(std::max(4000000U, 0U));
     } else {
-        ExecuteInstructions(std::max(system.CoreTiming().GetDowncount(), s64{0}));
+        ExecuteInstructions(
+            std::max(std::size_t(system.CoreTiming().GetDowncount()), std::size_t{0}));
     }
 }
 
@@ -166,7 +168,7 @@ void ARM_Unicorn::Step() {
 
 MICROPROFILE_DEFINE(ARM_Jit_Unicorn, "ARM JIT", "Unicorn", MP_RGB(255, 64, 64));
 
-void ARM_Unicorn::ExecuteInstructions(int num_instructions) {
+void ARM_Unicorn::ExecuteInstructions(std::size_t num_instructions) {
     MICROPROFILE_SCOPE(ARM_Jit_Unicorn);
     CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions));
     system.CoreTiming().AddTicks(num_instructions);
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h
index fe2ffd70ca..b39426ea0b 100644
--- a/src/core/arm/unicorn/arm_unicorn.h
+++ b/src/core/arm/unicorn/arm_unicorn.h
@@ -34,7 +34,7 @@ public:
     void LoadContext(const ThreadContext& ctx) override;
     void PrepareReschedule() override;
     void ClearExclusiveState() override;
-    void ExecuteInstructions(int num_instructions);
+    void ExecuteInstructions(std::size_t num_instructions);
     void Run() override;
     void Step() override;
     void ClearInstructionCache() override;