Coverage Report

Created: 2026-07-16 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/lib/executor/instantiate/memory.cpp
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
#include "executor/executor.h"
5
6
#include <cstdint>
7
8
namespace WasmEdge {
9
namespace Executor {
10
11
// Instantiate memory instance. See "include/executor/executor.h".
12
Expect<void> Executor::instantiate(Runtime::Instance::ModuleInstance &ModInst,
13
0
                                   const AST::MemorySection &MemSec) {
14
  // Prepare pointers vector for compiled functions.
15
0
  ModInst.MemoryPtrs.resize(ModInst.getMemoryNum() +
16
0
                            MemSec.getContent().size());
17
0
  ModInst.MemorySizePtrs.resize(ModInst.getMemoryNum() +
18
0
                                MemSec.getContent().size());
19
20
  // Set the memory pointers of imported memories.
21
0
  for (uint32_t I = 0; I < ModInst.getMemoryNum(); ++I) {
22
#if WASMEDGE_ALLOCATOR_IS_STABLE
23
    ModInst.MemoryPtrs[I] = (*ModInst.getMemory(I))->getDataPtr();
24
#else
25
0
    ModInst.MemoryPtrs[I] = &(*ModInst.getMemory(I))->getDataPtr();
26
0
#endif
27
0
    ModInst.MemorySizePtrs[I] = (*ModInst.getMemory(I))->getPageSizePtr();
28
0
  }
29
30
  // Iterate through the memory types to instantiate memory instances.
31
0
  for (const auto &MemType : MemSec.getContent()) {
32
    // Create and add the memory instance to the module instance.
33
0
    ModInst.addMemory(MemType, Conf.getRuntimeConfigure().getMaxMemoryPage());
34
0
    const auto Index = ModInst.getMemoryNum() - 1;
35
0
    Runtime::Instance::MemoryInstance *MemInst = *ModInst.getMemory(Index);
36
    // Set the memory pointers of instantiated memories.
37
#if WASMEDGE_ALLOCATOR_IS_STABLE
38
    ModInst.MemoryPtrs[Index] = MemInst->getDataPtr();
39
#else
40
0
    ModInst.MemoryPtrs[Index] = &MemInst->getDataPtr();
41
0
#endif
42
0
    ModInst.MemorySizePtrs[Index] = MemInst->getPageSizePtr();
43
0
  }
44
0
  return {};
45
0
}
46
47
} // namespace Executor
48
} // namespace WasmEdge