towards not calling system malloc
authorroot <root@dw-6.eecs.uci.edu>
Fri, 28 Jun 2019 18:55:28 +0000 (11:55 -0700)
committerroot <root@dw-6.eecs.uci.edu>
Fri, 28 Jun 2019 18:55:28 +0000 (11:55 -0700)
Makefile
history.h
libthreads.cc
model.cc
mymemory.cc
pthread.cc
snapshot.cc

index 00b99cc45a12d0b89e0c4d447b3a2fb1ef4d4c84..771c187a0e7e724cd2fcd3a03ff1a4796303277e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ README.html: README.md
        $(MARKDOWN) $< > $@
 
 malloc.o: malloc.c
        $(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)
 
 futex.o: futex.cc
        $(CXX) -fPIC -c futex.cc -std=c++11 $(CPPFLAGS)
index 441a999f46f2ab6cb6e7f1f4124ae1e90b156e77..179439ce44ad24d6a0fafc0d31689558de94820c 100644 (file)
--- a/history.h
+++ b/history.h
@@ -22,7 +22,7 @@ public:
        HashTable<uint32_t, action_mlist_t *, uintptr_t, 4> * getFuncHistory() { return &func_history; }
 
        void print();
        HashTable<uint32_t, action_mlist_t *, uintptr_t, 4> * getFuncHistory() { return &func_history; }
 
        void print();
-
+       MEMALLOC
 private:
        uint32_t func_id;
 
 private:
        uint32_t func_id;
 
index 5ff106c8535982bd82835366a0444ce77c0f300e..ca69fdabdfcd6956086b4b424ab5a1956ea3757d 100644 (file)
@@ -12,7 +12,7 @@
  */
 int thrd_create(thrd_t *t, thrd_start_t start_routine, void *arg)
 {
  */
 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)&params));
        return 0;
        /* 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)&params));
        return 0;
index b4bbb70e926bfdba2610509f4cdfc8265b137e1d..5ef9651cc42b3f13ffb16b124797cbf47cfe2fdf 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -42,7 +42,7 @@ ModelChecker::ModelChecker() :
        inspect_plugin(NULL)
 {
        memset(&stats,0,sizeof(struct execution_stats));
        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(&params);
        execution->add_thread(init_thread);
        scheduler->set_current_thread(init_thread);
        execution->setParams(&params);
index 84600ae9d39ebac840d9cfe606bb5b030778b170..e72c1421f011a7297b33da2eb2a6c026b92bc3c9 100644 (file)
@@ -1,3 +1,4 @@
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <dlfcn.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <dlfcn.h>
@@ -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)
 {
 /** @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;
 }
        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)
 {
 /** @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;
 }
        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)
 {
 /** @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;
 }
        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)
 {
 /** @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. */
 }
 
 /** 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)
 {
 /** @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)
 {
 }
 
 /** @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 */
 }
 
 #endif /* !USE_MPROTECT_SNAPSHOT */
index 9a222b9d85a24bccb70d04a92d549bebf5f9a33c..b8c97510219368ab973ac61d0e2ac4ddf749cdf5 100644 (file)
 
 int pthread_create(pthread_t *t, const pthread_attr_t * attr,
                                                                         pthread_start_t start_routine, void * arg) {
 
 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)&params);
        struct pthread_params params = { start_routine, arg };
 
        ModelAction *act = new ModelAction(PTHREAD_CREATE, std::memory_order_seq_cst, t, (uint64_t)&params);
@@ -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) {
 }
 
 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
        ModelExecution *execution = model->get_execution();
 
        /* to protect the case where PTHREAD_MUTEX_INITIALIZER is used
index 2901be3c385db322689a3b8793c340c613921920..c24e5ec54097d876851b32e681f8334621afd165 100644 (file)
@@ -372,9 +372,7 @@ static void fork_snapshot_init(unsigned int numbackingpages,
        if (!fork_snap)
                createSharedMemory();
 
        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() {
 }
 
 static void fork_loop() {