feat: Dynamically size runtime globals

master
Sean McBride 3 years ago
parent eb74a306ff
commit 54f36f8471

@ -1 +1 @@
Subproject commit 9732a7b02712e8c7b5e80daaf6493b372c5b43a9
Subproject commit 669c1889008f15fccaf4693708de847053489aa4

@ -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.

@ -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;

@ -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;
}

@ -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:

@ -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

Loading…
Cancel
Save