/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "internal_config.h"
+#include "mc_object_info.h"
#include "mc_private.h"
+#include "smpi/private.h"
+#include "mc/mc_snapshot.h"
+#include "mc_ignore.h"
+#include "mc_protocol.h"
+#include "mc_client.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc,
"Logging specific to MC ignore mechanism");
/**************************** Global variables ******************************/
-xbt_dynar_t mc_checkpoint_ignore;
+// Those structures live with the MCer and should be moved in the model_checker
+// structure but they are currently used before the MC initialisation
+// (in standalone mode).
+
extern xbt_dynar_t mc_heap_comparison_ignore;
extern xbt_dynar_t stacks_areas;
checkpoint_ignore_region_free((mc_checkpoint_ignore_region_t) * (void **) r);
}
-/***********************************************************************/
-
-void MC_ignore_heap(void *address, size_t size)
+xbt_dynar_t MC_checkpoint_ignore_new(void)
{
+ return xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t),
+ checkpoint_ignore_region_free_voidp);
+}
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
- MC_SET_MC_HEAP;
-
- mc_heap_ignore_region_t region = NULL;
- region = xbt_new0(s_mc_heap_ignore_region_t, 1);
- region->address = address;
- region->size = size;
-
- region->block =
- ((char *) address -
- (char *) ((xbt_mheap_t) std_heap)->heapbase) / BLOCKSIZE + 1;
-
- if (((xbt_mheap_t) std_heap)->heapinfo[region->block].type == 0) {
- region->fragment = -1;
- ((xbt_mheap_t) std_heap)->heapinfo[region->block].busy_block.ignore++;
- } else {
- region->fragment =
- ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> ((xbt_mheap_t)
- std_heap)->
- heapinfo[region->block].type;
- ((xbt_mheap_t) std_heap)->heapinfo[region->block].busy_frag.ignore[region->
- fragment]++;
- }
+/***********************************************************************/
+// Mcer
+void MC_heap_region_ignore_insert(mc_heap_ignore_region_t region)
+{
if (mc_heap_comparison_ignore == NULL) {
mc_heap_comparison_ignore =
xbt_dynar_new(sizeof(mc_heap_ignore_region_t),
heap_ignore_region_free_voidp);
xbt_dynar_push(mc_heap_comparison_ignore, ®ion);
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
return;
}
int start = 0;
int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
+ // Find the position where we want to insert the mc_heap_ignore_region_t:
while (start <= end) {
cursor = (start + end) / 2;
current_region =
(mc_heap_ignore_region_t) xbt_dynar_get_as(mc_heap_comparison_ignore,
cursor,
mc_heap_ignore_region_t);
- if (current_region->address == address) {
+ if (current_region->address == region->address) {
heap_ignore_region_free(region);
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
return;
- } else if (current_region->address < address) {
+ } else if (current_region->address < region->address) {
start = cursor + 1;
} else {
end = cursor - 1;
}
}
- if (current_region->address < address)
+ // Insert it mc_heap_ignore_region_t:
+ if (current_region->address < region->address)
xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor + 1, ®ion);
else
xbt_dynar_insert_at(mc_heap_comparison_ignore, cursor, ®ion);
+}
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
+// MCed:
+static void MC_heap_region_ignore_send(mc_heap_ignore_region_t region)
+{
+ s_mc_ignore_heap_message_t message;
+ message.type = MC_MESSAGE_IGNORE_HEAP;
+ message.region = *region;
+ if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
+ xbt_die("Could not send ignored region to MCer");
}
-void MC_remove_ignore_heap(void *address, size_t size)
+// MCed:
+void MC_ignore_heap(void *address, size_t size)
{
+ xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+
+ mc_heap_ignore_region_t region = xbt_new0(s_mc_heap_ignore_region_t, 1);
+ region->address = address;
+ region->size = size;
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
+ region->block =
+ ((char *) address -
+ (char *) std_heap->heapbase) / BLOCKSIZE + 1;
+
+ if (std_heap->heapinfo[region->block].type == 0) {
+ region->fragment = -1;
+ std_heap->heapinfo[region->block].busy_block.ignore++;
+ } else {
+ region->fragment =
+ ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >> std_heap->
+ heapinfo[region->block].type;
+ std_heap->heapinfo[region->block].busy_frag.ignore[region->fragment]++;
+ }
+
+ MC_heap_region_ignore_insert(region);
+
+#if 1
+ if (mc_mode == MC_MODE_CLIENT)
+ MC_heap_region_ignore_send(region);
+#endif
+ mmalloc_set_current_heap(heap);
+}
+
+void MC_remove_ignore_heap(void *address, size_t size)
+{
+ if (mc_mode == MC_MODE_CLIENT) {
+ s_mc_ignore_memory_message_t message;
+ message.type = MC_MESSAGE_UNIGNORE_HEAP;
+ message.addr = address;
+ message.size = size;
+ MC_client_send_message(&message, sizeof(message));
+ }
- MC_SET_MC_HEAP;
+ xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
unsigned int cursor = 0;
int start = 0;
xbt_dynar_remove_at(mc_heap_comparison_ignore, cursor, NULL);
MC_remove_ignore_heap(address, size);
}
-
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
-
+ mmalloc_set_current_heap(heap);
}
+// MCer
void MC_ignore_global_variable(const char *name)
{
+ mc_process_t process = &mc_model_checker->process;
+ xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+ xbt_assert(process->object_infos, "MC subsystem not initialized");
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
- MC_SET_MC_HEAP;
+ size_t n = process->object_infos_size;
+ for (size_t i=0; i!=n; ++i) {
+ mc_object_info_t info = process->object_infos[i];
- xbt_assert(mc_libsimgrid_info, "MC subsystem not initialized");
-
- unsigned int cursor = 0;
- dw_variable_t current_var;
- int start = 0;
- int end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
-
- while (start <= end) {
- cursor = (start + end) / 2;
- current_var =
- (dw_variable_t) xbt_dynar_get_as(mc_libsimgrid_info->global_variables,
- cursor, dw_variable_t);
- if (strcmp(current_var->name, name) == 0) {
- xbt_dynar_remove_at(mc_libsimgrid_info->global_variables, cursor, NULL);
- start = 0;
- end = xbt_dynar_length(mc_libsimgrid_info->global_variables) - 1;
- } else if (strcmp(current_var->name, name) < 0) {
- start = cursor + 1;
- } else {
- end = cursor - 1;
+ // Binary search:
+ int start = 0;
+ int end = xbt_dynar_length(info->global_variables) - 1;
+ while (start <= end) {
+ unsigned int cursor = (start + end) / 2;
+ dw_variable_t current_var =
+ (dw_variable_t) xbt_dynar_get_as(info->global_variables,
+ cursor, dw_variable_t);
+ if (strcmp(current_var->name, name) == 0) {
+ xbt_dynar_remove_at(info->global_variables, cursor, NULL);
+ start = 0;
+ end = xbt_dynar_length(info->global_variables) - 1;
+ } else if (strcmp(current_var->name, name) < 0) {
+ start = cursor + 1;
+ } else {
+ end = cursor - 1;
+ }
}
}
-
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
+ mmalloc_set_current_heap(heap);
}
/** \brief Ignore a local variable in a scope
{
// Processing of direct variables:
- // If the current subprogram matche the given name:
- if (subprogram_name == NULL || strcmp(subprogram_name, subprogram->name) == 0) {
+ // If the current subprogram matches the given name:
+ if (!subprogram_name ||
+ (subprogram->name && strcmp(subprogram_name, subprogram->name) == 0)) {
// Try to find the variable and remove it:
int start = 0;
}
}
+// MCer
void MC_ignore_local_variable(const char *var_name, const char *frame_name)
{
-
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
+ mc_process_t process = &mc_model_checker->process;
if (strcmp(frame_name, "*") == 0)
frame_name = NULL;
+ xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
- MC_SET_MC_HEAP;
-
- MC_ignore_local_variable_in_object(var_name, frame_name, mc_libsimgrid_info);
- if (frame_name != NULL)
- MC_ignore_local_variable_in_object(var_name, frame_name, mc_binary_info);
-
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
+ size_t n = process->object_infos_size;
+ size_t i;
+ for (i=0; i!=n; ++i) {
+ MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]);
+ }
+ mmalloc_set_current_heap(heap);
}
-void MC_new_stack_area(void *stack, char *name, void *context, size_t size)
+void MC_stack_area_add(stack_region_t stack_area)
{
-
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
- MC_SET_MC_HEAP;
-
if (stacks_areas == NULL)
stacks_areas = xbt_dynar_new(sizeof(stack_region_t), NULL);
+ xbt_dynar_push(stacks_areas, &stack_area);
+}
- stack_region_t region = NULL;
- region = xbt_new0(s_stack_region_t, 1);
+/** @brief Register a stack in the model checker
+ *
+ * The stacks are allocated in the heap. The MC handle them especially
+ * when we analyse/compare the content of the heap so it must be told where
+ * they are with this function.
+ *
+ * @param stack
+ * @param process Process owning the stack
+ * @param context
+ * @param size Size of the stack
+ */
+void MC_new_stack_area(void *stack, smx_process_t process, void *context, size_t size)
+{
+ xbt_mheap_t heap = mmalloc_set_current_heap(mc_heap);
+
+ stack_region_t region = xbt_new0(s_stack_region_t, 1);
region->address = stack;
- region->process_name = strdup(name);
region->context = context;
region->size = size;
region->block =
((char *) stack -
- (char *) ((xbt_mheap_t) std_heap)->heapbase) / BLOCKSIZE + 1;
- xbt_dynar_push(stacks_areas, ®ion);
+ (char *) std_heap->heapbase) / BLOCKSIZE + 1;
+#ifdef HAVE_SMPI
+ if (smpi_privatize_global_variables && process) {
+ region->process_index = smpi_process_index_of_smx_process(process);
+ } else
+#endif
+ region->process_index = -1;
+
+ if (mc_mode == MC_MODE_CLIENT) {
+ s_mc_stack_region_message_t message;
+ message.type = MC_MESSAGE_STACK_REGION;
+ message.stack_region = *region;
+ MC_client_send_message(&message, sizeof(message));
+ }
+
+ MC_stack_area_add(region);
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
+ mmalloc_set_current_heap(heap);
}
-void MC_ignore(void *addr, size_t size)
+void MC_process_ignore_memory(mc_process_t process, void *addr, size_t size)
{
-
- int raw_mem_set = (mmalloc_get_current_heap() == mc_heap);
-
- MC_SET_MC_HEAP;
-
- if (mc_checkpoint_ignore == NULL)
- mc_checkpoint_ignore =
- xbt_dynar_new(sizeof(mc_checkpoint_ignore_region_t),
- checkpoint_ignore_region_free_voidp);
-
+ xbt_dynar_t checkpoint_ignore = process->checkpoint_ignore;
mc_checkpoint_ignore_region_t region =
xbt_new0(s_mc_checkpoint_ignore_region_t, 1);
region->addr = addr;
region->size = size;
- if (xbt_dynar_is_empty(mc_checkpoint_ignore)) {
- xbt_dynar_push(mc_checkpoint_ignore, ®ion);
+ if (xbt_dynar_is_empty(checkpoint_ignore)) {
+ xbt_dynar_push(checkpoint_ignore, ®ion);
} else {
unsigned int cursor = 0;
int start = 0;
- int end = xbt_dynar_length(mc_checkpoint_ignore) - 1;
+ int end = xbt_dynar_length(checkpoint_ignore) - 1;
mc_checkpoint_ignore_region_t current_region = NULL;
while (start <= end) {
cursor = (start + end) / 2;
current_region =
- (mc_checkpoint_ignore_region_t) xbt_dynar_get_as(mc_checkpoint_ignore,
+ (mc_checkpoint_ignore_region_t) xbt_dynar_get_as(checkpoint_ignore,
cursor,
mc_checkpoint_ignore_region_t);
if (current_region->addr == addr) {
if (current_region->size == size) {
checkpoint_ignore_region_free(region);
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
return;
} else if (current_region->size < size) {
start = cursor + 1;
if (current_region->addr == addr) {
if (current_region->size < size) {
- xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
+ xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, ®ion);
} else {
- xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
+ xbt_dynar_insert_at(checkpoint_ignore, cursor, ®ion);
}
} else if (current_region->addr < addr) {
- xbt_dynar_insert_at(mc_checkpoint_ignore, cursor + 1, ®ion);
+ xbt_dynar_insert_at(checkpoint_ignore, cursor + 1, ®ion);
} else {
- xbt_dynar_insert_at(mc_checkpoint_ignore, cursor, ®ion);
+ xbt_dynar_insert_at(checkpoint_ignore, cursor, ®ion);
}
}
-
- if (!raw_mem_set)
- MC_SET_STD_HEAP;
}