Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'support-sendrecv-ti' into 'master'
authorAugustin Degomme <26892-adegomme@users.noreply.framagit.org>
Fri, 22 Jul 2022 14:38:49 +0000 (14:38 +0000)
committerAugustin Degomme <26892-adegomme@users.noreply.framagit.org>
Fri, 22 Jul 2022 14:38:49 +0000 (14:38 +0000)
Quick and dirty support of SendRecv in time-independent traces

See merge request simgrid/simgrid!115

27 files changed:
include/simgrid/modelchecker.h
src/bindings/java/org/simgrid/NativeLib.java
src/include/xbt/mmalloc.h
src/include/xbt/xbt_modinter.h
src/mc/api.cpp
src/mc/mc_client_api.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/mc_protocol.h
src/sthread/sthread.c
src/sthread/sthread_impl.cpp
src/xbt/mmalloc/mfree.c
src/xbt/mmalloc/mm_interface.c [new file with mode: 0644]
src/xbt/mmalloc/mm_legacy.c
src/xbt/mmalloc/mm_module.c
src/xbt/mmalloc/mmalloc.c
src/xbt/mmalloc/mmorecore.c
src/xbt/mmalloc/mmprivate.h
src/xbt/mmalloc/swag.c
src/xbt/mmalloc/swag.h
src/xbt/xbt_main.cpp
teshsuite/smpi/coll-allreduce/coll-allreduce-automatic.tesh
teshsuite/xbt/CMakeLists.txt
teshsuite/xbt/mmalloc/mmalloc_32.tesh
teshsuite/xbt/mmalloc/mmalloc_64.tesh
teshsuite/xbt/mmalloc/mmalloc_test.cpp
tools/cmake/DefinePackages.cmake
tools/cmake/MakeLib.cmake

index 661fc12..ea97b21 100644 (file)
@@ -44,7 +44,6 @@ XBT_PUBLIC void MC_assert(int);
 XBT_PUBLIC void MC_automaton_new_propositional_symbol(const char* id, int (*fct)(void));
 XBT_PUBLIC void MC_automaton_new_propositional_symbol_pointer(const char* id, int* value);
 
-XBT_PUBLIC void MC_cut(void);
 XBT_PUBLIC void MC_ignore(void* addr, size_t size);
 
 XBT_PUBLIC void MC_ignore_heap(void* address, size_t size);
@@ -59,7 +58,6 @@ XBT_PUBLIC void MC_ignore_global_variable(const char* var_name);
 #define MC_assert(a)                    xbt_assert(a)
 #define MC_automaton_new_propositional_symbol(a, b) ((void)0)
 #define MC_automaton_new_propositional_symbol_pointer(a, b) ((void)0)
-#define MC_cut()                        ((void)0)
 #define MC_ignore(a, b)                 ((void)0)
 
 #define MC_ignore_heap(a,s)             ((void)0)
index 5d2b646..507a2cb 100644 (file)
@@ -48,6 +48,12 @@ public final class NativeLib {
                NativeLib.nativeInit("simgrid");
                NativeLib.nativeInit("simgrid-java");
                isNativeInited = true;
+
+                /* Don't leak the files on disk */
+                if (tempDir != null) {
+                  FileCleaner fclean = new FileCleaner(tempDir.toFile());
+                  fclean.run();
+                }
        }
 
        /** Helper function trying to load one requested library */
@@ -108,8 +114,6 @@ public final class NativeLib {
                        }
 
                        tempDir = Files.createTempDirectory(tempPrefix);
-                       // don't leak the files on disk, but remove it on JVM shutdown
-                       Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(tempDir.toFile())));
                }
 
                /* For each possible filename of the given library on all possible OSes, try it */
index f2b85ac..6a872fe 100644 (file)
 
 #include "src/internal_config.h"
 
+/** Environment variable name used to pass the communication socket.
+ *
+ * It is set by `simgrid-mc` to enable MC support in the children processes.
+ *
+ * It is placed in this file so that it's visible from mmalloc and MC without sharing anythin of xbt in mmalloc
+ */
+#define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD"
+
 #include <stdio.h>     /* for NULL */
 #include <sys/types.h> /* for size_t */
 
-#include "xbt/dict.h"
-#include "xbt/dynar.h"
-
 SG_BEGIN_DECL
 
 /* Datatype representing a separate heap. The whole point of the mmalloc module is to allow several such heaps in the
index 254f554..5913b17 100644 (file)
@@ -20,9 +20,6 @@ void xbt_log_postexit(void);
 void xbt_dict_preinit(void);
 void xbt_dict_postexit(void);
 
-xbt_mheap_t mmalloc_preinit(void);
-void mmalloc_postexit(void);
-
 extern int xbt_initialized;
 
 SG_END_DECL
index a29dbf2..ce024e6 100644 (file)
@@ -37,9 +37,18 @@ simgrid::mc::Exploration* Api::initialize(char** argv, const std::unordered_map<
     int i = 1;
     while (argv[i] != nullptr && argv[i][0] == '-')
       i++;
+    if (env.find("LD_PRELOAD") == env.end())
+      setenv("LD_PRELOAD", "libsgmalloc.so", 1);
+
     for (auto const& [key, val] : env) {
-      XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str());
-      setenv(key.c_str(), val.c_str(), 1);
+      if (key == "LD_PRELOAD") {
+        auto v2 = std::string("libsgmalloc.so:") + val;
+        XBT_INFO("setenv '%s'='%s'", key.c_str(), v2.c_str());
+        setenv(key.c_str(), v2.c_str(), 1);
+      } else {
+        XBT_INFO("setenv '%s'='%s'", key.c_str(), val.c_str());
+        setenv(key.c_str(), val.c_str(), 1);
+      }
     }
     xbt_assert(argv[i] != nullptr,
                "Unable to find a binary to exec on the command line. Did you only pass config flags?");
index 7d11040..d8044c3 100644 (file)
@@ -31,15 +31,6 @@ void MC_assert(int prop)
   }
 }
 
-void MC_cut()
-{
-  xbt_assert(mc_model_checker == nullptr);
-  if (not MC_is_active())
-    return;
-  // FIXME, We want to do this in the model-checker:
-  xbt_die("MC_cut() not implemented");
-}
-
 void MC_ignore(void* addr, size_t size)
 {
   xbt_assert(mc_model_checker == nullptr);
index 2d4dfbe..929c97c 100644 (file)
@@ -73,7 +73,7 @@ AppSide* AppSide::initialize(xbt_dynar_t actors_addr)
   xbt_assert(errno == 0 && raise(SIGSTOP) == 0, "Could not wait for the model-checker (errno = %d: %s)", errno,
              strerror(errno));
 
-  s_mc_message_initial_addresses_t message{MessageType::INITIAL_ADDRESSES, mmalloc_preinit(),
+  s_mc_message_initial_addresses_t message{MessageType::INITIAL_ADDRESSES, mmalloc_get_current_heap(),
                                            kernel::actor::ActorImpl::get_maxpid_addr(), actors_addr};
   xbt_assert(instance_->channel_.send(message) == 0, "Could not send the initial message with addresses.");
 
index e83a281..c04acc1 100644 (file)
@@ -8,12 +8,6 @@
 
 // ***** Environment variables for passing context to the model-checked process
 
-/** Environment variable name used to pass the communication socket.
- *
- * It is set by `simgrid-mc` to enable MC support in the children processes
- */
-#define MC_ENV_SOCKET_FD "SIMGRID_MC_SOCKET_FD"
-
 #ifdef __cplusplus
 
 #include "src/kernel/actor/SimcallObserver.hpp"
index 5b31764..a52fec8 100644 (file)
@@ -70,7 +70,7 @@ int pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*start_
     return raw_pthread_create(thread, attr, start_routine, arg);
 
   sthread_inside_simgrid = 1;
-  int res                = sthread_create(thread, attr, start_routine, arg);
+  int res                = sthread_create((sthread_t*)thread, attr, start_routine, arg);
   sthread_inside_simgrid = 0;
   return res;
 }
@@ -83,7 +83,7 @@ int pthread_join(pthread_t thread, void** retval)
     return raw_pthread_join(thread, retval);
 
   sthread_inside_simgrid = 1;
-  int res                = sthread_join(thread, retval);
+  int res                = sthread_join((sthread_t)thread, retval);
   sthread_inside_simgrid = 0;
   return res;
 }
@@ -229,11 +229,6 @@ int sem_post(sem_t *sem) {
        return raw_sem_post(sem);
 }
 
-int pthread_join(pthread_t thread, void **retval) {
-       sg_actor_join(thread, -1);
-    return 0;
-}
-
 int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) {
     *cond = sg_cond_init();
     return 0;
index 768a0d5..7721982 100644 (file)
@@ -166,11 +166,6 @@ int sem_post(sem_t *sem) {
        return raw_sem_post(sem);
 }
 
-int pthread_join(pthread_t thread, void **retval) {
-       sg_actor_join(thread, -1);
-    return 0;
-}
-
 int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) {
     *cond = sg_cond_init();
     return 0;
index 10c47ff..4863878 100644 (file)
@@ -11,7 +11,6 @@
    Heavily modified Mar 1992 by Fred Fish.  (fnf@cygnus.com) */
 
 #include "mmprivate.h"
-#include "xbt/ex.h"
 #include "mc/mc.h"
 
 /* Return memory to the heap.
@@ -39,12 +38,14 @@ void mfree(struct mdesc *mdp, void *ptr)
   switch (type) {
   case MMALLOC_TYPE_HEAPINFO:
     UNLOCK(mdp);
-    THROW("Asked to free a fragment in a heapinfo block. I'm confused.\n");
+    fprintf(stderr, "Asked to free a fragment in a heapinfo block. I'm confused.\n");
+    abort();
     break;
 
   case MMALLOC_TYPE_FREE: /* Already free */
     UNLOCK(mdp);
-    THROW("Asked to free a fragment in a block that is already free. I'm puzzled.\n");
+    fprintf(stderr, "Asked to free a fragment in a block that is already free. I'm puzzled.\n");
+    abort();
     break;
 
   case MMALLOC_TYPE_UNFRAGMENTED:
@@ -167,7 +168,8 @@ void mfree(struct mdesc *mdp, void *ptr)
 
     if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){
       UNLOCK(mdp);
-      THROW("Asked to free a fragment that is already free. I'm puzzled\n");
+      fprintf(stderr, "Asked to free a fragment that is already free. I'm puzzled\n");
+      abort();
     }
 
     if (MC_is_active() && mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
diff --git a/src/xbt/mmalloc/mm_interface.c b/src/xbt/mmalloc/mm_interface.c
new file mode 100644 (file)
index 0000000..28534b0
--- /dev/null
@@ -0,0 +1,59 @@
+/* External interface to a mmap'd malloc managed region. */
+
+/* Copyright (c) 2012-2022. The 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. */
+
+/* Copyright 1992, 2000 Free Software Foundation, Inc.
+
+   Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com
+
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If
+   not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fcntl.h> /* After sys/types.h, at least for dpx/2.  */
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "mmprivate.h"
+
+// This is the underlying implementation of mmalloc_get_bytes_used_remote.
+// Is it used directly to evaluate the bytes used from a different process.
+size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
+{
+  int bytes = 0;
+  for (size_t i = 0; i < heaplimit; ++i) {
+    if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED) {
+      if (heapinfo[i].busy_block.busy_size > 0)
+        bytes += heapinfo[i].busy_block.busy_size;
+    } else if (heapinfo[i].type > 0) {
+      for (size_t j = 0; j < (size_t)(BLOCKSIZE >> heapinfo[i].type); j++) {
+        if (heapinfo[i].busy_frag.frag_size[j] > 0)
+          bytes += heapinfo[i].busy_frag.frag_size[j];
+      }
+    }
+  }
+  return bytes;
+}
+
+__attribute__((weak)) xbt_mheap_t mmalloc_get_current_heap(void)
+{
+  fprintf(stderr, "Fake mmalloc_get_current_heap()\n");
+  return NULL;
+}
\ No newline at end of file
index 3228074..84a7eb4 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2010-2022. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2010-2022. The 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. */
@@ -7,19 +6,16 @@
 /* Redefine the classical malloc/free/realloc functions so that they fit well in the mmalloc framework */
 #define _GNU_SOURCE
 
-#include <stdlib.h>
+#include "mmprivate.h"
 
 #include <dlfcn.h>
-
-#include "mmprivate.h"
-#include "src/internal_config.h"
-#include "src/mc/remote/mc_protocol.h"
-#include "xbt/xbt_modinter.h"
 #include <math.h>
+#include <stdlib.h>
 
 /* ***** Whether to use `mmalloc` of the underlying malloc ***** */
 
 static int __malloc_use_mmalloc;
+int mmalloc_pagesize = 0;
 
 int malloc_use_mmalloc(void)
 {
@@ -43,8 +39,6 @@ xbt_mheap_t mmalloc_get_current_heap(void)
 }
 
 /* Override the malloc-like functions if MC is activated at compile time */
-#if SIMGRID_HAVE_MC
-
 /* ***** Temporary allocator
  *
  * This is used before we have found the real malloc implementation with dlsym.
@@ -132,6 +126,8 @@ XBT_ATTRIB_CONSTRUCTOR(101) static void mm_legacy_constructor()
     mm_real_calloc   = dlsym(RTLD_NEXT, "calloc");
 #endif
   }
+  mmalloc_pagesize = getpagesize();
+
   mm_initializing = 0;
   mm_initialized = 1;
 }
@@ -238,4 +234,3 @@ void free(void *p)
   mfree(mdp, p);
   UNLOCK(mdp);
 }
-#endif /* SIMGRID_HAVE_MC */
index 8358d43..d8b5359 100644 (file)
    not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include "src/internal_config.h"
 #include <sys/types.h>
 #include <fcntl.h>              /* After sys/types.h, at least for dpx/2.  */
 #include <sys/stat.h>
 #include <string.h>
 #include "mmprivate.h"
-#include "xbt/ex.h"
-#include "xbt/xbt_modinter.h" /* declarations of mmalloc_preinit and friends that live here */
 
 /* Initialize access to a mmalloc managed region.
 
@@ -49,7 +46,7 @@
    so that users of the package don't have to worry about the actual
    implementation details.
 
-   On failure returns NULL. */
+   On failure, returns NULL. */
 
 xbt_mheap_t xbt_mheap_new(void* baseaddr, int options)
 {
@@ -189,48 +186,24 @@ static void mmalloc_fork_child(void)
   }
 }
 
-/* Initialize the default malloc descriptor. */
+/* Initialize the default malloc descriptor.
+ *
+ * There is no malloc_postexit() destroying the default mdp, because it would break ldl trying to free its memory
+ */
 xbt_mheap_t mmalloc_preinit(void)
 {
   if (__mmalloc_default_mdp == NULL) {
-    if(!xbt_pagesize)
-      xbt_pagesize = getpagesize();
-    unsigned long mask = ~((unsigned long)xbt_pagesize - 1);
+    if (!mmalloc_pagesize)
+      mmalloc_pagesize = getpagesize();
+    unsigned long mask    = ~((unsigned long)mmalloc_pagesize - 1);
     void *addr = (void*)(((unsigned long)sbrk(0) + HEAP_OFFSET) & mask);
     __mmalloc_default_mdp = xbt_mheap_new(addr, XBT_MHEAP_OPTION_MEMSET);
 
     // atfork mandated at least on FreeBSD, or simgrid-mc will fail to fork the verified app
     int res = pthread_atfork(mmalloc_fork_prepare, mmalloc_fork_parent, mmalloc_fork_child);
-    xbt_assert(res == 0, "pthread_atfork() failed: return value %d", res);
+    mmalloc_assert(res == 0, "pthread_atfork() failed: return value %d", res);
   }
-  xbt_assert(__mmalloc_default_mdp != NULL);
+  mmalloc_assert(__mmalloc_default_mdp != NULL, "__mmalloc_default_mdp cannot be NULL");
 
   return __mmalloc_default_mdp;
 }
-
-void mmalloc_postexit(void)
-{
-  /* Do not destroy the default mdp or ldl won't be able to free the memory it
-   * allocated since we're in memory */
-  // xbt_mheap_destroy_no_free(__mmalloc_default_mdp)
-}
-
-// This is the underlying implementation of mmalloc_get_bytes_used_remote.
-// Is it used directly in order to evaluate the bytes used from a different
-// process.
-size_t mmalloc_get_bytes_used_remote(size_t heaplimit, const malloc_info* heapinfo)
-{
-  int bytes = 0;
-  for (size_t i=0; i < heaplimit; ++i){
-    if (heapinfo[i].type == MMALLOC_TYPE_UNFRAGMENTED){
-      if (heapinfo[i].busy_block.busy_size > 0)
-        bytes += heapinfo[i].busy_block.busy_size;
-    } else if (heapinfo[i].type > 0) {
-      for (size_t j=0; j < (size_t) (BLOCKSIZE >> heapinfo[i].type); j++){
-        if(heapinfo[i].busy_frag.frag_size[j] > 0)
-          bytes += heapinfo[i].busy_frag.frag_size[j];
-      }
-    }
-  }
-  return bytes;
-}
index e1db0d4..be0070f 100644 (file)
@@ -51,7 +51,7 @@ static void* mmalloc_aligned(struct mdesc* mdp, size_t size)
 static void initialize_heapinfo_heapinfo(const s_xbt_mheap_t* mdp)
 {
   // Update heapinfo about the heapinfo pages (!):
-  xbt_assert((uintptr_t) mdp->heapinfo % BLOCKSIZE == 0);
+  mmalloc_assert((uintptr_t)mdp->heapinfo % BLOCKSIZE == 0, "Failed assert in initialize_heapinfo_heapinfo()");
   size_t block   = BLOCK(mdp->heapinfo);
   size_t nblocks = mdp->heapsize * sizeof(malloc_info) / BLOCKSIZE;
   // Mark them as free:
@@ -214,8 +214,9 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
       for (candidate_frag=0;candidate_frag<(size_t) (BLOCKSIZE >> log);candidate_frag++)
         if (candidate_info->busy_frag.frag_size[candidate_frag] == -1)
           break;
-      xbt_assert(candidate_frag < (size_t) (BLOCKSIZE >> log),
-          "Block %zu was registered as containing free fragments of type %zu, but I can't find any",candidate_block,log);
+      mmalloc_assert(candidate_frag < (size_t)(BLOCKSIZE >> log),
+                     "Block %zu was registered as containing free fragments of type %zu, but I can't find any",
+                     candidate_block, log);
 
       result = (void*) (((char*)ADDRESS(candidate_block)) + (candidate_frag << log));
 
index 828e2f5..fcb2fa0 100644 (file)
@@ -10,7 +10,6 @@
 
    Contributed by Fred Fish at Cygnus Support.   fnf@cygnus.com */
 
-#include "src/internal_config.h"
 #include <stdio.h>
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -23,8 +22,7 @@
 #define MAP_ANONYMOUS MAP_ANON
 #endif
 
-#define PAGE_ALIGN(addr) (void*) (((long)(addr) + xbt_pagesize - 1) &   \
-                                  ~((long)xbt_pagesize - 1))
+#define PAGE_ALIGN(addr) (void*)(((long)(addr) + mmalloc_pagesize - 1) & ~((long)mmalloc_pagesize - 1))
 
 /** @brief Add memory to this heap
  *
@@ -49,6 +47,10 @@ void *mmorecore(struct mdesc *mdp, ssize_t size)
     return mdp->breakval;
   }
 
+  if (mmalloc_pagesize == 0) { // Not initialized yet
+    mmalloc_pagesize = (int)sysconf(_SC_PAGESIZE);
+  }
+
   if (size < 0) {
     /* We are deallocating memory.  If the amount requested would cause us to try to deallocate back past the base of
      * the mmap'd region then die verbosely.  Otherwise, deallocate the memory and return the old break value. */
@@ -76,7 +78,8 @@ void *mmorecore(struct mdesc *mdp, ssize_t size)
 
     if (mapto == MAP_FAILED) {
       char buff[1024];
-      fprintf(stderr, "Internal error: mmap returned MAP_FAILED! error: %s\n", strerror(errno));
+      fprintf(stderr, "Internal error: mmap returned MAP_FAILED! pagesize:%d error: %s\n", mmalloc_pagesize,
+              strerror(errno));
       snprintf(buff, 1024, "cat /proc/%d/maps", getpid());
       int status = system(buff);
       if (status == -1 || !(WIFEXITED(status) && WEXITSTATUS(status) == 0))
index 648bd1f..2756de4 100644 (file)
 #ifndef XBT_MMPRIVATE_H
 #define XBT_MMPRIVATE_H 1
 
-#include <xbt/base.h>
-#include <xbt/misc.h>
-
 #include "swag.h"
 #include "src/internal_config.h"
 #include "xbt/mmalloc.h"
-#include "xbt/ex.h"
-#include "xbt/dynar.h"
 
+#include <limits.h>
 #include <pthread.h>
 #include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
 
-#include <limits.h>
+// This macro is veery similar to xbt_assert, but with no dependency on XBT
+#define mmalloc_assert(cond, ...)                                                                                      \
+  do {                                                                                                                 \
+    if (!(cond)) {                                                                                                     \
+      fprintf(stderr, __VA_ARGS__);                                                                                    \
+      abort();                                                                                                         \
+    }                                                                                                                  \
+  } while (0)
+
+XBT_PUBLIC_DATA int mmalloc_pagesize;
+XBT_PRIVATE xbt_mheap_t mmalloc_preinit(void);
 
 #define MMALLOC_MAGIC    "mmalloc"       /* Mapped file magic number */
 #define MMALLOC_MAGIC_SIZE  8       /* Size of magic number buf */
  * information are kept in fixed length arrays. Here is the computation of
  * that size.
  *
- * Never make SMALLEST_POSSIBLE_MALLOC smaller than sizeof(list) because we
- * need to enlist the free fragments.
+ * Never make SMALLEST_POSSIBLE_MALLOC too small because we need to enlist
+ * the free fragments.
+ *
+ * FIXME: what's the correct size, actually? The used one is a guess.
  */
 
-#define SMALLEST_POSSIBLE_MALLOC (16*sizeof(struct list))
+#define SMALLEST_POSSIBLE_MALLOC (32 * sizeof(void*))
 #define MAX_FRAGMENT_PER_BLOCK (BLOCKSIZE / SMALLEST_POSSIBLE_MALLOC)
 
 /* The difference between two pointers is a signed int.  On machines where
 
 SG_BEGIN_DECL
 
-/* Doubly linked lists of free fragments.  */
-struct list {
-  struct list *next;
-  struct list *prev;
-};
-
 /* Statistics available to the user. */
 struct mstats
 {
index a3cdcb9..550b89b 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2004-2022. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2004-2022. The 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. */
@@ -11,7 +10,7 @@
 /* This type should be added to a type that is to be used in such a swag */
 
 #include "swag.h"
-#include "xbt/asserts.h"
+#include "mmprivate.h" // mmalloc_assert
 
 typedef s_xbt_swag_hookup_t *xbt_swag_hookup_t;
 typedef struct xbt_swag* xbt_swag_t;
@@ -63,11 +62,12 @@ static inline void xbt_swag_init(xbt_swag_t swag, size_t offset)
  */
 static inline void xbt_swag_insert(void *obj, xbt_swag_t swag)
 {
-  xbt_assert(!xbt_swag_belongs(obj, swag) || swag->tail,
-             "This object belongs to an empty swag! Did you correctly initialize the object's hookup?");
+
+  mmalloc_assert(!xbt_swag_belongs(obj, swag) || swag->tail,
+                 "This object belongs to an empty swag! Did you correctly initialize the object's hookup?");
 
   if (!swag->head) {
-    xbt_assert(!(swag->tail), "Inconsistent swag.");
+    mmalloc_assert(!(swag->tail), "Inconsistent swag.");
     swag->head = obj;
     swag->tail = obj;
     swag->count++;
index c88a996..032c741 100644 (file)
@@ -9,8 +9,6 @@
 #ifndef XBT_SWAG_H
 #define XBT_SWAG_H
 
-#include "xbt/sysdep.h" /* size_t */
-
 /*
  * XBT_swag: a O(1) set based on linked lists
  *
index 8ee72a4..15a5959 100644 (file)
@@ -115,9 +115,6 @@ static void xbt_postexit()
   xbt_initialized--;
   xbt_dict_postexit();
   xbt_log_postexit();
-#if SIMGRID_HAVE_MC
-  mmalloc_postexit();
-#endif
 }
 
 /** @brief Initialize the xbt mechanisms. */
index 940489f..fff9336 100644 (file)
@@ -2,7 +2,7 @@
 
 p Test allreduce
 ! output sort
-$ ${bindir:=.}/../../../smpi_script/bin/smpirun -map -hostfile ../hostfile_coll -platform ${platfdir:=.}/small_platform.xml -np 16 --log=xbt_cfg.thres:critical ${bindir:=.}/coll-allreduce --log=smpi_config.thres:warning --log=smpi_coll.thres:error --cfg=smpi/allreduce:automatic --cfg=smpi/async-small-thresh:65536 --cfg=smpi/send-is-detached-thresh:128000 --cfg=smpi/simulate-computation:no "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=smpi_mpi.thres:error --log=smpi_pmpi.thres:error
+$ ${bindir:=.}/../../../smpi_script/bin/smpirun -map -hostfile ../hostfile_coll -platform ${platfdir:=.}/small_platform.xml -np 16 --log=xbt_cfg.thres:critical ${bindir:=.}/coll-allreduce --log=smpi_config.thres:warning --log=smpi_coll.thres:error --cfg=smpi/allreduce:automatic --cfg=smpi/async-small-thresh:65536 --cfg=smpi/send-is-detached-thresh:128000 --cfg=smpi/simulate-computation:no "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n" --log=smpi_mpi.thres:error --log=smpi_pmpi.thres:error  --log=root.app:stdout
 > [  0.000000] (0:maestro@) [rank 0] -> Tremblay
 > [  0.000000] (0:maestro@) [rank 1] -> Tremblay
 > [  0.000000] (0:maestro@) [rank 2] -> Tremblay
index 1d9a841..fb10524 100644 (file)
@@ -21,7 +21,7 @@ endforeach()
 
 if(HAVE_MMALLOC)
   add_executable       (mmalloc_test EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_test.cpp)
-  target_link_libraries(mmalloc_test simgrid)
+  target_link_libraries(mmalloc_test simgrid sgmalloc)
   set_target_properties(mmalloc_test PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/mmalloc)
   set_property(TARGET mmalloc_test APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
   add_dependencies(tests mmalloc_test)
index 06bc543..8bb9bac 100644 (file)
@@ -104,7 +104,6 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n
 > All blocks were correctly allocated. Free every second block
 > Memset every second block to zero (yeah, they are not currently allocated :)
 > Re-allocate every second block
-> free all blocks (each one twice, to check that double free are correctly caught)
-> free again all blocks (to really check that double free are correctly caught)
+> free all blocks
 > Let's try different codepaths for mrealloc
 > Damnit, I cannot break mmalloc this time. That's SO disappointing.
index 17356ee..ec276c3 100644 (file)
@@ -104,7 +104,6 @@ $ ${bindir:=.}/mmalloc_test --log=root.fmt:%m%n
 > All blocks were correctly allocated. Free every second block
 > Memset every second block to zero (yeah, they are not currently allocated :)
 > Re-allocate every second block
-> free all blocks (each one twice, to check that double free are correctly caught)
-> free again all blocks (to really check that double free are correctly caught)
+> free all blocks
 > Let's try different codepaths for mrealloc
 > Damnit, I cannot break mmalloc this time. That's SO disappointing.
index 22ec933..6f798f0 100644 (file)
@@ -70,28 +70,9 @@ int main(int argc, char**argv)
     pointers[i] = mmalloc(heapA, size);
   }
 
-  XBT_INFO("free all blocks (each one twice, to check that double free are correctly caught)");
-  for (i = 0; i < TESTSIZE; i++) {
-    bool gotit = false;
+  XBT_INFO("free all blocks");
+  for (i = 0; i < TESTSIZE; i++)
     mfree(heapA, pointers[i]);
-    try {
-      mfree(heapA, pointers[i]);
-    } catch (const simgrid::Exception&) {
-      gotit = true;
-    }
-    xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
-  }
-
-  XBT_INFO("free again all blocks (to really check that double free are correctly caught)");
-  for (i = 0; i < TESTSIZE; i++) {
-    bool gotit = false;
-    try {
-      mfree(heapA, pointers[i]);
-    } catch (const simgrid::Exception&) {
-      gotit = true;
-    }
-    xbt_assert(gotit, "FAIL: A double-free went undetected (for size:%d)", size_of_block(i));
-  }
 
   XBT_INFO("Let's try different codepaths for mrealloc");
   for (i = 0; i < TESTSIZE; i++) {
index 2fbe539..813d829 100644 (file)
@@ -288,7 +288,7 @@ set(XBT_SRC
   )
 
 if(HAVE_MMALLOC)
-  set(XBT_SRC ${XBT_SRC}  src/xbt/mmalloc/mm.c )
+  set(SGMALLOC_SRC src/xbt/mmalloc/mm.c)
 else()
   set(EXTRA_DIST ${EXTRA_DIST} src/xbt/mmalloc/mm.c)
 endif()
@@ -655,6 +655,8 @@ set(MC_SRC
   src/mc/mc_smx.cpp
   src/mc/udpor_global.cpp
   src/mc/udpor_global.hpp
+
+  src/xbt/mmalloc/mm_interface.c
   )
 
 set(MC_SIMGRID_MC_SRC  src/mc/explo/simgrid_mc.cpp)
index c50bd88..551c48e 100644 (file)
@@ -35,6 +35,12 @@ else()
   set(EXTRA_DIST ${EXTRA_DIST} ${STHREAD_SRC})
 endif()
 
+if(HAVE_MMALLOC)
+  add_library(sgmalloc SHARED ${SGMALLOC_SRC})
+  set_property(TARGET sgmalloc
+                APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
+endif()
+
 if(enable_model-checking)
   add_executable(simgrid-mc ${MC_SIMGRID_MC_SRC})
   target_link_libraries(simgrid-mc simgrid)