cloud9_root/src/cloud9/lib/Core/CacheSideChannel.cpp
// solve constraints to get all tests according to side-channel observations
solve constraints to get all tests according to side-channel observations
solve constraints to get all tests according to side - channel observations
int CacheChannel::getAllTests(ExecutionState& state, TimingSolver* solver, long bound) {
	ExecutionState cState(state);
	int nsolution = 0;
	if (missVars.size() == 0) return 1;
	{
		std::vector<std::vector<unsigned char> > values;
		std::vector<const Array*> objects;
		for (unsigned i = 0; i != state.symbolics.size(); i++) {
			llvm::errs() << "\n\n -> Found symbolic memory object, name: \"" << state.symbolics[i].first->name << "\"\n";
			llvm::errs() << "address = " << state.symbolics[i].first->address << "\n";
			objects.push_back(state.symbolics[i].second);
		}
		for (unsigned i = 0; i != missVars.size(); i++) {
			llvm::errs() << "\n\n -> Found symbolic hit/miss variable..." << missVars[i]->name << "\n";
			objects.push_back(missVars[i]);
		}
		bool success = true;
		while (success) {
			success = solver->getInitialValues(data::SIDE_CHANNEL_ANALYSIS, cState, objects, values);
			solver->setTimeout(0);
			if (!success) {
				llvm::errs() << "\n\n..... test generation finished (no more observations possible) .....\n\n";
			} else {
				llvm::errs() << "\n\n..... printing one test for the chosen observer model .....\n\n";
				for (unsigned SI = 0; SI < state.symbolics.size(); SI++) {
					llvm::errs() << state.symbolics[SI].first->name << " = ";
					llvm::errs() << "(size " << state.symbolics[SI].second->size << ", little-endian) ";
					for (unsigned II = 0; II < values[SI].size(); II++)
						fprintf(stdout, "%d ", values[SI][II]);
					fprintf(stdout, "\n");
				}
				unsigned nSymbolic = state.symbolics.size();
				for (unsigned i = 0; i < missVars.size(); i++) {
					llvm::errs() << missVars[i]->getName() << " = ";
					llvm::errs() << "(size " << missVars[i]->getSize() << ", little-endian) ";
					for (unsigned j = 0; j < missVars[i]->getSize(); j++)
						fprintf(stdout, "%d ", values[nSymbolic + i][j]);
					fprintf(stdout, "\n");
				}
				nsolution++;
				llvm::errs() << "..... #tests generated so far = " << nsolution << ".....\n\n";
				if (nsolution >= bound) break;
				if (CacheChannel::observer == MISS_COUNT) getNextTestForObsCount(state, cState, values);
				else if (CacheChannel::observer == MISS_SEQUENCE) getNextTestForObsSeq(state, cState, values);
				else
				assert(0 && "fatal: observer model is not supported");
			}
		}
	}
	return nsolution;
}
int CacheChannel :: getAllTests ( ExecutionState & state , TimingSolver * solver , long bound ) { ExecutionState cState ( state ) ; int nsolution = 0 ; if ( missVars . size ( ) == 0 ) return 1 ; { std :: vector < std :: vector < unsigned char > > values ; std :: vector < const Array * > objects ; for ( unsigned i = 0 ; i != state . symbolics . size ( ) ; i ++ ) { llvm :: errs ( ) << " \n \n \" " << state . symbolics [ i ] . first -> name << " \" \n " ; llvm :: errs ( ) << " " << state . symbolics [ i ] . first -> address << " \n " ; objects . push_back ( state . symbolics [ i ] . second ) ; } for ( unsigned i = 0 ; i != missVars . size ( ) ; i ++ ) { llvm :: errs ( ) << " \n \n " << missVars [ i ] -> name << " \n " ; objects . push_back ( missVars [ i ] ) ; } bool success = true ; while ( success ) { success = solver -> getInitialValues ( data :: SIDE_CHANNEL_ANALYSIS , cState , objects , values ) ; solver -> setTimeout ( 0 ) ; if ( ! success ) { llvm :: errs ( ) << " \n \n \n \n " ; } else { llvm :: errs ( ) << " \n \n \n \n " ; for ( unsigned SI = 0 ; SI < state . symbolics . size ( ) ; SI ++ ) { llvm :: errs ( ) << state . symbolics [ SI ] . first -> name << " " ; llvm :: errs ( ) << " " << state . symbolics [ SI ] . second -> size << " " ; for ( unsigned II = 0 ; II < values [ SI ] . size ( ) ; II ++ ) fprintf ( stdout , " " , values [ SI ] [ II ] ) ; fprintf ( stdout , " \n " ) ; } unsigned nSymbolic = state . symbolics . size ( ) ; for ( unsigned i = 0 ; i < missVars . size ( ) ; i ++ ) { llvm :: errs ( ) << missVars [ i ] -> getName ( ) << " " ; llvm :: errs ( ) << " " << missVars [ i ] -> getSize ( ) << " " ; for ( unsigned j = 0 ; j < missVars [ i ] -> getSize ( ) ; j ++ ) fprintf ( stdout , " " , values [ nSymbolic + i ] [ j ] ) ; fprintf ( stdout , " \n " ) ; } nsolution ++ ; llvm :: errs ( ) << " " << nsolution << " \n \n " ; if ( nsolution >= bound ) break ; if ( CacheChannel :: observer == MISS_COUNT ) getNextTestForObsCount ( state , cState , values ) ; else if ( CacheChannel :: observer == MISS_SEQUENCE ) getNextTestForObsSeq ( state , cState , values ) ; else assert ( 0 && " " ) ; } } } return nsolution ; }
solve constraints to get all tests according to side-channel observations
solve constraints to get all tests according to side - channel observations
// sanity check (cache performance does not depend on the input) // get the models for cache miss constraints // 1. add all symbolic inputs // 2. now add all symbolic variables /******* KEY Test Genration Loop to get tests, each of which leads to a unique observation *******/ /* get a model (solution) for the observed cache misses */ /* no solution exists */ /* we have a solution for observed cache misses */ //ExprPPrinter::printQuery(llvm::errs(), cState.constraints, //                    	ConstantExpr::alloc(0, Expr::Bool)); /* print test input for the respective solution */ /* print observation for the respective solution */ /* print the name of hit/miss variable */ /* sudiptac: only get as many as "bound" tests */ /* constrain the state space to get a different solution next time */ /********** END of test generation loop **********/