mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-07-11 15:03:33 +00:00
Compare commits
3 Commits
35ab0c3069
...
f25b42da3d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f25b42da3d | ||
![]() |
392482c875 | ||
![]() |
12f923db46 |
|
@ -1654,14 +1654,70 @@ wasm_runtime_instantiate(WASMModuleCommon *module, uint32 stack_size,
|
||||||
error_buf_size);
|
error_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
instantiation_args_set_defaults(struct InstantiationArgs2 *args)
|
||||||
|
{
|
||||||
|
memset(args, 0, sizeof(*args));
|
||||||
|
}
|
||||||
|
|
||||||
WASMModuleInstanceCommon *
|
WASMModuleInstanceCommon *
|
||||||
wasm_runtime_instantiate_ex(WASMModuleCommon *module,
|
wasm_runtime_instantiate_ex(WASMModuleCommon *module,
|
||||||
const InstantiationArgs *args, char *error_buf,
|
const InstantiationArgs *args, char *error_buf,
|
||||||
uint32 error_buf_size)
|
uint32 error_buf_size)
|
||||||
|
{
|
||||||
|
struct InstantiationArgs2 v2;
|
||||||
|
instantiation_args_set_defaults(&v2);
|
||||||
|
v2.v1 = *args;
|
||||||
|
return wasm_runtime_instantiate_ex2(module, &v2, error_buf, error_buf_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p)
|
||||||
|
{
|
||||||
|
struct InstantiationArgs2 *args = wasm_runtime_malloc(sizeof(*args));
|
||||||
|
if (args == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
instantiation_args_set_defaults(args);
|
||||||
|
*p = args;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p)
|
||||||
|
{
|
||||||
|
wasm_runtime_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_default_stack_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v)
|
||||||
|
{
|
||||||
|
p->v1.default_stack_size = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_host_managed_heap_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v)
|
||||||
|
{
|
||||||
|
p->v1.host_managed_heap_size = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_max_memory_pages(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v)
|
||||||
|
{
|
||||||
|
p->v1.max_memory_pages = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
WASMModuleInstanceCommon *
|
||||||
|
wasm_runtime_instantiate_ex2(WASMModuleCommon *module,
|
||||||
|
const struct InstantiationArgs2 *args,
|
||||||
|
char *error_buf, uint32 error_buf_size)
|
||||||
{
|
{
|
||||||
return wasm_runtime_instantiate_internal(
|
return wasm_runtime_instantiate_internal(
|
||||||
module, NULL, NULL, args->default_stack_size,
|
module, NULL, NULL, args->v1.default_stack_size,
|
||||||
args->host_managed_heap_size, args->max_memory_pages, error_buf,
|
args->v1.host_managed_heap_size, args->v1.max_memory_pages, error_buf,
|
||||||
error_buf_size);
|
error_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -612,6 +612,10 @@ WASMExecEnv *
|
||||||
wasm_runtime_get_exec_env_tls(void);
|
wasm_runtime_get_exec_env_tls(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
struct InstantiationArgs2 {
|
||||||
|
InstantiationArgs v1;
|
||||||
|
};
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
WASM_RUNTIME_API_EXTERN bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_init(void);
|
wasm_runtime_init(void);
|
||||||
|
@ -700,6 +704,40 @@ wasm_runtime_instantiate_ex(WASMModuleCommon *module,
|
||||||
const InstantiationArgs *args, char *error_buf,
|
const InstantiationArgs *args, char *error_buf,
|
||||||
uint32 error_buf_size);
|
uint32 error_buf_size);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN
|
||||||
|
bool
|
||||||
|
wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_default_stack_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_host_managed_heap_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN
|
||||||
|
void
|
||||||
|
wasm_runtime_instantiation_args_set_max_memory_pages(
|
||||||
|
struct InstantiationArgs2 *p, uint32 v);
|
||||||
|
|
||||||
|
/* See wasm_export.h for description */
|
||||||
|
WASM_RUNTIME_API_EXTERN WASMModuleInstanceCommon *
|
||||||
|
wasm_runtime_instantiate_ex2(WASMModuleCommon *module,
|
||||||
|
const struct InstantiationArgs2 *args,
|
||||||
|
char *error_buf, uint32 error_buf_size);
|
||||||
|
|
||||||
/* See wasm_export.h for description */
|
/* See wasm_export.h for description */
|
||||||
WASM_RUNTIME_API_EXTERN bool
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
|
wasm_runtime_set_running_mode(wasm_module_inst_t module_inst,
|
||||||
|
|
|
@ -289,6 +289,8 @@ typedef struct InstantiationArgs {
|
||||||
} InstantiationArgs;
|
} InstantiationArgs;
|
||||||
#endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
|
#endif /* INSTANTIATION_ARGS_OPTION_DEFINED */
|
||||||
|
|
||||||
|
struct InstantiationArgs2;
|
||||||
|
|
||||||
#ifndef WASM_VALKIND_T_DEFINED
|
#ifndef WASM_VALKIND_T_DEFINED
|
||||||
#define WASM_VALKIND_T_DEFINED
|
#define WASM_VALKIND_T_DEFINED
|
||||||
typedef uint8_t wasm_valkind_t;
|
typedef uint8_t wasm_valkind_t;
|
||||||
|
@ -733,6 +735,46 @@ wasm_runtime_instantiate_ex(const wasm_module_t module,
|
||||||
const InstantiationArgs *args, char *error_buf,
|
const InstantiationArgs *args, char *error_buf,
|
||||||
uint32_t error_buf_size);
|
uint32_t error_buf_size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an InstantiationArgs2 object with default parameters.
|
||||||
|
*
|
||||||
|
* @return true if success, false otherwise
|
||||||
|
*/
|
||||||
|
WASM_RUNTIME_API_EXTERN bool
|
||||||
|
wasm_runtime_instantiation_args_create(struct InstantiationArgs2 **p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispose an InstantiationArgs2 object.
|
||||||
|
*/
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_instantiation_args_destroy(struct InstantiationArgs2 *p);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter functions for the InstantiationArgs2 object.
|
||||||
|
*/
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_instantiation_args_set_default_stack_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32_t v);
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_instantiation_args_set_host_managed_heap_size(
|
||||||
|
struct InstantiationArgs2 *p, uint32_t v);
|
||||||
|
|
||||||
|
WASM_RUNTIME_API_EXTERN void
|
||||||
|
wasm_runtime_instantiation_args_set_max_memory_pages(
|
||||||
|
struct InstantiationArgs2 *p, uint32_t v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a WASM module, with specified instantiation arguments
|
||||||
|
*
|
||||||
|
* Same as wasm_runtime_instantiate_ex, but this version takes
|
||||||
|
* InstantiationArgs2, which can be extended without breaking the ABI.
|
||||||
|
*/
|
||||||
|
WASM_RUNTIME_API_EXTERN wasm_module_inst_t
|
||||||
|
wasm_runtime_instantiate_ex2(const wasm_module_t module,
|
||||||
|
const struct InstantiationArgs2 *args,
|
||||||
|
char *error_buf, uint32_t error_buf_size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the running mode of a WASM module instance, override the
|
* Set the running mode of a WASM module instance, override the
|
||||||
* default running mode of the runtime. Note that it only makes sense when
|
* default running mode of the runtime. Note that it only makes sense when
|
||||||
|
|
|
@ -596,6 +596,7 @@ main(int argc, char *argv[])
|
||||||
wasm_module_inst_t wasm_module_inst = NULL;
|
wasm_module_inst_t wasm_module_inst = NULL;
|
||||||
RunningMode running_mode = 0;
|
RunningMode running_mode = 0;
|
||||||
RuntimeInitArgs init_args;
|
RuntimeInitArgs init_args;
|
||||||
|
struct InstantiationArgs2 *inst_args;
|
||||||
char error_buf[128] = { 0 };
|
char error_buf[128] = { 0 };
|
||||||
#if WASM_ENABLE_LOG != 0
|
#if WASM_ENABLE_LOG != 0
|
||||||
int log_verbose_level = 2;
|
int log_verbose_level = 2;
|
||||||
|
@ -949,10 +950,20 @@ main(int argc, char *argv[])
|
||||||
libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx);
|
libc_wasi_init(wasm_module, argc, argv, &wasi_parse_ctx);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!wasm_runtime_instantiation_args_create(&inst_args)) {
|
||||||
|
printf("failed to create instantiate args\n");
|
||||||
|
goto fail3;
|
||||||
|
}
|
||||||
|
wasm_runtime_instantiation_args_set_default_stack_size(inst_args,
|
||||||
|
stack_size);
|
||||||
|
wasm_runtime_instantiation_args_set_host_managed_heap_size(inst_args,
|
||||||
|
heap_size);
|
||||||
|
|
||||||
/* instantiate the module */
|
/* instantiate the module */
|
||||||
if (!(wasm_module_inst =
|
wasm_module_inst = wasm_runtime_instantiate_ex2(
|
||||||
wasm_runtime_instantiate(wasm_module, stack_size, heap_size,
|
wasm_module, inst_args, error_buf, sizeof(error_buf));
|
||||||
error_buf, sizeof(error_buf)))) {
|
wasm_runtime_instantiation_args_destroy(inst_args);
|
||||||
|
if (!wasm_module_inst) {
|
||||||
printf("%s\n", error_buf);
|
printf("%s\n", error_buf);
|
||||||
goto fail3;
|
goto fail3;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user