memory_order_release, memory_order_acq_rel, memory_order_seq_cst
};
-#define ensureModel(action) \
- if (!modelchecker_started) { \
- if (!model) { \
- snapshot_system_init(10000, 1024, 1024, 40000); \
- model = new ModelChecker(); \
- } \
- model->get_execution()->check_current_action(action); \
- }else { \
- model->switch_to_master(action); \
- }
-
-
-#define ensureModelValue(action, type) \
- if (!modelchecker_started) { \
- if (!model) { \
- snapshot_system_init(10000, 1024, 1024, 40000); \
- model = new ModelChecker(); \
- } \
- model->get_execution()->check_current_action(action); \
- return (type) thread_current()->get_return_value(); \
- } else { \
- return (type) model->switch_to_master(action); \
+static void ensureModel() {
+ if (!model) {
+ snapshot_system_init(10000, 1024, 1024, 40000);
+ model = new ModelChecker();
+ model->startChecker();
}
+}
/** Performs a read action.*/
uint64_t model_read_action(void * obj, memory_order ord) {
/* --- helper functions --- */
uint64_t model_rmwrcas_action_helper(void *obj, int atomic_index, uint64_t oldval, int size, const char *position) {
- ensureModelValue(
- new ModelAction(ATOMIC_RMWRCAS, position, orders[atomic_index], obj, oldval, size), uint64_t
- );
+ ensureModel();
+ return model->switch_to_master(new ModelAction(ATOMIC_RMWRCAS, position, orders[atomic_index], obj, oldval, size));
}
uint64_t model_rmwr_action_helper(void *obj, int atomic_index, const char *position) {
- ensureModelValue(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj), uint64_t);
+ ensureModel();
+ return model->switch_to_master(new ModelAction(ATOMIC_RMWR, position, orders[atomic_index], obj));
}
void model_rmw_action_helper(void *obj, uint64_t val, int atomic_index, const char * position) {
- ensureModel(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_RMW, position, orders[atomic_index], obj, val));
}
void model_rmwc_action_helper(void *obj, int atomic_index, const char *position) {
- ensureModel(new ModelAction(ATOMIC_RMWC, position, orders[atomic_index], obj));
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_RMWC, position, orders[atomic_index], obj));
}
// cds atomic inits
void cds_atomic_init8(void * obj, uint8_t val, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val));
}
void cds_atomic_init16(void * obj, uint16_t val, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val));
}
void cds_atomic_init32(void * obj, uint32_t val, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, (uint64_t) val));
}
void cds_atomic_init64(void * obj, uint64_t val, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_INIT, position, memory_order_relaxed, obj, val));
}
// cds atomic loads
uint8_t cds_atomic_load8(void * obj, int atomic_index, const char * position) {
- ensureModelValue(
- new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint8_t);
+ ensureModel();
+ return (uint8_t) model->switch_to_master(
+ new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
}
uint16_t cds_atomic_load16(void * obj, int atomic_index, const char * position) {
- ensureModelValue(
- new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint16_t);
+ ensureModel();
+ return (uint16_t) model->switch_to_master(
+ new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
}
uint32_t cds_atomic_load32(void * obj, int atomic_index, const char * position) {
- ensureModelValue(
- new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint32_t
+ ensureModel();
+ return (uint32_t) model->switch_to_master(
+ new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj)
);
}
uint64_t cds_atomic_load64(void * obj, int atomic_index, const char * position) {
- ensureModelValue(
- new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj), uint64_t);
+ ensureModel();
+ return model->switch_to_master(
+ new ModelAction(ATOMIC_READ, position, orders[atomic_index], obj));
}
// cds atomic stores
void cds_atomic_store8(void * obj, uint8_t val, int atomic_index, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val));
}
void cds_atomic_store16(void * obj, uint16_t val, int atomic_index, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val));
}
void cds_atomic_store32(void * obj, uint32_t val, int atomic_index, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val));
}
void cds_atomic_store64(void * obj, uint64_t val, int atomic_index, const char * position) {
- ensureModel(
- new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, val)
- );
+ ensureModel();
+ model->switch_to_master(new ModelAction(ATOMIC_WRITE, position, orders[atomic_index], obj, (uint64_t) val));
}
#define _ATOMIC_RMW_(__op__, size, addr, val, atomic_index, position) \
#include "params.h"
ModelChecker *model = NULL;
-bool modelchecker_started = false;
/** Wrapper to run the user's main function, with appropriate arguments */
void user_main_wrapper(void *)
bugs->size(),
bugs->size() > 1 ? "s" : "");
for (unsigned int i = 0;i < bugs->size();i++)
- (*bugs)[i] -> print();
+ (*bugs)[i]->print();
}
/**
*/
void ModelChecker::record_stats()
{
- stats.num_total ++;
+ stats.num_total++;
if (!execution->isfeasibleprefix())
- stats.num_infeasible ++;
+ stats.num_infeasible++;
else if (execution->have_bug_reports())
- stats.num_buggy_executions ++;
+ stats.num_buggy_executions++;
else if (execution->is_complete_execution())
- stats.num_complete ++;
+ stats.num_complete++;
else {
- stats.num_redundant ++;
+ stats.num_redundant++;
/**
* @todo We can violate this ASSERT() when fairness/sleep sets
return true;
}
// test code
- execution_number ++;
+ execution_number++;
reset_to_initial_state();
return false;
}
/** @brief Run trace analyses on complete trace */
void ModelChecker::run_trace_analyses() {
- for (unsigned int i = 0;i < trace_analyses.size();i ++)
- trace_analyses[i] -> analyze(execution->get_action_trace());
+ for (unsigned int i = 0;i < trace_analyses.size();i++)
+ trace_analyses[i]->analyze(execution->get_action_trace());
}
/**
return old->get_return_value();
}
+static void runChecker() {
+ model->run();
+ delete model;
+}
+
+void ModelChecker::startChecker() {
+ startExecution(get_system_context(), runChecker);
+}
+
bool ModelChecker::should_terminate_execution()
{
/* Infeasible -> don't take any more steps */
execution_number = 1;
}
+void ModelChecker::startMainThread() {
+ init_thread->setContext();
+}
+
/** @brief Run ModelChecker for the user program */
void ModelChecker::run()
{
char random_state[256];
initstate(423121, random_state, sizeof(random_state));
- for(int exec = 0;exec < params.maxexecutions;exec ++) {
+ for(int exec = 0;exec < params.maxexecutions;exec++) {
Thread * t = init_thread;
do {
snapshot_add_memory_region(pagealignedbase, numheappages);
}
-
-static void mprot_startExecution(VoidFuncPtr entryPoint) {
- entryPoint();
+static void mprot_startExecution(ucontext_t * context, VoidFuncPtr entryPoint) {
+ /* setup the shared-stack context */
+ create_context(context, fork_snap->mStackBase, model_calloc(STACK_SIZE_DEFAULT, 1), STACK_SIZE_DEFAULT, entryPoint);
}
static void mprot_add_to_snapshot(void *addr, unsigned int numPages)
getcontext(ctxt);
ctxt->uc_stack.ss_sp = stack;
ctxt->uc_stack.ss_size = stacksize;
+ ctxt->uc_link = NULL;
makecontext(ctxt, func, 0);
}
* process */
static void fork_exit()
{
- /* Intentionally empty */
+ _Exit(EXIT_SUCCESS);
}
static void createSharedMemory()
model_snapshot_space = create_mspace_with_base(pagealignedbase, numheappages * PAGESIZE, 1);
}
-static void fork_startExecution(VoidFuncPtr entryPoint) {
- /* setup an "exiting" context */
- char stack[128];
- create_context(&exit_ctxt, stack, sizeof(stack), fork_exit);
-
- /* setup the shared-stack context */
- create_context(&fork_snap->shared_ctxt, fork_snap->mStackBase,
- STACK_SIZE_DEFAULT, entryPoint);
- /* switch to a new entryPoint context, on a new stack */
- model_swapcontext(&private_ctxt, &fork_snap->shared_ctxt);
-
+static void fork_loop() {
/* switch back here when takesnapshot is called */
snapshotid = fork_snap->currSnapShotID;
if (model->params.nofork) {
}
}
-static snapshot_id fork_take_snapshot()
-{
+static void fork_startExecution(ucontext_t *context, VoidFuncPtr entryPoint) {
+ /* setup an "exiting" context */
+ char stack[128];
+ create_context(&exit_ctxt, stack, sizeof(stack), fork_exit);
+
+ /* setup the system context */
+ create_context(context, fork_snap->mStackBase, STACK_SIZE_DEFAULT, entryPoint);
+ /* switch to a new entryPoint context, on a new stack */
+ create_context(&private_ctxt, snapshot_calloc(STACK_SIZE_DEFAULT, 1), STACK_SIZE_DEFAULT, fork_loop);
+}
+
+static snapshot_id fork_take_snapshot() {
model_swapcontext(&fork_snap->shared_ctxt, &private_ctxt);
DEBUG("TAKESNAPSHOT RETURN\n");
return snapshotid;
#endif
}
-void startExecution(VoidFuncPtr entryPoint)
+void startExecution(ucontext_t *context, VoidFuncPtr entryPoint)
{
#if USE_MPROTECT_SNAPSHOT
- mprot_startExecution(entryPoint);
+ mprot_startExecution(context, entryPoint);
#else
- fork_startExecution(entryPoint);
+ fork_startExecution(context, entryPoint);
#endif
}