The import tool does support the following import strategies: - BasicImporter: generates def-use equivalence classes for read and write memory accesses - DCiAOKernelImporter: generates equivalence classes for read access in the ciao kernel space. Change-Id: I8960561d3e14dcf5dffa3ff7a59b61a5e8f7e719
113 lines
3.1 KiB
C++
113 lines
3.1 KiB
C++
#include <iostream>
|
|
#include <set>
|
|
|
|
#include "util/Logger.hpp"
|
|
extern fail::Logger log;
|
|
|
|
using namespace fail;
|
|
|
|
#include "DCiAOKernelImporter.hpp"
|
|
|
|
bool DCiAOKernelImporter::inDynamicKernelMemory(fail::address_t addr) {
|
|
const std::string &name = m_elf->getSymbol(addr).getDemangledName();
|
|
bool dynamic = name.find("os::data::dynamic", 0) != std::string::npos;
|
|
bool stack = name.find("_stack") != std::string::npos;
|
|
|
|
return dynamic && !stack;
|
|
}
|
|
|
|
bool DCiAOKernelImporter::copy_to_database(fail::ProtoIStream &ps) {
|
|
if (m_elf == 0) {
|
|
log << "Please give an ELF Binary as a parameter" << std::endl;
|
|
exit(-1);
|
|
}
|
|
|
|
if (getEnterKernelAddress() == 0 || getLeaveKernelAddress() == 0) {
|
|
log << "Pleave give a valid CiAO Binary with kernel dependability options enabled" << std::endl;
|
|
exit(-1);
|
|
}
|
|
|
|
unsigned row_count = 0;
|
|
|
|
// instruction counter within trace
|
|
unsigned instr = 0;
|
|
unsigned instr_last_kernel_leave = 0;
|
|
|
|
address_t enter_kernel_addr = getEnterKernelAddress();
|
|
address_t leave_kernel_addr = getLeaveKernelAddress();
|
|
|
|
|
|
Trace_Event ev;
|
|
|
|
// Collect all memory addresses that
|
|
std::set<address_t> already_written_addresses;
|
|
|
|
bool in_kernel_space = false;
|
|
|
|
while (ps.getNext(&ev)) {
|
|
// instruction events just get counted
|
|
if (!ev.has_memaddr()) {
|
|
// new instruction
|
|
instr++;
|
|
|
|
if (ev.ip() == enter_kernel_addr) {
|
|
in_kernel_space = true;
|
|
}
|
|
|
|
if (ev.ip() == leave_kernel_addr) {
|
|
instr_last_kernel_leave = instr;
|
|
in_kernel_space = false;
|
|
already_written_addresses.clear();
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (in_kernel_space && inDynamicKernelMemory(ev.memaddr())) {
|
|
if (ev.accesstype() == ev.WRITE) {
|
|
/* If a address is written in the protected kernel
|
|
space, we ignore it for further injections */
|
|
address_t from = ev.memaddr(), to = ev.memaddr() + ev.width();
|
|
// Iterate over all accessed bytes
|
|
for (address_t data_address = from; data_address < to; ++data_address) {
|
|
already_written_addresses.insert(data_address);
|
|
}
|
|
} else {
|
|
/* Read address was not written in this kernel section
|
|
-> Insert an trace event */
|
|
address_t from = ev.memaddr(), to = ev.memaddr() + ev.width();
|
|
// Iterate over all accessed bytes
|
|
for (address_t data_address = from; data_address < to; ++data_address) {
|
|
int instr1 = instr_last_kernel_leave;
|
|
int instr2 = instr; // the current instruction
|
|
|
|
/* Was the byte already written in this kernel
|
|
space */
|
|
if (already_written_addresses.find(data_address)
|
|
== already_written_addresses.end())
|
|
continue;
|
|
|
|
ev.set_memaddr(data_address);
|
|
ev.set_width(1);
|
|
|
|
// we now have an interval-terminating R/W event to the memaddr
|
|
// we're currently looking at; the EC is defined by
|
|
// data_address [last_kernel_leave, read_instr] (instr_absolute)
|
|
if (!add_trace_event(instr1, instr2, ev)) {
|
|
log << "add_trace_event failed" << std::endl;
|
|
return false;
|
|
}
|
|
row_count ++;
|
|
if (row_count % 1000 == 0) {
|
|
log << "Imported " << row_count << " traces into the database" << std::endl;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
log << "Inserted " << row_count << " traces into the database" << std::endl;
|
|
|
|
return true;
|
|
}
|