Skip to content

Commit

Permalink
Factor initial trace capture out of fault injection analysis
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 555297325
  • Loading branch information
ncbray authored and copybara-github committed Aug 9, 2023
1 parent 4adcbb6 commit f2c453f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
24 changes: 10 additions & 14 deletions tracing/analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include "./tracing/analysis.h"

#include "./tracing/disassembler.h"
#include <algorithm>
#include <string>

#include "./tracing/execution_trace.h"
#include "./tracing/unicorn_tracer.h"
#include "./util/arch.h"
Expand Down Expand Up @@ -55,13 +57,7 @@ absl::Status TraceSnippetWithSkip(const std::string& instructions,

template <typename Arch>
absl::StatusOr<FaultInjectionResult> AnalyzeSnippetWithFaultInjection(
const std::string& instructions, Disassembler& disas,
ExecutionTrace<Arch>& execution_trace) {
// Capture an unmodified trace.
UnicornTracer<Arch> tracer;
RETURN_IF_NOT_OK(tracer.InitSnippet(instructions));
RETURN_IF_NOT_OK(CaptureTrace(tracer, disas, execution_trace));

const std::string& instructions, ExecutionTrace<Arch>& execution_trace) {
size_t expected_instructions_executed = execution_trace.NumInstructions();
UContext<Arch> expected_ucontext = execution_trace.LastContext();

Expand Down Expand Up @@ -99,11 +95,11 @@ absl::StatusOr<FaultInjectionResult> AnalyzeSnippetWithFaultInjection(
}

// Instantiate concrete instances of exported functions.
template absl::StatusOr<FaultInjectionResult> AnalyzeSnippetWithFaultInjection<
X86_64>(const std::string& instructions, Disassembler& disas,
ExecutionTrace<X86_64>& execution_trace);
template absl::StatusOr<FaultInjectionResult> AnalyzeSnippetWithFaultInjection<
AArch64>(const std::string& instructions, Disassembler& disas,
ExecutionTrace<AArch64>& execution_trace);
template absl::StatusOr<FaultInjectionResult>
AnalyzeSnippetWithFaultInjection<X86_64>(
const std::string& instructions, ExecutionTrace<X86_64>& execution_trace);
template absl::StatusOr<FaultInjectionResult>
AnalyzeSnippetWithFaultInjection<AArch64>(
const std::string& instructions, ExecutionTrace<AArch64>& execution_trace);

} // namespace silifuzz
8 changes: 4 additions & 4 deletions tracing/analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ struct FaultInjectionResult {
};

// Perform fault analysis on the snippet `instructions`.
// `execution_trace` must contain a valid trace. If this function is successful,
// the trace is annotated with which instructions were critical in detecting
// faults.
// If successful, this function returns aggregate statistics about the fault
// injection.
// A full trace is returned in `execution_trace` with annotations on which
// instructions were critical in detecting faults.
template <typename Arch>
absl::StatusOr<FaultInjectionResult> AnalyzeSnippetWithFaultInjection(
const std::string& instructions, Disassembler& disas,
ExecutionTrace<Arch>& execution_trace);
const std::string& instructions, ExecutionTrace<Arch>& execution_trace);

} // namespace silifuzz

Expand Down
9 changes: 6 additions & 3 deletions tracing/trace_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ absl::Status AnalyzeSnippet(const std::string& instructions,
size_t max_instructions, LinePrinter& out) {
DefaultDisassembler<Arch> disas;
ExecutionTrace<Arch> execution_trace(max_instructions);
UnicornTracer<Arch> tracer;
RETURN_IF_NOT_OK(tracer.InitSnippet(instructions));
RETURN_IF_NOT_OK(CaptureTrace(tracer, disas, execution_trace));

ASSIGN_OR_RETURN_IF_NOT_OK(FaultInjectionResult result,
AnalyzeSnippetWithFaultInjection<Arch>(
instructions, disas, execution_trace));
ASSIGN_OR_RETURN_IF_NOT_OK(
FaultInjectionResult result,
AnalyzeSnippetWithFaultInjection<Arch>(instructions, execution_trace));
out.Line("Detected ", result.fault_detection_count, "/",
result.fault_injection_count, " faults - ",
static_cast<int>(100 * result.sensitivity), "% sensitive");
Expand Down

0 comments on commit f2c453f

Please sign in to comment.