mem_alloc.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. typedef void (*gc_finalizer_t)(void *obj, void *data);
  16. mem_allocator_t
  17. mem_allocator_create(void *mem, uint32_t size);
  18. mem_allocator_t
  19. mem_allocator_create_with_struct_and_pool(void *struct_buf,
  20. uint32_t struct_buf_size,
  21. void *pool_buf,
  22. uint32_t pool_buf_size);
  23. int
  24. mem_allocator_destroy(mem_allocator_t allocator);
  25. uint32
  26. mem_allocator_get_heap_struct_size(void);
  27. void *
  28. mem_allocator_malloc(mem_allocator_t allocator, uint32_t size);
  29. void *
  30. mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
  31. void
  32. mem_allocator_free(mem_allocator_t allocator, void *ptr);
  33. int
  34. mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
  35. uint32 pool_buf_size);
  36. bool
  37. mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
  38. #if WASM_ENABLE_GC != 0
  39. void *
  40. mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size);
  41. #if WASM_GC_MANUALLY != 0
  42. void
  43. mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr);
  44. #endif
  45. #if WASM_ENABLE_THREAD_MGR == 0
  46. void
  47. mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env);
  48. #else
  49. void
  50. mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster);
  51. #endif
  52. int
  53. mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj);
  54. bool
  55. mem_allocator_set_gc_finalizer(mem_allocator_t allocator, void *obj,
  56. gc_finalizer_t cb, void *data);
  57. void
  58. mem_allocator_unset_gc_finalizer(mem_allocator_t allocator, void *obj);
  59. #if WASM_ENABLE_GC_PERF_PROFILING != 0
  60. void
  61. mem_allocator_dump_perf_profiling(mem_allocator_t allocator);
  62. #endif
  63. #endif /* end of WASM_ENABLE_GC != 0 */
  64. bool
  65. mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif /* #ifndef __MEM_ALLOC_H */