#include <sys/types.h>
+#include <xbt/mmalloc.h>
+#include "xbt/mmalloc/mmprivate.h"
+
+#include "simix/popping_private.h"
+
#include "mc_forward.h"
+#include "mc_mmalloc.h" // std_heap
#include "mc_memory_map.h"
+#include "mc_address_space.h"
SG_BEGIN_DECL()
MC_PROCESS_SELF_FLAG = 1,
} e_mc_process_flags_t;
+// Those flags are used to track down which cached information
+// is still up to date and which information needs to be updated.
+typedef enum {
+ MC_PROCESS_CACHE_FLAG_HEAP = 1,
+ MC_PROCESS_CACHE_FLAG_MALLOC_INFO = 2,
+} e_mc_process_cache_flags_t ;
+
/** Representation of a process
*/
struct s_mc_process {
+ s_mc_address_space_t address_space;
e_mc_process_flags_t process_flags;
pid_t pid;
memory_map_t memory_map;
mc_object_info_t* object_infos;
size_t object_infos_size;
int memory_file;
+
+ // Cache: don't use those fields directly but with the getters
+ // which ensure that proper synchronisation has been done.
+
+ e_mc_process_cache_flags_t cache_flags;
+
+ /** Address of the heap structure in the target process.
+ */
+ void* heap_address;
+
+ /** Copy of the heap structure of the process
+ *
+ * This is refreshed with the `MC_process_refresh` call.
+ * This is not used if the process is the current one:
+ * use `MC_process_get_heap_info` in order to use it.
+ */
+ xbt_mheap_t heap;
+
+ /** Copy of the allocation info structure
+ *
+ * This is refreshed with the `MC_process_refresh` call.
+ * This is not used if the process is the current one:
+ * use `MC_process_get_malloc_info` in order to use it.
+ */
+ malloc_info* heap_info;
};
void MC_process_init(mc_process_t process, pid_t pid);
void MC_process_clear(mc_process_t process);
+/** Refresh the information about the process
+ *
+ * Do not use direclty, this is used by the getters when appropriate
+ * in order to have fresh data.
+ */
+void MC_process_refresh_heap(mc_process_t process);
+
+/** Refresh the information about the process
+ *
+ * Do not use direclty, this is used by the getters when appropriate
+ * in order to have fresh data.
+ * */
+void MC_process_refresh_malloc_info(mc_process_t process);
+
static inline
bool MC_process_is_self(mc_process_t process)
{
* @param remote target process memory address (source)
* @param len data size
*/
-void MC_process_read(mc_process_t process, void* local, const void* remote, size_t len);
+const void* MC_process_read(mc_process_t process,
+ e_adress_space_read_flags_t flags,
+ void* local, const void* remote, size_t len,
+ int process_index);
/** Write data to a process memory
*
/* Functions, variables of the process: */
-mc_object_info_t MC_process_find_object_info(mc_process_t process, void* ip);
-dw_frame_t MC_process_find_function(mc_process_t process, void* ip);
+mc_object_info_t MC_process_find_object_info(mc_process_t process, const void* addr);
+mc_object_info_t MC_process_find_object_info_exec(mc_process_t process, const void* addr);
+mc_object_info_t MC_process_find_object_info_rw(mc_process_t process, const void* addr);
+
+dw_frame_t MC_process_find_function(mc_process_t process, const void* ip);
+
+static inline xbt_mheap_t MC_process_get_heap(mc_process_t process)
+{
+ if (MC_process_is_self(process))
+ return std_heap;
+ if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_HEAP))
+ MC_process_refresh_heap(process);
+ return process->heap;
+}
+
+static inline malloc_info* MC_process_get_malloc_info(mc_process_t process)
+{
+ if (MC_process_is_self(process))
+ return std_heap->heapinfo;
+ if (!(process->cache_flags & MC_PROCESS_CACHE_FLAG_MALLOC_INFO))
+ MC_process_refresh_malloc_info(process);
+ return process->heap_info;
+}
+
+/** Find (one occurence of) the named variable definition
+ */
+dw_variable_t MC_process_find_variable_by_name(mc_process_t process, const char* name);
SG_END_DECL()