- for (size_t i = 0; i != NB_REGIONS; ++i) {
- mc_mem_region_t region = snapshot->regions[i];
- void* start = region->start_addr;
- void* end = (char*) start + region->size;
-
- if (addr >= start && addr < end) {
- return region;
+ size_t n = snapshot->snapshot_regions_count;
+ for (size_t i = 0; i != n; ++i) {
+ mc_mem_region_t region = snapshot->snapshot_regions[i];
+ if (!(region && mc_region_contain(region, addr)))
+ continue;
+
+ if (region->storage_type == MC_REGION_STORAGE_TYPE_PRIVATIZED) {
+#ifdef HAVE_SMPI
+ // Use the current process index of the snapshot:
+ if (process_index == MC_PROCESS_INDEX_DISABLED) {
+ process_index = snapshot->privatization_index;
+ }
+ if (process_index < 0) {
+ xbt_die("Missing process index");
+ }
+ if (process_index >= region->privatized.regions_count) {
+ xbt_die("Invalid process index");
+ }
+ mc_mem_region_t priv_region = region->privatized.regions[process_index];
+ xbt_assert(mc_region_contain(priv_region, addr));
+ return priv_region;
+#else
+ xbt_die("Privatized region in a non SMPI build (this should not happen)");
+#endif