1 #ifndef ROSE_BinaryAnalysis_Reachability_H
2 #define ROSE_BinaryAnalysis_Reachability_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BitFlags.h>
7 #include <boost/serialization/access.hpp>
8 #include <boost/serialization/split_member.hpp>
9 #include <Rose/BinaryAnalysis/Partitioner2/ControlFlowGraph.h>
10 #include <Sawyer/Map.h>
11 #include <Sawyer/Tracker.h>
16 namespace BinaryAnalysis {
83 addressAlignment(0), addressNBytes(0), byteOrder(
ByteOrder::ORDER_UNSPECIFIED),
84 precomputeImplicitFunctionReferents(true)
97 std::vector<ReasonFlags> intrinsicReachability_;
98 std::vector<ReasonFlags> reachability_;
99 FunctionToVertexMap dfReferents_;
102 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
104 friend class boost::serialization::access;
107 void serialize(S &s,
const unsigned version) {
112 ASSERT_not_reachable(
"aborting due to unsupported old serialization file format");
114 s & BOOST_SERIALIZATION_NVP(intrinsicReachability_);
115 s & BOOST_SERIALIZATION_NVP(reachability_);
116 s & BOOST_SERIALIZATION_NVP(intrinsicReachability_);
117 s & BOOST_SERIALIZATION_NVP(reachability_);
177 Reason dfltArg,
const std::string &doc);
245 size_t alignment = 0, ByteOrder::Endianness sex = ByteOrder::ORDER_UNSPECIFIED,
275 template<
class ForwardIterator>
365 static std::set<size_t>
376 size_t alignment = 0, ByteOrder::Endianness sex = ByteOrder::ORDER_UNSPECIFIED);
382 static std::set<size_t>
Vertex is a signal handler.
void settings(const Settings &s)
Property: Settings that influence the analysis.
ByteOrder::Endianness byteOrder
Byte order to use when reading constants from virtual memory.
std::vector< size_t > reachableVertices(ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Return a list of reachable vertex IDs.
const std::vector< ReasonFlags > & intrinsicReachability() const
Query intrinsic reachability.
Address appears as a constant in some reachable instruction.
static std::string reasonArgument(Reason)
Convert a reachability reason enum constant to a parsable reason name.
Reachability()
Default constructor.
size_t markExportFunctions(const Partitioner2::PartitionerConstPtr &, ReasonFlags how=EXPORTED_FUNCTION)
Mark exported functions as intrinsically reachable.
const std::vector< ReasonFlags > & reachability() const
Query computed reachability.
rose_addr_t addressAlignment
Alignment when reading constants from virtual memory.
ReasonFlags markingExplicitInstructionReferents
If not empty, run markExplicitInstructionReferents during iteration.
Settings & settings()
Property: Settings that influence the analysis.
static bool hasReasons(ReasonFlags reasons, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags())
Predicate to match reason flags.
size_t intrinsicallyReachable(size_t vertexId, ReasonFlags how)
Change intrinsic reachability for one vertex.
static std::string reasonArgumentDocumentation()
Documentation for the possible reason arguments.
size_t markEntryFunctions(const Partitioner2::PartitionerConstPtr &, ReasonFlags how=PROGRAM_ENTRY_POINT)
Mark entry points as intrinsically reachable.
size_t intrinsicallyReachable(ForwardIterator begin, ForwardIterator end, ReasonFlags how)
Change intrinsic reachabability for multiple vertices.
Settings controlling the analysis.
A collection of related switch declarations.
void clear()
Clear previous results.
Assumed reachable for cases when the analysis wasn't run.
Sawyer::Optional< size_t > nThreads
Parallelism; 0 means system; unset means use global value.
bool precomputeImplicitFunctionReferents
Implicit function referents are precomputed in parallel.
Main namespace for the ROSE library.
Vertex is an exported function.
Reason
Predefined bit flags for why something is reachable.
Messages that indicate an abnormal situation from which the program was unable to recover...
const Settings & settings() const
Property: Settings that influence the analysis.
void clearReachability()
Clear all reachability.
size_t propagate(const Partitioner2::PartitionerConstPtr &)
Propagate intrinsic reachability through the graph.
static void insertReasonSwitch(Sawyer::CommandLine::SwitchGroup &, const std::string &switchName, ReasonFlags &storage, Reason dfltArg, const std::string &doc)
Insert a switch that takes a reason argument.
static std::string reasonDocumentation(Reason dflt)
Generate documentation for the command-line switches.
static Sawyer::CommandLine::ValueParser::Ptr reasonParser(ReasonFlags &storage)
Creates a command-line parser for reachability reason names.
Sawyer::SharedPointer< Function > FunctionPtr
Shared-ownership pointer for Function.
size_t markImplicitFunctionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &, ReasonFlags how=IMPLICIT_FUNC_CONSTANT)
Mark vertices whose addressses appear in a function.
void iterate(const Partitioner2::PartitionerConstPtr &partitioner)
Iteratively propagate and mark.
std::set< size_t > findExplicitMemoryReferents(const Partitioner2::PartitionerConstPtr &, const MemoryMapPtr &, size_t bytesPerWord=0, size_t alignment=0, ByteOrder::Endianness sex=ByteOrder::ORDER_UNSPECIFIED)
Find all CFG vertices mentioned in memory.
size_t markExplicitMemoryReferents(const Partitioner2::PartitionerConstPtr &, const MemoryMapPtr &, size_t bytesPerWord=0, size_t alignment=0, ByteOrder::Endianness sex=ByteOrder::ORDER_UNSPECIFIED, ReasonFlags how=EXPLICIT_MEM_CONSTANT)
Mark vertices whose addresses appear in memory.
BitFlags< Reason, uint32_t > ReasonFlags
Bit flags for reachability.
size_t addressNBytes
Size of addresses when reading constants from virtual memory.
Vertex is a program entry point.
static Sawyer::CommandLine::SwitchGroup commandLineSwitches(Settings &settings)
Describes how to parse switches related to reachability.
size_t markStartingPoints(const Partitioner2::PartitionerConstPtr &, MemoryMapPtr map=MemoryMap::Ptr())
Mark starting points as intrinsically reachable according to settings.
static void initDiagnostics()
Initialize diagnostic streams.
static std::set< size_t > findImplicitFunctionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::FunctionPtr &)
Find all CFG vertices referenced from a function.
bool isReachable(size_t vertexId, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Query whether a vertex is reachable.
Analysis that computes reachability of CFG vertices.
ReasonFlags markingEntryFunctions
If not empty, run markEntryFunctions at startup.
ReasonFlags markingExplicitMemoryReferents
If not empty, run markExplicitMemoryReferents at startup.
static std::set< size_t > findExplicitInstructionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &)
Find all CFG vertices mentioned explicitly in a basic block.
static Diagnostics::Facility mlog
Facility for emitting diagnostics.
Address appears during data-flow in some reachable function.
ReasonFlags markingExportFunctions
If not empty, run markExportFunctions at startup.
Address appears in memory.
size_t markExplicitInstructionReferents(const Partitioner2::PartitionerConstPtr &, const Partitioner2::BasicBlockPtr &, ReasonFlags how=EXPLICIT_INSN_CONSTANT)
Mark vertices whose addresses appear in instructions.
size_t markSpecifiedVas(const Partitioner2::PartitionerConstPtr &, const std::vector< AddressInterval > &, ReasonFlags)
Mark all basic blocks with in the specified ranges.
Container associating values with keys.
bool isIntrinsicallyReachable(size_t vertexId, ReasonFlags any=ReasonFlags(), ReasonFlags all=ReasonFlags(), ReasonFlags none=ReasonFlags()) const
Query whether a vertex is intrinsic reachable.
ReasonFlags markingImplicitFunctionReferents
If not empty, run markImplicitFunctionReferents during iteration.