wasm_loader.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_LOADER_H
  6. #define _WASM_LOADER_H
  7. #include "wasm.h"
  8. #include "bh_hashmap.h"
  9. #include "../common/wasm_runtime_common.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /**
  14. * Load a WASM module from a specified byte buffer.
  15. *
  16. * @param buf the byte buffer which contains the WASM binary data
  17. * @param size the size of the buffer
  18. * @param error_buf output of the exception info
  19. * @param error_buf_size the size of the exception string
  20. *
  21. * @return return module loaded, NULL if failed
  22. */
  23. WASMModule*
  24. wasm_loader_load(const uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size);
  25. /**
  26. * Load a WASM module from a specified WASM section list.
  27. *
  28. * @param section_list the section list which contains each section data
  29. * @param error_buf output of the exception info
  30. * @param error_buf_size the size of the exception string
  31. *
  32. * @return return WASM module loaded, NULL if failed
  33. */
  34. WASMModule*
  35. wasm_loader_load_from_sections(WASMSection *section_list,
  36. char *error_buf, uint32 error_buf_size);
  37. /**
  38. * Unload a WASM module.
  39. *
  40. * @param module the module to be unloaded
  41. */
  42. void
  43. wasm_loader_unload(WASMModule *module);
  44. /**
  45. * Find address of related else opcode and end opcode of opcode block/loop/if
  46. * according to the start address of opcode.
  47. *
  48. * @param module the module to find
  49. * @param start_addr the next address of opcode block/loop/if
  50. * @param code_end_addr the end address of function code block
  51. * @param block_type the type of block, 0/1/2 denotes block/loop/if
  52. * @param p_else_addr returns the else addr if found
  53. * @param p_end_addr returns the end addr if found
  54. * @param error_buf returns the error log for this function
  55. * @param error_buf_size returns the error log string length
  56. *
  57. * @return true if success, false otherwise
  58. */
  59. bool
  60. wasm_loader_find_block_addr(WASMModule *module,
  61. const uint8 *start_addr,
  62. const uint8 *code_end_addr,
  63. uint8 block_type,
  64. uint8 **p_else_addr,
  65. uint8 **p_end_addr,
  66. char *error_buf,
  67. uint32 error_buf_size);
  68. #ifdef __cplusplus
  69. }
  70. #endif
  71. #endif /* end of _WASM_LOADER_H */