Update Emscripten API layout; expose inner parts to to C API; add test

This commit is contained in:
Mark McCaskey
2019-12-16 15:45:28 -05:00
parent f1c95a81ab
commit e86b3941d0
10 changed files with 484 additions and 58 deletions

View File

@ -14,6 +14,7 @@
#endif
#endif
#define WASMER_EMSCRIPTEN_ENABLED
#endif // WASMER_H_MACROS
@ -61,6 +62,15 @@ struct wasmer_module_t {
};
struct wasmer_instance_t {
};
struct wasmer_byte_array {
const uint8_t *bytes;
uint32_t bytes_len;
};
#if defined(WASMER_EMSCRIPTEN_ENABLED)
/// Type used to construct an import_object_t with Emscripten imports.
struct wasmer_emscripten_globals_t {
@ -77,11 +87,6 @@ struct wasmer_export_descriptor_t {
};
struct wasmer_byte_array {
const uint8_t *bytes;
uint32_t bytes_len;
};
/// Opaque pointer to `NamedExportDescriptors`.
struct wasmer_export_descriptors_t {
@ -162,10 +167,6 @@ struct wasmer_import_object_iter_t {
};
struct wasmer_instance_t {
};
struct wasmer_instance_context_t {
};
@ -223,6 +224,21 @@ wasmer_result_t wasmer_compile(wasmer_module_t **module,
uint8_t *wasm_bytes,
uint32_t wasm_bytes_len);
#if defined(WASMER_EMSCRIPTEN_ENABLED)
/// Convenience function for setting up arguments and calling the Emscripten
/// main function.
///
/// WARNING:
///
/// Do not call this function on untrusted code when operating without
/// additional sandboxing in place.
/// Emscripten has access to many host system calls and therefore may do very
/// bad things.
wasmer_result_t wasmer_emscripten_call_main(wasmer_instance_t *instance,
const wasmer_byte_array *args,
unsigned int args_len);
#endif
#if defined(WASMER_EMSCRIPTEN_ENABLED)
/// Destroy `wasmer_emscrpten_globals_t` created by
/// `wasmer_emscripten_get_emscripten_globals`.
@ -233,6 +249,11 @@ void wasmer_emscripten_destroy_emscripten_globals(wasmer_emscripten_globals_t *g
/// Create a `wasmer_import_object_t` with Emscripten imports, use
/// `wasmer_emscripten_get_emscripten_globals` to get a
/// `wasmer_emscripten_globals_t` from a `wasmer_module_t`.
///
/// WARNING:
///1
/// This `import_object_t` contains thin-wrappers around host system calls.
/// Do not use this to execute untrusted code without additional sandboxing.
wasmer_import_object_t *wasmer_emscripten_generate_import_object(wasmer_emscripten_globals_t *globals);
#endif
@ -241,6 +262,16 @@ wasmer_import_object_t *wasmer_emscripten_generate_import_object(wasmer_emscript
wasmer_emscripten_globals_t *wasmer_emscripten_get_emscripten_globals(const wasmer_module_t *module);
#endif
#if defined(WASMER_EMSCRIPTEN_ENABLED)
/// Execute global constructors (required if the module is compiled from C++)
/// and sets up the internal environment.
///
/// This function sets the data pointer in the same way that
/// [`wasmer_instance_context_data_set`] does.
wasmer_result_t wasmer_emscripten_set_up_emscripten(wasmer_instance_t *instance,
wasmer_emscripten_globals_t *globals);
#endif
/// Gets export descriptor kind
wasmer_import_export_kind wasmer_export_descriptor_kind(wasmer_export_descriptor_t *export_);