Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Cleanup mc_ignore/mcer_ignore
[simgrid.git] / src / mc / mc_ignore.cpp
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 "internal_config.h"
8 #include "mc_object_info.h"
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   s_mc_heap_ignore_region_t region;
29   memset(&region, 0, sizeof(region));
30   region.address = address;
31   region.size = size;
32   region.block =
33    ((char *) address -
34     (char *) std_heap->heapbase) / BLOCKSIZE + 1;
35   if (std_heap->heapinfo[region.block].type == 0) {
36     region.fragment = -1;
37     std_heap->heapinfo[region.block].busy_block.ignore++;
38   } else {
39     region.fragment =
40         ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap->
41         heapinfo[region.block].type;
42     std_heap->heapinfo[region.block].busy_frag.ignore[region.fragment]++;
43   }
44
45   s_mc_ignore_heap_message_t message;
46   message.type = MC_MESSAGE_IGNORE_HEAP;
47   message.region = region;
48   if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
49     xbt_die("Could not send ignored region to MCer");
50 }
51
52 void MC_remove_ignore_heap(void *address, size_t size)
53 {
54   if (mc_mode != MC_MODE_CLIENT)
55     return;
56
57   s_mc_ignore_memory_message_t message;
58   message.type = MC_MESSAGE_UNIGNORE_HEAP;
59   message.addr = address;
60   message.size = size;
61   MC_client_send_message(&message, sizeof(message));
62 }
63
64 void MC_ignore_global_variable(const char *name)
65 {
66   // TODO, send a message to the model_checker
67   xbt_die("Unimplemented");
68 }
69
70 // *****
71
72 extern xbt_dynar_t stacks_areas;
73
74 void MC_stack_area_add(stack_region_t stack_area)
75 {
76   if (stacks_areas == NULL)
77     stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
78   xbt_dynar_push(stacks_areas, &stack_area);
79 }
80
81 /** @brief Register a stack in the model checker
82  *
83  *  The stacks are allocated in the heap. The MC handle them especially
84  *  when we analyse/compare the content of the heap so it must be told where
85  *  they are with this function.
86  *
87  *  @param stack
88  *  @param process Process owning the stack
89  *  @param context
90  *  @param size    Size of the stack
91  */
92 void MC_new_stack_area(void *stack, smx_process_t process, void *context, size_t size)
93 {
94   xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
95
96   stack_region_t region = xbt_new0(s_stack_region_t, 1);
97   region->address = stack;
98   region->context = context;
99   region->size = size;
100   region->block =
101       ((char *) stack -
102        (char *) std_heap->heapbase) / BLOCKSIZE + 1;
103 #ifdef HAVE_SMPI
104   if (smpi_privatize_global_variables && process) {
105     region->process_index = smpi_process_index_of_smx_process(process);
106   } else
107 #endif
108   region->process_index = -1;
109
110   if (mc_mode == MC_MODE_CLIENT) {
111     s_mc_stack_region_message_t message;
112     message.type = MC_MESSAGE_STACK_REGION;
113     message.stack_region = *region;
114     MC_client_send_message(&message, sizeof(message));
115   }
116
117   MC_stack_area_add(region);
118
119   mmalloc_set_current_heap(heap);
120 }
121
122 }