12 #include "threads-model.h"
16 #define REQUESTS_BEFORE_ALLOC 1024
18 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
21 static mspace sStaticSpace = NULL;
23 /** Non-snapshotting calloc for our use. */
24 void *model_calloc(size_t count, size_t size)
27 sStaticSpace = create_shared_mspace();
28 return mspace_calloc(sStaticSpace, count, size);
31 /** Non-snapshotting malloc for our use. */
32 void *model_malloc(size_t size)
35 sStaticSpace = create_shared_mspace();
36 return mspace_malloc(sStaticSpace, size);
39 /** Non-snapshotting malloc for our use. */
40 void *model_realloc(void *ptr, size_t size)
43 sStaticSpace = create_shared_mspace();
44 return mspace_realloc(sStaticSpace, ptr, size);
47 /** @brief Snapshotting malloc, for use by model-checker (not user progs) */
48 void * snapshot_malloc(size_t size)
50 void *tmp = mspace_malloc(model_snapshot_space, size);
55 /** @brief Snapshotting calloc, for use by model-checker (not user progs) */
56 void * snapshot_calloc(size_t count, size_t size)
58 void *tmp = mspace_calloc(model_snapshot_space, count, size);
63 /** @brief Snapshotting realloc, for use by model-checker (not user progs) */
64 void *snapshot_realloc(void *ptr, size_t size)
66 void *tmp = mspace_realloc(model_snapshot_space, ptr, size);
71 /** @brief Snapshotting free, for use by model-checker (not user progs) */
72 void snapshot_free(void *ptr)
74 mspace_free(model_snapshot_space, ptr);
77 /** Non-snapshotting free for our use. */
78 void model_free(void *ptr)
80 mspace_free(sStaticSpace, ptr);
83 /** Bootstrap allocation. Problem is that the dynamic linker calls require
84 * calloc to work and calloc requires the dynamic linker to work. */
86 #define BOOTSTRAPBYTES 131072
87 char bootstrapmemory[BOOTSTRAPBYTES];
90 void * HandleEarlyAllocationRequest(size_t sz)
92 /* Align to 8 byte boundary */
95 if (sz > (BOOTSTRAPBYTES-offset)) {
96 model_print("OUT OF BOOTSTRAP MEMORY. Increase the size of BOOTSTRAPBYTES in mymemory.cc\n");
100 void *pointer = (void *)&bootstrapmemory[offset];
105 /** @brief Global mspace reference for the model-checker's snapshotting heap */
106 mspace model_snapshot_space = NULL;
108 /** @brief Snapshotting allocation function for use by the Thread class only */
109 void * Thread_malloc(size_t size)
111 return snapshot_malloc(size);
114 /** @brief Snapshotting free function for use by the Thread class only */
115 void Thread_free(void *ptr)