From: Arnaud Giersch Date: Thu, 11 Jul 2019 21:24:19 +0000 (+0200) Subject: mc: better way to check if address is on heap. X-Git-Tag: v3.24~301 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/32f4ca6248c287dbd1e5f0ef88e82370a3a72ecf mc: better way to check if address is on heap. --- diff --git a/src/mc/compare.cpp b/src/mc/compare.cpp index febf10bc46..e8457a3c12 100644 --- a/src/mc/compare.cpp +++ b/src/mc/compare.cpp @@ -151,12 +151,6 @@ static ssize_t heap_comparison_ignore_size(const std::vectorprocess().get_heap(); - return address >= heap->heapbase && address < heap->breakval; -} - static bool is_stack(const void *address) { for (auto const& stack : mc_model_checker->process().stack_areas()) @@ -509,7 +503,7 @@ static bool heap_area_differ_without_type(simgrid::mc::StateComparator& state, c continue; } - if (is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2)) { + if (snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2)) { // Both addresses are in the heap: if (heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, nullptr, 0)) return true; @@ -651,7 +645,7 @@ static bool heap_area_differ_with_type(simgrid::mc::StateComparator& state, cons if (pointer_level <= 1) { addr_pointed1 = snapshot1.read(remote((void* const*)real_area1)); addr_pointed2 = snapshot2.read(remote((void* const*)real_area2)); - if (is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2)) + if (snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2)) return heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype, pointer_level); else @@ -660,7 +654,7 @@ static bool heap_area_differ_with_type(simgrid::mc::StateComparator& state, cons for (size_t i = 0; i < (area_size / sizeof(void*)); i++) { addr_pointed1 = snapshot1.read(remote((void* const*)((const char*)real_area1 + i * sizeof(void*)))); addr_pointed2 = snapshot2.read(remote((void* const*)((const char*)real_area2 + i * sizeof(void*)))); - bool differ = is_on_heap(addr_pointed1) && is_on_heap(addr_pointed2) + bool differ = snapshot1.on_heap(addr_pointed1) && snapshot2.on_heap(addr_pointed2) ? heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, previous, type->subtype, pointer_level) : addr_pointed1 != addr_pointed2; @@ -1131,8 +1125,8 @@ static bool areas_differ_with_type(simgrid::mc::StateComparator& state, const vo // * a pointer leads to the read-only segment of the current object // * a pointer lead to a different ELF object - if (is_on_heap(addr_pointed1)) { - if (not is_on_heap(addr_pointed2)) + if (snapshot1.on_heap(addr_pointed1)) { + if (not snapshot2.on_heap(addr_pointed2)) return true; // The pointers are both in the heap: return simgrid::mc::heap_area_differ(state, addr_pointed1, addr_pointed2, snapshot1, snapshot2, nullptr, diff --git a/src/mc/inspect/DwarfExpression.hpp b/src/mc/inspect/DwarfExpression.hpp index 064ba32e8c..efb089e10b 100644 --- a/src/mc/inspect/DwarfExpression.hpp +++ b/src/mc/inspect/DwarfExpression.hpp @@ -16,7 +16,6 @@ #include #include -#include "src/mc/AddressSpace.hpp" #include "src/mc/inspect/mc_dwarf.hpp" #include "src/mc/mc_forward.hpp" diff --git a/src/mc/remote/RemoteClient.hpp b/src/mc/remote/RemoteClient.hpp index 174517df1f..b5cfdc91da 100644 --- a/src/mc/remote/RemoteClient.hpp +++ b/src/mc/remote/RemoteClient.hpp @@ -6,8 +6,10 @@ #ifndef SIMGRID_MC_PROCESS_H #define SIMGRID_MC_PROCESS_H +#include "src/mc/AddressSpace.hpp" #include "src/mc/inspect/ObjectInformation.hpp" #include "src/mc/remote/Channel.hpp" +#include "src/mc/remote/RemotePtr.hpp" #include "src/xbt/mmalloc/mmprivate.h" #include diff --git a/src/mc/sosp/Snapshot.hpp b/src/mc/sosp/Snapshot.hpp index ad755f745a..f227fe72ee 100644 --- a/src/mc/sosp/Snapshot.hpp +++ b/src/mc/sosp/Snapshot.hpp @@ -59,12 +59,17 @@ namespace mc { class XBT_PRIVATE Snapshot final : public AddressSpace { public: + /* Initialization */ Snapshot(int num_state, RemoteClient* process = &mc_model_checker->process()); ~Snapshot() = default; - /* Initialization */ - /* Regular use */ + bool on_heap(const void* address) const + { + const xbt_mheap_t heap = process()->get_heap(); + return address >= heap->heapbase && address < heap->breakval; + } + void* read_bytes(void* buffer, std::size_t size, RemotePtr address, ReadOptions options = ReadOptions::none()) const override; Region* get_region(const void* addr) const;