Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
64a62ac8d79d518a9c74e70b2035a8a986862ceb
[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
12 #include "simgrid_config.h"
13
14 #include <sys/types.h>
15
16 #include <xbt/mmalloc.h>
17 #include "xbt/mmalloc/mmprivate.h"
18
19 #include "simix/popping_private.h"
20
21 #include "mc_forward.h"
22 #include "mc_mmalloc.h" // std_heap
23 #include "mc_memory_map.h"
24 #include "mc_address_space.h"
25
26 SG_BEGIN_DECL()
27
28 typedef enum {
29   MC_PROCESS_NO_FLAG = 0,
30   MC_PROCESS_SELF_FLAG = 1,
31 } e_mc_process_flags_t;
32
33 // Those flags are used to track down which cached information
34 // is still up to date and which information needs to be updated.
35 typedef enum {
36   MC_PROCESS_CACHE_FLAG_HEAP = 1,
37   MC_PROCESS_CACHE_FLAG_MALLOC_INFO = 2,
38 } e_mc_process_cache_flags_t ;
39
40 /** Representation of a process
41  */
42 struct s_mc_process {
43   s_mc_address_space_t address_space;
44   e_mc_process_flags_t process_flags;
45   pid_t pid;
46   memory_map_t memory_map;
47   void *maestro_stack_start, *maestro_stack_end;
48   mc_object_info_t libsimgrid_info;
49   mc_object_info_t binary_info;
50   mc_object_info_t* object_infos;
51   size_t object_infos_size;
52   int memory_file;
53
54   // Cache: don't use those fields directly but with the getters
55   // which ensure that proper synchronisation has been done.
56
57   e_mc_process_cache_flags_t cache_flags;
58
59   /** Address of the heap structure in the target process.
60    */
61   void* heap_address;
62
63   /** Copy of the heap structure of the process
64    *
65    *  This is refreshed with the `MC_process_refresh` call.
66    *  This is not used if the process is the current one:
67    *  use `MC_process_get_heap_info` in order to use it.
68    */
69    xbt_mheap_t heap;
70
71   /** Copy of the allocation info structure
72    *
73    *  This is refreshed with the `MC_process_refresh` call.
74    *  This is not used if the process is the current one:
75    *  use `MC_process_get_malloc_info` in order to use it.
76    */
77   malloc_info* heap_info;
78 };
79
80 void MC_process_init(mc_process_t process, pid_t pid);
81 void MC_process_clear(mc_process_t process);
82
83 /** Refresh the information about the process
84  *
85  *  Do not use direclty, this is used by the getters when appropriate
86  *  in order to have fresh data.
87  */
88 void MC_process_refresh_heap(mc_process_t process);
89
90 /** Refresh the information about the process
91  *
92  *  Do not use direclty, this is used by the getters when appropriate
93  *  in order to have fresh data.
94  * */
95 void MC_process_refresh_malloc_info(mc_process_t process);
96
97 static inline
98 bool MC_process_is_self(mc_process_t process)
99 {
100   return process->process_flags & MC_PROCESS_SELF_FLAG;
101 }
102
103 /* Process memory access: */
104
105 /** Read data from a process memory
106  *
107  *  @param process the process
108  *  @param local   local memory address (destination)
109  *  @param remote  target process memory address (source)
110  *  @param len     data size
111  */
112 const void* MC_process_read(mc_process_t process,
113   e_adress_space_read_flags_t flags,
114   void* local, const void* remote, size_t len,
115   int process_index);
116
117 /** Write data to a process memory
118  *
119  *  @param process the process
120  *  @param local   local memory address (source)
121  *  @param remote  target process memory address (target)
122  *  @param len     data size
123  */
124 void MC_process_write(mc_process_t process, const void* local, void* remote, size_t len);
125
126 /* Functions, variables of the process: */
127
128 mc_object_info_t MC_process_find_object_info(mc_process_t process, const void* addr);
129 mc_object_info_t MC_process_find_object_info_exec(mc_process_t process, const void* addr);
130 mc_object_info_t MC_process_find_object_info_rw(mc_process_t process, const void* addr);
131
132 dw_frame_t MC_process_find_function(mc_process_t process, const void* ip);
133
134 static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
135 {
136   if (MC_process_is_self(process))
137     return std_heap;
138   if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
139     MC_process_refresh_heap(process);
140   return process->heap;
141 }
142
143 static inline malloc_info* MC_process_get_malloc_info(mc_process_t process)
144 {
145   if (MC_process_is_self(process))
146     return std_heap->heapinfo;
147   if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
148     MC_process_refresh_malloc_info(process);
149   return process->heap_info;
150 }
151
152 /** Find (one occurence of) the named variable definition
153  */
154 dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char* name);
155
156 SG_END_DECL()
157
158 #endif