mspace_malloc will call into mmap if it runs out of memory... this does not play...
authorBrian Demsky <bdemsky@uci.edu>
Wed, 3 Oct 2012 09:57:32 +0000 (02:57 -0700)
committerBrian Demsky <bdemsky@uci.edu>
Wed, 3 Oct 2012 09:57:32 +0000 (02:57 -0700)
snapshotting the mspace of course...

turn off the mmap option and give us a bigger heap...
add assertions to malloc/calloc/realloc if they return NULL (which is now possible with MMAP turned off)

Makefile
main.cc
mymemory.cc
snapshotimp.h

index 19f9a2c06900c5835fae6d256ff91d83437dbdc3..c11ebb45c0e261d0f693a2c95d39d0a4db905592 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -39,7 +39,7 @@ $(LIB_SO): $(OBJECTS)
        $(CXX) $(SHARED) -o $(LIB_SO) $(OBJECTS) $(LDFLAGS)
 
 malloc.o: malloc.c
-       $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES $(CPPFLAGS)
+       $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES -DHAVE_MMAP=0 $(CPPFLAGS)
 
 %.o: %.cc
        $(CXX) -fPIC -c $< $(CPPFLAGS)
diff --git a/main.cc b/main.cc
index 26d8beb79d52f8d09a9d16b97f96c79972941822..5b03c85c2c11f82ef308cc08464330792f617b53 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -117,5 +117,5 @@ int main(int argc, char ** argv) {
        main_argv = argv;
 
        /* Let's jump in quickly and start running stuff */
-       initSnapShotLibrary(10000, 1024, 1024, 1000, &real_main);
+       initSnapShotLibrary(10000, 1024, 1024, 4000, &real_main);
 }
index 29fd2ea94a1ebaa57767a3542dd1d78fe454d25d..6caf27a3d1d3799a1e11be74f615b95fd9a1d7b0 100644 (file)
@@ -158,7 +158,9 @@ bool DontFree( void * ptr ){
 /** Snapshotting malloc implementation for user programs. */
 void *malloc( size_t size ) {
        if (mySpace) {
-               return mspace_malloc( mySpace, size );
+               void *tmp=mspace_malloc( mySpace, size );
+               ASSERT(tmp);
+               return tmp;
        }       else
                return HandleEarlyAllocationRequest( size );
 }
@@ -171,14 +173,18 @@ void free( void * ptr ){
 
 /** Snapshotting realloc implementation for user programs. */
 void *realloc( void *ptr, size_t size ){
-       return mspace_realloc( mySpace, ptr, size );
+       void *tmp=mspace_realloc( mySpace, ptr, size );
+       ASSERT(tmp);
+       return tmp;
 }
 
 /** Snapshotting calloc implementation for user programs. */
 void * calloc( size_t num, size_t size ){
-       if (mySpace)
-               return mspace_calloc( mySpace, num, size );
-       else {
+       if (mySpace) {
+               void *tmp=mspace_calloc( mySpace, num, size );
+               ASSERT(tmp);
+               return tmp;
+       } else {
                void *tmp=HandleEarlyAllocationRequest( size * num );
                std::memset( tmp, 0, size * num );
                return tmp;
index e5c331a2e5ee765fe7e3ec6d7a4fa189fa6e0b2b..2e4929d0477e4605cd5363fb86266cd054d1f3fe 100644 (file)
@@ -11,7 +11,7 @@
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <csignal>
-#define SHARED_MEMORY_DEFAULT  (100 * ((size_t)1 << 20)) // 100mb for the shared memory
+#define SHARED_MEMORY_DEFAULT  (100 * ((size_t)1 << 20)) // 100mb for the shared memory
 #define STACK_SIZE_DEFAULT      (((size_t)1 << 20) * 20)  // 20 mb out of the above 100 mb for my stack
 
 #if USE_MPROTECT_SNAPSHOT