2019-05-07 02:18:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Intel Corporation. All rights reserved.
|
2019-11-11 23:45:21 +00:00
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-05-07 02:18:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __MEM_ALLOC_H
|
|
|
|
#define __MEM_ALLOC_H
|
|
|
|
|
2020-03-16 08:43:57 +00:00
|
|
|
#include "bh_platform.h"
|
2024-02-06 12:47:11 +00:00
|
|
|
#if WASM_ENABLE_GC != 0
|
|
|
|
#include "../../common/gc/gc_object.h"
|
|
|
|
#endif
|
2019-05-07 02:18:18 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void *mem_allocator_t;
|
|
|
|
|
2024-02-06 12:47:11 +00:00
|
|
|
typedef void (*gc_finalizer_t)(void *obj, void *data);
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
mem_allocator_t
|
|
|
|
mem_allocator_create(void *mem, uint32_t size);
|
|
|
|
|
2020-10-22 10:52:33 +00:00
|
|
|
mem_allocator_t
|
|
|
|
mem_allocator_create_with_struct_and_pool(void *struct_buf,
|
|
|
|
uint32_t struct_buf_size,
|
|
|
|
void *pool_buf,
|
|
|
|
uint32_t pool_buf_size);
|
|
|
|
|
2022-09-01 08:15:00 +00:00
|
|
|
int
|
2019-05-07 02:18:18 +00:00
|
|
|
mem_allocator_destroy(mem_allocator_t allocator);
|
|
|
|
|
2020-10-22 10:52:33 +00:00
|
|
|
uint32
|
|
|
|
mem_allocator_get_heap_struct_size(void);
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
void *
|
|
|
|
mem_allocator_malloc(mem_allocator_t allocator, uint32_t size);
|
|
|
|
|
2020-03-08 13:18:18 +00:00
|
|
|
void *
|
|
|
|
mem_allocator_realloc(mem_allocator_t allocator, void *ptr, uint32_t size);
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
void
|
|
|
|
mem_allocator_free(mem_allocator_t allocator, void *ptr);
|
|
|
|
|
2020-04-13 02:49:40 +00:00
|
|
|
int
|
2021-10-14 01:12:07 +00:00
|
|
|
mem_allocator_migrate(mem_allocator_t allocator, char *pool_buf_new,
|
|
|
|
uint32 pool_buf_size);
|
2020-04-13 02:49:40 +00:00
|
|
|
|
2021-01-05 10:05:30 +00:00
|
|
|
bool
|
|
|
|
mem_allocator_is_heap_corrupted(mem_allocator_t allocator);
|
2020-04-13 02:49:40 +00:00
|
|
|
|
2024-02-06 12:47:11 +00:00
|
|
|
#if WASM_ENABLE_GC != 0
|
|
|
|
void *
|
|
|
|
mem_allocator_malloc_with_gc(mem_allocator_t allocator, uint32_t size);
|
|
|
|
|
|
|
|
#if WASM_GC_MANUALLY != 0
|
|
|
|
void
|
|
|
|
mem_allocator_free_with_gc(mem_allocator_t allocator, void *ptr);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WASM_ENABLE_THREAD_MGR == 0
|
|
|
|
void
|
|
|
|
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *exec_env);
|
|
|
|
#else
|
|
|
|
void
|
|
|
|
mem_allocator_enable_gc_reclaim(mem_allocator_t allocator, void *cluster);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
mem_allocator_add_root(mem_allocator_t allocator, WASMObjectRef obj);
|
|
|
|
|
|
|
|
bool
|
|
|
|
mem_allocator_set_gc_finalizer(mem_allocator_t allocator, void *obj,
|
|
|
|
gc_finalizer_t cb, void *data);
|
|
|
|
|
|
|
|
void
|
|
|
|
mem_allocator_unset_gc_finalizer(mem_allocator_t allocator, void *obj);
|
|
|
|
|
|
|
|
#if WASM_ENABLE_GC_PERF_PROFILING != 0
|
|
|
|
void
|
|
|
|
mem_allocator_dump_perf_profiling(mem_allocator_t allocator);
|
|
|
|
#endif
|
|
|
|
#endif /* end of WASM_ENABLE_GC != 0 */
|
|
|
|
|
2022-08-31 08:39:25 +00:00
|
|
|
bool
|
|
|
|
mem_allocator_get_alloc_info(mem_allocator_t allocator, void *mem_alloc_info);
|
|
|
|
|
2019-05-07 02:18:18 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* #ifndef __MEM_ALLOC_H */
|