1 /* Copyright (c) 2008-2014. 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. */
12 #include "simgrid_config.h"
14 #include <sys/types.h>
16 #include <xbt/mmalloc.h>
17 #include "xbt/mmalloc/mmprivate.h"
19 #include "simix/popping_private.h"
21 #include "mc_forward.h"
22 #include "mc_mmalloc.h" // std_heap
23 #include "mc_memory_map.h"
28 MC_PROCESS_NO_FLAG = 0,
29 MC_PROCESS_SELF_FLAG = 1,
30 } e_mc_process_flags_t;
32 // Those flags are used to track down which cached information
33 // is still up to date and which information needs to be updated.
35 MC_PROCESS_CACHE_FLAG_HEAP = 1,
36 MC_PROCESS_CACHE_FLAG_MALLOC_INFO = 2,
37 } e_mc_process_cache_flags_t ;
39 /** Representation of a process
42 e_mc_process_flags_t process_flags;
44 memory_map_t memory_map;
45 void *maestro_stack_start, *maestro_stack_end;
46 mc_object_info_t libsimgrid_info;
47 mc_object_info_t binary_info;
48 mc_object_info_t* object_infos;
49 size_t object_infos_size;
52 // Cache: don't use those fields directly but with the getters
53 // which ensure that proper synchronisation has been done.
55 e_mc_process_cache_flags_t cache_flags;
57 /** Address of the heap structure in the target process.
61 /** Copy of the heap structure of the process
63 * This is refreshed with the `MC_process_refresh` call.
64 * This is not used if the process is the current one:
65 * use `MC_process_get_heap_info` in order to use it.
69 /** Copy of the allocation info structure
71 * This is refreshed with the `MC_process_refresh` call.
72 * This is not used if the process is the current one:
73 * use `MC_process_get_malloc_info` in order to use it.
75 malloc_info* heap_info;
78 void MC_process_init(mc_process_t process, pid_t pid);
79 void MC_process_clear(mc_process_t process);
81 /** Refresh the information about the process
83 * Do not use direclty, this is used by the getters when appropriate
84 * in order to have fresh data.
86 void MC_process_refresh_heap(mc_process_t process);
88 /** Refresh the information about the process
90 * Do not use direclty, this is used by the getters when appropriate
91 * in order to have fresh data.
93 void MC_process_refresh_malloc_info(mc_process_t process);
96 bool MC_process_is_self(mc_process_t process)
98 return process->process_flags & MC_PROCESS_SELF_FLAG;
101 /* Process memory access: */
103 /** Read data from a process memory
105 * @param process the process
106 * @param local local memory address (destination)
107 * @param remote target process memory address (source)
108 * @param len data size
110 void MC_process_read(mc_process_t process, void* local, const void* remote, size_t len);
112 /** Write data to a process memory
114 * @param process the process
115 * @param local local memory address (source)
116 * @param remote target process memory address (target)
117 * @param len data size
119 void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len);
121 /* Functions, variables of the process: */
123 mc_object_info_t MC_process_find_object_info(mc_process_t process, void* ip);
124 dw_frame_t MC_process_find_function(mc_process_t process, void* ip);
126 static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
128 if (MC_process_is_self(process))
130 if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
131 MC_process_refresh_heap(process);
132 return process->heap;
135 static inline malloc_info* MC_process_get_malloc_info(mc_process_t process)
137 if (MC_process_is_self(process))
138 return std_heap->heapinfo;
139 if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
140 MC_process_refresh_malloc_info(process);
141 return process->heap_info;
144 /** Find (one occurence of) the named variable definition
146 dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char* name);