1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker 17*795d594fSAndroid Build Coastguard Worker #ifndef ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_ 18*795d594fSAndroid Build Coastguard Worker #define ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_ 19*795d594fSAndroid Build Coastguard Worker 20*795d594fSAndroid Build Coastguard Worker #include <deque> 21*795d594fSAndroid Build Coastguard Worker #include <tuple> 22*795d594fSAndroid Build Coastguard Worker 23*795d594fSAndroid Build Coastguard Worker #include "dex_file.h" 24*795d594fSAndroid Build Coastguard Worker 25*795d594fSAndroid Build Coastguard Worker namespace art { 26*795d594fSAndroid Build Coastguard Worker namespace dex { 27*795d594fSAndroid Build Coastguard Worker namespace tracking { 28*795d594fSAndroid Build Coastguard Worker 29*795d594fSAndroid Build Coastguard Worker // Class for (un)poisoning various sections of Dex Files 30*795d594fSAndroid Build Coastguard Worker // 31*795d594fSAndroid Build Coastguard Worker // This class provides the means to log accesses only of sections whose 32*795d594fSAndroid Build Coastguard Worker // accesses are needed. All accesses are displayed as stack traces in 33*795d594fSAndroid Build Coastguard Worker // logcat. 34*795d594fSAndroid Build Coastguard Worker class DexFileTrackingRegistrar { 35*795d594fSAndroid Build Coastguard Worker public: DexFileTrackingRegistrar(const DexFile * const dex_file)36*795d594fSAndroid Build Coastguard Worker explicit DexFileTrackingRegistrar(const DexFile* const dex_file) 37*795d594fSAndroid Build Coastguard Worker : dex_file_(dex_file) { 38*795d594fSAndroid Build Coastguard Worker } 39*795d594fSAndroid Build Coastguard Worker 40*795d594fSAndroid Build Coastguard Worker // This function is where the functions below it are called to actually 41*795d594fSAndroid Build Coastguard Worker // poison sections. 42*795d594fSAndroid Build Coastguard Worker void SetDexSections(); 43*795d594fSAndroid Build Coastguard Worker 44*795d594fSAndroid Build Coastguard Worker // Uses data contained inside range_values_ to poison memory through the 45*795d594fSAndroid Build Coastguard Worker // memory tool. 46*795d594fSAndroid Build Coastguard Worker void SetCurrentRanges(); 47*795d594fSAndroid Build Coastguard Worker 48*795d594fSAndroid Build Coastguard Worker private: 49*795d594fSAndroid Build Coastguard Worker void SetDexFileRegistration(bool should_poison); 50*795d594fSAndroid Build Coastguard Worker 51*795d594fSAndroid Build Coastguard Worker // Set of functions concerning Code Items of dex_file_ 52*795d594fSAndroid Build Coastguard Worker void SetAllCodeItemRegistration(bool should_poison); 53*795d594fSAndroid Build Coastguard Worker // Sets the insns_ section of all code items. 54*795d594fSAndroid Build Coastguard Worker void SetAllInsnsRegistration(bool should_poison); 55*795d594fSAndroid Build Coastguard Worker // This function finds the code item of a class based on class name. 56*795d594fSAndroid Build Coastguard Worker void SetCodeItemRegistration(const char* class_name, bool should_poison); 57*795d594fSAndroid Build Coastguard Worker // Sets the size and offset information along with first instruction in insns_ 58*795d594fSAndroid Build Coastguard Worker // section of all code items. 59*795d594fSAndroid Build Coastguard Worker void SetAllCodeItemStartRegistration(bool should_poison); 60*795d594fSAndroid Build Coastguard Worker 61*795d594fSAndroid Build Coastguard Worker // Set of functions concerning String Data Items of dex_file_ 62*795d594fSAndroid Build Coastguard Worker void SetAllStringDataRegistration(bool should_poison); 63*795d594fSAndroid Build Coastguard Worker // Sets the first byte of size value and data section of all string data 64*795d594fSAndroid Build Coastguard Worker // items. 65*795d594fSAndroid Build Coastguard Worker void SetAllStringDataStartRegistration(bool should_poison); 66*795d594fSAndroid Build Coastguard Worker 67*795d594fSAndroid Build Coastguard Worker // Contains tuples of all ranges of memory that need to be explicitly 68*795d594fSAndroid Build Coastguard Worker // (un)poisoned by the memory tool. 69*795d594fSAndroid Build Coastguard Worker std::deque<std::tuple<const void *, size_t, bool>> range_values_; 70*795d594fSAndroid Build Coastguard Worker 71*795d594fSAndroid Build Coastguard Worker const DexFile* const dex_file_; 72*795d594fSAndroid Build Coastguard Worker }; 73*795d594fSAndroid Build Coastguard Worker 74*795d594fSAndroid Build Coastguard Worker // This function is meant to called externally to use DexfileTrackingRegistrar 75*795d594fSAndroid Build Coastguard Worker void RegisterDexFile(const DexFile* dex_file); 76*795d594fSAndroid Build Coastguard Worker 77*795d594fSAndroid Build Coastguard Worker } // namespace tracking 78*795d594fSAndroid Build Coastguard Worker } // namespace dex 79*795d594fSAndroid Build Coastguard Worker } // namespace art 80*795d594fSAndroid Build Coastguard Worker 81*795d594fSAndroid Build Coastguard Worker #endif // ART_LIBDEXFILE_DEX_DEX_FILE_TRACKING_REGISTRAR_H_ 82