free(ptr);
}
-void *system_malloc(size_t size)
-{
- static void *(*mallocp)(size_t size);
- char *error;
- void *ptr;
-
- /* get address of libc malloc */
- if (!mallocp) {
- mallocp = (void * (*)(size_t))dlsym(RTLD_NEXT, "malloc");
- if ((error = dlerror()) != NULL) {
- fputs(error, stderr);
- exit(EXIT_FAILURE);
- }
- }
- ptr = mallocp(size);
- return ptr;
-}
-
/** Non-snapshotting free for our use. */
void model_free(void *ptr)
{
#endif
}
-/** @brief Global mspace reference for the snapshotting heap */
-mspace mySpace = NULL;
-
/** Bootstrap allocation. Problem is that the dynamic linker calls
* require calloc to work and calloc requires the dynamic linker to
* work. */
return pointer;
}
+#if USE_MPROTECT_SNAPSHOT
+
+/** @brief Global mspace reference for the snapshotting heap */
+mspace snapshot_space = NULL;
+
/** Check whether this is bootstrapped memory that we should not free */
static bool DontFree(void *ptr)
{
/** @brief Snapshotting malloc implementation for user programs */
void *malloc(size_t size)
{
- if (mySpace) {
- void *tmp = mspace_malloc(mySpace, size);
+ if (snapshot_space) {
+ void *tmp = mspace_malloc(snapshot_space, size);
ASSERT(tmp);
return tmp;
} else
void free(void * ptr)
{
if (!DontFree(ptr))
- mspace_free(mySpace, ptr);
+ mspace_free(snapshot_space, ptr);
}
/** @brief Snapshotting realloc implementation for user programs */
void *realloc(void *ptr, size_t size)
{
- void *tmp = mspace_realloc(mySpace, ptr, size);
+ void *tmp = mspace_realloc(snapshot_space, ptr, size);
ASSERT(tmp);
return tmp;
}
/** @brief Snapshotting calloc implementation for user programs */
void * calloc(size_t num, size_t size)
{
- if (mySpace) {
- void *tmp = mspace_calloc(mySpace, num, size);
+ if (snapshot_space) {
+ void *tmp = mspace_calloc(snapshot_space, num, size);
ASSERT(tmp);
return tmp;
} else {
{
free(p);
}
+#endif /* USE_MPROTECT_SNAPSHOT */