From 0403cb2a09782c54f12f413be0a2ccd7ea6ae60a Mon Sep 17 00:00:00 2001 From: weiyu Date: Wed, 24 Jul 2019 17:09:41 -0700 Subject: [PATCH] avoid the use of 'func_id_list_t *' to prevent potential seg faults --- execution.h | 4 ++-- history.cc | 45 ++++++++++++++++++++++++++------------------- history.h | 1 + 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/execution.h b/execution.h index f1d3dc56..e958148f 100644 --- a/execution.h +++ b/execution.h @@ -89,7 +89,7 @@ public: HashTable * getMutexMap() {return &mutex_map;} ModelAction * check_current_action(ModelAction *curr); - SnapVector * get_thrd_func_list() { return &thrd_func_list; } + SnapVector * get_thrd_func_list() { return &thrd_func_list; } SnapVector< SnapList *> * get_thrd_func_inst_lists() { return &thrd_func_inst_lists; } SNAPSHOTALLOC @@ -203,7 +203,7 @@ private: * * This data structure is handled by ModelHistory */ - SnapVector< func_id_list_t * > thrd_func_list; + SnapVector thrd_func_list; /* Keeps track of atomic actions that thread i has performed in some * function. Index of SnapVector is thread id. SnapList simulates diff --git a/history.cc b/history.cc index a3398f9c..abf11823 100644 --- a/history.cc +++ b/history.cc @@ -20,7 +20,7 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) { //model_print("thread %d entering func %d\n", tid, func_id); uint32_t id = id_to_int(tid); - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); @@ -29,20 +29,14 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) thrd_func_inst_lists->resize( id + 1 ); } - func_id_list_t * func_list = thrd_func_list->at(id); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - if (func_list == NULL) { - func_list = new func_id_list_t(); - thrd_func_list->at(id) = func_list; - } - if (func_inst_lists == NULL) { func_inst_lists = new SnapList< func_inst_list_t *>(); thrd_func_inst_lists->at(id) = func_inst_lists; } - func_list->push_back(func_id); + (*thrd_func_list)[id].push_back(func_id); func_inst_lists->push_back( new func_inst_list_t() ); if ( func_nodes.size() <= func_id ) @@ -53,14 +47,12 @@ void ModelHistory::enter_function(const uint32_t func_id, thread_id_t tid) void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) { uint32_t id = id_to_int(tid); - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); - func_id_list_t * func_list = thrd_func_list->at(id); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - - uint32_t last_func_id = func_list->back(); + uint32_t last_func_id = (*thrd_func_list)[id].back(); if (last_func_id == func_id) { /* clear read map upon exiting functions */ @@ -70,7 +62,7 @@ void ModelHistory::exit_function(const uint32_t func_id, thread_id_t tid) func_inst_list_t * curr_inst_list = func_inst_lists->back(); func_node->link_insts(curr_inst_list); - func_list->pop_back(); + (*thrd_func_list)[id].pop_back(); func_inst_lists->pop_back(); } else { model_print("trying to exit with a wrong function id\n"); @@ -99,22 +91,20 @@ void ModelHistory::process_action(ModelAction *act, thread_id_t tid) { /* return if thread i has not entered any function or has exited from all functions */ - SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); SnapVector< SnapList *> * thrd_func_inst_lists = model->get_execution()->get_thrd_func_inst_lists(); uint32_t id = id_to_int(tid); if ( thrd_func_list->size() <= id ) return; - else if (thrd_func_list->at(id) == NULL) - return; +// else if ( (*thrd_func_list)[id] == NULL) +// return; /* get the function id that thread i is currently in */ - func_id_list_t * func_list = thrd_func_list->at(id); SnapList * func_inst_lists = thrd_func_inst_lists->at(id); - uint32_t func_id = func_list->back(); - + uint32_t func_id = (*thrd_func_list)[id].back(); if ( func_nodes.size() <= func_id ) resize_func_nodes( func_id + 1 ); @@ -145,6 +135,23 @@ FuncNode * ModelHistory::get_func_node(uint32_t func_id) return func_nodes[func_id]; } +uint64_t ModelHistory::query_last_read(void * location, thread_id_t tid) +{ + SnapVector * thrd_func_list = model->get_execution()->get_thrd_func_list(); + uint32_t id = id_to_int(tid); + + ASSERT( thrd_func_list->size() > id ); + uint32_t func_id = (*thrd_func_list)[id].back(); + FuncNode * func_node = func_nodes[func_id]; + + uint64_t last_read_val = 0xdeadbeef; + if (func_node != NULL) { + last_read_val = func_node->query_last_read(location, tid); + } + + return last_read_val; +} + void ModelHistory::print() { /* function id starts with 1 */ diff --git a/history.h b/history.h index 0984e03a..184646c6 100644 --- a/history.h +++ b/history.h @@ -22,6 +22,7 @@ public: ModelVector * getFuncNodes() { return &func_nodes; } FuncNode * get_func_node(uint32_t func_id); + uint64_t query_last_read(void * location, thread_id_t tid); void print(); -- 2.34.1