// 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"
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
// The following are configurations of poisoning certain sections of a Dex File. // More will be added enum DexTrackingType { // Poisons all of a Dex File when set.
kWholeDexTracking, // Poisons all Code Items of a Dex File when set.
kCodeItemTracking, // Poisons all subsections of a Code Item, except the Insns bytecode array // section, when set for all Code Items in a Dex File.
kCodeItemNonInsnsTracking, // Poisons all subsections of a Code Item, except the Insns bytecode array // section, when set for all Code Items in a Dex File. // Additionally unpoisons the entire Code Item when method is a class // initializer.
kCodeItemNonInsnsNoClinitTracking, // Poisons the size and offset information along with the first instruction. // This is so that accessing multiple instructions while accessing a code item // once will not trigger unnecessary accesses.
kCodeItemStartTracking, // Poisons all String Data Items of a Dex Files when set.
kStringDataItemTracking, // Poisons the first byte of the utf16_size value and the first byte of the // data section for all String Data Items of a Dex File.
kStringDataItemStartTracking, // Poisons based on a custom tracking system which can be specified in // SetDexSections
kCustomTracking,
};
// Intended for local changes only. // Represents the current configuration being run. static constexpr DexTrackingType kCurrentTrackingSystem = kWholeDexTracking;
// Intended for local changes only. void DexFileTrackingRegistrar::SetDexSections() { if (kDexFileAccessTracking && dex_file_ != nullptr) { // Logs the Dex File's location and starting address if tracking is enabled
LOG(ERROR) << "RegisterDexFile: " << dex_file_->GetLocation() + " @ " << std::hex
<< reinterpret_cast<uintptr_t>(dex_file_->Begin()); switch (kCurrentTrackingSystem) { case kWholeDexTracking:
SetDexFileRegistration(true); break; case kCodeItemTracking:
SetAllCodeItemRegistration(true); break; case kCodeItemNonInsnsTracking:
SetAllCodeItemRegistration(true);
SetAllInsnsRegistration(false); break; case kCodeItemNonInsnsNoClinitTracking:
SetAllCodeItemRegistration(true);
SetAllInsnsRegistration(false);
SetCodeItemRegistration("<clinit>", false); break; case kCodeItemStartTracking:
SetAllCodeItemStartRegistration(true); break; case kStringDataItemTracking:
SetAllStringDataRegistration(true); break; case kStringDataItemStartTracking:
SetAllStringDataStartRegistration(true); break; case kCustomTracking: // TODO: Add/remove additional calls here to (un)poison sections of // dex_file_ break; default: break;
}
}
}
inlinevoid SetRegistrationRange(constvoid* begin, size_t size, bool should_poison) { if (should_poison) {
MEMORY_TOOL_MAKE_NOACCESS(begin, size);
} else { // Note: MEMORY_TOOL_MAKE_UNDEFINED has the same functionality with Address // Sanitizer. // Historical note: The difference has not been tested with Valgrind.
MEMORY_TOOL_MAKE_DEFINED(begin, size);
}
}
void DexFileTrackingRegistrar::SetCurrentRanges() { // This also empties range_values_ to avoid redundant (un)poisoning upon // subsequent calls. while (!range_values_.empty()) { const std::tuple<constvoid*, size_t, bool>& current_range = range_values_.front();
SetRegistrationRange(std::get<0>(current_range),
std::get<1>(current_range),
std::get<2>(current_range));
range_values_.pop_front();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.