Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
46b70965a30152fc3e31ffd5ba24df9135279bd8
[simgrid.git] / src / mc / mc_checkpoint.c
1 /* Copyright (c) 2008-2012 Da 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 #include <libgen.h>
7 #include "mc_private.h"
8 #include "xbt/module.h"
9
10 #include "../simix/smx_private.h"
11
12 #include <libunwind.h>
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
15                                 "Logging specific to mc_checkpoint");
16
17 void *start_text_libsimgrid;
18 void *start_plt_libsimgrid, *end_plt_libsimgrid;
19 void *start_got_plt_libsimgrid, *end_got_plt_libsimgrid;
20 void *start_plt_binary, *end_plt_binary;
21 void *start_got_plt_binary, *end_got_plt_binary;
22 char *libsimgrid_path;
23 void *start_data_libsimgrid, *start_bss_libsimgrid;
24 void *start_data_binary, *start_bss_binary;
25 void *start_text_binary;
26
27 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size);
28 static void MC_region_restore(mc_mem_region_t reg);
29 static void MC_region_destroy(mc_mem_region_t reg);
30
31 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size);
32
33 static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val);
34 static xbt_dynar_t take_snapshot_stacks(mc_snapshot_t *s, void *heap);
35 static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap);
36 static void print_local_variables_values(xbt_dynar_t all_variables);
37 static void *get_stack_pointer(void *stack_context, void *heap);
38
39 static void snapshot_stack_free(mc_snapshot_stack_t s);
40 static xbt_dynar_t take_snapshot_ignore(void);
41
42 static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size)
43 {
44   mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1);
45   new_reg->start_addr = start_addr;
46   new_reg->size = size;
47   new_reg->data = xbt_malloc0(size);
48   memcpy(new_reg->data, start_addr, size);
49
50   XBT_DEBUG("New region : type : %d, data : %p (real addr %p), size : %zu", type, new_reg->data, start_addr, size);
51   
52   return new_reg;
53 }
54
55 static void MC_region_restore(mc_mem_region_t reg)
56 {
57   /*FIXME: check if start_addr is still mapped, if it is not, then map it
58     before copying the data */
59  
60   memcpy(reg->start_addr, reg->data, reg->size);
61  
62   return;
63 }
64
65 static void MC_region_destroy(mc_mem_region_t reg)
66 {
67   xbt_free(reg->data);
68   xbt_free(reg);
69 }
70
71 static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size)
72 {
73   mc_mem_region_t new_reg = MC_region_new(type, start_addr, size);
74   snapshot->regions[type] = new_reg;
75   return;
76
77
78 void MC_init_memory_map_info(){
79
80   int raw_mem_set = (mmalloc_get_current_heap() == raw_heap);
81
82   MC_SET_RAW_MEM;
83   
84   unsigned int i = 0;
85   s_map_region_t reg;
86   memory_map_t maps = get_memory_map();
87
88   while (i < maps->mapsize) {
89     reg = maps->regions[i];
90     if ((reg.prot & PROT_WRITE)){
91       if (maps->regions[i].pathname != NULL){
92         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
93           start_data_libsimgrid = reg.start_addr;
94           i++;
95           reg = maps->regions[i];
96           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize)
97             start_bss_libsimgrid = reg.start_addr;
98         }else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
99           start_data_binary = reg.start_addr;
100           i++;
101           reg = maps->regions[i];
102           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && reg.start_addr != std_heap && reg.start_addr != raw_heap && i < maps->mapsize){
103             start_bss_binary = reg.start_addr;
104             i++;
105           }
106         }else if(!memcmp(maps->regions[i].pathname, "[stack]", 7)){
107           maestro_stack_start = reg.start_addr;
108           maestro_stack_end = reg.end_addr;
109           i++;
110         }
111       }
112     }else if ((reg.prot & PROT_READ) && (reg.prot & PROT_EXEC)){
113       if (maps->regions[i].pathname != NULL){
114         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
115           start_text_libsimgrid = reg.start_addr;
116           libsimgrid_path = strdup(maps->regions[i].pathname);
117         }else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
118           start_text_binary = reg.start_addr;
119         }
120       }
121     }
122     i++;
123   }
124   
125   free_memory_map(maps);
126
127   MC_UNSET_RAW_MEM;
128
129   if(raw_mem_set)
130     MC_SET_RAW_MEM;
131
132 }
133
134 mc_snapshot_t SIMIX_pre_mc_snapshot(smx_simcall_t simcall){
135   return MC_take_snapshot();
136 }
137
138 mc_snapshot_t MC_take_snapshot()
139 {
140   int raw_mem = (mmalloc_get_current_heap() == raw_heap);
141   
142   MC_SET_RAW_MEM;
143
144   mc_snapshot_t snapshot = xbt_new0(s_mc_snapshot_t, 1);
145   snapshot->nb_processes = xbt_swag_size(simix_global->process_list);
146
147   unsigned int i = 0;
148   s_map_region_t reg;
149   memory_map_t maps = get_memory_map();
150   void *heap = NULL;
151   size_t size = 0;
152   void *start = NULL;
153
154   /* Save the std heap and the writable mapped pages of libsimgrid */
155   while (i < maps->mapsize) {
156     reg = maps->regions[i];
157     if ((reg.prot & PROT_WRITE)){
158       if (maps->regions[i].pathname == NULL){
159         if (reg.start_addr == std_heap){ // only save the std heap (and not the raw one)
160           MC_snapshot_add_region(snapshot, 0, reg.start_addr, (char*)reg.end_addr - (char*)reg.start_addr);
161           snapshot->heap_bytes_used = mmalloc_get_bytes_used(std_heap);
162           heap = snapshot->regions[0]->data;
163         }
164         i++;
165       } else{ 
166         if (!memcmp(basename(maps->regions[i].pathname), "libsimgrid", 10)){
167           size = (char*)reg.end_addr - (char*)reg.start_addr;
168           start = reg.start_addr;
169           i++;
170           reg = maps->regions[i];
171           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && i < maps->mapsize){
172             size += (char*)reg.end_addr - (char*)reg.start_addr;
173             reg = maps->regions[i];
174             i++;
175           }
176           MC_snapshot_add_region(snapshot, 1, start, size);
177         }else if(!memcmp(maps->regions[i].pathname, "[stack]", 7)){
178           maestro_stack_start = reg.start_addr;
179           maestro_stack_end = reg.end_addr;
180           i++;
181         } else if (!memcmp(basename(maps->regions[i].pathname), basename(xbt_binary_name), strlen(basename(xbt_binary_name)))){
182           size = (char*)reg.end_addr - (char*)reg.start_addr;
183           start = reg.start_addr;
184           i++;
185           reg = maps->regions[i];
186           if(reg.pathname == NULL && (reg.prot & PROT_WRITE) && reg.start_addr != std_heap && reg.start_addr != raw_heap && i < maps->mapsize){
187             size += (char*)reg.end_addr - (char*)reg.start_addr;
188             reg = maps->regions[i];
189             i++;
190           }
191           MC_snapshot_add_region(snapshot, 2, start, size);
192         }else{
193           i++;
194         }
195       }
196     }else{
197       i++;
198     }
199   }
200
201   snapshot->to_ignore = take_snapshot_ignore();
202
203   if(_sg_mc_visited > 0 || strcmp(_sg_mc_property_file,""))
204     snapshot->stacks = take_snapshot_stacks(&snapshot, heap);
205   
206   free_memory_map(maps);
207
208   MC_UNSET_RAW_MEM;
209
210   if(raw_mem)
211     MC_SET_RAW_MEM;
212
213   return snapshot;
214
215 }
216
217 void MC_restore_snapshot(mc_snapshot_t snapshot)
218 {
219   unsigned int i;
220   for(i=0; i < NB_REGIONS; i++){
221     MC_region_restore(snapshot->regions[i]);
222   }
223
224 }
225
226 void MC_free_snapshot(mc_snapshot_t snapshot)
227 {
228   unsigned int i;
229   for(i=0; i < NB_REGIONS; i++)
230     MC_region_destroy(snapshot->regions[i]);
231
232   xbt_dynar_free(&(snapshot->stacks));
233   xbt_dynar_free(&(snapshot->to_ignore));
234   xbt_free(snapshot);
235 }
236
237
238 void get_libsimgrid_plt_section(){
239
240   FILE *fp;
241   char *line = NULL;            /* Temporal storage for each line that is readed */
242   ssize_t read;                 /* Number of bytes readed */
243   size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
244
245   char *lfields[7];
246   int i, plt_found = 0;
247   unsigned long int size, offset;
248
249   char *command = bprintf("objdump --section-headers %s", libsimgrid_path);
250
251   fp = popen(command, "r");
252
253   if(fp == NULL){
254     perror("popen failed");
255     xbt_abort();
256   }
257
258   while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
259
260     if(n == 0)
261       continue;
262
263     /* Wipeout the new line character */
264     line[read - 1] = '\0';
265
266     lfields[0] = strtok(line, " ");
267
268     if(lfields[0] == NULL)
269       continue;
270
271     if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], libsimgrid_path, strlen(libsimgrid_path)) == 0)
272       continue;
273
274     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
275       lfields[i] = strtok(NULL, " ");
276     }
277
278     if(i>=6){
279       if(strcmp(lfields[1], ".plt") == 0){
280         size = strtoul(lfields[2], NULL, 16);
281         offset = strtoul(lfields[5], NULL, 16);
282         start_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
283         end_plt_libsimgrid = (char *)start_plt_libsimgrid + size;
284         plt_found++;
285       }else if(strcmp(lfields[1], ".got.plt") == 0){
286         size = strtoul(lfields[2], NULL, 16);
287         offset = strtoul(lfields[5], NULL, 16);
288         start_got_plt_libsimgrid = (char *)start_text_libsimgrid + offset;
289         end_got_plt_libsimgrid = (char *)start_got_plt_libsimgrid + size;
290         plt_found++;
291        }
292
293     }
294     
295   }
296
297   xbt_free(command);
298   xbt_free(line);
299   pclose(fp);
300
301 }
302
303 void get_binary_plt_section(){
304
305   FILE *fp;
306   char *line = NULL;            /* Temporal storage for each line that is readed */
307   ssize_t read;                 /* Number of bytes readed */
308   size_t n = 0;                 /* Amount of bytes to read by xbt_getline */
309
310   char *lfields[7];
311   int i, plt_found = 0;
312   unsigned long int size;
313
314   char *command = bprintf( "objdump --section-headers %s", xbt_binary_name);
315
316   fp = popen(command, "r");
317
318   if(fp == NULL){
319     perror("popen failed");
320     xbt_abort();
321   }
322
323   while ((read = xbt_getline(&line, &n, fp)) != -1 && plt_found != 2) {
324
325     if(n == 0)
326       continue;
327
328     /* Wipeout the new line character */
329     line[read - 1] = '\0';
330
331     lfields[0] = strtok(line, " ");
332
333     if(lfields[0] == NULL)
334       continue;
335
336     if(strcmp(lfields[0], "Sections:") == 0 || strcmp(lfields[0], "Idx") == 0 || strncmp(lfields[0], basename(xbt_binary_name), strlen(xbt_binary_name)) == 0)
337       continue;
338
339     for (i = 1; i < 7 && lfields[i - 1] != NULL; i++) {
340       lfields[i] = strtok(NULL, " ");
341     }
342
343     if(i>=6){
344       if(strcmp(lfields[1], ".plt") == 0){
345         size = strtoul(lfields[2], NULL, 16);
346         start_plt_binary = (void *)strtoul(lfields[3], NULL, 16);
347         end_plt_binary = (char *)start_plt_binary + size;
348         plt_found++;
349       }else if(strcmp(lfields[1], ".got.plt") == 0){
350         size = strtoul(lfields[2], NULL, 16);
351         start_got_plt_binary = (char *)strtoul(lfields[3], NULL, 16);
352         end_got_plt_binary = (char *)start_got_plt_binary + size;
353         plt_found++;
354        }
355     }
356     
357     
358   }
359
360   xbt_free(command);
361   xbt_free(line);
362   pclose(fp);
363
364 }
365
366 static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val){
367   variable_value_t value = xbt_new0(s_variable_value_t, 1);
368   value->type = strdup(type);
369   if(strcmp(type, "value") == 0){
370     value->value.res = val;
371   }else{
372     value->value.address = (void *)val;
373   }
374   xbt_dynar_push(*list, &value);
375 }
376
377 static xbt_dynar_t take_snapshot_stacks(mc_snapshot_t *snapshot, void *heap){
378
379   xbt_dynar_t res = xbt_dynar_new(sizeof(s_mc_snapshot_stack_t), snapshot_stack_free_voidp);
380
381   unsigned int cursor = 0;
382   stack_region_t current_stack;
383   
384   xbt_dynar_foreach(stacks_areas, cursor, current_stack){
385     mc_snapshot_stack_t st = xbt_new(s_mc_snapshot_stack_t, 1);
386     st->local_variables = get_local_variables_values(current_stack->context, heap);
387     st->stack_pointer = get_stack_pointer(current_stack->context, heap);
388     xbt_dynar_push(res, &st);
389     (*snapshot)->stack_sizes = xbt_realloc((*snapshot)->stack_sizes, (cursor + 1) * sizeof(size_t));
390     (*snapshot)->stack_sizes[cursor] = current_stack->size - ((char *)st->stack_pointer - (char *)((char *)heap + ((char *)current_stack->address - (char *)std_heap)));
391   }
392
393   return res;
394
395 }
396
397 static void *get_stack_pointer(void *stack_context, void *heap){
398
399   unw_cursor_t c;
400   int ret;
401   unw_word_t sp;
402
403   ret = unw_init_local(&c, (unw_context_t *)stack_context);
404   if(ret < 0){
405     XBT_INFO("unw_init_local failed");
406     xbt_abort();
407   }
408
409   unw_get_reg(&c, UNW_REG_SP, &sp);
410
411   return ((char *)heap + (size_t)(((char *)((long)sp) - (char*)std_heap)));
412
413 }
414
415 static xbt_strbuff_t get_local_variables_values(void *stack_context, void *heap){
416   
417   unw_cursor_t c;
418   int ret;
419
420   char frame_name[256];
421   
422   ret = unw_init_local(&c, (unw_context_t *)stack_context);
423   if(ret < 0){
424     XBT_INFO("unw_init_local failed");
425     xbt_abort();
426   }
427
428   unw_word_t ip, sp, off;
429   dw_frame_t frame;
430  
431   xbt_dynar_t compose = xbt_dynar_new(sizeof(variable_value_t), variable_value_free_voidp);
432
433   xbt_strbuff_t variables = xbt_strbuff_new();
434   xbt_dict_cursor_t dict_cursor;
435   char *variable_name;
436   dw_local_variable_t current_variable;
437   unsigned int cursor = 0, cursor2 = 0;
438   dw_location_entry_t entry = NULL;
439   dw_location_t location_entry = NULL;
440   unw_word_t res;
441   int frame_found = 0;
442   void *frame_pointer_address = NULL;
443   long true_ip;
444   char *to_append;
445
446   while(ret >= 0){
447
448     unw_get_reg(&c, UNW_REG_IP, &ip);
449     unw_get_reg(&c, UNW_REG_SP, &sp);
450
451     unw_get_proc_name(&c, frame_name, sizeof (frame_name), &off);
452
453     frame = xbt_dict_get_or_null(mc_local_variables, frame_name);
454
455     if(frame == NULL){
456       xbt_dynar_free(&compose);
457       xbt_dict_cursor_free(&dict_cursor);
458       return variables;
459     }
460
461     to_append = bprintf("ip=%lx\n", ip);
462     xbt_strbuff_append(variables, to_append);
463     xbt_free(to_append);
464     to_append = bprintf("frame_name=%s\n", frame_name);
465     xbt_strbuff_append(variables, to_append);
466     xbt_free(to_append);
467
468     true_ip = (long)frame->low_pc + (long)off;
469
470     /* Get frame pointer */
471     switch(frame->frame_base->type){
472     case e_dw_loclist:
473       while((cursor < xbt_dynar_length(frame->frame_base->location.loclist)) && frame_found == 0){
474         entry = xbt_dynar_get_as(frame->frame_base->location.loclist, cursor, dw_location_entry_t);
475         if((true_ip >= entry->lowpc) && (true_ip < entry->highpc)){
476           frame_found = 1;
477           switch(entry->location->type){
478           case e_dw_compose:
479             xbt_dynar_reset(compose);
480             cursor2 = 0;
481             while(cursor2 < xbt_dynar_length(entry->location->location.compose)){
482               location_entry = xbt_dynar_get_as(entry->location->location.compose, cursor2, dw_location_t);
483               switch(location_entry->type){
484               case e_dw_register:
485                 unw_get_reg(&c, location_entry->location.reg, &res);
486                 add_value(&compose, "address", (long)res);
487                 break;
488               case e_dw_bregister_op:
489                 unw_get_reg(&c, location_entry->location.breg_op.reg, &res);
490                 add_value(&compose, "address", (long)res + location_entry->location.breg_op.offset);
491                 break;
492               default:
493                 xbt_dynar_reset(compose);
494                 break;
495               }
496               cursor2++;
497             }
498
499             if(!xbt_dynar_is_empty(compose)){
500               frame_pointer_address = xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address ; 
501             }
502             break;
503           default :
504             frame_pointer_address = NULL;
505             break;
506           }
507         }
508         cursor++;
509       }
510       break;
511     default :
512       frame_pointer_address = NULL;
513       break;
514     }
515
516     frame_found = 0;
517     cursor = 0;
518
519     xbt_dict_foreach(frame->variables, dict_cursor, variable_name, current_variable){
520       if(current_variable->location != NULL){
521         switch(current_variable->location->type){
522         case e_dw_compose:
523           xbt_dynar_reset(compose);
524           cursor = 0;
525           while(cursor < xbt_dynar_length(current_variable->location->location.compose)){
526             location_entry = xbt_dynar_get_as(current_variable->location->location.compose, cursor, dw_location_t);
527             switch(location_entry->type){
528             case e_dw_register:
529               unw_get_reg(&c, location_entry->location.reg, &res);
530               add_value(&compose, "value", (long)res);
531               break;
532             case e_dw_bregister_op:
533               unw_get_reg(&c, location_entry->location.breg_op.reg, &res);
534               add_value(&compose, "address", (long)res + location_entry->location.breg_op.offset);
535               break;
536             case e_dw_fbregister_op:
537               if(frame_pointer_address != NULL)
538                 add_value(&compose, "address", (long)((char *)frame_pointer_address + location_entry->location.fbreg_op));
539               break;
540             default:
541               xbt_dynar_reset(compose);
542               break;
543             }
544             cursor++;
545           }
546           
547           if(!xbt_dynar_is_empty(compose)){
548             if(strcmp(xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->type, "value") == 0){
549               to_append = bprintf("%s=%lx\n", current_variable->name, xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.res);
550               xbt_strbuff_append(variables, to_append);
551               xbt_free(to_append);
552             }else{
553               if((long)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address < 0 || *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) == NULL){
554                 to_append = bprintf("%s=NULL\n", current_variable->name);
555                 xbt_strbuff_append(variables, to_append);
556                 xbt_free(to_append);
557               }else if(((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) > 0xffffffff) || ((long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1,variable_value_t)->value.address) < (long)start_text_binary)){
558                 to_append = bprintf("%s=%u\n", current_variable->name, (unsigned int)(long)*((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));
559                 xbt_strbuff_append(variables, to_append);
560                 xbt_free(to_append);
561               }else{ 
562                 to_append = bprintf("%s=%p\n", current_variable->name, *((void**)xbt_dynar_get_as(compose, xbt_dynar_length(compose) - 1, variable_value_t)->value.address));
563                 xbt_strbuff_append(variables, to_append);
564                 xbt_free(to_append);
565               }
566             }
567           }else{
568             to_append = bprintf("%s=undefined\n", current_variable->name);
569             xbt_strbuff_append(variables, to_append);
570             xbt_free(to_append);
571           }
572           break;
573         default :
574           break;
575         }
576       }else{
577         to_append = bprintf("%s=undefined\n", current_variable->name);
578         xbt_strbuff_append(variables, to_append);
579         xbt_free(to_append);
580       }
581     }    
582  
583     ret = unw_step(&c);
584      
585   }
586
587   xbt_dynar_free(&compose);
588   xbt_dict_cursor_free(&dict_cursor);
589
590   return variables;
591
592 }
593
594 static void print_local_variables_values(xbt_dynar_t all_variables){
595
596   unsigned cursor = 0;
597   mc_snapshot_stack_t stack;
598
599   xbt_dynar_foreach(all_variables, cursor, stack){
600     XBT_INFO("%s", stack->local_variables->data);
601   }
602 }
603
604
605 static void snapshot_stack_free(mc_snapshot_stack_t s){
606   if(s){
607     xbt_free(s->local_variables->data);
608     xbt_free(s->local_variables);
609     xbt_free(s);
610   }
611 }
612
613 void snapshot_stack_free_voidp(void *s){
614   snapshot_stack_free((mc_snapshot_stack_t) * (void **) s);
615 }
616
617 void *MC_snapshot(void){
618
619   return simcall_mc_snapshot();
620   
621 }
622
623 void variable_value_free(variable_value_t v){
624   if(v){
625     xbt_free(v->type);
626     xbt_free(v);
627   }
628 }
629
630 void variable_value_free_voidp(void* v){
631   variable_value_free((variable_value_t) * (void **)v);
632 }
633
634 static xbt_dynar_t take_snapshot_ignore(){
635   
636   if(mc_heap_comparison_ignore == NULL)
637     return NULL;
638
639   xbt_dynar_t cpy = xbt_dynar_new(sizeof(mc_heap_ignore_region_t), heap_ignore_region_free_voidp);
640
641   unsigned int cursor = 0;
642   mc_heap_ignore_region_t current_region;
643
644   xbt_dynar_foreach(mc_heap_comparison_ignore, cursor, current_region){
645     mc_heap_ignore_region_t new_region = NULL;
646     new_region = xbt_new0(s_mc_heap_ignore_region_t, 1);
647     new_region->address = current_region->address;
648     new_region->size = current_region->size;
649     new_region->block = current_region->block;
650     new_region->fragment = current_region->fragment;
651     xbt_dynar_push(cpy, &new_region);
652   }
653
654   return cpy;
655
656 }