lib_export.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _LIB_EXPORT_H_
  6. #define _LIB_EXPORT_H_
  7. #include <stdint.h>
  8. #include "ConstStrDesc.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef union {
  13. const char *symbol_str;
  14. const ConstStrDescription * symbol;
  15. uint32 symbol_key;
  16. } NATIVE_SYMBOL_U;
  17. typedef struct NativeSymbol {
  18. NATIVE_SYMBOL_U u;
  19. void *func_ptr;
  20. const char *signature;
  21. /* attachment which can be retrieved in native API by
  22. calling wasm_runtime_get_function_attachment(exec_env) */
  23. void *attachment;
  24. } NativeSymbol;
  25. /* clang-format off */
  26. #define EXPORT_WASM_API(symbol) \
  27. { #symbol, (void *)symbol, NULL, NULL }
  28. #define EXPORT_WASM_API2(symbol) \
  29. { #symbol, (void *)symbol##_wrapper, NULL, NULL }
  30. #define EXPORT_WASM_API_WITH_SIG(symbol, signature) \
  31. { #symbol, (void *)symbol, signature, NULL }
  32. #define EXPORT_WASM_API_WITH_SIG2(symbol, signature) \
  33. { #symbol, (void *)symbol##_wrapper, signature, NULL }
  34. #define EXPORT_WASM_API_WITH_ATT(symbol, signature, attachment) \
  35. { #symbol, (void *)symbol, signature, attachment }
  36. #define EXPORT_WASM_API_WITH_ATT2(symbol, signature, attachment) \
  37. { #symbol, (void *)symbol##_wrapper, signature, attachment }
  38. /* clang-format on */
  39. /**
  40. * Get the exported APIs of base lib
  41. *
  42. * @param p_base_lib_apis return the exported API array of base lib
  43. *
  44. * @return the number of the exported API
  45. */
  46. uint32_t
  47. get_base_lib_export_apis(NativeSymbol **p_base_lib_apis);
  48. #ifdef __cplusplus
  49. }
  50. #endif
  51. #endif /* end of _LIB_EXPORT_H_ */