From: Brian Demsky Date: Wed, 3 Oct 2012 09:57:32 +0000 (-0700) Subject: mspace_malloc will call into mmap if it runs out of memory... this does not play... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=a330e8dbc94f534876cc35b1d9d1b1c06d83a437 mspace_malloc will call into mmap if it runs out of memory... this does not play well with 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) --- diff --git a/Makefile b/Makefile index 19f9a2c0..c11ebb45 100644 --- 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 26d8beb7..5b03c85c 100644 --- 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); } diff --git a/mymemory.cc b/mymemory.cc index 29fd2ea9..6caf27a3 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -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; diff --git a/snapshotimp.h b/snapshotimp.h index e5c331a2..2e4929d0 100644 --- a/snapshotimp.h +++ b/snapshotimp.h @@ -11,7 +11,7 @@ #include #include #include -#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