Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/executor/engine/proxy.cpp
Line
Count
Source (jump to first uncovered line)
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: 2019-2024 Second State INC
3
4
#include "executor/executor.h"
5
#include "system/fault.h"
6
7
#include <cstdint>
8
9
namespace WasmEdge {
10
namespace Executor {
11
12
thread_local Executor *Executor::This = nullptr;
13
thread_local Runtime::StackManager *Executor::CurrentStack = nullptr;
14
thread_local Executor::ExecutionContextStruct Executor::ExecutionContext;
15
thread_local std::array<uint32_t, 256> Executor::StackTrace;
16
thread_local size_t Executor::StackTraceSize = 0;
17
18
template <typename RetT, typename... ArgsT>
19
struct Executor::ProxyHelper<Expect<RetT> (Executor::*)(Runtime::StackManager &,
20
                                                        ArgsT...) noexcept> {
21
  template <Expect<RetT> (Executor::*Func)(Runtime::StackManager &,
22
                                           ArgsT...) noexcept>
23
0
  static auto proxy(ArgsT... Args) {
24
0
    Expect<RetT> Res = (This->*Func)(*CurrentStack, Args...);
25
0
    if (unlikely(!Res)) {
26
0
      Fault::emitFault(Res.error());
27
0
    }
28
0
    if constexpr (std::is_same_v<RetT, RefVariant>) {
29
#if defined(_MSC_VER) && !defined(__clang__) // MSVC
30
      return *reinterpret_cast<__m128 *>((*Res).getRawData().data());
31
#else
32
0
      return (*Res).getRawData();
33
0
#endif // MSVC
34
0
    } else if constexpr (!std::is_void_v<RetT>) {
35
0
      return *Res;
36
0
    }
37
0
  }
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTrap>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyCall>(unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyCallIndirect>(unsigned int, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyCallRef>(WasmEdge::RefVariant, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyRefFunc>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyStructNew>(unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, bool, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyStructGet>(WasmEdge::RefVariant, unsigned int, unsigned int, bool, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyStructSet>(WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayNew>(unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayNewData>(unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayNewElem>(unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, bool, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayGet>(WasmEdge::RefVariant, unsigned int, unsigned int, bool, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant>*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArraySet>(WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayLen>(WasmEdge::RefVariant)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayFill>(WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, WasmEdge::Variant<unsigned int, int, unsigned long, long, float, double, unsigned __int128, __int128, unsigned long __vector(2), long __vector(2), unsigned int __vector(4), int __vector(4), unsigned short __vector(8), short __vector(8), unsigned char __vector(16), signed char __vector(16), float __vector(4), double __vector(2), WasmEdge::RefVariant> const*)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayCopy>(WasmEdge::RefVariant, unsigned int, unsigned int, WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayInitData>(WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyArrayInitElem>(WasmEdge::RefVariant, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, WasmEdge::ValType) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyRefTest>(WasmEdge::RefVariant, WasmEdge::ValType)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant, WasmEdge::ValType) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyRefCast>(WasmEdge::RefVariant, WasmEdge::ValType)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<WasmEdge::RefVariant, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableGet>(unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, WasmEdge::RefVariant) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableSet>(unsigned int, unsigned int, WasmEdge::RefVariant)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableInit>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyElemDrop>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableCopy>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, WasmEdge::RefVariant, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableGrow>(unsigned int, WasmEdge::RefVariant, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableSize>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, WasmEdge::RefVariant, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableFill>(unsigned int, unsigned int, WasmEdge::RefVariant, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemGrow>(unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemSize>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemInit>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyDataDrop>(unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemCopy>(unsigned int, unsigned int, unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned char, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemFill>(unsigned int, unsigned int, unsigned char, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemAtomicNotify>(unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<unsigned int, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned long, long, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyMemAtomicWait>(unsigned int, unsigned int, unsigned long, long, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void*, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, unsigned int, unsigned int, unsigned int) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyTableGetFuncSymbol>(unsigned int, unsigned int, unsigned int)
Unexecuted instantiation: auto WasmEdge::Executor::Executor::ProxyHelper<cxx20::expected<void*, WasmEdge::ErrCode> (WasmEdge::Executor::Executor::*)(WasmEdge::Runtime::StackManager&, WasmEdge::RefVariant) noexcept>::proxy<&WasmEdge::Executor::Executor::proxyRefGetFuncSymbol>(WasmEdge::RefVariant)
38
};
39
40
#if defined(__clang_major__) && __clang_major__ >= 10
41
#pragma clang diagnostic push
42
#pragma clang diagnostic ignored "-Wc99-designator"
43
#endif
44
45
// Intrinsics table
46
const Executable::IntrinsicsTable Executor::Intrinsics = {
47
#if defined(_MSC_VER) && !defined(__clang__)
48
#define ENTRY(NAME, FUNC)                                                      \
49
  reinterpret_cast<void *>(&Executor::ProxyHelper<                             \
50
                           decltype(&Executor::FUNC)>::proxy<&Executor::FUNC>)
51
#else
52
#define ENTRY(NAME, FUNC)                                                      \
53
  [uint8_t(Executable::Intrinsics::NAME)] = reinterpret_cast<void *>(          \
54
      &Executor::ProxyHelper<decltype(&Executor::FUNC)>::proxy<                \
55
          &Executor::FUNC>)
56
#endif
57
    ENTRY(kTrap, proxyTrap),
58
    ENTRY(kCall, proxyCall),
59
    ENTRY(kCallIndirect, proxyCallIndirect),
60
    ENTRY(kCallRef, proxyCallRef),
61
    ENTRY(kRefFunc, proxyRefFunc),
62
    ENTRY(kStructNew, proxyStructNew),
63
    ENTRY(kStructGet, proxyStructGet),
64
    ENTRY(kStructSet, proxyStructSet),
65
    ENTRY(kArrayNew, proxyArrayNew),
66
    ENTRY(kArrayNewData, proxyArrayNewData),
67
    ENTRY(kArrayNewElem, proxyArrayNewElem),
68
    ENTRY(kArrayGet, proxyArrayGet),
69
    ENTRY(kArraySet, proxyArraySet),
70
    ENTRY(kArrayLen, proxyArrayLen),
71
    ENTRY(kArrayFill, proxyArrayFill),
72
    ENTRY(kArrayCopy, proxyArrayCopy),
73
    ENTRY(kArrayInitData, proxyArrayInitData),
74
    ENTRY(kArrayInitElem, proxyArrayInitElem),
75
    ENTRY(kRefTest, proxyRefTest),
76
    ENTRY(kRefCast, proxyRefCast),
77
    ENTRY(kTableGet, proxyTableGet),
78
    ENTRY(kTableSet, proxyTableSet),
79
    ENTRY(kTableInit, proxyTableInit),
80
    ENTRY(kElemDrop, proxyElemDrop),
81
    ENTRY(kTableCopy, proxyTableCopy),
82
    ENTRY(kTableGrow, proxyTableGrow),
83
    ENTRY(kTableSize, proxyTableSize),
84
    ENTRY(kTableFill, proxyTableFill),
85
    ENTRY(kMemGrow, proxyMemGrow),
86
    ENTRY(kMemSize, proxyMemSize),
87
    ENTRY(kMemInit, proxyMemInit),
88
    ENTRY(kDataDrop, proxyDataDrop),
89
    ENTRY(kMemCopy, proxyMemCopy),
90
    ENTRY(kMemFill, proxyMemFill),
91
    ENTRY(kMemAtomicNotify, proxyMemAtomicNotify),
92
    ENTRY(kMemAtomicWait, proxyMemAtomicWait),
93
    ENTRY(kTableGetFuncSymbol, proxyTableGetFuncSymbol),
94
    ENTRY(kRefGetFuncSymbol, proxyRefGetFuncSymbol),
95
#undef ENTRY
96
};
97
98
#if defined(__clang_major__) && __clang_major__ >= 10
99
#pragma clang diagnostic pop
100
#endif
101
102
Expect<void> Executor::proxyTrap(Runtime::StackManager &,
103
0
                                 const uint32_t Code) noexcept {
104
0
  return Unexpect(static_cast<ErrCategory>(Code >> 24), Code);
105
0
}
106
107
Expect<void> Executor::proxyCall(Runtime::StackManager &StackMgr,
108
                                 const uint32_t FuncIdx, const ValVariant *Args,
109
0
                                 ValVariant *Rets) noexcept {
110
0
  const auto *FuncInst = getFuncInstByIdx(StackMgr, FuncIdx);
111
0
  const auto &FuncType = FuncInst->getFuncType();
112
0
  const uint32_t ParamsSize =
113
0
      static_cast<uint32_t>(FuncType.getParamTypes().size());
114
0
  const uint32_t ReturnsSize =
115
0
      static_cast<uint32_t>(FuncType.getReturnTypes().size());
116
117
0
  for (uint32_t I = 0; I < ParamsSize; ++I) {
118
0
    StackMgr.push(Args[I]);
119
0
  }
120
121
0
  auto Instrs = FuncInst->getInstrs();
122
0
  EXPECTED_TRY(auto StartIt, enterFunction(StackMgr, *FuncInst, Instrs.end()));
123
0
  EXPECTED_TRY(execute(StackMgr, StartIt, Instrs.end()));
124
125
0
  for (uint32_t I = 0; I < ReturnsSize; ++I) {
126
0
    Rets[ReturnsSize - 1 - I] = StackMgr.pop();
127
0
  }
128
0
  return {};
129
0
}
130
131
Expect<void> Executor::proxyCallIndirect(Runtime::StackManager &StackMgr,
132
                                         const uint32_t TableIdx,
133
                                         const uint32_t FuncTypeIdx,
134
                                         const uint32_t FuncIdx,
135
                                         const ValVariant *Args,
136
0
                                         ValVariant *Rets) noexcept {
137
0
  const auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
138
0
  assuming(TabInst);
139
140
0
  if (unlikely(FuncIdx >= TabInst->getSize())) {
141
0
    return Unexpect(ErrCode::Value::UndefinedElement);
142
0
  }
143
144
0
  auto Ref = TabInst->getRefAddr(FuncIdx);
145
0
  assuming(Ref);
146
0
  if (unlikely(Ref->isNull())) {
147
0
    return Unexpect(ErrCode::Value::UninitializedElement);
148
0
  }
149
150
0
  const auto *ModInst = StackMgr.getModule();
151
0
  assuming(ModInst);
152
0
  const auto &ExpDefType = **ModInst->getType(FuncTypeIdx);
153
0
  const auto *FuncInst = retrieveFuncRef(*Ref);
154
0
  assuming(FuncInst);
155
0
  bool IsMatch = false;
156
0
  if (FuncInst->getModule()) {
157
0
    IsMatch = AST::TypeMatcher::matchType(
158
0
        ModInst->getTypeList(), *ExpDefType.getTypeIndex(),
159
0
        FuncInst->getModule()->getTypeList(), FuncInst->getTypeIndex());
160
0
  } else {
161
    // Independent host module instance case. Matching the composite type
162
    // directly.
163
0
    IsMatch = AST::TypeMatcher::matchType(
164
0
        ModInst->getTypeList(), ExpDefType.getCompositeType(),
165
0
        FuncInst->getHostFunc().getDefinedType().getCompositeType());
166
0
  }
167
0
  if (!IsMatch) {
168
0
    return Unexpect(ErrCode::Value::IndirectCallTypeMismatch);
169
0
  }
170
171
0
  const auto &FuncType = FuncInst->getFuncType();
172
0
  const uint32_t ParamsSize =
173
0
      static_cast<uint32_t>(FuncType.getParamTypes().size());
174
0
  const uint32_t ReturnsSize =
175
0
      static_cast<uint32_t>(FuncType.getReturnTypes().size());
176
177
0
  for (uint32_t I = 0; I < ParamsSize; ++I) {
178
0
    StackMgr.push(Args[I]);
179
0
  }
180
181
0
  auto Instrs = FuncInst->getInstrs();
182
0
  EXPECTED_TRY(auto StartIt, enterFunction(StackMgr, *FuncInst, Instrs.end()));
183
0
  EXPECTED_TRY(execute(StackMgr, StartIt, Instrs.end()));
184
185
0
  for (uint32_t I = 0; I < ReturnsSize; ++I) {
186
0
    Rets[ReturnsSize - 1 - I] = StackMgr.pop();
187
0
  }
188
0
  return {};
189
0
}
190
191
Expect<void> Executor::proxyCallRef(Runtime::StackManager &StackMgr,
192
                                    const RefVariant Ref,
193
                                    const ValVariant *Args,
194
0
                                    ValVariant *Rets) noexcept {
195
0
  const auto *FuncInst = retrieveFuncRef(Ref);
196
0
  const auto &FuncType = FuncInst->getFuncType();
197
0
  const uint32_t ParamsSize =
198
0
      static_cast<uint32_t>(FuncType.getParamTypes().size());
199
0
  const uint32_t ReturnsSize =
200
0
      static_cast<uint32_t>(FuncType.getReturnTypes().size());
201
202
0
  for (uint32_t I = 0; I < ParamsSize; ++I) {
203
0
    StackMgr.push(Args[I]);
204
0
  }
205
206
0
  auto Instrs = FuncInst->getInstrs();
207
0
  EXPECTED_TRY(auto StartIt, enterFunction(StackMgr, *FuncInst, Instrs.end()));
208
0
  EXPECTED_TRY(execute(StackMgr, StartIt, Instrs.end()));
209
210
0
  for (uint32_t I = 0; I < ReturnsSize; ++I) {
211
0
    Rets[ReturnsSize - 1 - I] = StackMgr.pop();
212
0
  }
213
214
0
  return {};
215
0
}
216
217
Expect<RefVariant> Executor::proxyRefFunc(Runtime::StackManager &StackMgr,
218
0
                                          const uint32_t FuncIdx) noexcept {
219
0
  auto *FuncInst = getFuncInstByIdx(StackMgr, FuncIdx);
220
0
  assuming(FuncInst);
221
0
  return RefVariant(FuncInst->getDefType(), FuncInst);
222
0
}
223
224
Expect<RefVariant> Executor::proxyStructNew(Runtime::StackManager &StackMgr,
225
                                            const uint32_t TypeIdx,
226
                                            const ValVariant *Args,
227
0
                                            const uint32_t ArgSize) noexcept {
228
0
  if (Args == nullptr) {
229
0
    return structNew(StackMgr, TypeIdx);
230
0
  } else {
231
0
    return structNew(StackMgr, TypeIdx, Span<const ValVariant>(Args, ArgSize));
232
0
  }
233
0
}
234
235
Expect<void> Executor::proxyStructGet(Runtime::StackManager &StackMgr,
236
                                      const RefVariant Ref,
237
                                      const uint32_t TypeIdx,
238
                                      const uint32_t Off, const bool IsSigned,
239
0
                                      ValVariant *Ret) noexcept {
240
0
  EXPECTED_TRY(auto Val, structGet(StackMgr, Ref, TypeIdx, Off, IsSigned));
241
0
  *Ret = Val;
242
0
  return {};
243
0
}
244
245
Expect<void> Executor::proxyStructSet(Runtime::StackManager &StackMgr,
246
                                      const RefVariant Ref,
247
                                      const uint32_t TypeIdx,
248
                                      const uint32_t Off,
249
0
                                      const ValVariant *Val) noexcept {
250
0
  return structSet(StackMgr, Ref, *Val, TypeIdx, Off);
251
0
}
252
253
Expect<RefVariant> Executor::proxyArrayNew(Runtime::StackManager &StackMgr,
254
                                           const uint32_t TypeIdx,
255
                                           const uint32_t Length,
256
                                           const ValVariant *Args,
257
0
                                           const uint32_t ArgSize) noexcept {
258
0
  assuming(ArgSize == 0 || ArgSize == 1 || ArgSize == Length);
259
0
  if (ArgSize == 0) {
260
0
    return arrayNew(StackMgr, TypeIdx, Length);
261
0
  } else if (ArgSize == 1) {
262
0
    return arrayNew(StackMgr, TypeIdx, Length, {Args[0]});
263
0
  } else {
264
0
    return arrayNew(StackMgr, TypeIdx, Length,
265
0
                    Span<const ValVariant>(Args, ArgSize));
266
0
  }
267
0
}
268
269
Expect<RefVariant> Executor::proxyArrayNewData(Runtime::StackManager &StackMgr,
270
                                               const uint32_t TypeIdx,
271
                                               const uint32_t DataIdx,
272
                                               const uint32_t Start,
273
0
                                               const uint32_t Length) noexcept {
274
0
  return arrayNewData(StackMgr, TypeIdx, DataIdx, Start, Length);
275
0
}
276
277
Expect<RefVariant> Executor::proxyArrayNewElem(Runtime::StackManager &StackMgr,
278
                                               const uint32_t TypeIdx,
279
                                               const uint32_t ElemIdx,
280
                                               const uint32_t Start,
281
0
                                               const uint32_t Length) noexcept {
282
0
  return arrayNewElem(StackMgr, TypeIdx, ElemIdx, Start, Length);
283
0
}
284
285
Expect<void> Executor::proxyArrayGet(Runtime::StackManager &StackMgr,
286
                                     const RefVariant Ref,
287
                                     const uint32_t TypeIdx, const uint32_t Idx,
288
                                     const bool IsSigned,
289
0
                                     ValVariant *Ret) noexcept {
290
0
  EXPECTED_TRY(auto Val, arrayGet(StackMgr, Ref, TypeIdx, Idx, IsSigned));
291
0
  *Ret = Val;
292
0
  return {};
293
0
}
294
295
Expect<void> Executor::proxyArraySet(Runtime::StackManager &StackMgr,
296
                                     const RefVariant Ref,
297
                                     const uint32_t TypeIdx, const uint32_t Idx,
298
0
                                     const ValVariant *Val) noexcept {
299
0
  return arraySet(StackMgr, Ref, *Val, TypeIdx, Idx);
300
0
}
301
302
Expect<uint32_t> Executor::proxyArrayLen(Runtime::StackManager &,
303
0
                                         const RefVariant Ref) noexcept {
304
0
  auto *Inst = Ref.getPtr<Runtime::Instance::ArrayInstance>();
305
0
  if (Inst == nullptr) {
306
0
    return Unexpect(ErrCode::Value::AccessNullArray);
307
0
  }
308
0
  return Inst->getLength();
309
0
}
310
311
Expect<void> Executor::proxyArrayFill(Runtime::StackManager &StackMgr,
312
                                      const RefVariant Ref,
313
                                      const uint32_t TypeIdx,
314
                                      const uint32_t Idx, const uint32_t Cnt,
315
0
                                      const ValVariant *Val) noexcept {
316
0
  return arrayFill(StackMgr, Ref, *Val, TypeIdx, Idx, Cnt);
317
0
}
318
319
Expect<void>
320
Executor::proxyArrayCopy(Runtime::StackManager &StackMgr,
321
                         const RefVariant DstRef, const uint32_t DstTypeIdx,
322
                         const uint32_t DstIdx, const RefVariant SrcRef,
323
                         const uint32_t SrcTypeIdx, const uint32_t SrcIdx,
324
0
                         const uint32_t Cnt) noexcept {
325
0
  return arrayCopy(StackMgr, DstRef, DstTypeIdx, DstIdx, SrcRef, SrcTypeIdx,
326
0
                   SrcIdx, Cnt);
327
0
}
328
329
Expect<void> Executor::proxyArrayInitData(
330
    Runtime::StackManager &StackMgr, const RefVariant Ref,
331
    const uint32_t TypeIdx, const uint32_t DataIdx, const uint32_t DstIdx,
332
0
    const uint32_t SrcIdx, const uint32_t Cnt) noexcept {
333
0
  return arrayInitData(StackMgr, Ref, TypeIdx, DataIdx, DstIdx, SrcIdx, Cnt);
334
0
}
335
336
Expect<void> Executor::proxyArrayInitElem(
337
    Runtime::StackManager &StackMgr, const RefVariant Ref,
338
    const uint32_t TypeIdx, const uint32_t ElemIdx, const uint32_t DstIdx,
339
0
    const uint32_t SrcIdx, const uint32_t Cnt) noexcept {
340
0
  return arrayInitElem(StackMgr, Ref, TypeIdx, ElemIdx, DstIdx, SrcIdx, Cnt);
341
0
}
342
343
Expect<uint32_t> Executor::proxyRefTest(Runtime::StackManager &StackMgr,
344
                                        const RefVariant Ref,
345
0
                                        ValType VTTest) noexcept {
346
  // Copy the value type here due to handling the externalized case.
347
0
  auto VT = Ref.getType();
348
0
  if (VT.isExternalized()) {
349
0
    VT = ValType(TypeCode::Ref, TypeCode::ExternRef);
350
0
  }
351
0
  const auto *ModInst = StackMgr.getModule();
352
0
  assuming(ModInst);
353
0
  Span<const AST::SubType *const> GotTypeList = ModInst->getTypeList();
354
0
  if (!VT.isAbsHeapType()) {
355
0
    auto *Inst = Ref.getPtr<Runtime::Instance::CompositeBase>();
356
    // Reference must not be nullptr here because the null references are typed
357
    // with the least abstract heap type.
358
0
    if (Inst->getModule()) {
359
0
      GotTypeList = Inst->getModule()->getTypeList();
360
0
    }
361
0
  }
362
363
0
  if (AST::TypeMatcher::matchType(ModInst->getTypeList(), VTTest, GotTypeList,
364
0
                                  VT)) {
365
0
    return static_cast<uint32_t>(1);
366
0
  } else {
367
0
    return static_cast<uint32_t>(0);
368
0
  }
369
0
}
370
371
Expect<RefVariant> Executor::proxyRefCast(Runtime::StackManager &StackMgr,
372
                                          const RefVariant Ref,
373
0
                                          ValType VTCast) noexcept {
374
  // Copy the value type here due to handling the externalized case.
375
0
  auto VT = Ref.getType();
376
0
  if (VT.isExternalized()) {
377
0
    VT = ValType(TypeCode::Ref, TypeCode::ExternRef);
378
0
  }
379
0
  const auto *ModInst = StackMgr.getModule();
380
0
  assuming(ModInst);
381
0
  Span<const AST::SubType *const> GotTypeList = ModInst->getTypeList();
382
0
  if (!VT.isAbsHeapType()) {
383
0
    auto *Inst = Ref.getPtr<Runtime::Instance::CompositeBase>();
384
    // Reference must not be nullptr here because the null references are typed
385
    // with the least abstract heap type.
386
0
    if (Inst->getModule()) {
387
0
      GotTypeList = Inst->getModule()->getTypeList();
388
0
    }
389
0
  }
390
391
0
  if (!AST::TypeMatcher::matchType(ModInst->getTypeList(), VTCast, GotTypeList,
392
0
                                   VT)) {
393
0
    return Unexpect(ErrCode::Value::CastFailed);
394
0
  }
395
0
  return Ref;
396
0
}
397
398
Expect<RefVariant> Executor::proxyTableGet(Runtime::StackManager &StackMgr,
399
                                           const uint32_t TableIdx,
400
0
                                           const uint32_t Off) noexcept {
401
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
402
0
  assuming(TabInst);
403
0
  return TabInst->getRefAddr(Off);
404
0
}
405
406
Expect<void> Executor::proxyTableSet(Runtime::StackManager &StackMgr,
407
                                     const uint32_t TableIdx,
408
                                     const uint32_t Off,
409
0
                                     const RefVariant Ref) noexcept {
410
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
411
0
  assuming(TabInst);
412
0
  return TabInst->setRefAddr(Off, Ref);
413
0
}
414
415
Expect<void> Executor::proxyTableInit(Runtime::StackManager &StackMgr,
416
                                      const uint32_t TableIdx,
417
                                      const uint32_t ElemIdx,
418
                                      const uint32_t DstOff,
419
                                      const uint32_t SrcOff,
420
0
                                      const uint32_t Len) noexcept {
421
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
422
0
  assuming(TabInst);
423
0
  auto *ElemInst = getElemInstByIdx(StackMgr, ElemIdx);
424
0
  assuming(ElemInst);
425
0
  return TabInst->setRefs(ElemInst->getRefs(), DstOff, SrcOff, Len);
426
0
}
427
428
Expect<void> Executor::proxyElemDrop(Runtime::StackManager &StackMgr,
429
0
                                     const uint32_t ElemIdx) noexcept {
430
0
  auto *ElemInst = getElemInstByIdx(StackMgr, ElemIdx);
431
0
  assuming(ElemInst);
432
0
  ElemInst->clear();
433
0
  return {};
434
0
}
435
436
Expect<void> Executor::proxyTableCopy(Runtime::StackManager &StackMgr,
437
                                      const uint32_t TableIdxDst,
438
                                      const uint32_t TableIdxSrc,
439
                                      const uint32_t DstOff,
440
                                      const uint32_t SrcOff,
441
0
                                      const uint32_t Len) noexcept {
442
0
  auto *TabInstDst = getTabInstByIdx(StackMgr, TableIdxDst);
443
0
  assuming(TabInstDst);
444
0
  auto *TabInstSrc = getTabInstByIdx(StackMgr, TableIdxSrc);
445
0
  assuming(TabInstSrc);
446
447
0
  EXPECTED_TRY(auto Refs, TabInstSrc->getRefs(0, SrcOff + Len));
448
0
  return TabInstDst->setRefs(Refs, DstOff, SrcOff, Len);
449
0
}
450
451
Expect<uint32_t> Executor::proxyTableGrow(Runtime::StackManager &StackMgr,
452
                                          const uint32_t TableIdx,
453
                                          const RefVariant Val,
454
0
                                          const uint32_t NewSize) noexcept {
455
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
456
0
  assuming(TabInst);
457
0
  const uint32_t CurrTableSize = TabInst->getSize();
458
0
  if (likely(TabInst->growTable(NewSize, Val))) {
459
0
    return CurrTableSize;
460
0
  } else {
461
0
    return static_cast<uint32_t>(-1);
462
0
  }
463
0
}
464
465
Expect<uint32_t> Executor::proxyTableSize(Runtime::StackManager &StackMgr,
466
0
                                          const uint32_t TableIdx) noexcept {
467
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
468
0
  assuming(TabInst);
469
0
  return TabInst->getSize();
470
0
}
471
472
Expect<void> Executor::proxyTableFill(Runtime::StackManager &StackMgr,
473
                                      const uint32_t TableIdx,
474
                                      const uint32_t Off, const RefVariant Ref,
475
0
                                      const uint32_t Len) noexcept {
476
0
  auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
477
0
  assuming(TabInst);
478
0
  return TabInst->fillRefs(Ref, Off, Len);
479
0
}
480
481
Expect<uint32_t> Executor::proxyMemGrow(Runtime::StackManager &StackMgr,
482
                                        const uint32_t MemIdx,
483
0
                                        const uint32_t NewSize) noexcept {
484
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
485
0
  assuming(MemInst);
486
0
  const uint32_t CurrPageSize = MemInst->getPageSize();
487
0
  if (MemInst->growPage(NewSize)) {
488
0
    return CurrPageSize;
489
0
  } else {
490
0
    return static_cast<uint32_t>(-1);
491
0
  }
492
0
}
493
494
Expect<uint32_t> Executor::proxyMemSize(Runtime::StackManager &StackMgr,
495
0
                                        const uint32_t MemIdx) noexcept {
496
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
497
0
  assuming(MemInst);
498
0
  return MemInst->getPageSize();
499
0
}
500
501
Expect<void>
502
Executor::proxyMemInit(Runtime::StackManager &StackMgr, const uint32_t MemIdx,
503
                       const uint32_t DataIdx, const uint32_t DstOff,
504
0
                       const uint32_t SrcOff, const uint32_t Len) noexcept {
505
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
506
0
  assuming(MemInst);
507
0
  auto *DataInst = getDataInstByIdx(StackMgr, DataIdx);
508
0
  assuming(DataInst);
509
0
  return MemInst->setBytes(DataInst->getData(), DstOff, SrcOff, Len);
510
0
}
511
512
Expect<void> Executor::proxyDataDrop(Runtime::StackManager &StackMgr,
513
0
                                     const uint32_t DataIdx) noexcept {
514
0
  auto *DataInst = getDataInstByIdx(StackMgr, DataIdx);
515
0
  assuming(DataInst);
516
0
  DataInst->clear();
517
0
  return {};
518
0
}
519
520
Expect<void> Executor::proxyMemCopy(Runtime::StackManager &StackMgr,
521
                                    const uint32_t DstMemIdx,
522
                                    const uint32_t SrcMemIdx,
523
                                    const uint32_t DstOff,
524
                                    const uint32_t SrcOff,
525
0
                                    const uint32_t Len) noexcept {
526
0
  auto *MemInstDst = getMemInstByIdx(StackMgr, DstMemIdx);
527
0
  assuming(MemInstDst);
528
0
  auto *MemInstSrc = getMemInstByIdx(StackMgr, SrcMemIdx);
529
0
  assuming(MemInstSrc);
530
531
0
  EXPECTED_TRY(auto Data, MemInstSrc->getBytes(SrcOff, Len));
532
0
  return MemInstDst->setBytes(Data, DstOff, 0, Len);
533
0
}
534
535
Expect<void> Executor::proxyMemFill(Runtime::StackManager &StackMgr,
536
                                    const uint32_t MemIdx, const uint32_t Off,
537
                                    const uint8_t Val,
538
0
                                    const uint32_t Len) noexcept {
539
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
540
0
  assuming(MemInst);
541
0
  return MemInst->fillBytes(Val, Off, Len);
542
0
}
543
544
Expect<uint32_t> Executor::proxyMemAtomicNotify(Runtime::StackManager &StackMgr,
545
                                                const uint32_t MemIdx,
546
                                                const uint32_t Offset,
547
0
                                                const uint32_t Count) noexcept {
548
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
549
0
  assuming(MemInst);
550
0
  return atomicNotify(*MemInst, Offset, Count);
551
0
}
552
553
Expect<uint32_t>
554
Executor::proxyMemAtomicWait(Runtime::StackManager &StackMgr,
555
                             const uint32_t MemIdx, const uint32_t Offset,
556
                             const uint64_t Expected, const int64_t Timeout,
557
0
                             const uint32_t BitWidth) noexcept {
558
0
  auto *MemInst = getMemInstByIdx(StackMgr, MemIdx);
559
0
  assuming(MemInst);
560
561
0
  if (BitWidth == 64) {
562
0
    return atomicWait<uint64_t>(*MemInst, Offset, Expected, Timeout);
563
0
  } else if (BitWidth == 32) {
564
0
    return atomicWait<uint32_t>(*MemInst, Offset,
565
0
                                static_cast<uint32_t>(Expected), Timeout);
566
0
  }
567
0
  assumingUnreachable();
568
0
}
569
570
Expect<void *> Executor::proxyTableGetFuncSymbol(
571
    Runtime::StackManager &StackMgr, const uint32_t TableIdx,
572
0
    const uint32_t FuncTypeIdx, const uint32_t FuncIdx) noexcept {
573
0
  const auto *TabInst = getTabInstByIdx(StackMgr, TableIdx);
574
0
  assuming(TabInst);
575
576
0
  if (unlikely(FuncIdx >= TabInst->getSize())) {
577
0
    return Unexpect(ErrCode::Value::UndefinedElement);
578
0
  }
579
580
0
  auto Ref = TabInst->getRefAddr(FuncIdx);
581
0
  assuming(Ref);
582
0
  if (unlikely(Ref->isNull())) {
583
0
    return Unexpect(ErrCode::Value::UninitializedElement);
584
0
  }
585
586
0
  const auto *ModInst = StackMgr.getModule();
587
0
  assuming(ModInst);
588
0
  const auto &ExpDefType = **ModInst->getType(FuncTypeIdx);
589
0
  const auto *FuncInst = retrieveFuncRef(*Ref);
590
0
  assuming(FuncInst);
591
0
  bool IsMatch = false;
592
0
  if (FuncInst->getModule()) {
593
0
    IsMatch = AST::TypeMatcher::matchType(
594
0
        ModInst->getTypeList(), *ExpDefType.getTypeIndex(),
595
0
        FuncInst->getModule()->getTypeList(), FuncInst->getTypeIndex());
596
0
  } else {
597
    // Independent host module instance case. Matching the composite type
598
    // directly.
599
0
    IsMatch = AST::TypeMatcher::matchType(
600
0
        ModInst->getTypeList(), ExpDefType.getCompositeType(),
601
0
        FuncInst->getHostFunc().getDefinedType().getCompositeType());
602
0
  }
603
0
  if (!IsMatch) {
604
0
    return Unexpect(ErrCode::Value::IndirectCallTypeMismatch);
605
0
  }
606
607
0
  if (unlikely(!FuncInst->isCompiledFunction())) {
608
0
    return nullptr;
609
0
  }
610
0
  return FuncInst->getSymbol().get();
611
0
}
612
613
Expect<void *> Executor::proxyRefGetFuncSymbol(Runtime::StackManager &,
614
0
                                               const RefVariant Ref) noexcept {
615
0
  const auto *FuncInst = retrieveFuncRef(Ref);
616
0
  assuming(FuncInst);
617
0
  if (unlikely(!FuncInst->isCompiledFunction())) {
618
0
    return nullptr;
619
0
  }
620
0
  return FuncInst->getSymbol().get();
621
0
}
622
623
} // namespace Executor
624
} // namespace WasmEdge