bh_memutils.c 621 B

123456789101112131415161718192021222324
  1. /*
  2. * Copyright (C) 2024 Amazon Inc. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "bh_memutils.h"
  6. void *
  7. bh_memory_remap_slow(void *old_addr, size_t old_size, size_t new_size)
  8. {
  9. void *new_memory =
  10. os_mmap(NULL, new_size, MMAP_PROT_WRITE | MMAP_PROT_READ, 0, -1);
  11. if (!new_memory) {
  12. return NULL;
  13. }
  14. /*
  15. * bh_memcpy_s can't be used as it doesn't support values bigger than
  16. * UINT32_MAX
  17. */
  18. memcpy(new_memory, old_addr, new_size < old_size ? new_size : old_size);
  19. os_munmap(old_addr, old_size);
  20. return new_memory;
  21. }