From a2f706b9c35ceb0110c870dee7e341a2c578c5e5 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 12 Sep 2022 16:58:30 +0200 Subject: [PATCH] Support executing arbitrary code section --- lib/evmone/CMakeLists.txt | 2 +- lib/evmone/baseline.cpp | 25 +++++++++++++++++-------- lib/evmone/baseline.hpp | 2 +- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/evmone/CMakeLists.txt b/lib/evmone/CMakeLists.txt index 0df3ca81ac..e7b57ef3d9 100644 --- a/lib/evmone/CMakeLists.txt +++ b/lib/evmone/CMakeLists.txt @@ -38,7 +38,7 @@ if(CABLE_COMPILER_GNULIKE) target_compile_options( evmone PRIVATE -fno-exceptions - $<$:-Wstack-usage=2500> + $<$:-Wstack-usage=3000> ) if(NOT SANITIZE MATCHES undefined) # RTTI can be disabled except for UBSan which checks vptr integrity. diff --git a/lib/evmone/baseline.cpp b/lib/evmone/baseline.cpp index e6a70d4862..f7b113b590 100644 --- a/lib/evmone/baseline.cpp +++ b/lib/evmone/baseline.cpp @@ -242,12 +242,20 @@ template break template -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) @@ -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(vm, state, analysis); + return execute(vm, state, analysis, code_index); - return execute(vm, state, analysis); + return execute(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(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(*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 diff --git a/lib/evmone/baseline.hpp b/lib/evmone/baseline.hpp index e277075209..fc80d07496 100644 --- a/lib/evmone/baseline.hpp +++ b/lib/evmone/baseline.hpp @@ -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