From 878f919f63c335e62866ad05c660adc721943292 Mon Sep 17 00:00:00 2001
From: degasus <wickmarkus@web.de>
Date: Fri, 14 Aug 2015 15:38:50 +0200
Subject: [PATCH] JitArm64: Fastmem: fixup map & lookup

---
 Source/Core/Common/BitSet.h                     |  2 ++
 Source/Core/Core/PowerPC/JitArm64/Jit.h         | 17 ++++++++++++-----
 .../PowerPC/JitArm64/JitArm64_BackPatch.cpp     |  3 +++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/Source/Core/Common/BitSet.h b/Source/Core/Common/BitSet.h
index 70b9204fa5..caa59c150f 100644
--- a/Source/Core/Common/BitSet.h
+++ b/Source/Core/Common/BitSet.h
@@ -155,6 +155,8 @@ public:
 	const Ref operator[](size_t bit) const { return (*const_cast<BitSet*>(this))[bit]; }
 	bool operator==(BitSet other) const { return m_val == other.m_val; }
 	bool operator!=(BitSet other) const { return m_val != other.m_val; }
+	bool operator<(BitSet other) const { return m_val < other.m_val; }
+	bool operator>(BitSet other) const { return m_val > other.m_val; }
 	BitSet operator|(BitSet other) const { return BitSet(m_val | other.m_val); }
 	BitSet operator&(BitSet other) const { return BitSet(m_val & other.m_val); }
 	BitSet operator^(BitSet other) const { return BitSet(m_val ^ other.m_val); }
diff --git a/Source/Core/Core/PowerPC/JitArm64/Jit.h b/Source/Core/Core/PowerPC/JitArm64/Jit.h
index de784b8f61..6271589ed2 100644
--- a/Source/Core/Core/PowerPC/JitArm64/Jit.h
+++ b/Source/Core/Core/PowerPC/JitArm64/Jit.h
@@ -185,11 +185,18 @@ private:
 		u32 flags;
 		bool operator< (const SlowmemHandler& rhs) const
 		{
-			return !(dest_reg == rhs.dest_reg &&
-			       addr_reg == rhs.addr_reg &&
-				 gprs == rhs.gprs &&
-				 fprs == rhs.fprs &&
-				 flags == rhs.flags);
+			if (dest_reg < rhs.dest_reg) return true;
+			if (dest_reg > rhs.dest_reg) return false;
+			if (addr_reg < rhs.addr_reg) return true;
+			if (addr_reg > rhs.addr_reg) return false;
+			if (gprs < rhs.gprs) return true;
+			if (gprs > rhs.gprs) return false;
+			if (fprs < rhs.fprs) return true;
+			if (fprs > rhs.fprs) return false;
+			if (flags < rhs.flags) return true;
+			if (flags > rhs.flags) return false;
+
+			return false;
 		}
 	};
 
diff --git a/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp b/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp
index 303f180e7f..e0b8ada73f 100644
--- a/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp
+++ b/Source/Core/Core/PowerPC/JitArm64/JitArm64_BackPatch.cpp
@@ -374,6 +374,9 @@ bool JitArm64::HandleFault(uintptr_t access_address, SContext* ctx)
 
 	std::map<const u8*, std::pair<SlowmemHandler, const u8*>>::iterator slow_handler_iter = m_fault_to_handler.find((const u8*)ctx->CTX_PC);
 
+	if (slow_handler_iter == m_fault_to_handler.end())
+		return false;
+
 	BackPatchInfo& info = m_backpatch_info[flags];
 	ARM64XEmitter emitter((u8*)(ctx->CTX_PC - info.m_fastmem_trouble_inst_offset * 4));
 	u64 new_pc = (u64)emitter.GetCodePtr();