mem_alloc.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef __MEM_ALLOC_H
  6. #define __MEM_ALLOC_H
  7. #include "bh_platform.h"
  8. #if WASM_ENABLE_GC != 0
  9. #include "../../common/gc/gc_object.h"
  10. #endif
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. typedef void *mem_allocator_t;
  15. mem_allocator_t
  16. mem_allocator_create(void *mem, uint32_t size);
  17. mem_allocator_t
  18. mem_allocator_create_with_struct_and_pool(void *struct_buf,
  19. uint32_t struct_buf_size,
  20. void *pool_buf,
  21. uint32_t pool_buf_size);
  22. int
  23. mem_allocator_destroy(mem_allocator_t allocator);
  24. uint32
  25. mem_allocator_get_heap_struct_size(void);
  26. void *
  27. mem_allocator_malloc(mem_allocator_t allocator, uint32_t size);
  28. void *
  29. mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
  30. void
  31. mem_allocator_free(mem_allocator_t allocator, void *ptr);
  32. int
  33. mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
  34. uint32 pool_buf_size);
  35. bool
  36. mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
  37. #if WASM_ENABLE_GC != 0
  38. void *
  39. mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size);
  40. #if WASM_GC_MANUALLY != 0
  41. void
  42. mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr);
  43. #endif
  44. #if WASM_ENABLE_THREAD_MGR == 0
  45. void
  46. mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env);
  47. #else
  48. void
  49. mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster);
  50. #endif
  51. int
  52. mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj);
  53. #endif /* end of WASM_ENABLE_GC != 0 */
  54. bool
  55. mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /* #ifndef __MEM_ALLOC_H */