Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : MUTEX_UNLOCK is invisible for MC
[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
12 #include "mc/mc.h"
13 #include "mc_object_info.h"
14 #include "mc_private.h"
15
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_memory, mc,
17                                 "Logging specific to MC (memory)");
18
19 /* Pointers to each of the heap regions to use */
20 xbt_mheap_t std_heap = NULL;          /* memory erased each time the MC stuff rollbacks to the beginning. Almost everything goes here */
21 xbt_mheap_t mc_heap = NULL;           /* memory persistent over the MC rollbacks. Only MC stuff should go there */
22
23 /* Initialize the model-checker memory subsystem */
24 /* It creates the two heap regions: std_heap and mc_heap */
25 void MC_memory_init()
26 {
27   /* Create the first region HEAP_OFFSET bytes after the heap break address */
28   std_heap = mmalloc_get_default_md();
29   xbt_assert(std_heap != NULL);
30
31 #if 0 && defined HAVE_GNU_LD && !defined MMALLOC_WANT_OVERRIDE_LEGACY
32   /* use the system malloc for the model-checker data */
33   mc_heap = NULL;
34 #else
35   /* Create the second region a page after the first one ends + safety gap */
36   mc_heap =
37       xbt_mheap_new_options(-1,
38                             (char *) (std_heap) + STD_HEAP_SIZE + xbt_pagesize,
39                             0);
40   xbt_assert(mc_heap != NULL);
41 #endif
42 }
43
44 /* Finalize the memory subsystem */
45 #include "xbt_modinter.h"
46 void MC_memory_exit(void)
47 {
48   MC_free_object_info(&mc_binary_info);
49   MC_free_object_info(&mc_libsimgrid_info);
50
51   if (mc_heap)
52     xbt_mheap_destroy(mc_heap);
53 }