Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8ae16f464e26afd4437ba81c3f439ee06776eba6
[simgrid.git] / src / mc / mc_ignore.cpp
1 /* Copyright (c) 2008-2015. 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 "internal_config.h"
8 #include "mc_dwarf.hpp"
9 #include "mc_private.h"
10 #include "smpi/private.h"
11 #include "mc/mc_snapshot.h"
12 #include "mc_ignore.h"
13 #include "mc_protocol.h"
14 #include "mc_client.h"
15
16 extern "C" {
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc,
19                                 "Logging specific to MC ignore mechanism");
20
21 // ***** Model-checked
22
23 void MC_ignore_heap(void *address, size_t size)
24 {
25   if (mc_mode != MC_MODE_CLIENT)
26     return;
27
28   xbt_mheap_t heap = mmalloc_get_current_heap();
29
30   s_mc_heap_ignore_region_t region;
31   memset(&region, 0, sizeof(region));
32   region.address = address;
33   region.size = size;
34   region.block =
35    ((char *) address -
36     (char *) heap->heapbase) / BLOCKSIZE + 1;
37   if (heap->heapinfo[region.block].type == 0) {
38     region.fragment = -1;
39     heap->heapinfo[region.block].busy_block.ignore++;
40   } else {
41     region.fragment =
42         ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >>
43         heap->heapinfo[region.block].type;
44     heap->heapinfo[region.block].busy_frag.ignore[region.fragment]++;
45   }
46
47   s_mc_ignore_heap_message_t message;
48   message.type = MC_MESSAGE_IGNORE_HEAP;
49   message.region = region;
50   if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
51     xbt_die("Could not send ignored region to MCer");
52 }
53
54 void MC_remove_ignore_heap(void *address, size_t size)
55 {
56   if (mc_mode != MC_MODE_CLIENT)
57     return;
58
59   s_mc_ignore_memory_message_t message;
60   message.type = MC_MESSAGE_UNIGNORE_HEAP;
61   message.addr = (std::uintptr_t) address;
62   message.size = size;
63   MC_client_send_message(&message, sizeof(message));
64 }
65
66 void MC_ignore_global_variable(const char *name)
67 {
68   // TODO, send a message to the model_checker
69   xbt_die("Unimplemented");
70 }
71
72 /** @brief Register a stack in the model checker
73  *
74  *  The stacks are allocated in the heap. The MC handle them especially
75  *  when we analyse/compare the content of the heap so it must be told where
76  *  they are with this function.
77  *
78  *  @param stack
79  *  @param process Process owning the stack
80  *  @param context
81  *  @param size    Size of the stack
82  */
83 void MC_register_stack_area(void *stack, smx_process_t process, void *context, size_t size)
84 {
85   if (mc_mode != MC_MODE_CLIENT)
86     return;
87
88   xbt_mheap_t heap = mmalloc_get_current_heap();
89
90   s_stack_region_t region;
91   memset(&region, 0, sizeof(region));
92   region.address = stack;
93   region.context = context;
94   region.size = size;
95   region.block =
96       ((char *) stack -
97        (char *) heap->heapbase) / BLOCKSIZE + 1;
98 #ifdef HAVE_SMPI
99   if (smpi_privatize_global_variables && process) {
100     region.process_index = smpi_process_index_of_smx_process(process);
101   } else
102 #endif
103   region.process_index = -1;
104
105   s_mc_stack_region_message_t message;
106   message.type = MC_MESSAGE_STACK_REGION;
107   message.stack_region = region;
108   MC_client_send_message(&message, sizeof(message));
109 }
110
111 }