Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/include/loader/aot_section.h
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
//===-- wasmedge/loader/aot_section.h - AOT Section definition ------------===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file contains the declaration of the AOTSection, which holds logics to
12
/// load from an AOTSection
13
///
14
//===----------------------------------------------------------------------===//
15
#pragma once
16
17
#include "ast/section.h"
18
#include "common/executable.h"
19
#include "common/filesystem.h"
20
#include "system/winapi.h"
21
22
#include <cstdint>
23
#include <memory>
24
#include <vector>
25
26
namespace WasmEdge {
27
namespace Loader {
28
29
/// Holder class for library handle
30
class AOTSection : public Executable {
31
public:
32
0
  AOTSection() noexcept = default;
33
0
  ~AOTSection() noexcept override { unload(); }
34
  Expect<void> load(const AST::AOTSection &AOTSec) noexcept;
35
  void unload() noexcept;
36
37
0
  Symbol<const IntrinsicsTable *> getIntrinsics() noexcept override {
38
0
    if (Binary) {
39
0
      return createSymbol<const IntrinsicsTable *>(
40
0
          getPointer<const IntrinsicsTable *>(IntrinsicsAddress));
41
0
    }
42
0
    return {};
43
0
  }
44
45
0
  std::vector<Symbol<Wrapper>> getTypes(size_t) noexcept override {
46
0
    std::vector<Symbol<Wrapper>> Result;
47
0
    if (Binary) {
48
0
      Result.reserve(TypesAddress.size());
49
0
      for (const auto Address : TypesAddress) {
50
0
        Result.push_back(createSymbol<Wrapper>(getPointer<Wrapper>(Address)));
51
0
      }
52
0
    }
53
0
    return Result;
54
0
  }
55
56
0
  std::vector<Symbol<void>> getCodes(size_t, size_t) noexcept override {
57
0
    std::vector<Symbol<void>> Result;
58
0
    if (Binary) {
59
0
      Result.reserve(CodesAddress.size());
60
0
      for (const auto Address : CodesAddress) {
61
0
        Result.push_back(createSymbol<void>(getPointer<void>(Address)));
62
0
      }
63
0
    }
64
0
    return Result;
65
0
  }
66
67
private:
68
0
  uintptr_t getOffset() const noexcept {
69
0
    return reinterpret_cast<uintptr_t>(Binary);
70
0
  }
71
72
0
  template <typename T> T *getPointer(uint64_t Address) const noexcept {
73
0
    return reinterpret_cast<T *>(getOffset() + Address);
74
0
  }
Unexecuted instantiation: void* const (**WasmEdge::Loader::AOTSection::getPointer<void* const (*) [38]>(unsigned long) const) [38]
Unexecuted instantiation: void (*WasmEdge::Loader::AOTSection::getPointer<void (void*, void*, 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>*)>(unsigned long) const)(void*, void*, 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: void* WasmEdge::Loader::AOTSection::getPointer<void>(unsigned long) const
75
76
  uint8_t *Binary = nullptr;
77
  uint64_t BinarySize = 0;
78
  uint64_t IntrinsicsAddress = 0;
79
  std::vector<uintptr_t> TypesAddress;
80
  std::vector<uintptr_t> CodesAddress;
81
#if WASMEDGE_OS_LINUX
82
  void *EHFrameAddress = nullptr;
83
#elif WASMEDGE_OS_MACOS
84
  uint8_t *EHFrameAddress = nullptr;
85
  uint32_t EHFrameSize = 0;
86
#elif WASMEDGE_OS_WINDOWS
87
  void *PDataAddress = nullptr;
88
  uint32_t PDataSize = 0;
89
#endif
90
};
91
92
} // namespace Loader
93
} // namespace WasmEdge