connection_wrapper.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "connection_lib.h"
  6. #include "wasm_export.h"
  7. #include "native_interface.h"
  8. /* Note:
  9. *
  10. * This file is the consumer of connection lib which is implemented by different platforms
  11. */
  12. uint32
  13. wasm_open_connection(wasm_exec_env_t exec_env,
  14. int32 name_offset, int32 args_offset, uint32 len)
  15. {
  16. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  17. attr_container_t *args;
  18. char *name, *args_buf;
  19. if (!validate_app_str_addr(name_offset) ||
  20. !validate_app_addr(args_offset, len) ||
  21. !(name = addr_app_to_native(name_offset)) ||
  22. !(args_buf = addr_app_to_native(args_offset)))
  23. return -1;
  24. args = (attr_container_t *)args_buf;
  25. if (connection_impl._open != NULL)
  26. return connection_impl._open(module_inst, name, args);
  27. return -1;
  28. }
  29. void
  30. wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle)
  31. {
  32. if (connection_impl._close != NULL)
  33. connection_impl._close(handle);
  34. }
  35. int
  36. wasm_send_on_connection(wasm_exec_env_t exec_env,
  37. uint32 handle, int32 data_offset, uint32 len)
  38. {
  39. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  40. char *data;
  41. if (!validate_app_addr(data_offset, len) ||
  42. !(data = addr_app_to_native(data_offset)))
  43. return -1;
  44. if (connection_impl._send != NULL)
  45. return connection_impl._send(handle, data, len);
  46. return -1;
  47. }
  48. bool
  49. wasm_config_connection(wasm_exec_env_t exec_env,
  50. uint32 handle, int32 cfg_offset, uint32 len)
  51. {
  52. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  53. char *cfg_buf;
  54. attr_container_t *cfg;
  55. if (!validate_app_addr(cfg_offset, len) ||
  56. !(cfg_buf = addr_app_to_native(cfg_offset)))
  57. return false;
  58. cfg = (attr_container_t *)cfg_buf;
  59. if (connection_impl._config != NULL)
  60. return connection_impl._config(handle, cfg);
  61. return false;
  62. }