blob: 8b7716e729c8c518d500ec3a40f93b7958ba0342 [file] [log] [blame]
Martin Stjernholmc15e7e42020-12-02 22:50:53 +00001/*
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#ifndef ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
18#define ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_
19
20#include <deque>
21#include <tuple>
22
23#include "dex_file.h"
24
25namespace art {
26namespace dex {
27namespace tracking {
28
29// Class for (un)poisoning various sections of Dex Files
30//
31// This class provides the means to log accesses only of sections whose
32// accesses are needed. All accesses are displayed as stack traces in
33// logcat.
34class DexFileTrackingRegistrar {
35 public:
36 explicit DexFileTrackingRegistrar(const DexFile* const dex_file)
37 : dex_file_(dex_file) {
38 }
39
40 // This function is where the functions below it are called to actually
41 // poison sections.
42 void SetDexSections();
43
44 // Uses data contained inside range_values_ to poison memory through the
45 // memory tool.
46 void SetCurrentRanges();
47
48 private:
49 void SetDexFileRegistration(bool should_poison);
50
51 // Set of functions concerning Code Items of dex_file_
52 void SetAllCodeItemRegistration(bool should_poison);
53 // Sets the insns_ section of all code items.
54 void SetAllInsnsRegistration(bool should_poison);
55 // This function finds the code item of a class based on class name.
56 void SetCodeItemRegistration(const char* class_name, bool should_poison);
57 // Sets the size and offset information along with first instruction in insns_
58 // section of all code items.
59 void SetAllCodeItemStartRegistration(bool should_poison);
60
61 // Set of functions concerning String Data Items of dex_file_
62 void SetAllStringDataRegistration(bool should_poison);
63 // Sets the first byte of size value and data section of all string data
64 // items.
65 void SetAllStringDataStartRegistration(bool should_poison);
66
67 // Contains tuples of all ranges of memory that need to be explicitly
68 // (un)poisoned by the memory tool.
69 std::deque<std::tuple<const void *, size_t, bool>> range_values_;
70
71 const DexFile* const dex_file_;
72};
73
74// This function is meant to called externally to use DexfileTrackingRegistrar
75void RegisterDexFile(const DexFile* dex_file);
76
77} // namespace tracking
78} // namespace dex
79} // namespace art
80
81#endif // ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_