wasm_memory.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. bool
  40. wasm_runtime_memory_init(mem_alloc_type_t mem_alloc_type,
  41. const MemAllocOption *alloc_option);
  42. void
  43. wasm_runtime_memory_destroy(void);
  44. unsigned
  45. wasm_runtime_memory_pool_size(void);
  46. void
  47. wasm_runtime_set_mem_bound_check_bytes(WASMMemoryInstance *memory,
  48. uint64 memory_data_size);
  49. void
  50. wasm_runtime_set_enlarge_mem_error_callback(
  51. const enlarge_memory_error_callback_t callback, void *user_data);
  52. void
  53. wasm_deallocate_linear_memory(WASMMemoryInstance *memory_inst);
  54. int
  55. wasm_allocate_linear_memory(uint8 **data, bool is_shared_memory,
  56. bool is_memory64, uint64 num_bytes_per_page,
  57. uint64 init_page_count, uint64 max_page_count,
  58. uint64 *memory_data_size);
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* end of _WASM_MEMORY_H */