12 #include "threads-model.h"
16 #define REQUESTS_BEFORE_ALLOC 1024
18 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
21 mspace sStaticSpace = NULL;
23 /** Non-snapshotting calloc for our use. */
24 void *model_calloc(size_t count, size_t size)
26 return mspace_calloc(sStaticSpace, count, size);
29 /** Non-snapshotting malloc for our use. */
30 void *model_malloc(size_t size)
32 return mspace_malloc(sStaticSpace, size);
35 /** Non-snapshotting malloc for our use. */
36 void *model_realloc(void *ptr, size_t size)
38 return mspace_realloc(sStaticSpace, ptr, size);
41 /** @brief Snapshotting malloc, for use by model-checker (not user progs) */
42 void * snapshot_malloc(size_t size)
44 void *tmp = mspace_malloc(model_snapshot_space, size);
49 /** @brief Snapshotting calloc, for use by model-checker (not user progs) */
50 void * snapshot_calloc(size_t count, size_t size)
52 void *tmp = mspace_calloc(model_snapshot_space, count, size);
57 /** @brief Snapshotting realloc, for use by model-checker (not user progs) */
58 void *snapshot_realloc(void *ptr, size_t size)
60 void *tmp = mspace_realloc(model_snapshot_space, ptr, size);
65 /** @brief Snapshotting free, for use by model-checker (not user progs) */
66 void snapshot_free(void *ptr)
68 mspace_free(model_snapshot_space, ptr);
71 /** Non-snapshotting free for our use. */
72 void model_free(void *ptr)
74 mspace_free(sStaticSpace, ptr);
77 /** Bootstrap allocation. Problem is that the dynamic linker calls require
78 * calloc to work and calloc requires the dynamic linker to work. */
80 #define BOOTSTRAPBYTES 131072
81 char bootstrapmemory[BOOTSTRAPBYTES];
84 void * HandleEarlyAllocationRequest(size_t sz)
86 /* Align to 8 byte boundary */
89 if (sz > (BOOTSTRAPBYTES-offset)) {
90 model_print("OUT OF BOOTSTRAP MEMORY. Increase the size of BOOTSTRAPBYTES in mymemory.cc\n");
94 void *pointer = (void *)&bootstrapmemory[offset];
99 /** @brief Global mspace reference for the model-checker's snapshotting heap */
100 mspace model_snapshot_space = NULL;
102 /** @brief Snapshotting allocation function for use by the Thread class only */
103 void * Thread_malloc(size_t size)
105 return snapshot_malloc(size);
108 /** @brief Snapshotting free function for use by the Thread class only */
109 void Thread_free(void *ptr)