MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / load

Method load

lib/loader/aot_section.cpp:38–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36namespace WasmEdge::Loader {
37
38Expect<void> AOTSection::load(const AST::AOTSection &AOTSec) noexcept {
39 BinarySize = 0;
40 for (const auto &Section : AOTSec.getSections()) {
41 const auto Offset = std::get<1>(Section);
42 const auto Size = std::get<2>(Section);
43 BinarySize = std::max(BinarySize, Offset + Size);
44 }
45 BinarySize = roundUpPageBoundary(BinarySize);
46
47 Binary = Allocator::allocate_chunk(BinarySize);
48 if (unlikely(!Binary)) {
49 spdlog::error(ErrCode::Value::MemoryOutOfBounds);
50 return Unexpect(ErrCode::Value::MemoryOutOfBounds);
51 }
52
53 std::vector<std::pair<uint8_t *, uint64_t>> ExecutableRanges;
54 for (const auto &Section : AOTSec.getSections()) {
55 const auto Offset = std::get<1>(Section);
56 const auto Size = std::get<2>(Section);
57 const auto &Content = std::get<3>(Section);
58 if (Size > BinarySize || Offset > BinarySize ||
59 Offset + Size > BinarySize || Content.size() > Size) {
60 return Unexpect(ErrCode::Value::IntegerTooLarge);
61 }
62 std::copy(Content.begin(), Content.end(), Binary + Offset);
63 switch (std::get<0>(Section)) {
64 case 1: { // Text
65 const auto O = roundDownPageBoundary(Offset);
66 const auto S = roundUpPageBoundary(Size + (Offset - O));
67 ExecutableRanges.emplace_back(Binary + O, S);
68 break;
69 }
70 case 2: // Data
71 break;
72 case 3: // BSS
73 break;
74#if WASMEDGE_OS_LINUX
75 case 4: // EHFrame
76 EHFrameAddress = reinterpret_cast<void *>(Binary + Offset);
77 break;
78#elif WASMEDGE_OS_MACOS
79 case 4: // EHFrame
80 EHFrameAddress = reinterpret_cast<uint8_t *>(Binary + Offset);
81 EHFrameSize = Size;
82 break;
83#elif WASMEDGE_OS_WINDOWS
84 case 4: // PData
85 PDataAddress = reinterpret_cast<void *>(Binary + Offset);
86 PDataSize =
87 static_cast<uint32_t>(Size / sizeof(winapi::RUNTIME_FUNCTION_));
88 break;
89#endif
90 default:
91 return Unexpect(ErrCode::Value::IntegerTooLarge);
92 }
93 }
94
95 for (const auto &[Pointer, Size] : ExecutableRanges) {

Callers 2

parseWasmUnitMethod · 0.45
loadUniversalWASMMethod · 0.45

Calls 10

roundUpPageBoundaryFunction · 0.85
unlikelyFunction · 0.85
UnexpectFunction · 0.85
roundDownPageBoundaryFunction · 0.85
getSectionsMethod · 0.80
getIntrinsicsAddressMethod · 0.80
errorFunction · 0.50
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected