wasm_exec_env.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #include "wasm_exec_env.h"
  6. #include "bh_memory.h"
  7. #include "wasm_runtime_common.h"
  8. WASMExecEnv *
  9. wasm_exec_env_create(struct WASMModuleInstanceCommon *module_inst,
  10. uint32 stack_size)
  11. {
  12. uint64 total_size = offsetof(WASMExecEnv, wasm_stack.s.bottom)
  13. + (uint64)stack_size;
  14. WASMExecEnv *exec_env;
  15. if (total_size >= UINT32_MAX
  16. || !(exec_env = wasm_malloc((uint32)total_size)))
  17. return NULL;
  18. memset(exec_env, 0, (uint32)total_size);
  19. exec_env->module_inst = module_inst;
  20. exec_env->wasm_stack_size = stack_size;
  21. exec_env->wasm_stack.s.top_boundary =
  22. exec_env->wasm_stack.s.bottom + stack_size;
  23. exec_env->wasm_stack.s.top = exec_env->wasm_stack.s.bottom;
  24. return exec_env;
  25. }
  26. void
  27. wasm_exec_env_destroy(WASMExecEnv *exec_env)
  28. {
  29. wasm_free(exec_env);
  30. }
  31. WASMModuleInstanceCommon *
  32. wasm_exec_env_get_module_inst(WASMExecEnv *exec_env)
  33. {
  34. return exec_env->module_inst;
  35. }