| 77 | } |
| 78 | |
| 79 | WASMEDGE_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 | |
| 112 | WASMEDGE_EXPORT void Allocator::release(uint8_t *Pointer, uint64_t) noexcept { |
| 113 | #if WASMEDGE_OS_WINDOWS |
no outgoing calls