Increase size of bootstrap bytes as some Linux distributions need more space.
[model-checker.git] / mymemory.cc
index ea8670d60ccdf7250307b7ae4bb55bc89f5507c5..4182e094e5251c1a8efedbe8a92c232c012f13f3 100644 (file)
@@ -8,6 +8,8 @@
 #include "mymemory.h"
 #include "snapshot.h"
 #include "common.h"
+#include "threads-model.h"
+#include "model.h"
 
 #define REQUESTS_BEFORE_ALLOC 1024
 
@@ -122,7 +124,7 @@ void model_free(void *ptr)
 /** Bootstrap allocation. Problem is that the dynamic linker calls require
  *  calloc to work and calloc requires the dynamic linker to work. */
 
-#define BOOTSTRAPBYTES 4096
+#define BOOTSTRAPBYTES 131072
 char bootstrapmemory[BOOTSTRAPBYTES];
 size_t offset = 0;
 
@@ -132,7 +134,7 @@ void * HandleEarlyAllocationRequest(size_t sz)
        sz = (sz + 7) & ~7;
 
        if (sz > (BOOTSTRAPBYTES-offset)) {
-               model_print("OUT OF BOOTSTRAP MEMORY\n");
+               model_print("OUT OF BOOTSTRAP MEMORY.  Increase the size of BOOTSTRAPBYTES in mymemory.cc\n");
                exit(EXIT_FAILURE);
        }
 
@@ -176,9 +178,11 @@ static void * user_malloc(size_t size)
  */
 void *malloc(size_t size)
 {
-       if (user_snapshot_space)
+       if (user_snapshot_space) {
+               /* Only perform user allocations from user context */
+               ASSERT(!model || thread_current());
                return user_malloc(size);
-       else
+       else
                return HandleEarlyAllocationRequest(size);
 }
 
@@ -246,4 +250,19 @@ void operator delete[](void *p, size_t size)
 {
        free(p);
 }
-#endif /* USE_MPROTECT_SNAPSHOT */
+
+#else /* !USE_MPROTECT_SNAPSHOT */
+
+/** @brief Snapshotting allocation function for use by the Thread class only */
+void * Thread_malloc(size_t size)
+{
+       return malloc(size);
+}
+
+/** @brief Snapshotting free function for use by the Thread class only */
+void Thread_free(void *ptr)
+{
+       free(ptr);
+}
+
+#endif /* !USE_MPROTECT_SNAPSHOT */