-static int allocated_junk = 0; /* keep track of many blocks of our little area was already given to someone */
-#define JUNK_SIZE 8
-#define MAX_JUNK_AREAS (32 * 1024 / JUNK_SIZE)
-static char junkareas[MAX_JUNK_AREAS][JUNK_SIZE];
-
-/* This version use mmalloc if there is a current heap, or the legacy implem if not */
-static void *malloc_or_calloc(size_t n, int setzero) {
- xbt_mheap_t mdp = __mmalloc_current_heap;
- void *ret;
-#ifdef MM_LEGACY_VERBOSE
- static int warned_raw = 0;
- static int warned_mmalloc = 0;
-#endif
-
- if (mdp) {
- LOCK(mdp);
- ret = mmalloc(mdp, n);
- UNLOCK(mdp);
- // This was already done by mmalloc:
- if (mdp->options & XBT_MHEAP_OPTION_MEMSET) {
- setzero = 0;
- }
-#ifdef MM_LEGACY_VERBOSE
- if (!warned_mmalloc) {
- fprintf(stderr,"Using mmalloc; enabling the model-checker in cmake may have a bad impact on your simulation performance\n");
- warned_mmalloc = 1;
- }
-#endif
- } else if (!real_malloc) {
- size_t needed_areas = n / JUNK_SIZE;
- if(needed_areas * JUNK_SIZE != n) needed_areas++;
- if (allocated_junk+needed_areas>=MAX_JUNK_AREAS) {
- fprintf(stderr,
- "Panic: real malloc symbol not resolved yet, and I already gave my little private memory chunk away.\n");
- exit(1);
- } else {
- size_t i = allocated_junk;
- allocated_junk += needed_areas;
- ret = junkareas[i];
- }
- }
- else {
-#ifdef MM_LEGACY_VERBOSE
- if (!warned_raw) {
- fprintf(stderr,"Using system malloc after interception; you seem to be currently model-checking\n");
- warned_raw = 1;
- }
-#endif
- ret = real_malloc(n);
- }
- if (ret && setzero) {
- memset(ret, 0, n);
- }
- return ret;
+static void* mm_fake_malloc(size_t n)
+{
+ // How many uint64_t do w need?
+ size_t count = n / sizeof(uint64_t);
+ if (n % sizeof(uint64_t))
+ count++;
+ // Check that we have enough availabel memory:
+ if (fake_alloc_index + count >= BUFFER_SIZE)
+ exit(127);
+ // Allocate it:
+ uint64_t* res = buffer + fake_alloc_index;
+ fake_alloc_index += count;
+ return res;