1 /* Copyright (c) 2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include <sys/types.h>
16 #include "../xbt/memory_map.hpp"
19 #include "private.hpp"
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_memory, smpi, "Memory layout support for SMPI");
23 static const int PROT_RWX = (PROT_READ | PROT_WRITE | PROT_EXEC);
24 static const int PROT_RW = (PROT_READ | PROT_WRITE );
25 static const int PROT_RX = (PROT_READ | PROT_EXEC );
27 void smpi_get_executable_global_size(void)
29 char buffer[PATH_MAX];
30 char* full_name = realpath(xbt_binary_name, buffer);
31 if (full_name == nullptr)
32 xbt_die("Could not resolve binary file name");
34 std::vector<simgrid::xbt::VmMap> map = simgrid::xbt::get_memory_map(getpid());
35 for (auto i = map.begin(); i != map.end() ; ++i) {
36 // TODO, In practice, this implementation would not detect a completely
37 // anonymous data segment. This does not happen in practice, however.
39 // File backed RW entry:
40 if (i->pathname == full_name && (i->prot & PROT_RWX) == PROT_RW) {
41 smpi_start_data_exe = (char*) i->start_addr;
42 smpi_size_data_exe = i->end_addr - i->start_addr;
44 /* Here we are making the assumption that a suitable empty region
45 following the rw- area is the end of the data segment. It would
46 be better to check with the size of the data segment. */
47 if (i != map.end() && i->pathname.empty() && (i->prot & PROT_RWX) == PROT_RW
48 && i->start_addr == (std::uint64_t) smpi_start_data_exe + smpi_size_data_exe) {
49 smpi_size_data_exe = i->end_addr - (std::uint64_t) smpi_start_data_exe;
54 xbt_die("Did not find my data segment.");