Merge branch 'ripple/se/fees' into ripple/smart-escrow

This commit is contained in:
Mayukha Vadari
2026-04-13 17:01:46 -04:00
committed by GitHub
11 changed files with 4866 additions and 1199 deletions

View File

@@ -103,6 +103,7 @@ floatLogImpl(Slice const& x, int32_t mode);
} // namespace wasm_float
// Intended to work only through wasm runtime. Don't call them directly, except with unit tests
struct HostFunctions
{
beast::Journal j_;
@@ -113,11 +114,11 @@ struct HostFunctions
// LCOV_EXCL_START
virtual void
setRT(void const*)
setRT(void*)
{
}
virtual void const*
virtual void*
getRT() const
{
return nullptr;

View File

@@ -4,6 +4,8 @@
#include <xrpl/tx/wasm/HostFunc.h>
namespace xrpl {
// Intended to work only through wasm runtime. Don't call them directly, except with unit tests
class WasmHostFunctionsImpl : public HostFunctions
{
ApplyContext& ctx_;
@@ -16,7 +18,7 @@ class WasmHostFunctionsImpl : public HostFunctions
std::optional<Bytes> data_;
void const* rt_ = nullptr;
void* rt_ = nullptr;
Expected<std::shared_ptr<SLE const>, HostFunctionError>
getCurrentLedgerObj() const
@@ -64,12 +66,12 @@ public:
}
virtual void
setRT(void const* rt) override
setRT(void* rt) override
{
rt_ = rt;
}
virtual void const*
virtual void*
getRT() const override
{
return rt_;

View File

@@ -1,6 +1,10 @@
#pragma once
#include <xrpl/tx/wasm/WasmiVM.h>
#include <xrpl/tx/wasm/ParamsHelper.h>
#include <wasm.h>
#include <cstdint>
namespace xrpl {

View File

@@ -32,6 +32,20 @@ struct WasmResult
};
typedef WasmResult<int32_t> EscrowResult;
struct WasmRuntimeWrapper
{
virtual ~WasmRuntimeWrapper() = default;
virtual wmem
getMem() = 0;
virtual std::int64_t
getGas() = 0;
virtual std::int64_t
setGas(std::int64_t gas) = 0;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum WasmTypes { WT_I32, WT_I64, WT_U8V };

View File

@@ -8,10 +8,12 @@
namespace xrpl {
template <class T, void (*Create)(T*, size_t), void (*Destroy)(T*)>
struct WasmVec
class WasmVec
{
using TD = std::remove_pointer_t<decltype(T::data)>;
T vec_;
public:
WasmVec(size_t s = 0) : vec_ WASM_EMPTY_VEC
{
if (s > 0)
@@ -58,6 +60,46 @@ struct WasmVec
vec_ = WASM_EMPTY_VEC;
return result;
}
T*
get()
{
return &vec_;
}
T const*
get() const
{
return &vec_;
}
TD&
operator[](size_t i)
{
if (i >= vec_.size)
Throw<std::runtime_error>("Out of bound");
return vec_.data[i];
}
TD const&
operator[](size_t i) const
{
if (i >= vec_.size)
Throw<std::runtime_error>("Out of bound");
return vec_.data[i];
}
size_t
size() const
{
return vec_.size;
}
bool
empty() const
{
return vec_.size == 0u;
}
};
using WasmValtypeVec =
@@ -175,8 +217,8 @@ public:
wmem
getMem() const;
InstanceWrapper const&
getInstance(int i = 0) const;
InstanceWrapper&
getInstance(int i = 0);
int
addInstance(StorePtr& s, WasmExternVec const& imports);
@@ -234,7 +276,7 @@ public:
getJournal() const;
private:
InstanceWrapper const&
InstanceWrapper&
getRT(int m = 0, int i = 0) const;
wmem

View File

@@ -96,7 +96,7 @@ public:
std::cout << std::setw(2) << (unsigned)c << " ";
std::cout << std::dec << std::setfill(' ') << std::endl;
#endif
return data;
return Expected<Bytes, HostFunctionError>(std::move(data));
}
};

View File

@@ -107,6 +107,7 @@ getAnyFieldData(FieldValue const& variantObj)
{
return getAnyFieldData(*obj);
}
if (uint256 const* const* u = std::get_if<uint256 const*>(&variantObj))
{
return Bytes((*u)->begin(), (*u)->end());

View File

@@ -8,6 +8,7 @@
#include <xrpl/protocol/digest.h>
#include <xrpl/tx/wasm/HostFunc.h>
#include <xrpl/tx/wasm/HostFuncWrapper.h>
#include <xrpl/tx/wasm/WasmVM.h>
namespace xrpl {
@@ -15,7 +16,7 @@ using SFieldCRef = std::reference_wrapper<SField const>;
static int32_t
setData(
InstanceWrapper const* runtime,
WasmRuntimeWrapper* runtime,
int32_t dst,
int32_t dstSize,
uint8_t const* src,
@@ -48,7 +49,7 @@ setData(
template <class IW>
static Expected<int32_t, HostFunctionError>
getDataInt32(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
getDataInt32(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const result = params->data[i].of.i32;
i++;
@@ -57,7 +58,7 @@ getDataInt32(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<int64_t, HostFunctionError>
getDataInt64(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
getDataInt64(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const result = params->data[i].of.i64;
i++;
@@ -66,7 +67,7 @@ getDataInt64(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
template <class T, class IW>
static Expected<T, HostFunctionError>
getDataUnsigned(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataUnsigned(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
static_assert(std::is_unsigned_v<T>);
auto const r = getDataSlice(runtime, params, i);
@@ -92,21 +93,21 @@ getDataUnsigned(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<uint32_t, HostFunctionError>
getDataUInt32(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataUInt32(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
return getDataUnsigned<uint32_t>(runtime, params, i);
}
template <class IW>
static Expected<uint64_t, HostFunctionError>
getDataUInt64(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataUInt64(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
return getDataUnsigned<uint64_t>(runtime, params, i);
}
template <class IW>
static Expected<SFieldCRef, HostFunctionError>
getDataSField(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
getDataSField(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const& m = SField::getKnownCodeToField();
auto const it = m.find(params->data[i].of.i32);
@@ -120,7 +121,7 @@ getDataSField(IW const* _runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<Slice, HostFunctionError>
getDataSlice(IW const* runtime, wasm_val_vec_t const* params, int32_t& i, bool isUpdate = false)
getDataSlice(IW* runtime, wasm_val_vec_t const* params, int32_t& i, bool isUpdate = false)
{
int64_t const ptr = params->data[i].of.i32;
int64_t const size = params->data[i + 1].of.i32;
@@ -149,7 +150,7 @@ getDataSlice(IW const* runtime, wasm_val_vec_t const* params, int32_t& i, bool i
template <class IW>
static Expected<uint256, HostFunctionError>
getDataUInt256(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataUInt256(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const slice = getDataSlice(runtime, params, i);
if (!slice)
@@ -166,7 +167,7 @@ getDataUInt256(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<AccountID, HostFunctionError>
getDataAccountID(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataAccountID(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const slice = getDataSlice(runtime, params, i);
if (!slice)
@@ -184,7 +185,7 @@ getDataAccountID(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<Currency, HostFunctionError>
getDataCurrency(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataCurrency(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const slice = getDataSlice(runtime, params, i);
if (!slice)
@@ -202,7 +203,7 @@ getDataCurrency(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<Asset, HostFunctionError>
getDataAsset(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataAsset(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const slice = getDataSlice(runtime, params, i);
if (!slice)
@@ -241,7 +242,7 @@ getDataAsset(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
template <class IW>
static Expected<std::string_view, HostFunctionError>
getDataString(IW const* runtime, wasm_val_vec_t const* params, int32_t& i)
getDataString(IW* runtime, wasm_val_vec_t const* params, int32_t& i)
{
auto const slice = getDataSlice(runtime, params, i);
if (!slice)
@@ -268,7 +269,7 @@ hfResult(wasm_val_vec_t* results, HostFunctionError value)
template <typename T>
static std::nullptr_t
returnResult(
InstanceWrapper const* runtime,
WasmRuntimeWrapper* runtime,
wasm_val_vec_t const* params,
wasm_val_vec_t* results,
Expected<T, HostFunctionError> const& res,
@@ -390,7 +391,7 @@ checkGas(void* env)
auto const* udata = reinterpret_cast<WasmUserData*>(env);
HostFunctions const* hf = reinterpret_cast<HostFunctions*>(udata->first);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
if (runtime == nullptr)
{
wasm_trap_t* trap = reinterpret_cast<wasm_trap_t*>( // NOLINT
@@ -426,7 +427,7 @@ getLedgerSqn_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int const index = 0;
return returnResult(runtime, params, results, hf->getLedgerSqn(), index);
@@ -438,7 +439,7 @@ getParentLedgerTime_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int const index = 0;
return returnResult(runtime, params, results, hf->getParentLedgerTime(), index);
@@ -450,7 +451,7 @@ getParentLedgerHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int const index = 0;
return returnResult(runtime, params, results, hf->getParentLedgerHash(), index);
@@ -462,7 +463,7 @@ getBaseFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int const index = 0;
return returnResult(runtime, params, results, hf->getBaseFee(), index);
@@ -474,7 +475,7 @@ isAmendmentEnabled_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const slice = getDataSlice(runtime, params, index);
@@ -506,7 +507,7 @@ cacheLedgerObj_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* res
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const id = getDataUInt256(runtime, params, index);
@@ -530,7 +531,7 @@ getTxField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const fname = getDataSField(runtime, params, index);
@@ -547,7 +548,7 @@ getCurrentLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const fname = getDataSField(runtime, params, index);
@@ -565,7 +566,7 @@ getLedgerObjField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const cache = getDataInt32(runtime, params, index);
@@ -589,7 +590,7 @@ getTxNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* r
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index);
@@ -610,7 +611,7 @@ getCurrentLedgerObjNestedField_wrap(
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index);
@@ -628,7 +629,7 @@ getLedgerObjNestedField_wrap(void* env, wasm_val_vec_t const* params, wasm_val_v
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const cache = getDataInt32(runtime, params, index);
@@ -653,7 +654,7 @@ getTxArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const fname = getDataSField(runtime, params, index);
@@ -671,7 +672,7 @@ getCurrentLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_v
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const fname = getDataSField(runtime, params, index);
@@ -689,7 +690,7 @@ getLedgerObjArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const cache = getDataInt32(runtime, params, index);
@@ -713,7 +714,7 @@ getTxNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index);
@@ -734,7 +735,7 @@ getCurrentLedgerObjNestedArrayLen_wrap(
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index);
@@ -752,7 +753,7 @@ getLedgerObjNestedArrayLen_wrap(void* env, wasm_val_vec_t const* params, wasm_va
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const cache = getDataInt32(runtime, params, index);
@@ -776,7 +777,7 @@ updateData_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index, true);
@@ -794,7 +795,7 @@ checkSignature_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* res
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const message = getDataSlice(runtime, params, index);
@@ -825,7 +826,7 @@ computeSha512HalfHash_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const bytes = getDataSlice(runtime, params, index);
@@ -842,7 +843,7 @@ accountKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -860,7 +861,7 @@ ammKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const issue1 = getDataAsset(runtime, params, index);
@@ -885,7 +886,7 @@ checkKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -909,7 +910,7 @@ credentialKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* r
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const subj = getDataAccountID(runtime, params, index);
@@ -940,7 +941,7 @@ delegateKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* res
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -965,7 +966,7 @@ depositPreauthKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -990,7 +991,7 @@ didKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1008,7 +1009,7 @@ escrowKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1032,7 +1033,7 @@ lineKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc1 = getDataAccountID(runtime, params, index);
@@ -1067,7 +1068,7 @@ mptIssuanceKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1092,7 +1093,7 @@ mptokenKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const slice = getDataSlice(runtime, params, index);
@@ -1122,7 +1123,7 @@ nftOfferKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* res
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1147,7 +1148,7 @@ offerKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1171,7 +1172,7 @@ oracleKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1194,7 +1195,7 @@ paychanKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1225,7 +1226,7 @@ permissionedDomainKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1250,7 +1251,7 @@ signersKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1268,7 +1269,7 @@ ticketKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1293,7 +1294,7 @@ vaultKeylet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1317,7 +1318,7 @@ getNFT_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const acc = getDataAccountID(runtime, params, index);
@@ -1341,7 +1342,7 @@ getNFTIssuer_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const nftId = getDataUInt256(runtime, params, index);
@@ -1359,7 +1360,7 @@ getNFTTaxon_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const nftId = getDataUInt256(runtime, params, index);
@@ -1377,7 +1378,7 @@ getNFTFlags_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const nftId = getDataUInt256(runtime, params, index);
@@ -1395,7 +1396,7 @@ getNFTTransferFee_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const nftId = getDataUInt256(runtime, params, index);
@@ -1413,7 +1414,7 @@ getNFTSerial_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
auto const nftId = getDataUInt256(runtime, params, index);
@@ -1431,7 +1432,7 @@ trace_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
if (params->data[1].of.i32 + params->data[3].of.i32 > maxWasmParamLength)
@@ -1470,7 +1471,7 @@ traceNum_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int index = 0;
if (params->data[1].of.i32 > maxWasmParamLength)
{
@@ -1498,7 +1499,7 @@ traceAccount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
if (params->data[1].of.i32 > maxWasmParamLength)
return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE);
@@ -1521,7 +1522,7 @@ traceFloat_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
if (params->data[1].of.i32 > maxWasmParamLength)
return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE);
@@ -1544,7 +1545,7 @@ traceAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
if (params->data[1].of.i32 > maxWasmParamLength)
return hfResult(results, HostFunctionError::DATA_FIELD_TOO_LARGE);
@@ -1582,7 +1583,7 @@ floatFromInt_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataInt64(runtime, params, i);
@@ -1604,7 +1605,7 @@ floatFromUint_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataUInt64(runtime, params, i);
@@ -1626,7 +1627,7 @@ floatFromSTAmount_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1661,7 +1662,7 @@ floatFromSTNumber_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t*
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1696,7 +1697,7 @@ floatToInt_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1718,7 +1719,7 @@ floatToMantissaAndExponent_wrap(void* env, wasm_val_vec_t const* params, wasm_va
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1735,7 +1736,7 @@ floatNegate_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1752,7 +1753,7 @@ floatAbs_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1769,7 +1770,7 @@ floatSet_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const exp = getDataInt32(runtime, params, i);
@@ -1795,7 +1796,7 @@ floatCompare_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resul
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1815,7 +1816,7 @@ floatAdd_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1841,7 +1842,7 @@ floatSubtract_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1867,7 +1868,7 @@ floatMultiply_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* resu
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1893,7 +1894,7 @@ floatDivide_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* result
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1919,7 +1920,7 @@ floatRoot_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1945,7 +1946,7 @@ floatPower_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1971,7 +1972,7 @@ floatLog_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
if (auto g = checkGas(env); !g)
return g.error(); // LCOV_EXCL_LINE
auto* hf = getHF(env);
auto const* runtime = reinterpret_cast<InstanceWrapper const*>(hf->getRT());
auto* runtime = reinterpret_cast<WasmRuntimeWrapper*>(hf->getRT());
int i = 0;
auto const x = getDataSlice(runtime, params, i);
@@ -1990,16 +1991,16 @@ floatLog_wrap(void* env, wasm_val_vec_t const* params, wasm_val_vec_t* results)
// LCOV_EXCL_START
namespace test {
class MockInstanceWrapper
class MockWasmRuntimeWrapper
{
wmem mem_;
public:
MockInstanceWrapper(wmem memory) : mem_(memory)
MockWasmRuntimeWrapper(wmem memory) : mem_(memory)
{
}
// Mock methods to simulate the behavior of InstanceWrapper
// Mock methods to simulate the behavior of WasmRuntimeWrapper
wmem
getMem() const
{
@@ -2013,7 +2014,7 @@ testGetDataIncrement()
wasm_val_t values[4];
std::array<std::uint8_t, 128> buffer = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
MockInstanceWrapper const runtime(wmem{buffer.data(), buffer.size()});
MockWasmRuntimeWrapper runtime(wmem{buffer.data(), buffer.size()});
{
// test int32_t

View File

@@ -52,6 +52,33 @@ print_wasm_error(std::string_view msg, wasm_trap_t* trap, beast::Journal jlog)
} // namespace
struct WasmiRuntimeWrapper : public WasmRuntimeWrapper
{
InstanceWrapper& iw_;
WasmiRuntimeWrapper(InstanceWrapper& iw) : iw_(iw)
{
}
virtual wmem
getMem() override
{
return iw_.getMem();
}
virtual std::int64_t
getGas() override
{
return iw_.getGas();
}
virtual std::int64_t
setGas(std::int64_t gas) override
{
return iw_.setGas(gas);
}
};
InstancePtr
InstanceWrapper::init(
StorePtr& s,
@@ -62,14 +89,14 @@ InstanceWrapper::init(
{
wasm_trap_t* trap = nullptr;
InstancePtr mi = InstancePtr(
wasm_instance_new(s.get(), m.get(), &imports.vec_, &trap), &wasm_instance_delete);
wasm_instance_new(s.get(), m.get(), imports.get(), &trap), &wasm_instance_delete);
if (!mi || (trap != nullptr))
{
print_wasm_error("can't create instance", trap, j);
throw std::runtime_error("can't create instance");
}
wasm_instance_exports(mi.get(), &expt.vec_);
wasm_instance_exports(mi.get(), expt.get());
return mi;
}
@@ -126,14 +153,14 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp
if (!instance_)
throw std::runtime_error("no instance"); // LCOV_EXCL_LINE
if (exportTypes.vec_.size == 0u)
if (exportTypes.empty())
throw std::runtime_error("no export"); // LCOV_EXCL_LINE
if (exportTypes.vec_.size != exports_.vec_.size)
if (exportTypes.size() != exports_.size())
throw std::runtime_error("invalid export"); // LCOV_EXCL_LINE
for (unsigned i = 0; i < exportTypes.vec_.size; ++i)
for (unsigned i = 0; i < exportTypes.size(); ++i)
{
auto const* expType(exportTypes.vec_.data[i]);
auto const* expType(exportTypes[i]);
wasm_name_t const* name = wasm_exporttype_name(expType);
wasm_externtype_t const* exnType = wasm_exporttype_type(expType);
@@ -142,7 +169,7 @@ InstanceWrapper::getFunc(std::string_view funcName, WasmExporttypeVec const& exp
if (funcName != std::string_view(name->data, name->size))
continue;
auto const* exn(exports_.vec_.data[i]);
auto const* exn(exports_[i]);
if (wasm_extern_kind(exn) != WASM_EXTERN_FUNC)
throw std::runtime_error("invalid export"); // LCOV_EXCL_LINE
@@ -163,15 +190,15 @@ InstanceWrapper::getMem() const
{
if (memIdx_ >= 0)
{
auto* e(exports_.vec_.data[memIdx_]);
auto* e(exports_[memIdx_]);
wasm_memory_t* mem = wasm_extern_as_memory(e);
return {reinterpret_cast<std::uint8_t*>(wasm_memory_data(mem)), wasm_memory_data_size(mem)};
}
wasm_memory_t* mem = nullptr;
for (int i = 0; i < exports_.vec_.size; ++i)
for (int i = 0; i < exports_.size(); ++i)
{
auto* e(exports_.vec_.data[i]);
auto* e(exports_[i]);
if (wasm_extern_kind(e) == WASM_EXTERN_MEMORY)
{
memIdx_ = i;
@@ -249,7 +276,7 @@ ModuleWrapper::ModuleWrapper(
beast::Journal j)
: module_(init(s, wasmBin, j)), j_(j)
{
wasm_module_exports(module_.get(), &exportTypes_.vec_);
wasm_module_exports(module_.get(), exportTypes_.get());
auto wimports = buildImports(s, imports);
if (instantiate)
{
@@ -295,10 +322,10 @@ makeImpParams(WasmImportFunc const& imp)
switch (vt)
{
case WT_I32:
v.vec_.data[i] = wasm_valtype_new_i32();
v[i] = wasm_valtype_new_i32();
break;
case WT_I64:
v.vec_.data[i] = wasm_valtype_new_i64();
v[i] = wasm_valtype_new_i64();
break;
// LCOV_EXCL_START
default:
@@ -319,11 +346,11 @@ makeImpReturn(WasmImportFunc const& imp)
switch (*imp.result)
{
case WT_I32:
v.vec_.data[0] = wasm_valtype_new_i32();
v[0] = wasm_valtype_new_i32();
break;
// LCOV_EXCL_START
case WT_I64:
v.vec_.data[0] = wasm_valtype_new_i64();
v[0] = wasm_valtype_new_i64();
break;
default:
throw std::runtime_error("invalid return type");
@@ -336,19 +363,19 @@ WasmExternVec
ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const
{
WasmImporttypeVec importTypes;
wasm_module_imports(module_.get(), &importTypes.vec_);
wasm_module_imports(module_.get(), importTypes.get());
if (importTypes.vec_.size == 0u)
if (importTypes.empty())
return {};
if (imports.empty())
throw std::runtime_error("Missing imports");
WasmExternVec wimports(importTypes.vec_.size);
WasmExternVec wimports(importTypes.size());
unsigned impCnt = 0;
for (unsigned i = 0; i < importTypes.vec_.size; ++i)
for (unsigned i = 0; i < importTypes.size(); ++i)
{
wasm_importtype_t const* importType = importTypes.vec_.data[i];
wasm_importtype_t const* importType = importTypes[i];
// wasm_name_t const* mn = wasm_importtype_module(importtype);
// auto modName = std::string_view(mn->data, mn->num_elems);
@@ -377,7 +404,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const
WasmValtypeVec results(makeImpReturn(imp));
std::unique_ptr<wasm_functype_t, decltype(&wasm_functype_delete)> const ftype(
wasm_functype_new(&params.vec_, &results.vec_), &wasm_functype_delete);
wasm_functype_new(params.get(), results.get()), &wasm_functype_delete);
params.release();
results.release();
@@ -395,7 +422,7 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const
// LCOV_EXCL_STOP
}
wimports.vec_.data[i] = wasm_func_as_extern(func);
wimports[i] = wasm_func_as_extern(func);
++impCnt;
impSet = true;
@@ -408,11 +435,11 @@ ModuleWrapper::buildImports(StorePtr& s, ImportVec const& imports) const
}
}
if (impCnt != importTypes.vec_.size)
if (impCnt != importTypes.size())
{
print_wasm_error(
std::string("Imports not finished: ") + std::to_string(impCnt) + "/" +
std::to_string(importTypes.vec_.size),
std::to_string(importTypes.size()),
nullptr,
j_);
throw std::runtime_error("Missing imports");
@@ -430,9 +457,9 @@ ModuleWrapper::getFunc(std::string_view funcName) const
wasm_functype_t*
ModuleWrapper::getFuncType(std::string_view funcName) const
{
for (size_t i = 0; i < exportTypes_.vec_.size; i++)
for (size_t i = 0; i < exportTypes_.size(); i++)
{
auto const* exp_type(exportTypes_.vec_.data[i]);
auto const* exp_type(exportTypes_[i]);
wasm_name_t const* name = wasm_exporttype_name(exp_type);
wasm_externtype_t const* exn_type = wasm_exporttype_type(exp_type);
if (wasm_externtype_kind(exn_type) == WASM_EXTERN_FUNC &&
@@ -451,8 +478,8 @@ ModuleWrapper::getMem() const
return instanceWrap_.getMem();
}
InstanceWrapper const&
ModuleWrapper::getInstance(int) const
InstanceWrapper&
ModuleWrapper::getInstance(int)
{
return instanceWrap_;
}
@@ -661,11 +688,7 @@ template <int NR, class... Types>
WasmiResult
WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in)
{
// wasm_val_t rs[1] = {WASM_I32_VAL(0)};
WasmiResult ret(NR);
// if (NR) { wasm_val_vec_new_uninitialized(&ret, NR); //
// wasm_val_vec_new(&ret, NR, &rs[0]); // ret = WASM_ARRAY_VEC(rs); }
wasm_val_vec_t const inv =
in.empty() ? wasm_val_vec_t WASM_EMPTY_VEC : wasm_val_vec_t{in.size(), in.data()};
@@ -673,7 +696,7 @@ WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in)
auto const start = usecs();
#endif
wasm_trap_t* trap = wasm_func_call(f.first, &inv, &ret.r.vec_);
wasm_trap_t* trap = wasm_func_call(f.first, &inv, ret.r.get());
#ifdef SHOW_CALL_TIME
auto const finish = usecs();
@@ -687,9 +710,6 @@ WasmiEngine::call(FuncInfo const& f, std::vector<wasm_val_t>& in)
print_wasm_error("failure to call func", trap, j_);
}
// assert(results[0].kind == WASM_I32);
// if (NR) printf("Result P5: %d\n", ret[0].of.i32);
return ret;
}
@@ -782,7 +802,10 @@ WasmiEngine::runHlp(
if (!moduleWrap_ || !moduleWrap_->instanceWrap_)
throw std::runtime_error("no instance"); // LCOV_EXCL_LINE
hfs.setRT(&getRT());
auto clear = [](HostFunctions* p) { p->setRT(nullptr); };
std::unique_ptr<HostFunctions, decltype(clear)> const clearGuard(&hfs, clear);
WasmiRuntimeWrapper iw(getRT());
hfs.setRT(&iw);
// Call main
auto const f = getFunc(!funcName.empty() ? funcName : "_start");
@@ -801,21 +824,23 @@ WasmiEngine::runHlp(
{
throw std::runtime_error("<" + std::string(funcName) + "> failure");
}
if (res.r.vec_.size == 0u)
if (res.r.empty())
{
throw std::runtime_error(
"<" + std::string(funcName) + "> return nothing"); // LCOV_EXCL_LINE
}
if (res.r.vec_.data[0].kind != WASM_I32)
if (res.r[0].kind != WASM_I32)
{
throw std::runtime_error(
"<" + std::string(funcName) + "> return type mismatch, ret: " +
std::to_string(static_cast<int>(res.r.vec_.data[0].kind)));
"<" + std::string(funcName) +
"> return type mismatch, ret: " + std::to_string(static_cast<int>(res.r[0].kind)));
}
if (gas == -1)
gas = std::numeric_limits<decltype(gas)>::max();
WasmResult<int32_t> const ret{res.r.vec_.data[0].of.i32, gas - moduleWrap_->getGas()};
WasmResult<int32_t> const ret{res.r[0].of.i32, gas - moduleWrap_->getGas()};
// #ifdef DEBUG_OUTPUT
// auto& j = std::cerr;
@@ -901,7 +926,7 @@ WasmiEngine::getMem() const
return moduleWrap_ ? moduleWrap_->getMem() : wmem();
}
InstanceWrapper const&
InstanceWrapper&
WasmiEngine::getRT(int m, int i) const
{
if (!moduleWrap_)

File diff suppressed because it is too large Load Diff

View File

@@ -15,7 +15,7 @@ namespace test {
struct TestLedgerDataProvider : public HostFunctions
{
jtx::Env& env_;
void const* rt_ = nullptr;
void* rt_ = nullptr;
public:
TestLedgerDataProvider(jtx::Env& env) : HostFunctions(env.journal), env_(env)
@@ -23,12 +23,12 @@ public:
}
virtual void
setRT(void const* rt) override
setRT(void* rt) override
{
rt_ = rt;
}
virtual void const*
virtual void*
getRT() const override
{
return rt_;
@@ -47,7 +47,7 @@ struct TestHostFunctions : public HostFunctions
AccountID accountID_;
Bytes data_;
int clock_drift_ = 0;
void const* rt_ = nullptr;
void* rt_ = nullptr;
public:
TestHostFunctions(test::jtx::Env& env, int cd = 0)
@@ -59,12 +59,12 @@ public:
}
virtual void
setRT(void const* rt) override
setRT(void* rt) override
{
rt_ = rt;
}
virtual void const*
virtual void*
getRT() const override
{
return rt_;