Skip to content

Commit

Permalink
Support executing arbitrary code section
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Sep 12, 2022
1 parent 6fb0693 commit a2f706b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/evmone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if(CABLE_COMPILER_GNULIKE)
target_compile_options(
evmone PRIVATE
-fno-exceptions
$<$<CXX_COMPILER_ID:GNU>:-Wstack-usage=2500>
$<$<CXX_COMPILER_ID:GNU>:-Wstack-usage=3000>
)
if(NOT SANITIZE MATCHES undefined)
# RTTI can be disabled except for UBSan which checks vptr integrity.
Expand Down
25 changes: 17 additions & 8 deletions lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,20 @@ template <evmc_opcode Op>
break

template <bool TracingEnabled>
evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& analysis) noexcept
evmc_result execute(
const VM& vm, ExecutionState& state, const CodeAnalysis& analysis, size_t code_index) noexcept
{
state.analysis.baseline = &analysis; // Assign code analysis for instruction implementations.

// Use padded code.
state.code = {analysis.padded_code.get(), state.code.size()};
if (analysis.is_legacy_code)
{
// Use padded code.
state.code = {analysis.padded_code.get(), state.code.size()};
}
else
{
state.code = analysis.codes[code_index];
}

auto* tracer = vm.get_tracer();
if constexpr (TracingEnabled)
Expand Down Expand Up @@ -299,21 +307,22 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
}
} // namespace

evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& analysis) noexcept
evmc_result execute(
const VM& vm, ExecutionState& state, const CodeAnalysis& analysis, size_t code_index) noexcept
{
if (INTX_UNLIKELY(vm.get_tracer() != nullptr))
return execute<true>(vm, state, analysis);
return execute<true>(vm, state, analysis, code_index);

return execute<false>(vm, state, analysis);
return execute<false>(vm, state, analysis, code_index);
}

evmc_result execute(evmc_vm* c_vm, const evmc_host_interface* host, evmc_host_context* ctx,
evmc_revision rev, const evmc_message* msg, const uint8_t* code, size_t code_size) noexcept
{
auto vm = static_cast<VM*>(c_vm);
const auto jumpdest_map = analyze(rev, {code, code_size});
const auto code_analysis = analyze(rev, {code, code_size});
auto state =
std::make_unique<ExecutionState>(*msg, rev, *host, ctx, bytes_view{code, code_size});
return execute(*vm, *state, jumpdest_map);
return execute(*vm, *state, code_analysis, 0);
}
} // namespace evmone::baseline
2 changes: 1 addition & 1 deletion lib/evmone/baseline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ evmc_result execute(evmc_vm* vm, const evmc_host_interface* host, evmc_host_cont

/// Executes in Baseline interpreter on the given external and initialized state.
EVMC_EXPORT evmc_result execute(
const VM&, ExecutionState& state, const CodeAnalysis& analysis) noexcept;
const VM&, ExecutionState& state, const CodeAnalysis& analysis, size_t code_index) noexcept;

} // namespace baseline
} // namespace evmone

0 comments on commit a2f706b

Please sign in to comment.