Coverage Report

Created: 2025-07-01 06:18

/src/WasmEdge/lib/executor/instantiate/memory.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
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
18
  // Set the memory pointers of imported memories.
19
0
  for (uint32_t I = 0; I < ModInst.getMemoryNum(); ++I) {
20
#if WASMEDGE_ALLOCATOR_IS_STABLE
21
    ModInst.MemoryPtrs[I] = (*ModInst.getMemory(I))->getDataPtr();
22
#else
23
0
    ModInst.MemoryPtrs[I] = &(*ModInst.getMemory(I))->getDataPtr();
24
0
#endif
25
0
  }
26
27
  // Iterate through the memory types to instantiate memory instances.
28
0
  for (const auto &MemType : MemSec.getContent()) {
29
    // Create and add the memory instance into the module instance.
30
0
    ModInst.addMemory(MemType, Conf.getRuntimeConfigure().getMaxMemoryPage());
31
0
    const auto Index = ModInst.getMemoryNum() - 1;
32
0
    Runtime::Instance::MemoryInstance *MemInst = *ModInst.getMemory(Index);
33
    // Set the memory pointers of instantiated memories.
34
#if WASMEDGE_ALLOCATOR_IS_STABLE
35
    ModInst.MemoryPtrs[Index] = MemInst->getDataPtr();
36
#else
37
0
    ModInst.MemoryPtrs[Index] = &MemInst->getDataPtr();
38
0
#endif
39
0
  }
40
0
  return {};
41
0
}
42
43
} // namespace Executor
44
} // namespace WasmEdge