Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
MC: inline a function that is now trivial
[simgrid.git] / src / mc / sosp / mc_checkpoint.cpp
1 /* Copyright (c) 2008-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef WIN32
7 #include <sys/mman.h>
8 #endif
9
10 #include "xbt/file.hpp"
11
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"
17
18 using simgrid::mc::remote;
19
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc, "Logging specific to mc_checkpoint");
21
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)
25
26 namespace simgrid {
27 namespace mc {
28
29 /************************************  Free functions **************************************/
30 /*****************************************************************************************/
31
32
33
34 /** @brief Fills the position of the segments (executable, read-only, read/write).
35  * */
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)
38 {
39   std::string name = simgrid::xbt::Path(result->file_name).get_base_name();
40
41   for (size_t i = 0; i < maps.size(); ++i) {
42     simgrid::xbt::VmMap const& reg = maps[i];
43     if (maps[i].pathname.empty())
44       continue;
45     std::string map_basename = simgrid::xbt::Path(maps[i].pathname).get_base_name();
46     if (map_basename != name)
47       continue;
48
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;
54
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;
59     }
60
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;
67
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;
73       }
74     }
75
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;
81     }
82   }
83
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;
89
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;
95
96   xbt_assert(result->start_exec || result->start_rw || result->start_ro);
97 }
98
99 } // namespace mc
100 } // namespace simgrid