From 3bff85e67310d6ff6ab9f38b33da9cabf381d57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Can=20B=C3=B6l=C3=BCk?= Date: Sun, 23 Aug 2020 03:02:13 +0200 Subject: [PATCH] Clone now fixes depth-ord cache, move out of multivariate. --- VTIL-Architecture/routine/routine.cpp | 25 ++++++++++++++----------- VTIL-Architecture/routine/routine.hpp | 21 +++++++++++++++------ 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/VTIL-Architecture/routine/routine.cpp b/VTIL-Architecture/routine/routine.cpp index 5b14876..d25da5f 100644 --- a/VTIL-Architecture/routine/routine.cpp +++ b/VTIL-Architecture/routine/routine.cpp @@ -291,16 +291,6 @@ namespace vtil // Gets a list of depth ordered block lists that can be analysed in parallel without any dependencies on previous level. // - struct depth_ordered_list_cache - { - struct entry - { - epoch_t epoch = invalid_epoch; - std::vector list; - }; - entry directions[ 2 ]; - }; - std::vector routine::get_depth_ordered_list( bool fwd ) const { // Acquire the routine mutex. @@ -309,7 +299,7 @@ namespace vtil // Return if already cached. // - auto& cache = context.get().directions[ fwd ? 1 : 0 ]; + auto& cache = depth_ordered_list_cache[ fwd ? 1 : 0 ]; if ( std::exchange( cache.epoch, cfg_epoch ) == cfg_epoch ) return cache.list; @@ -521,6 +511,19 @@ namespace vtil map = map_l1; } + // Fix depth ordered list cache. + // + for ( auto& list : copy->depth_ordered_list_cache ) + { + if ( list.epoch == copy->cfg_epoch ) + { + for ( auto& entry : list.list ) + { + entry.block = copy->get_block( entry.block->entry_vip ); + } + } + } + // Return the copy. // return copy; diff --git a/VTIL-Architecture/routine/routine.hpp b/VTIL-Architecture/routine/routine.hpp index 081134e..6562a90 100644 --- a/VTIL-Architecture/routine/routine.hpp +++ b/VTIL-Architecture/routine/routine.hpp @@ -105,6 +105,21 @@ namespace vtil // Multivariate runtime context. // multivariate context = {}; + + // Cache of depth ordered lists. + // + struct depth_entry + { + size_t level_dependency; + size_t level_depth; + const basic_block* block; + }; + struct depth_ordered_list + { + epoch_t epoch = invalid_epoch; + std::vector list; + }; + mutable depth_ordered_list depth_ordered_list_cache[ 2 ]; // Epoch provided to allow external entities determine if the routine // is modified or not since their last read from it in an easy and fast way. @@ -221,12 +236,6 @@ namespace vtil // Gets a list of depth ordered block lists that can be analysed in parallel without any dependencies on previous level. // - struct depth_entry - { - size_t level_dependency; - size_t level_depth; - const basic_block* block; - }; std::vector get_depth_ordered_list( bool fwd ) const; // Provide basic statistics about the complexity of the routine.