X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=mymemory.cc;h=e05cb783e2455bdf68aaa5b495fa664e000677f2;hb=fc32611957cecd106751b62bc4de4aeddc9af56c;hp=387d6de02365803b8dd33675539918b8d825ebbc;hpb=b5000a06086de6ea8799168d463f018cab785830;p=model-checker.git diff --git a/mymemory.cc b/mymemory.cc index 387d6de..e05cb78 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -1,12 +1,17 @@ -#include "mymemory.h" -#include "snapshot.h" -#include "snapshotimp.h" +#include #include #include #include -#include +#include +#include + +#include "mymemory.h" +#include "snapshot.h" +#include "snapshotimp.h" #include "common.h" + #define REQUESTS_BEFORE_ALLOC 1024 + size_t allocatedReqs[ REQUESTS_BEFORE_ALLOC ] = { 0 }; int nextRequest = 0; int howManyFreed = 0; @@ -73,19 +78,31 @@ void *model_malloc(size_t size) /** @brief Snapshotting malloc, for use by model-checker (not user progs) */ void * snapshot_malloc(size_t size) { - return malloc(size); + void *tmp = mspace_malloc(model_snapshot_space, size); + ASSERT(tmp); + return tmp; } /** @brief Snapshotting calloc, for use by model-checker (not user progs) */ void * snapshot_calloc(size_t count, size_t size) { - return calloc(count, size); + void *tmp = mspace_calloc(model_snapshot_space, count, size); + ASSERT(tmp); + return tmp; +} + +/** @brief Snapshotting realloc, for use by model-checker (not user progs) */ +void *snapshot_realloc(void *ptr, size_t size) +{ + void *tmp = mspace_realloc(model_snapshot_space, ptr, size); + ASSERT(tmp); + return tmp; } /** @brief Snapshotting free, for use by model-checker (not user progs) */ void snapshot_free(void *ptr) { - free(ptr); + mspace_free(model_snapshot_space, ptr); } /** Non-snapshotting free for our use. */ @@ -123,7 +140,7 @@ void * HandleEarlyAllocationRequest(size_t sz) sz = (sz + 7) & ~7; if (sz > (BOOTSTRAPBYTES-offset)) { - printf("OUT OF BOOTSTRAP MEMORY\n"); + model_print("OUT OF BOOTSTRAP MEMORY\n"); exit(EXIT_FAILURE); } @@ -137,9 +154,7 @@ mspace model_snapshot_space = NULL; #if USE_MPROTECT_SNAPSHOT -/** @brief Global mspace reference for the user's snapshotting heap - * @todo use this ONLY for user's allocations, not for internal snapshotting - * state */ +/** @brief Global mspace reference for the user's snapshotting heap */ mspace user_snapshot_space = NULL; /** Check whether this is bootstrapped memory that we should not free */ @@ -183,7 +198,7 @@ void * calloc(size_t num, size_t size) return tmp; } else { void *tmp = HandleEarlyAllocationRequest(size * num); - std::memset(tmp, 0, size * num); + memset(tmp, 0, size * num); return tmp; } }