From 84124764143d4f35961e2c61494d97640ac7f99f Mon Sep 17 00:00:00 2001 From: Brian Potchik Date: Wed, 25 Aug 2021 22:59:50 -0400 Subject: Update workflows c++ examples. --- examples/workflows/inliner/inliner.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'examples/workflows/inliner/inliner.cpp') diff --git a/examples/workflows/inliner/inliner.cpp b/examples/workflows/inliner/inliner.cpp index 01eacbd2..4ce05a31 100644 --- a/examples/workflows/inliner/inliner.cpp +++ b/examples/workflows/inliner/inliner.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -25,16 +26,26 @@ extern "C" { BN_DECLARE_CORE_ABI_VERSION - unordered_map> g_callSiteInlines; + // TODO: Replace with analysis cache opaque datastore. + std::mutex g_mutex; + unordered_map>> g_callSiteInlines; void FunctionInliner(Ref analysisContext) { + std::unique_lock lock(g_mutex); + Ref function = analysisContext->GetFunction(); Ref data = function->GetView(); + auto gItr = g_callSiteInlines.find(data->GetObject()); + if (gItr == g_callSiteInlines.end()) + return; + + auto itr = gItr->second.find(function->GetStart()); + if (itr == gItr->second.end()) + return; - set callSiteInlines; - if (const auto& itr = g_callSiteInlines.find(function->GetStart()); itr != g_callSiteInlines.end()) - callSiteInlines = itr->second; + auto& callSiteInlines = itr->second; + lock.unlock(); bool updated = false; uint8_t opcode[BN_MAX_INSTRUCTION_LENGTH]; @@ -95,7 +106,6 @@ extern "C" { LowLevelILLabel label; label.operand = instrIndex + 1; - llilFunc->AddInstruction(llilFunc->Pop(instr.size)); llilFunc->AddInstruction(llilFunc->Goto(label)); } else @@ -140,7 +150,8 @@ extern "C" [](BinaryView* view, Function* func) { // TODO func->Inform("inlinedCallSites") // TODO resolve multiple embedded inlines - g_callSiteInlines[func->GetStart()].insert(view->GetCurrentOffset()); + std::lock_guard lock(g_mutex); + g_callSiteInlines[view->GetObject()][func->GetStart()].insert(view->GetCurrentOffset()); func->Reanalyze(); }, inlinerIsValid); -- cgit v1.3.1