Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Move methods in Process class
[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_base.h"
28 #include "mc_mmalloc.h" // std_heap
29 #include "mc_memory_map.h"
30 #include "AddressSpace.hpp"
31 #include "mc_protocol.h"
32
33 typedef int mc_process_flags_t;
34 #define MC_PROCESS_NO_FLAG 0
35 #define MC_PROCESS_SELF_FLAG 1
36
37 // Those flags are used to track down which cached information
38 // is still up to date and which information needs to be updated.
39 typedef int mc_process_cache_flags_t;
40 #define MC_PROCESS_CACHE_FLAG_NONE 0
41 #define MC_PROCESS_CACHE_FLAG_HEAP 1
42 #define MC_PROCESS_CACHE_FLAG_MALLOC_INFO 2
43 #define MC_PROCESS_CACHE_FLAG_SIMIX_PROCESSES 4
44
45 typedef struct s_mc_smx_process_info s_mc_smx_process_info_t, *mc_smx_process_info_t;
46
47 namespace simgrid {
48 namespace mc {
49
50 /** Representation of a process
51  */
52 class Process : public AddressSpace {
53 public:
54   Process(pid_t pid, int sockfd);
55   ~Process();
56
57   bool is_self() const
58   {
59     return this->process_flags & MC_PROCESS_SELF_FLAG;
60   }
61
62   // Read memory:
63   const void* read_bytes(void* buffer, std::size_t size,
64     remote_ptr<void> address, int process_index = ProcessIndexAny,
65     ReadMode mode = Normal) const override;
66   void read_variable(const char* name, void* target, size_t size) const;
67   char* read_string(remote_ptr<void> address) const;
68
69   // Write memory:
70   void write_bytes(const void* buffer, size_t len, remote_ptr<void> address);
71   void clear_bytes(remote_ptr<void> address, size_t len);
72
73   // Debug information:
74   mc_object_info_t find_object_info(remote_ptr<void> addr) const;
75   mc_object_info_t find_object_info_exec(remote_ptr<void> addr) const;
76   mc_object_info_t find_object_info_rw(remote_ptr<void> addr) const;
77   dw_frame_t find_function(remote_ptr<void> ip) const;
78   dw_variable_t find_variable(const char* name) const;
79
80   // Heap access:
81   xbt_mheap_t get_heap()
82   {
83     if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
84       this->refresh_heap();
85     return this->heap;
86   }
87   malloc_info* get_malloc_info()
88   {
89     if (!(this->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
90       this->refresh_malloc_info();
91     return this->heap_info;
92   }
93
94 private:
95   void init_memory_map_info();
96   void refresh_heap();
97   void refresh_malloc_info();
98 public: // to be private
99   mc_process_flags_t process_flags;
100   pid_t pid;
101   int socket;
102   int status;
103   bool running;
104   memory_map_t memory_map;
105   void *maestro_stack_start, *maestro_stack_end;
106   mc_object_info_t libsimgrid_info;
107   mc_object_info_t binary_info;
108   mc_object_info_t* object_infos;
109   size_t object_infos_size;
110   int memory_file;
111
112   /** Copy of `simix_global->process_list`
113    *
114    *  See mc_smx.c.
115    */
116   xbt_dynar_t smx_process_infos;
117
118   /** Copy of `simix_global->process_to_destroy`
119    *
120    *  See mc_smx.c.
121    */
122   xbt_dynar_t smx_old_process_infos;
123
124   /** State of the cache (which variables are up to date) */
125   mc_process_cache_flags_t cache_flags;
126
127   /** Address of the heap structure in the MCed process. */
128   void* heap_address;
129
130   /** Copy of the heap structure of the process
131    *
132    *  This is refreshed with the `MC_process_refresh` call.
133    *  This is not used if the process is the current one:
134    *  use `get_heap_info()` in order to use it.
135    */
136    xbt_mheap_t heap;
137
138   /** Copy of the allocation info structure
139    *
140    *  This is refreshed with the `MC_process_refresh` call.
141    *  This is not used if the process is the current one:
142    *  use `get_malloc_info()` in order to use it.
143    */
144   malloc_info* heap_info;
145
146   // ***** Libunwind-data
147
148   /** Full-featured MC-aware libunwind address space for the process
149    *
150    *  This address space is using a mc_unw_context_t
151    *  (with mc_process_t/mc_address_space_t and unw_context_t).
152    */
153   unw_addr_space_t unw_addr_space;
154
155   /** Underlying libunwind addres-space
156    *
157    *  The `find_proc_info`, `put_unwind_info`, `get_dyn_info_list_addr`
158    *  operations of the native MC address space is currently delegated
159    *  to this address space (either the local or a ptrace unwinder).
160    */
161   unw_addr_space_t unw_underlying_addr_space;
162
163   /** The corresponding context
164    */
165   void* unw_underlying_context;
166
167   xbt_dynar_t checkpoint_ignore;
168 };
169
170 /** Open a FD to a remote process memory (`/dev/$pid/mem`)
171  */
172 int open_vm(pid_t pid, int flags);
173
174 }
175 }
176
177 SG_BEGIN_DECL()
178
179 XBT_INTERNAL const void* MC_process_read_dynar_element(mc_process_t process,
180   void* local, const void* remote_dynar, size_t i, size_t len);
181 XBT_INTERNAL unsigned long MC_process_read_dynar_length(mc_process_t process,
182   const void* remote_dynar);
183
184 XBT_INTERNAL void MC_invalidate_cache(void);
185
186 SG_END_DECL()
187
188 #endif