Logo AND Algorithmique Numérique Distribuée

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