test_module_malloc.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 <stdio.h>
  6. #include <stdlib.h>
  7. #include "wasm_export.h"
  8. static uint32_t
  9. test_module_malloc_wrapper(wasm_exec_env_t exec_env, uint32_t buf_size)
  10. {
  11. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  12. return wasm_runtime_module_malloc(module_inst, buf_size, NULL);
  13. }
  14. static void
  15. test_module_free_wrapper(wasm_exec_env_t exec_env, uint32_t ptr)
  16. {
  17. wasm_module_inst_t module_inst = get_module_inst(exec_env);
  18. wasm_runtime_module_free(module_inst, ptr);
  19. }
  20. /* clang-format off */
  21. #define REG_NATIVE_FUNC(func_name, signature) \
  22. { #func_name, func_name##_wrapper, signature, NULL }
  23. static NativeSymbol native_symbols[] = {
  24. REG_NATIVE_FUNC(test_module_malloc, "(i)i"),
  25. REG_NATIVE_FUNC(test_module_free, "(i)")
  26. };
  27. /* clang-format on */
  28. uint32_t
  29. get_native_lib(char **p_module_name, NativeSymbol **p_native_symbols)
  30. {
  31. *p_module_name = "env";
  32. *p_native_symbols = native_symbols;
  33. return sizeof(native_symbols) / sizeof(NativeSymbol);
  34. }