Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Don't modify loop counter inside of loop body.
[simgrid.git] / src / smpi / internals / smpi_memory.cpp
index 55b7551..723c5df 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -55,10 +55,10 @@ void smpi_prepare_global_memory_segment()
 
 static void smpi_get_executable_global_size()
 {
-  char buffer[PATH_MAX];
-  const char* full_name = realpath(simgrid::xbt::binary_name.c_str(), buffer);
-  xbt_assert(full_name != nullptr, "Could not resolve real path of binary file '%s'",
-             simgrid::xbt::binary_name.c_str());
+  char* buffer = realpath(simgrid::xbt::binary_name.c_str(), nullptr);
+  xbt_assert(buffer != nullptr, "Could not resolve real path of binary file '%s'", simgrid::xbt::binary_name.c_str());
+  std::string full_name = buffer;
+  free(buffer);
 
   std::vector<simgrid::xbt::VmMap> map = simgrid::xbt::get_memory_map(getpid());
   for (auto i = map.begin(); i != map.end() ; ++i) {
@@ -72,14 +72,14 @@ static void smpi_get_executable_global_size()
       /* Here we are making the assumption that a suitable empty region
          following the rw- area is the end of the data segment. It would
          be better to check with the size of the data segment. */
-      ++i;
-      if (i != map.end() && i->pathname.empty() && (i->prot & PROT_RWX) == PROT_RW &&
-          (char*)i->start_addr == smpi_data_exe_start + smpi_data_exe_size) {
+      auto j = i + 1;
+      if (j != map.end() && j->pathname.empty() && (j->prot & PROT_RWX) == PROT_RW &&
+          (char*)j->start_addr == smpi_data_exe_start + smpi_data_exe_size) {
         // Only count the portion of this region not present in the initial map.
-        auto found = std::find_if(initial_vm_map.begin(), initial_vm_map.end(), [&i](const simgrid::xbt::VmMap& m) {
-          return i->start_addr <= m.start_addr && m.start_addr < i->end_addr;
+        auto found    = std::find_if(initial_vm_map.begin(), initial_vm_map.end(), [&j](const simgrid::xbt::VmMap& m) {
+          return j->start_addr <= m.start_addr && m.start_addr < j->end_addr;
         });
-        auto end_addr      = (found == initial_vm_map.end() ? i->end_addr : found->start_addr);
+        auto end_addr = (found == initial_vm_map.end() ? j->end_addr : found->start_addr);
         smpi_data_exe_size = (char*)end_addr - smpi_data_exe_start;
       }
       return;
@@ -176,7 +176,7 @@ void* smpi_temp_shm_mmap(int fd, size_t size)
   return mem;
 }
 
-/** Map a given SMPI privatization segment (make a SMPI process active)
+/** Map a given SMPI privatization segment (make an SMPI process active)
  *
  *  When doing a state restoration, the state of the restored variables  might not be consistent with the state of the
  *  virtual memory. In this case, we to change the data segment.
@@ -192,7 +192,7 @@ void smpi_switch_data_segment(simgrid::s4u::ActorPtr actor)
 #if HAVE_PRIVATIZATION
   // FIXME, cross-process support (mmap across process when necessary)
   XBT_DEBUG("Switching data frame to the one of process %ld", actor->get_pid());
-  simgrid::smpi::ActorExt* process = smpi_process_remote(actor);
+  const simgrid::smpi::ActorExt* process = smpi_process_remote(actor);
   int current                     = process->privatized_region()->file_descriptor;
   const void* tmp = mmap(TOPAGE(smpi_data_exe_start), smpi_data_exe_size, PROT_RW, MAP_FIXED | MAP_SHARED, current, 0);
   if (tmp != TOPAGE(smpi_data_exe_start))