diff --git a/src/experiments/l4-sys/aluinstr.cc b/src/experiments/l4-sys/aluinstr.cc index 5e465074..9f2d1362 100644 --- a/src/experiments/l4-sys/aluinstr.cc +++ b/src/experiments/l4-sys/aluinstr.cc @@ -1,4 +1,6 @@ #include "aluinstr.hpp" +#include +#include #include #include #include "bochs.h" @@ -90,12 +92,14 @@ bool BochsALUInstructions::isALUInstruction(bxInstruction_c const *src) { return false; } -bxInstruction_c BochsALUInstructions::randomEquivalent() const { +void BochsALUInstructions::randomEquivalent(bxInstruction_c &result, + std::string &details) const { // find a random member of the same equivalence class X86AluClass equClassID = lastInstr.aluClass; if (equClassID == ALU_UNDEF) { // something went wrong - just return the original instruction - return lastOrigInstr; + result = lastOrigInstr; + return; } InstrList const &destList = equivalenceClasses.at(equClassID); @@ -106,8 +110,16 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const { dest = destList[index]; } while (memcmp(&dest, &lastInstr, sizeof(BochsALUInstr)) == 0); + // alternative chosen -- now store the necessary details + std::ostringstream oss; + oss << "Opcode 0x" << std::hex << static_cast(dest.opcode) << std::dec; + if (dest.reg < dest.REG_COUNT) oss << " # " << static_cast(dest.reg); + if (dest.opcodeRegisterOffset <= dest.REG_COUNT) + oss << " # " << static_cast(dest.opcodeRegisterOffset); + details = oss.str(); + // first, copy everything - bxInstruction_c result = lastOrigInstr; + result = lastOrigInstr; // then change what has to be different // execute functions @@ -124,12 +136,9 @@ bxInstruction_c BochsALUInstructions::randomEquivalent() const { if (dest.opcodeRegisterOffset < BochsALUInstr::REG_COUNT) { result.setRm(dest.opcodeRegisterOffset); } - // finally, return the result - return result; } #ifdef DEBUG -#include void BochsALUInstructions::printNestedMap() { for (EquivClassMap::iterator it = equivalenceClasses.begin(); diff --git a/src/experiments/l4-sys/aluinstr.hpp b/src/experiments/l4-sys/aluinstr.hpp index b85db913..82e4cae4 100644 --- a/src/experiments/l4-sys/aluinstr.hpp +++ b/src/experiments/l4-sys/aluinstr.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "config.h" #include "cpu/instr.h" @@ -321,9 +322,10 @@ public: /** * Determines a new bxInstruction_c object with an equivalent * addressing mode. - * @returns a bxInstruction_c object as described above + * @param result the resulting bxInstruction_c object as described above + * @param details after completion contains details about \c result */ - bxInstruction_c randomEquivalent() const; + void randomEquivalent(bxInstruction_c &result, std::string &details) const; protected: /** * Convert a bxInstruction_c object into its matching BochsALUInstr object. diff --git a/src/experiments/l4-sys/experiment.cc b/src/experiments/l4-sys/experiment.cc index fc3cd76c..363da284 100644 --- a/src/experiments/l4-sys/experiment.cc +++ b/src/experiments/l4-sys/experiment.cc @@ -377,6 +377,7 @@ bool L4SysExperiment::run() { stringstream ss; ss << "Sent package did not contain the injection location (register offset)" << endl; param.msg.set_details(ss.str()); + m_jc.sendResult(param); simulator.terminate(30); } int reg_offset = param.msg.register_offset(); @@ -540,8 +541,14 @@ bool L4SysExperiment::run() { currInstr = simulator.getCurrentInstruction())) { singleStep(); } + + // store the real injection point + param.msg.set_injection_ip(simulator.getRegisterManager().getInstructionPointer()); + // now exchange it with a random equivalent - bxInstruction_c newInstr = aluInstrObject.randomEquivalent(); + bxInstruction_c newInstr; + string details; + aluInstrObject.randomEquivalent(newInstr, details); if (memcmp(&newInstr, currInstr, sizeof(bxInstruction_c)) == 0) { // something went wrong - exit experiment param.msg.set_resulttype(param.msg.UNKNOWN); @@ -549,11 +556,15 @@ bool L4SysExperiment::run() { simulator.getRegisterManager().getInstructionPointer()); param.msg.set_output(sanitised(output.c_str())); - stringstream ss; - ss << "Did not hit an ALU instruction - correct the source code please!" << endl; - param.msg.set_details(ss.str()); + ostringstream oss; + oss << "Did not hit an ALU instruction - correct the source code please!" << endl; + param.msg.set_details(oss.str()); + m_jc.sendResult(param); simulator.terminate(40); } + // record information on the new instruction + param.msg.set_details(details); + // inject it injectInstruction(currInstr, &newInstr); @@ -567,7 +578,6 @@ bool L4SysExperiment::run() { BPSingleListener ev_incomplete(ANY_ADDR, L4SYS_ADDRESS_SPACE); ev_incomplete.setCounter(static_cast(L4SYS_NUMINSTR * 1.1)); simulator.addListener(&ev_incomplete); - log << calculateTimeout() << endl; TimerListener ev_timeout(calculateTimeout()); simulator.addListener(&ev_timeout);