Logo AND Algorithmique Numérique Distribuée

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