native_impl.c 857 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (C) 2023 Midokura Japan KK. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include <stddef.h>
  6. #include <stdio.h>
  7. #include "wasm_export.h"
  8. #include "my_context.h"
  9. void
  10. set_context(wasm_exec_env_t exec_env, int32_t n)
  11. {
  12. wasm_module_inst_t inst = wasm_runtime_get_module_inst(exec_env);
  13. printf("%s called on module inst %p\n", __func__, inst);
  14. struct my_context *ctx = &my_context;
  15. ctx->x = n;
  16. wasm_runtime_set_context_spread(inst, my_context_key, ctx);
  17. }
  18. int32_t
  19. get_context(wasm_exec_env_t exec_env)
  20. {
  21. wasm_module_inst_t inst = wasm_runtime_get_module_inst(exec_env);
  22. printf("%s called on module inst %p\n", __func__, inst);
  23. struct my_context *ctx = wasm_runtime_get_context(inst, my_context_key);
  24. if (ctx == NULL) {
  25. return -1;
  26. }
  27. return ctx->x;
  28. }