Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Remove the dual heap mc_heap/std_heap
[simgrid.git] / src / mc / mc_process.h
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 #ifndef MC_PROCESS_H
8 #define MC_PROCESS_H
9
10 #include <stdbool.h>
11 #include <sys/types.h>
12
13 #include "simgrid_config.h"
14 #include <sys/types.h>
15
16 #include <xbt/mmalloc.h>
17
18 #ifdef HAVE_MC
19 #include "xbt/mmalloc/mmprivate.h"
20 #endif
21
22 #include <simgrid/simix.h>
23 #include "simix/popping_private.h"
24 #include "simix/smx_private.h"
25
26 #include "mc_forward.h"
27 #include "mc_mmalloc.h" // std_heap
28 #include "mc_memory_map.h"
29 #include "mc_address_space.h"
30 #include "mc_protocol.h"
31
32 SG_BEGIN_DECL()
33
34 int MC_process_vm_open(pid_t pid, int flags);
35
36 typedef int mc_process_flags_t;
37 #define MC_PROCESS_NO_FLAG 0
38 #define MC_PROCESS_SELF_FLAG 1
39
40 // Those flags are used to track down which cached information
41 // is still up to date and which information needs to be updated.
42 typedef int mc_process_cache_flags_t;
43 #define MC_PROCESS_CACHE_FLAG_NONE 0
44 #define MC_PROCESS_CACHE_FLAG_HEAP 1
45 #define MC_PROCESS_CACHE_FLAG_MALLOC_INFO 2
46 #define MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES 4
47
48 typedef struct s_mc_smx_process_info s_mc_smx_process_info_t, *mc_smx_process_info_t;
49
50 /** Representation of a process
51  */
52 struct s_mc_process {
53   s_mc_address_space_t address_space;
54   mc_process_flags_t process_flags;
55   pid_t pid;
56   int socket;
57   int status;
58   bool running;
59   memory_map_t memory_map;
60   void *maestro_stack_start, *maestro_stack_end;
61   mc_object_info_t libsimgrid_info;
62   mc_object_info_t binary_info;
63   mc_object_info_t* object_infos;
64   size_t object_infos_size;
65   int memory_file;
66
67   /** Copy of `simix_global->process_list`
68    *
69    *  See mc_smx.c.
70    */
71   xbt_dynar_t smx_process_infos;
72
73   /** Copy of `simix_global->process_to_destroy`
74    *
75    *  See mc_smx.c.
76    */
77   xbt_dynar_t smx_old_process_infos;
78
79   /** State of the cache (which variables are up to date) */
80   mc_process_cache_flags_t cache_flags;
81
82   /** Address of the heap structure in the MCed process. */
83   void* heap_address;
84
85   /** Copy of the heap structure of the process
86    *
87    *  This is refreshed with the `MC_process_refresh` call.
88    *  This is not used if the process is the current one:
89    *  use `MC_process_get_heap_info` in order to use it.
90    */
91    xbt_mheap_t heap;
92
93   /** Copy of the allocation info structure
94    *
95    *  This is refreshed with the `MC_process_refresh` call.
96    *  This is not used if the process is the current one:
97    *  use `MC_process_get_malloc_info` in order to use it.
98    */
99   malloc_info* heap_info;
100
101   // ***** Libunwind-data
102
103   /** Full-featured MC-aware libunwind address space for the process
104    *
105    *  This address space is using a mc_unw_context_t
106    *  (with mc_process_t/mc_address_space_t and unw_context_t).
107    */
108   unw_addr_space_t unw_addr_space;
109
110   /** Underlying libunwind addres-space
111    *
112    *  The `find_proc_info`, `put_unwind_info`, `get_dyn_info_list_addr`
113    *  operations of the native MC address space is currently delegated
114    *  to this address space (either the local or a ptrace unwinder).
115    */
116   unw_addr_space_t unw_underlying_addr_space;
117
118   /** The corresponding context
119    */
120   void* unw_underlying_context;
121
122   xbt_dynar_t checkpoint_ignore;
123 };
124
125 bool MC_is_process(mc_address_space_t p);
126
127 void MC_process_init(mc_process_t process, pid_t pid, int sockfd);
128 void MC_process_clear(mc_process_t process);
129
130 /** Refresh the information about the process
131  *
132  *  Do not use direclty, this is used by the getters when appropriate
133  *  in order to have fresh data.
134  */
135 void MC_process_refresh_heap(mc_process_t process);
136
137 /** Refresh the information about the process
138  *
139  *  Do not use direclty, this is used by the getters when appropriate
140  *  in order to have fresh data.
141  * */
142 void MC_process_refresh_malloc_info(mc_process_t process);
143
144 static inline
145 bool MC_process_is_self(mc_process_t process)
146 {
147   return process->process_flags & MC_PROCESS_SELF_FLAG;
148 }
149
150 /* Process memory access: */
151
152 /** Read data from a process memory
153  *
154  *  @param process the process
155  *  @param local   local memory address (destination)
156  *  @param remote  target process memory address (source)
157  *  @param len     data size
158  */
159 const void* MC_process_read(mc_process_t process,
160   adress_space_read_flags_t flags,
161   void* local, const void* remote, size_t len,
162   int process_index);
163
164 // Simplified versions/wrappers (whould be moved in mc_address_space):
165 const void* MC_process_read_simple(mc_process_t process,
166   void* local, const void* remote, size_t len);
167 const void* MC_process_read_dynar_element(mc_process_t process,
168   void* local, const void* remote_dynar, size_t i, size_t len);
169 unsigned long MC_process_read_dynar_length(mc_process_t process, const void* remote_dynar);
170
171 /** Write data to a process memory
172  *
173  *  @param process the process
174  *  @param local   local memory address (source)
175  *  @param remote  target process memory address (target)
176  *  @param len     data size
177  */
178 void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len);
179
180 void MC_process_clear_memory(mc_process_t process, void* remote, size_t len);
181
182 /* Functions, variables of the process: */
183
184 mc_object_info_t MC_process_find_object_info(mc_process_t process, const void* addr);
185 mc_object_info_t MC_process_find_object_info_exec(mc_process_t process, const void* addr);
186 mc_object_info_t MC_process_find_object_info_rw(mc_process_t process, const void* addr);
187
188 dw_frame_t MC_process_find_function(mc_process_t process, const void* ip);
189
190 void MC_process_read_variable(mc_process_t process, const char* name, void* target, size_t size);
191 char* MC_process_read_string(mc_process_t, void* address);
192
193 static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
194 {
195   if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
196     MC_process_refresh_heap(process);
197   return process->heap;
198 }
199
200 static inline malloc_info* MC_process_get_malloc_info(mc_process_t process)
201 {
202   if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
203     MC_process_refresh_malloc_info(process);
204   return process->heap_info;
205 }
206
207 /** Find (one occurence of) the named variable definition
208  */
209 dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char* name);
210
211 void MC_invalidate_cache(void);
212
213 SG_END_DECL()
214
215 #endif