wasm_memory.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_MEMORY_H
  6. #define _WASM_MEMORY_H
  7. #include "bh_common.h"
  8. #include "../include/wasm_export.h"
  9. #include "../interpreter/wasm_runtime.h"
  10. #include "../common/wasm_shared_memory.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. #if WASM_ENABLE_SHARED_MEMORY != 0 && BH_ATOMIC_64_IS_ATOMIC != 0
  15. #define GET_LINEAR_MEMORY_SIZE(memory) \
  16. BH_ATOMIC_64_LOAD(memory->memory_data_size)
  17. #define SET_LINEAR_MEMORY_SIZE(memory, size) \
  18. BH_ATOMIC_64_STORE(memory->memory_data_size, size)
  19. #elif WASM_ENABLE_SHARED_MEMORY != 0
  20. static inline uint64
  21. GET_LINEAR_MEMORY_SIZE(const WASMMemoryInstance *memory)
  22. {
  23. SHARED_MEMORY_LOCK(memory);
  24. uint64 memory_data_size = BH_ATOMIC_64_LOAD(memory->memory_data_size);
  25. SHARED_MEMORY_UNLOCK(memory);
  26. return memory_data_size;
  27. }
  28. static inline void
  29. SET_LINEAR_MEMORY_SIZE(WASMMemoryInstance *memory, uint64 size)
  30. {
  31. SHARED_MEMORY_LOCK(memory);
  32. BH_ATOMIC_64_STORE(memory->memory_data_size, size);
  33. SHARED_MEMORY_UNLOCK(memory);
  34. }
  35. #else
  36. #define GET_LINEAR_MEMORY_SIZE(memory) memory->memory_data_size
  37. #define SET_LINEAR_MEMORY_SIZE(memory, size) memory->memory_data_size = size
  38. #endif
  39. #if WASM_ENABLE_SHARED_HEAP != 0
  40. WASMSharedHeap *
  41. wasm_runtime_create_shared_heap(SharedHeapInitArgs *init_args, char *error_buf,
  42. uint32 error_buf_size);
  43. bool
  44. wasm_runtime_attach_shared_heap(WASMModuleInstanceCommon *module_inst,
  45. WASMSharedHeap *shared_heap);
  46. bool
  47. wasm_runtime_attach_shared_heap_internal(WASMModuleInstanceCommon *module_inst,
  48. WASMSharedHeap *shared_heap);
  49. void
  50. wasm_runtime_detach_shared_heap(WASMModuleInstanceCommon *module_inst);
  51. void
  52. wasm_runtime_detach_shared_heap_internal(WASMModuleInstanceCommon *module_inst);
  53. uint64
  54. wasm_runtime_shared_heap_malloc(WASMModuleInstanceCommon *module_inst,
  55. uint64 size, void **p_native_addr);
  56. void
  57. wasm_runtime_shared_heap_free(WASMModuleInstanceCommon *module_inst,
  58. uint64 ptr);
  59. #endif
  60. bool
  61. wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
  62. const MemAllocOption *alloc_option);
  63. void
  64. wasm_runtime_memory_destroy(void);
  65. unsigned
  66. wasm_runtime_memory_pool_size(void);
  67. void
  68. wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory,
  69. uint64 memory_data_size);
  70. void
  71. wasm_runtime_set_enlarge_mem_error_callback(
  72. const enlarge_memory_error_callback_t callback, void *user_data);
  73. void
  74. wasm_deallocate_linear_memory(WASMMemoryInstance *memory_inst);
  75. int
  76. wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
  77. bool is_memory64, uint64 num_bytes_per_page,
  78. uint64 init_page_count, uint64 max_page_count,
  79. uint64 *memory_data_size);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* end of _WASM_MEMORY_H */