1 /* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/file.hpp"
12 #include "src/mc/mc_config.hpp"
13 #include "src/mc/mc_hash.hpp"
14 #include "src/mc/mc_private.hpp"
15 #include "src/mc/mc_smx.hpp"
16 #include "src/mc/sosp/mc_snapshot.hpp"
18 using simgrid::mc::remote;
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_checkpoint");
22 #define PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC)
23 #define PROT_RW (PROT_READ | PROT_WRITE)
24 #define PROT_RX (PROT_READ | PROT_EXEC)
29 /************************************ Free functions **************************************/
30 /*****************************************************************************************/
34 /** @brief Fills the position of the segments (executable, read-only, read/write).
36 // TODO, use the ELF segment information for more robustness
37 void find_object_address(std::vector<simgrid::xbt::VmMap> const& maps, simgrid::mc::ObjectInformation* result)
39 std::string name = simgrid::xbt::Path(result->file_name).get_base_name();
41 for (size_t i = 0; i < maps.size(); ++i) {
42 simgrid::xbt::VmMap const& reg = maps[i];
43 if (maps[i].pathname.empty())
45 std::string map_basename = simgrid::xbt::Path(maps[i].pathname).get_base_name();
46 if (map_basename != name)
49 // This is the non-GNU_RELRO-part of the data segment:
50 if (reg.prot == PROT_RW) {
51 xbt_assert(not result->start_rw, "Multiple read-write segments for %s, not supported", maps[i].pathname.c_str());
52 result->start_rw = (char*)reg.start_addr;
53 result->end_rw = (char*)reg.end_addr;
55 // The next VMA might be end of the data segment:
56 if (i + 1 < maps.size() && maps[i + 1].pathname.empty() && maps[i + 1].prot == PROT_RW &&
57 maps[i + 1].start_addr == reg.end_addr)
58 result->end_rw = (char*)maps[i + 1].end_addr;
61 // This is the text segment:
62 else if (reg.prot == PROT_RX) {
63 xbt_assert(not result->start_exec, "Multiple executable segments for %s, not supported",
64 maps[i].pathname.c_str());
65 result->start_exec = (char*)reg.start_addr;
66 result->end_exec = (char*)reg.end_addr;
68 // The next VMA might be end of the data segment:
69 if (i + 1 < maps.size() && maps[i + 1].pathname.empty() && maps[i + 1].prot == PROT_RW &&
70 maps[i + 1].start_addr == reg.end_addr) {
71 result->start_rw = (char*)maps[i + 1].start_addr;
72 result->end_rw = (char*)maps[i + 1].end_addr;
76 // This is the GNU_RELRO-part of the data segment:
77 else if (reg.prot == PROT_READ) {
78 xbt_assert(not result->start_ro, "Multiple read only segments for %s, not supported", maps[i].pathname.c_str());
79 result->start_ro = (char*)reg.start_addr;
80 result->end_ro = (char*)reg.end_addr;
84 result->start = result->start_rw;
85 if ((const void*)result->start_ro < result->start)
86 result->start = result->start_ro;
87 if ((const void*)result->start_exec < result->start)
88 result->start = result->start_exec;
90 result->end = result->end_rw;
91 if (result->end_ro && (const void*)result->end_ro > result->end)
92 result->end = result->end_ro;
93 if (result->end_exec && (const void*)result->end_exec > result->end)
94 result->end = result->end_exec;
96 xbt_assert(result->start_exec || result->start_rw || result->start_ro);
100 } // namespace simgrid