wasm_export.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _WASM_EXPORT_H
  17. #define _WASM_EXPORT_H
  18. #include <inttypes.h>
  19. #include <stdbool.h>
  20. /**
  21. * API exported to WASM application
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * Get current WASM module instance of the current native thread
  28. *
  29. * @return current WASM module instance of the current native thread, 0
  30. * if not found
  31. * Note: the return type is uint64_t but not pointer type, because that
  32. * the we only supports WASM-32, in which the pointer type is
  33. * compiled to WASM i32 type, but the pointer type in native can be
  34. * 32-bit and 64-bit. And if the native pointer is 64-bit, data loss
  35. * occurs after converting it to WASM i32 type.
  36. */
  37. uint64_t
  38. wasm_runtime_get_current_module_inst();
  39. /**
  40. * Validate the app address, check whether it belongs to WASM module
  41. * instance's address space, or in its heap space or memory space.
  42. *
  43. * @param module_inst the WASM module instance
  44. * @param app_offset the app address to validate, which is a relative address
  45. * @param size the size bytes of the app address
  46. *
  47. * @return true if success, false otherwise.
  48. */
  49. bool
  50. wasm_runtime_validate_app_addr(uint64_t module_inst,
  51. int32_t app_offset, uint32_t size);
  52. /**
  53. * Validate the native address, check whether it belongs to WASM module
  54. * instance's address space, or in its heap space or memory space.
  55. *
  56. * @param module_inst the WASM module instance
  57. * @param native_ptr the native address to validate, which is an absolute
  58. * address
  59. * @param size the size bytes of the app address
  60. *
  61. * @return true if success, false otherwise.
  62. */
  63. bool
  64. wasm_runtime_validate_native_addr(uint64_t module_inst,
  65. uint64_t native_ptr, uint32_t size);
  66. /**
  67. * Convert app address(relative address) to native address(absolute address)
  68. *
  69. * @param module_inst the WASM module instance
  70. * @param app_offset the app adress
  71. *
  72. * @return the native address converted
  73. */
  74. uint64_t
  75. wasm_runtime_addr_app_to_native(uint64_t module_inst,
  76. int32_t app_offset);
  77. /**
  78. * Convert native address(absolute address) to app address(relative address)
  79. *
  80. * @param module_inst the WASM module instance
  81. * @param native_ptr the native address
  82. *
  83. * @return the app address converted
  84. */
  85. int32_t
  86. wasm_runtime_addr_native_to_app(uint64_t module_inst,
  87. uint64_t native_ptr);
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* end of _WASM_EXPORT_H */