diff --git a/awsm b/awsm index 9732a7b..669c188 160000 --- a/awsm +++ b/awsm @@ -1 +1 @@ -Subproject commit 9732a7b02712e8c7b5e80daaf6493b372c5b43a9 +Subproject commit 669c1889008f15fccaf4693708de847053489aa4 diff --git a/libsledge/README.md b/libsledge/README.md index d40bdd7..2ea7857 100644 --- a/libsledge/README.md +++ b/libsledge/README.md @@ -144,6 +144,7 @@ The path to the JSON file is passed to `module_alloc_from_json`, which uses the `module.abi.entrypoint` -> `SLEDGE_ABI__ENTRYPOINT` -> `wasmf__start` `module.abi.starting_pages` -> `SLEDGE_ABI__STARTING_PAGES` -> `starting_pages` `module.abi.max_pages` -> `SLEDGE_ABI__MAX_PAGES` -> `max_pages` +`module.abi.globals_len` -> `SLEDGE_ABI__GLOBALS_LEN` -> `globals_len` `module init` then calls `module.abi.initialize_table`, which populates the indirect function table with the actual functions. This is performed once during module initialization because this table does not actually vary between instances of a module. diff --git a/libsledge/include/sledge_abi.h b/libsledge/include/sledge_abi.h index 11b16a0..45dc640 100644 --- a/libsledge/include/sledge_abi.h +++ b/libsledge/include/sledge_abi.h @@ -92,6 +92,9 @@ typedef uint32_t (*sledge_abi__wasm_memory_starting_pages_fn_t)(void); typedef uint32_t (*sledge_abi__wasm_memory_max_pages_fn_t)(void); #define SLEDGE_ABI__MAX_PAGES "sledge_abi__wasm_memory_max_pages" +typedef uint32_t (*sledge_abi__wasm_memory_globals_len_fn_t)(void); +#define SLEDGE_ABI__GLOBALS_LEN "sledge_abi__wasm_globals_len" + typedef uint32_t __wasi_clockid_t; typedef uint64_t __wasi_dircookie_t; typedef uint32_t __wasi_exitcode_t; diff --git a/libsledge/src/instantiation.c b/libsledge/src/instantiation.c index a79bc13..11c1354 100644 --- a/libsledge/src/instantiation.c +++ b/libsledge/src/instantiation.c @@ -20,6 +20,7 @@ extern void populate_table(void); extern int32_t wasmf__start(void); extern uint32_t starting_pages; extern uint32_t max_pages; +extern uint32_t globals_len; WEAK void populate_globals(){}; @@ -58,3 +59,9 @@ sledge_abi__wasm_memory_max_pages(void) { return max_pages; } + +EXPORT uint32_t +sledge_abi__wasm_globals_len(void) +{ + return globals_len; +} diff --git a/runtime/include/sledge_abi_symbols.h b/runtime/include/sledge_abi_symbols.h index 091ae17..4238697 100644 --- a/runtime/include/sledge_abi_symbols.h +++ b/runtime/include/sledge_abi_symbols.h @@ -16,6 +16,7 @@ struct sledge_abi_symbols { sledge_abi__entrypoint_fn_t entrypoint; uint32_t starting_pages; uint32_t max_pages; + uint32_t globals_len; }; /* Initializes the ABI object using the *.so file at path */ @@ -78,6 +79,14 @@ sledge_abi_symbols_init(struct sledge_abi_symbols *abi, char *path) } abi->max_pages = get_max_pages(); + sledge_abi__wasm_memory_globals_len_fn_t get_globals_len = dlsym(abi->handle, SLEDGE_ABI__GLOBALS_LEN); + if (get_max_pages == NULL) { + fprintf(stderr, "Failed to resolve symbol %s in %s with error: %s\n", SLEDGE_ABI__GLOBALS_LEN, path, + dlerror()); + goto dl_error; + } + abi->globals_len = get_globals_len(); + done: return rc; dl_error: diff --git a/runtime/src/sandbox.c b/runtime/src/sandbox.c index 3b41e74..b50dce6 100644 --- a/runtime/src/sandbox.c +++ b/runtime/src/sandbox.c @@ -59,7 +59,7 @@ sandbox_allocate_globals(struct sandbox *sandbox) assert(sandbox); assert(sandbox->module); - return wasm_globals_init(&sandbox->globals, 50); + return wasm_globals_init(&sandbox->globals, sandbox->module->abi.globals_len); } static inline void