-int allocated_junk=0; /* keep track of whether our little area was already given to someone */
-char junkarea[512];
-
-/* This version use mmalloc if there is a current heap, or the legacy implem if not */
-void *malloc(size_t n) {
- 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);
-#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) {
- if (allocated_junk) {
- fprintf(stderr,
- "Panic: real malloc symbol not resolved yet, and I already gave my little private memory chunk away. "
- "Damn LD, we must extend our code to have several such areas.\n");
- exit(1);
- } else if (n>512) {
- fprintf(stderr,
- "Panic: real malloc symbol not resolved yet, and I need %zu bytes while my little private memory chunk is only 512 bytes wide. "
- "Damn LD, we must fix our code to extend this area.\n",n);
- exit(1);
- } else {
- allocated_junk = 1;
- return junkarea;
- }
- }
-#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);
- }
- 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;