- status = ftruncate(file_descriptor, smpi_data_exe_size);
- if (status)
- xbt_die("Impossible to set the size of the temporary file for memory mapping");
-
- /* Ask for a free region */
- address = mmap(nullptr, smpi_data_exe_size, PROT_READ | PROT_WRITE, MAP_SHARED, file_descriptor, 0);
- if (address == MAP_FAILED)
- xbt_die("Couldn't find a free region for memory mapping");
-
- status = shm_unlink(path);
- if (status)
- xbt_die("Impossible to unlink temporary file for memory mapping");
-
- // initialize the values
- asan_safe_memcpy(address, smpi_data_exe_copy, smpi_data_exe_size);
-
- // store the address of the mapping for further switches
- smpi_privatization_region_t tmp =
- static_cast<smpi_privatization_region_t>(xbt_malloc(sizeof(struct s_smpi_privatization_region)));
-
- tmp->file_descriptor = file_descriptor;
- tmp->address = address;
- smpi_privatization_regions.insert(tmp);
-
- return tmp;
+ /* Ask for a free region */
+ address = mmap(nullptr, smpi_data_exe_size, PROT_RW, MAP_SHARED, file_descriptor, 0);
+ if (address == MAP_FAILED)
+ xbt_die("Couldn't find a free region for memory mapping");
+
+ status = shm_unlink(path);
+ if (status)
+ xbt_die("Impossible to unlink temporary file for memory mapping");
+
+ // initialize the values
+ asan_safe_memcpy(address, smpi_data_exe_copy, smpi_data_exe_size);
+
+ // store the address of the mapping for further switches
+ smpi_privatization_regions.emplace_back(s_smpi_privatization_region_t{address, file_descriptor});
+
+ return &smpi_privatization_regions.back();