From: weiyu Date: Sat, 21 Mar 2020 01:52:27 +0000 (-0700) Subject: Add pthread functions X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=884ebb4495edcb6fed84c0b4746b882bb0918ddc Add pthread functions --- diff --git a/execution.cc b/execution.cc index a98567ed..de54394c 100644 --- a/execution.cc +++ b/execution.cc @@ -1527,6 +1527,40 @@ void ModelExecution::print_summary() } +void ModelExecution::print_tail() +{ + model_print("Execution trace %d:\n", get_execution_number()); + + sllnode *it; + + model_print("------------------------------------------------------------------------------------\n"); + model_print("# t Action type MO Location Value Rf CV\n"); + model_print("------------------------------------------------------------------------------------\n"); + + unsigned int hash = 0; + + int length = 25; + int counter = 0; + SnapList list; + for (it = action_trace.end(); it != NULL; it = it->getPrev()) { + if (counter > length) + break; + + ModelAction * act = it->getVal(); + list.push_front(act); + counter++; + } + + for (it = list.begin();it != NULL;it=it->getNext()) { + const ModelAction *act = it->getVal(); + if (act->get_seq_number() > 0) + act->print(); + hash = hash^(hash<<3)^(it->getVal()->hash()); + } + model_print("HASH %u\n", hash); + model_print("------------------------------------------------------------------------------------\n"); +} + /** * Add a Thread to the system for the first time. Should only be called once * per thread. @@ -1577,8 +1611,12 @@ Thread * ModelExecution::get_pthread(pthread_t pid) { } x; x.p = pid; uint32_t thread_id = x.v; + return get_thread(thread_id); // Temporary fix for firefox + +/* if (thread_id < pthread_counter + 1) return pthread_map[thread_id]; else return NULL; +*/ } /** diff --git a/execution.h b/execution.h index 6cdaeaf1..722b8647 100644 --- a/execution.h +++ b/execution.h @@ -41,6 +41,7 @@ public: Thread * take_step(ModelAction *curr); void print_summary(); + void print_tail(); #if SUPPORT_MOD_ORDER_DUMP void dumpGraph(char *filename); #endif diff --git a/include/mypthread.h b/include/mypthread.h index ff7458ed..4b2b615f 100644 --- a/include/mypthread.h +++ b/include/mypthread.h @@ -16,6 +16,23 @@ struct pthread_params { void *arg; }; +struct pthread_attr +{ + /* Scheduler parameters and priority. */ + struct sched_param schedparam; + int schedpolicy; + /* Various flags like detachstate, scope, etc. */ + int flags; + /* Size of guard area. */ + size_t guardsize; + /* Stack handling. */ + void *stackaddr; + size_t stacksize; + /* Affinity map. */ + cpu_set_t *cpuset; + size_t cpusetsize; +}; + extern "C" { int user_main(int, char**); } diff --git a/newfuzzer.cc b/newfuzzer.cc index ad279770..fca9da8d 100644 --- a/newfuzzer.cc +++ b/newfuzzer.cc @@ -33,7 +33,7 @@ void NewFuzzer::register_engine(ModelChecker *_model, ModelExecution *execution) int NewFuzzer::selectWrite(ModelAction *read, SnapVector * rf_set) { -// return random() % rf_set->size(); + return random() % rf_set->size(); thread_id_t tid = read->get_tid(); int thread_id = id_to_int(tid); @@ -344,7 +344,6 @@ Thread * NewFuzzer::selectThread(int * threadlist, int numthreads) wake_up_paused_threads(threadlist, &numthreads); //model_print("list size: %d, active t id: %d\n", numthreads, threadlist[0]); } - int random_index = random() % numthreads; int thread = threadlist[random_index]; thread_id_t curr_tid = int_to_id(thread); diff --git a/pthread.cc b/pthread.cc index b5fb7ce9..706f1b75 100644 --- a/pthread.cc +++ b/pthread.cc @@ -162,6 +162,12 @@ int pthread_mutex_timedlock (pthread_mutex_t *__restrict p_mutex, } pthread_t pthread_self() { + if (!model) { + snapshot_system_init(10000, 1024, 1024, 40000); + model = new ModelChecker(); + model->startChecker(); + } + Thread* th = model->get_current_thread(); return (pthread_t)th->get_id(); } @@ -246,3 +252,37 @@ int pthread_cond_destroy(pthread_cond_t *p_cond) { } return 0; } + +/* https://github.com/lattera/glibc/blob/master/nptl/pthread_getattr_np.c */ +int pthread_getattr_np(pthread_t t, pthread_attr_t *attr) +{ + ModelExecution *execution = model->get_execution(); + Thread *th = execution->get_pthread(t); + + struct pthread_attr *iattr = (struct pthread_attr *) attr; + + /* The sizes are subject to alignment. */ + if (th != NULL) { +#if _STACK_GROWS_DOWN + ASSERT(false); +#else + iattr->stackaddr = (char *) th->get_stack_addr(); +#endif + + } else { + ASSERT(false); + } + + return 0; +} + +int pthread_setname_np(pthread_t t, const char *name) +{ + ModelExecution *execution = model->get_execution(); + Thread *th = execution->get_pthread(t); + + if (th != NULL) + return 0; + + return 1; +} diff --git a/threads-model.h b/threads-model.h index c6078200..e159697d 100644 --- a/threads-model.h +++ b/threads-model.h @@ -101,6 +101,8 @@ public: bool is_model_thread() const { return model_thread; } + void * get_stack_addr() { return stack; } + friend void thread_startup(); #ifdef TLS friend void setup_context(); @@ -156,6 +158,7 @@ private: void *arg; ucontext_t context; void *stack; + uint32_t stack_size; #ifdef TLS void * helper_stack; public: