-int allocated_junk=0; /* keep track of whether our little area was already given to someone */
-char junkarea[4096];
-
-/* 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 > sizeof junkarea) {
- fprintf(stderr,
- "Panic: real malloc symbol not resolved yet, and I need %zu bytes while my little private memory chunk is only %zu bytes wide. "
- "Damn LD, we must fix our code to extend this area.\n", n, sizeof junkarea);
- 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);
+static void* mm_fake_malloc(size_t n)
+{
+ mmalloc_preinit_buffer = buffer;
+
+ // 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 available memory:
+ if (fake_alloc_index + count >= mmalloc_preinit_buffer_size) {
+ puts("mmalloc is not initialized yet, but the static buffer used as malloc replacement is already exhausted. "
+ "Please increase `mmalloc_preinit_buffer_size` in mm_legacy.c\n");
+ exit(127);