1 /* Copyright (c) 2008-2015. The SimGrid Team.
2 * All rights reserved. */
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. */
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/mc_client.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ignore, mc,
18 "Logging specific to MC ignore mechanism");
20 // ***** Model-checked
22 void MC_ignore_heap(void *address, size_t size)
24 if (mc_mode != MC_MODE_CLIENT)
27 xbt_mheap_t heap = mmalloc_get_current_heap();
29 s_mc_ignore_heap_message_t message;
30 message.type = MC_MESSAGE_IGNORE_HEAP;
31 message.address = 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++;
41 ((uintptr_t) (ADDR2UINT(address) % (BLOCKSIZE))) >>
42 heap->heapinfo[message.block].type;
43 heap->heapinfo[message.block].busy_frag.ignore[message.fragment]++;
46 if (MC_protocol_send(mc_client->fd, &message, sizeof(message)))
47 xbt_die("Could not send ignored region to MCer");
50 void MC_remove_ignore_heap(void *address, size_t size)
52 if (mc_mode != MC_MODE_CLIENT)
55 s_mc_ignore_memory_message_t message;
56 message.type = MC_MESSAGE_UNIGNORE_HEAP;
57 message.addr = (std::uintptr_t) address;
59 MC_client_send_message(&message, sizeof(message));
62 void MC_ignore_global_variable(const char *name)
64 // TODO, send a message to the model_checker
65 xbt_die("Unimplemented");
68 /** @brief Register a stack in the model checker
70 * The stacks are allocated in the heap. The MC handle them especially
71 * when we analyse/compare the content of the heap so it must be told where
72 * they are with this function.
75 * @param process Process owning the stack
77 * @param size Size of the stack
79 void MC_register_stack_area(void *stack, smx_process_t process, ucontext_t* context, size_t size)
81 if (mc_mode != MC_MODE_CLIENT)
84 xbt_mheap_t heap = mmalloc_get_current_heap();
86 s_stack_region_t region;
87 memset(®ion, 0, sizeof(region));
88 region.address = stack;
89 region.context = context;
93 (char *) heap->heapbase) / BLOCKSIZE + 1;
95 if (smpi_privatize_global_variables && process)
96 region.process_index = smpi_process_index_of_smx_process(process);
99 region.process_index = -1;
101 s_mc_stack_region_message_t message;
102 message.type = MC_MESSAGE_STACK_REGION;
103 message.stack_region = region;
104 MC_client_send_message(&message, sizeof(message));