Added DexFileAsanRegistrar and necessary additions

This class was made so that sections of dex files
can be easily poisoned to check accesses to those sections.

In order to enable logging of reads to poisoned sections,
use art/tools/add_package_property.sh along with package
name on the device and art/tools/asan.sh.

Bug: 37754950
Test: export ART_DEX_FILE_ACCESS_TRACKING=true ; mm -j && mm -j
SANITIZE_TARGET=address SANITIZE_LITE=true test-art-host;

(cherry picked from commit ecfa103caf2ccead029bd0e1bfcee02601a0c212)

Change-Id: Ie57aa935b7f5f6854ba53d7740cc0d1547b40847
diff --git a/runtime/dex_file_tracking_registrar.cc b/runtime/dex_file_tracking_registrar.cc
new file mode 100644
index 0000000..cfbca3d
--- /dev/null
+++ b/runtime/dex_file_tracking_registrar.cc
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "dex_file_tracking_registrar.h"
+
+// For dex tracking through poisoning. Note: Requires forcing sanitization. This is the reason for
+// the ifdefs and early include.
+#ifdef ART_DEX_FILE_ACCESS_TRACKING
+#ifndef ART_ENABLE_ADDRESS_SANITIZER
+#define ART_ENABLE_ADDRESS_SANITIZER
+#endif
+#endif
+#include "base/memory_tool.h"
+
+#include "base/logging.h"
+
+namespace art {
+namespace dex {
+namespace tracking {
+
+// If true, poison dex files to track accesses.
+static constexpr bool kDexFileAccessTracking =
+#ifdef ART_DEX_FILE_ACCESS_TRACKING
+    true;
+#else
+    false;
+#endif
+
+void RegisterDexFile(const DexFile* const dex_file) {
+  if (kDexFileAccessTracking && dex_file != nullptr) {
+    LOG(ERROR) << dex_file->GetLocation() + " @ " << std::hex
+               << reinterpret_cast<uintptr_t>(dex_file->Begin());
+    MEMORY_TOOL_MAKE_NOACCESS(dex_file->Begin(), dex_file->Size());
+  }
+}
+
+}  // namespace tracking
+}  // namespace dex
+}  // namespace art