From: root Date: Fri, 28 Jun 2019 18:55:28 +0000 (-0700) Subject: towards not calling system malloc X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=f186d74da258bf0a24b57b13a10b40641e09efd6 towards not calling system malloc --- diff --git a/Makefile b/Makefile index 00b99cc4..771c187a 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ README.html: README.md $(MARKDOWN) $< > $@ malloc.o: malloc.c - $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES -DHAVE_MMAP=0 $(CPPFLAGS) -Wno-unused-variable + $(CC) -fPIC -c malloc.c -DMSPACES -DONLY_MSPACES -DHAVE_MMAP=1 $(CPPFLAGS) -Wno-unused-variable futex.o: futex.cc $(CXX) -fPIC -c futex.cc -std=c++11 $(CPPFLAGS) diff --git a/history.h b/history.h index 441a999f..179439ce 100644 --- a/history.h +++ b/history.h @@ -22,7 +22,7 @@ public: HashTable * getFuncHistory() { return &func_history; } void print(); - + MEMALLOC private: uint32_t func_id; diff --git a/libthreads.cc b/libthreads.cc index 5ff106c8..ca69fdab 100644 --- a/libthreads.cc +++ b/libthreads.cc @@ -12,7 +12,7 @@ */ int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg) { - struct thread_params params = { start_routine, arg }; + struct thread_params params = { start_routine, arg }; /* seq_cst is just a 'don't care' parameter */ model->switch_to_master(new ModelAction(THREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)¶ms)); return 0; diff --git a/model.cc b/model.cc index b4bbb70e..5ef9651c 100644 --- a/model.cc +++ b/model.cc @@ -42,7 +42,7 @@ ModelChecker::ModelChecker() : inspect_plugin(NULL) { memset(&stats,0,sizeof(struct execution_stats)); - init_thread = new Thread(execution->get_next_id(), (thrd_t *) malloc(sizeof(thrd_t)), &user_main_wrapper, NULL, NULL); // L: user_main_wrapper passes the user program + init_thread = new Thread(execution->get_next_id(), (thrd_t *) model_malloc(sizeof(thrd_t)), &user_main_wrapper, NULL, NULL); // L: user_main_wrapper passes the user program execution->add_thread(init_thread); scheduler->set_current_thread(init_thread); execution->setParams(¶ms); diff --git a/mymemory.cc b/mymemory.cc index 84600ae9..e72c1421 100644 --- a/mymemory.cc +++ b/mymemory.cc @@ -1,3 +1,4 @@ + #include #include #include @@ -74,7 +75,7 @@ void *model_malloc(size_t size) /** @brief Snapshotting malloc, for use by model-checker (not user progs) */ void * snapshot_malloc(size_t size) { - void *tmp = malloc(size); + void *tmp = mspace_malloc(model_snapshot_space, size); ASSERT(tmp); return tmp; } @@ -82,7 +83,7 @@ void * snapshot_malloc(size_t size) /** @brief Snapshotting calloc, for use by model-checker (not user progs) */ void * snapshot_calloc(size_t count, size_t size) { - void *tmp = calloc(count, size); + void *tmp = mspace_calloc(model_snapshot_space, count, size); ASSERT(tmp); return tmp; } @@ -90,7 +91,7 @@ void * snapshot_calloc(size_t count, size_t size) /** @brief Snapshotting realloc, for use by model-checker (not user progs) */ void *snapshot_realloc(void *ptr, size_t size) { - void *tmp = realloc(ptr, size); + void *tmp = mspace_realloc(model_snapshot_space, ptr, size); ASSERT(tmp); return tmp; } @@ -98,7 +99,7 @@ void *snapshot_realloc(void *ptr, size_t size) /** @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. */ @@ -264,13 +265,13 @@ void operator delete[](void *p, size_t size) /** @brief Snapshotting allocation function for use by the Thread class only */ void * Thread_malloc(size_t size) { - return malloc(size); + return snapshot_malloc(size); } /** @brief Snapshotting free function for use by the Thread class only */ void Thread_free(void *ptr) { - free(ptr); + snapshot_free(ptr); } #endif /* !USE_MPROTECT_SNAPSHOT */ diff --git a/pthread.cc b/pthread.cc index 9a222b9d..b8c97510 100644 --- a/pthread.cc +++ b/pthread.cc @@ -16,6 +16,12 @@ int pthread_create(pthread_t *t, const pthread_attr_t * attr, pthread_start_t start_routine, void * arg) { + if (!model) { + snapshot_system_init(10000, 1024, 1024, 40000); + model = new ModelChecker(); + model->startChecker(); + } + struct pthread_params params = { start_routine, arg }; ModelAction *act = new ModelAction(PTHREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)¶ms); @@ -63,6 +69,13 @@ int pthread_mutex_init(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *) { } int pthread_mutex_lock(pthread_mutex_t *p_mutex) { + if (!model) { + snapshot_system_init(10000, 1024, 1024, 40000); + model = new ModelChecker(); + model->startChecker(); + } + + ModelExecution *execution = model->get_execution(); /* to protect the case where PTHREAD_MUTEX_INITIALIZER is used diff --git a/snapshot.cc b/snapshot.cc index 2901be3c..c24e5ec5 100644 --- a/snapshot.cc +++ b/snapshot.cc @@ -372,9 +372,7 @@ static void fork_snapshot_init(unsigned int numbackingpages, if (!fork_snap) createSharedMemory(); - void *base_model_snapshot_space = malloc((numheappages + 1) * PAGESIZE); - void *pagealignedbase = PageAlignAddressUpward(base_model_snapshot_space); - model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1); + model_snapshot_space = create_mspace(numheappages * PAGESIZE, 1); } static void fork_loop() {