| 60 | } |
| 61 | |
| 62 | bool ValdiRuntimeTweaks::enableTSNForModule(const StringBox& moduleName) const { |
| 63 | auto const key = StringCache::getGlobal().makeStringFromLiteral(std::string_view("VALDI_TSN_ENABLED_MODULES")); |
| 64 | auto const fallback = Value(makeShared<ValueTypedArray>(TypedArrayType::Uint8Array, Valdi::BytesView())); |
| 65 | |
| 66 | Value binary = _tweakValueProvider->getBinary(key, fallback); |
| 67 | |
| 68 | // If configured (has at least one per-module config, use per-module config) |
| 69 | if (binary.isTypedArray()) { |
| 70 | const ValueTypedArray* array = binary.getTypedArray(); |
| 71 | const BytesView& bytes = array->getBuffer(); |
| 72 | |
| 73 | Valdi::TsnConfig tsnConfig; |
| 74 | bool parsed = tsnConfig.ParseFromArray(bytes.data(), static_cast<int>(bytes.size())); |
| 75 | |
| 76 | if (parsed) { |
| 77 | // trivial first pass because this is only used for a very small number of elements |
| 78 | for (const auto& module : tsnConfig.enabled_modules()) { |
| 79 | if (moduleName.hasPrefix(module.c_str())) { |
| 80 | Valdi::ConsoleLogger::getLogger().log( |
| 81 | Valdi::LogTypeDebug, fmt::format("TSN enabled for module: {} ", moduleName.slowToString())); |
| 82 | return true; // prefix match success |
| 83 | } |
| 84 | } |
| 85 | // has configured modules, but not a match, return false |
| 86 | // not configured (empty list), return true |
| 87 | return tsnConfig.enabled_modules_size() == 0; |
| 88 | } |
| 89 | } |
| 90 | // If not configured(null, failing to parse), return true |
| 91 | // (fallback to global tsn config) |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | bool ValdiRuntimeTweaks::shouldCrashOnANR() const { |
| 96 | return getConfigKey("VALDI_ENABLE_CRASH_ON_ANR"); |