mem_alloc.h 2.3 KB

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