Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remote support for filling state->internal_comm
[simgrid.git] / src / mc / mc_memory.c
1 /* Copyright (c) 2008-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include <sys/stat.h>
8 #include <fcntl.h>
9
10 #include "xbt/log.h"
11 #include "xbt/dynar.h"
12 #include "xbt/virtu.h"
13
14 #include "mc/mc.h"
15 #include "mc_object_info.h"
16 #include "mc_private.h"
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_memory, mc,
19                                 "Logging specific to MC (memory)");
20
21 /* Pointers to each of the heap regions to use */
22 xbt_mheap_t std_heap = NULL;          /* memory erased each time the MC stuff rollbacks to the beginning. Almost everything goes here */
23 xbt_mheap_t mc_heap = NULL;           /* memory persistent over the MC rollbacks. Only MC stuff should go there */
24
25 /* Initialize the model-checker memory subsystem */
26 /* It creates the two heap regions: std_heap and mc_heap */
27 void MC_memory_init()
28 {
29   if (!malloc_use_mmalloc()) {
30     xbt_die("Model-checking support is not enabled: run with simgrid-mc.");
31   }
32
33   /* Create the first region HEAP_OFFSET bytes after the heap break address */
34   std_heap = mmalloc_get_default_md();
35   xbt_assert(std_heap != NULL);
36
37   /* Create the second region a page after the first one ends + safety gap */
38   mc_heap =
39       xbt_mheap_new_options(-1,
40                             (char *) (std_heap) + STD_HEAP_SIZE + xbt_pagesize,
41                             0);
42   xbt_assert(mc_heap != NULL);
43 }
44
45 /* Finalize the memory subsystem */
46 #include "xbt_modinter.h"
47 void MC_memory_exit(void)
48 {
49   if (mc_heap && mc_heap != std_heap)
50     xbt_mheap_destroy(mc_heap);
51 }