wasm_native.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_NATIVE_H
  6. #define _WASM_NATIVE_H
  7. #include "bh_common.h"
  8. #include "../include/wasm_export.h"
  9. #include "../interpreter/wasm.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. typedef struct NativeSymbolsNode {
  14. struct NativeSymbolsNode *next;
  15. const char *module_name;
  16. NativeSymbol *native_symbols;
  17. uint32 n_native_symbols;
  18. bool call_conv_raw;
  19. } NativeSymbolsNode, *NativeSymbolsList;
  20. /**
  21. * Lookup global variable of a given import global
  22. * from libc builtin globals
  23. *
  24. * @param module_name the module name of the import global
  25. * @param global_name the global name of the import global
  26. * @param global return the global data
  27. *
  28. * @param true if success, false otherwise
  29. */
  30. bool
  31. wasm_native_lookup_libc_builtin_global(const char *module_name,
  32. const char *global_name,
  33. WASMGlobalImport *global);
  34. /**
  35. * Resolve native symbol in all libraries, including libc-builtin, libc-wasi,
  36. * base lib and extension lib, and user registered natives
  37. * function, which can be auto checked by vm before calling native function
  38. *
  39. * @param module_name the module name of the import function
  40. * @param func_name the function name of the import function
  41. * @param func_type the function prototype of the import function
  42. * @param p_signature output the signature if resolve success
  43. *
  44. * @return the native function pointer if success, NULL otherwise
  45. */
  46. void *
  47. wasm_native_resolve_symbol(const char *module_name, const char *field_name,
  48. const WASMFuncType *func_type,
  49. const char **p_signature, void **p_attachment,
  50. bool *p_call_conv_raw);
  51. bool
  52. wasm_native_register_natives(const char *module_name,
  53. NativeSymbol *native_symbols,
  54. uint32 n_native_symbols);
  55. bool
  56. wasm_native_register_natives_raw(const char *module_name,
  57. NativeSymbol *native_symbols,
  58. uint32 n_native_symbols);
  59. bool
  60. wasm_native_unregister_natives(const char *module_name,
  61. NativeSymbol *native_symbols);
  62. #if WASM_ENABLE_MODULE_INST_CONTEXT != 0
  63. struct WASMModuleInstanceCommon;
  64. void *
  65. wasm_native_create_context_key(
  66. void (*dtor)(struct WASMModuleInstanceCommon *inst, void *ctx));
  67. void
  68. wasm_native_destroy_context_key(void *key);
  69. void
  70. wasm_native_set_context(struct WASMModuleInstanceCommon *inst, void *key,
  71. void *ctx);
  72. void
  73. wasm_native_set_context_spread(struct WASMModuleInstanceCommon *inst, void *key,
  74. void *ctx);
  75. void *
  76. wasm_native_get_context(struct WASMModuleInstanceCommon *inst, void *key);
  77. void
  78. wasm_native_call_context_dtors(struct WASMModuleInstanceCommon *inst);
  79. void
  80. wasm_native_inherit_contexts(struct WASMModuleInstanceCommon *child,
  81. struct WASMModuleInstanceCommon *parent);
  82. #else /* WASM_ENABLE_MODULE_INST_CONTEXT */
  83. #define wasm_native_call_context_dtors(inst) (void)(inst)
  84. #define wasm_native_inherit_contexts(child, parent) (void)(parent)
  85. #endif /* WASM_ENABLE_MODULE_INST_CONTEXT */
  86. bool
  87. wasm_native_init(void);
  88. void
  89. wasm_native_destroy(void);
  90. #if WASM_ENABLE_QUICK_AOT_ENTRY != 0
  91. void *
  92. wasm_native_lookup_quick_aot_entry(const WASMFuncType *func_type);
  93. #endif
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* end of _WASM_NATIVE_H */