connection_wrapper.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "connection_native_api.h"
  9. /* Note:
  10. *
  11. * This file is the consumer of connection lib which is implemented by different platforms
  12. */
  13. uint32
  14. wasm_open_connection(wasm_exec_env_t exec_env,
  15. int32 name_offset, int32 args_offset, uint32 len)
  16. {
  17. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  18. attr_container_t *args;
  19. char *name, *args_buf;
  20. if (!validate_app_str_addr(name_offset) ||
  21. !validate_app_addr(args_offset, len) ||
  22. !(name = addr_app_to_native(name_offset)) ||
  23. !(args_buf = addr_app_to_native(args_offset)))
  24. return -1;
  25. args = (attr_container_t *)args_buf;
  26. if (connection_impl._open != NULL)
  27. return connection_impl._open(module_inst, name, args);
  28. return -1;
  29. }
  30. void
  31. wasm_close_connection(wasm_exec_env_t exec_env, uint32 handle)
  32. {
  33. if (connection_impl._close != NULL)
  34. connection_impl._close(handle);
  35. }
  36. int
  37. wasm_send_on_connection(wasm_exec_env_t exec_env,
  38. uint32 handle, int32 data_offset, uint32 len)
  39. {
  40. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  41. char *data;
  42. if (!validate_app_addr(data_offset, len) ||
  43. !(data = addr_app_to_native(data_offset)))
  44. return -1;
  45. if (connection_impl._send != NULL)
  46. return connection_impl._send(handle, data, len);
  47. return -1;
  48. }
  49. bool
  50. wasm_config_connection(wasm_exec_env_t exec_env,
  51. uint32 handle, int32 cfg_offset, uint32 len)
  52. {
  53. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  54. char *cfg_buf;
  55. attr_container_t *cfg;
  56. if (!validate_app_addr(cfg_offset, len) ||
  57. !(cfg_buf = addr_app_to_native(cfg_offset)))
  58. return false;
  59. cfg = (attr_container_t *)cfg_buf;
  60. if (connection_impl._config != NULL)
  61. return connection_impl._config(handle, cfg);
  62. return false;
  63. }