Verify that the elf matches the expected arch.

To avoid a case where a malicious app might try and trick the system to
create an elf and register object that mismatches, always verify that they
are the same arch.

Test: Ran unit tests.
Change-Id: I66978e9e02f8e4f396856912e7019528ead4838e
diff --git a/libunwindstack/Global.cpp b/libunwindstack/Global.cpp
index f0ad2b6..7a3de01 100644
--- a/libunwindstack/Global.cpp
+++ b/libunwindstack/Global.cpp
@@ -31,6 +31,13 @@
 Global::Global(std::shared_ptr<Memory>& memory, std::vector<std::string>& search_libs)
     : memory_(memory), search_libs_(search_libs) {}
 
+void Global::SetArch(ArchEnum arch) {
+  if (arch_ == ARCH_UNKNOWN) {
+    arch_ = arch;
+    ProcessArch();
+  }
+}
+
 uint64_t Global::GetVariableOffset(MapInfo* info, const std::string& variable) {
   if (!search_libs_.empty()) {
     bool found = false;
@@ -46,7 +53,7 @@
     }
   }
 
-  Elf* elf = info->GetElf(memory_);
+  Elf* elf = info->GetElf(memory_, arch());
   uint64_t ptr;
   // Find first non-empty list (libraries might be loaded multiple times).
   if (elf->GetGlobalVariable(variable, &ptr) && ptr != 0) {