Skip to content

Commit e90a08f

Browse files
WeiN76LQh0cyn
authored andcommitted
[SharedCache] Add parameter to SharedCache::InitializeHeader to check if m_exportInfos was modified
This probably makes more sense than the current solution of using execution of the callback parameter to determine if `m_exportInfos` was modified.
1 parent 8953660 commit e90a08f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,18 +2808,24 @@ std::vector<Ref<Symbol>> SharedCache::ParseExportTrie(std::shared_ptr<MMappedFil
28082808
}
28092809

28102810

2811-
std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> SharedCache::GetExportListForHeader(SharedCacheMachOHeader header, std::function<std::shared_ptr<MMappedFileAccessor>()> provideLinkeditFile)
2811+
std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> SharedCache::GetExportListForHeader(SharedCacheMachOHeader header, std::function<std::shared_ptr<MMappedFileAccessor>()> provideLinkeditFile, bool* didModifyExportList)
28122812
{
28132813
if (auto it = m_state->exportInfos.find(header.textBase); it != m_state->exportInfos.end())
28142814
{
2815+
if (didModifyExportList)
2816+
*didModifyExportList = false;
28152817
return it->second;
28162818
}
28172819
else
28182820
{
28192821
// TODO does this have to be a functor? can't we just pass the accessor? if not, why?
28202822
std::shared_ptr<MMappedFileAccessor> linkeditFile = provideLinkeditFile();
28212823
if (!linkeditFile)
2824+
{
2825+
if (didModifyExportList)
2826+
*didModifyExportList = false;
28222827
return std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>>();
2828+
}
28232829

28242830
auto exportList = SharedCache::ParseExportTrie(linkeditFile, header);
28252831
std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> exportMapping(exportList.size());
@@ -2828,6 +2834,8 @@ std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> SharedCac
28282834
exportMapping.push_back({sym->GetAddress(), {sym->GetType(), sym->GetRawName()}});
28292835
}
28302836
m_state->exportInfos[header.textBase] = exportMapping;
2837+
if (didModifyExportList)
2838+
*didModifyExportList = true;
28312839
return exportMapping;
28322840
}
28332841
}
@@ -2858,15 +2866,14 @@ std::vector<std::pair<std::string, Ref<Symbol>>> SharedCache::LoadAllSymbolsAndW
28582866
auto exportList = GetExportListForHeader(*header, [&]() {
28592867
try {
28602868
auto mapping = MMappedFileAccessor::Open(m_dscView, m_dscView->GetFile()->GetSessionId(), header->exportTriePath)->lock();
2861-
doSave = true;
28622869
return mapping;
28632870
}
28642871
catch (...)
28652872
{
28662873
m_logger->LogWarn("Serious Error: Failed to open export trie %s for %s", header->exportTriePath.c_str(), header->installName.c_str());
28672874
return std::shared_ptr<MMappedFileAccessor>(nullptr);
28682875
}
2869-
});
2876+
}, &doSave);
28702877
for (const auto& sym : exportList)
28712878
{
28722879
symbols.push_back({img.installName, new Symbol(sym.second.first, sym.second.second, sym.first)});

view/sharedcache/core/SharedCache.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,8 @@ namespace SharedCacheCore {
643643
std::shared_ptr<MMappedFileAccessor> linkeditFile, const SharedCacheMachOHeader& header);
644644

645645
std::vector<std::pair<uint64_t, std::pair<BNSymbolType, std::string>>> GetExportListForHeader(
646-
SharedCacheMachOHeader header, std::function<std::shared_ptr<MMappedFileAccessor>()> provideLinkeditFile);
646+
SharedCacheMachOHeader header, std::function<std::shared_ptr<MMappedFileAccessor>()> provideLinkeditFile,
647+
bool* didModifyExportList = nullptr);
647648

648649
Ref<TypeLibrary> TypeLibraryForImage(const std::string& installName);
649650

0 commit comments

Comments
 (0)