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

Method resize

lib/system/allocator.cpp:79–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79WASMEDGE_EXPORT uint8_t *Allocator::resize(uint8_t *Pointer,
80 uint64_t OldPageCount,
81 uint64_t NewPageCount) noexcept {
82 assuming(NewPageCount > OldPageCount);
83#if WASMEDGE_OS_WINDOWS
84 if (winapi::VirtualAlloc(Pointer + OldPageCount * kPageSize,
85 (NewPageCount - OldPageCount) * kPageSize,
86 winapi::MEM_COMMIT_,
87 winapi::PAGE_READWRITE_) == nullptr) {
88 return nullptr;
89 }
90 return Pointer;
91#elif defined(HAVE_MMAP) && (defined(__x86_64__) || defined(__aarch64__) || \
92 (defined(__riscv) && __riscv_xlen == 64)) || \
93 defined(__s390x__)
94 if (mmap(Pointer + OldPageCount * kPageSize,
95 (NewPageCount - OldPageCount) * kPageSize, PROT_READ | PROT_WRITE,
96 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0) == MAP_FAILED) {
97 return nullptr;
98 }
99 return Pointer;
100#else
101 auto Result = reinterpret_cast<uint8_t *>(
102 std::realloc(Pointer, NewPageCount * kPageSize));
103 if (Result == nullptr) {
104 return nullptr;
105 }
106 std::memset(Result + OldPageCount * kPageSize, 0,
107 (NewPageCount - OldPageCount) * kPageSize);
108 return Result;
109#endif
110}
111
112WASMEDGE_EXPORT void Allocator::release(uint8_t *Pointer, uint64_t) noexcept {
113#if WASMEDGE_OS_WINDOWS

Callers 15

CAPIPluginRegisterMethod · 0.80
resolvePathMethod · 0.80
initMethod · 0.80
initWithFdsMethod · 0.80
fdReaddirMethod · 0.80
waitMethod · 0.80
fdPreadMethod · 0.80
fdPwriteMethod · 0.80
fdReadMethod · 0.80
fdWriteMethod · 0.80
fdReaddirMethod · 0.80

Calls

no outgoing calls

Tested by 7

TEST_PFunction · 0.64
TEST_PFunction · 0.64
TEST_PFunction · 0.64
readToVectorFunction · 0.64
TESTFunction · 0.64
TESTFunction · 0.64
TESTFunction · 0.64