blob: cfbca3d00f735e7610c7a7c3365cbd6645f7bbd7 [file] [log] [blame]
Bharadwaj Kalandhabhatta0bb40312017-06-01 10:47:00 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "dex_file_tracking_registrar.h"
18
19// For dex tracking through poisoning. Note: Requires forcing sanitization. This is the reason for
20// the ifdefs and early include.
21#ifdef ART_DEX_FILE_ACCESS_TRACKING
22#ifndef ART_ENABLE_ADDRESS_SANITIZER
23#define ART_ENABLE_ADDRESS_SANITIZER
24#endif
25#endif
26#include "base/memory_tool.h"
27
28#include "base/logging.h"
29
30namespace art {
31namespace dex {
32namespace tracking {
33
34// If true, poison dex files to track accesses.
35static constexpr bool kDexFileAccessTracking =
36#ifdef ART_DEX_FILE_ACCESS_TRACKING
37 true;
38#else
39 false;
40#endif
41
42void RegisterDexFile(const DexFile* const dex_file) {
43 if (kDexFileAccessTracking && dex_file != nullptr) {
44 LOG(ERROR) << dex_file->GetLocation() + " @ " << std::hex
45 << reinterpret_cast<uintptr_t>(dex_file->Begin());
46 MEMORY_TOOL_MAKE_NOACCESS(dex_file->Begin(), dex_file->Size());
47 }
48}
49
50} // namespace tracking
51} // namespace dex
52} // namespace art