MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / SaveModifiedStateToKCView

Method SaveModifiedStateToKCView

view/kernelcache/core/KernelCache.cpp:1982–2051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1980
1981
1982bool KernelCache::SaveModifiedStateToKCView(std::lock_guard<std::mutex>&)
1983{
1984 if (!m_kcView)
1985 return false;
1986
1987 {
1988 std::lock_guard lock(m_viewSpecificState->stateMutex);
1989
1990 uint64_t modificationNumber = m_viewSpecificState->savedModifications++;
1991 if (modificationNumber == 0)
1992 {
1993 // The cached state in the view-specific state has not yet been saved.
1994 // For the initial load of a shared cache this will be empty, but if
1995 // the shared cache has been loaded from a database then this will
1996 // contain the full state that was saved.
1997 std::string metadataKey = KernelCacheMetadata::ModifiedStateTagPrefix + std::to_string(modificationNumber);
1998 auto data = m_viewSpecificState->state.AsMetadata(m_viewSpecificState->viewState);
1999
2000 m_kcView->StoreMetadata(metadataKey, data);
2001 m_kcView->GetParentView()->StoreMetadata(metadataKey, data);
2002 modificationNumber = m_viewSpecificState->savedModifications++;
2003 }
2004
2005 std::string metadataKey = KernelCacheMetadata::ModifiedStateTagPrefix + std::to_string(modificationNumber);
2006 auto data = m_modifiedState->AsMetadata();
2007
2008 m_kcView->StoreMetadata(metadataKey, data);
2009 m_kcView->GetParentView()->StoreMetadata(metadataKey, data);
2010
2011 Ref<Metadata> count = new Metadata(m_viewSpecificState->savedModifications);
2012 m_kcView->StoreMetadata(KernelCacheMetadata::ModifiedStateCountTag, count);
2013 m_kcView->GetParentView()->StoreMetadata(KernelCacheMetadata::ModifiedStateCountTag, count);
2014
2015 m_viewSpecificState->state.loadedImages.merge(m_modifiedState->loadedImages);
2016 // `merge` will move a node to the target map if the corresponding key does not yet exist.
2017 // If we've redundantly loaded images, we may be left with symbols in the source maps.
2018 m_modifiedState->loadedImages.clear();
2019
2020 // Clean up any metadata entries past the current modification number.
2021 // These can happen after being loaded from a database as all modifications are
2022 // merged into a single state object and the modification count is reset to zero.
2023 for (size_t i = modificationNumber + 1; i < std::numeric_limits<size_t>::max(); ++i)
2024 {
2025 std::string modifiedStateMetadataKey = KernelCacheMetadata::ModifiedStateTagPrefix + std::to_string(i);
2026 bool done = true;
2027 if (m_kcView->QueryMetadata(modifiedStateMetadataKey))
2028 {
2029 done = false;
2030 m_kcView->RemoveMetadata(modifiedStateMetadataKey);
2031 }
2032 if (m_kcView->GetParentView()->QueryMetadata(modifiedStateMetadataKey))
2033 {
2034 done = false;
2035 m_kcView->GetParentView()->RemoveMetadata(modifiedStateMetadataKey);
2036 }
2037 if (done)
2038 break;
2039 }

Callers

nothing calls this directly

Calls 8

AsMetadataMethod · 0.80
GetParentViewMethod · 0.80
mergeMethod · 0.80
StoreMetadataMethod · 0.45
clearMethod · 0.45
QueryMetadataMethod · 0.45
RemoveMetadataMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected