+/* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include <libgen.h>
+#include "mc_private.h"
+#include "xbt/module.h"
+
+#include "../simix/smx_private.h"
+
+#include <libunwind.h>
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_checkpoint, mc,
+ "Logging specific to mc_checkpoint");
+
+void *start_text_libsimgrid;
+void *start_plt, *end_plt;
+char *libsimgrid_path;
+
+static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size);
+static void MC_region_restore(mc_mem_region_t reg);
+static void MC_region_destroy(mc_mem_region_t reg);
+
+static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size);
+
+static void add_value(xbt_dynar_t *list, const char *type, unsigned long int val);
+static xbt_dynar_t take_snapshot_stacks(void *heap);
+static void get_local_variables_values(xbt_dynar_t *all_variables, stack_region_t stack, void *heap);
+static void print_local_variables_values(xbt_dynar_t all_variables);
+
+static mc_mem_region_t MC_region_new(int type, void *start_addr, size_t size)
+{
+ mc_mem_region_t new_reg = xbt_new0(s_mc_mem_region_t, 1);
+ new_reg->type = type;
+ new_reg->start_addr = start_addr;
+ new_reg->size = size;
+ new_reg->data = xbt_malloc0(size);
+ memcpy(new_reg->data, start_addr, size);
+
+ XBT_DEBUG("New region : type : %d, data : %p, size : %zu", type, new_reg->data, size);
+
+ return new_reg;
+}
+
+static void MC_region_restore(mc_mem_region_t reg)
+{
+ /*FIXME: check if start_addr is still mapped, if it is not, then map it
+ before copying the data */
+
+ memcpy(reg->start_addr, reg->data, reg->size);
+
+ return;
+}
+
+static void MC_region_destroy(mc_mem_region_t reg)
+{
+ xbt_free(reg->data);
+ xbt_free(reg);
+}
+
+static void MC_snapshot_add_region(mc_snapshot_t snapshot, int type, void *start_addr, size_t size)
+{
+ mc_mem_region_t new_reg = MC_region_new(type, start_addr, size);
+ snapshot->regions = xbt_realloc(snapshot->regions, (snapshot->num_reg + 1) * sizeof(mc_mem_region_t));
+ snapshot->regions[snapshot->num_reg] = new_reg;
+ snapshot->num_reg++;
+ return;
+}