diff options
author | Rodrigo Kumpera <kumpera@users.noreply.github.com> | 2018-09-18 01:42:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-18 01:42:31 +0300 |
commit | 2646cf41df8404b94c5c8f58be1ec83220808684 (patch) | |
tree | 65cdb93687240056111b516dc282a0169d835445 /sdks | |
parent | d00adcc077e2fe8563a3d05f1fbaf2b0de922431 (diff) | |
parent | 3b18995587c215a1584bdf2994ce95769788eaf6 (diff) |
Merge pull request #10624 from kumpera/dont-mmap-for-assemblies
[wasm] Switch to mkbundle style mono_register_bundled_assemblies instead of relying on emcc filesystem emulation. Fixes #10603.
Diffstat (limited to 'sdks')
-rw-r--r-- | sdks/wasm/driver.c | 43 | ||||
-rw-r--r-- | sdks/wasm/library_mono.js | 7 |
2 files changed, 49 insertions, 1 deletions
diff --git a/sdks/wasm/driver.c b/sdks/wasm/driver.c index 956eb7b3faf..5467b04f438 100644 --- a/sdks/wasm/driver.c +++ b/sdks/wasm/driver.c @@ -162,6 +162,14 @@ int mono_array_length (MonoArray *array); int mono_array_element_size(MonoClass *klass); void mono_gc_wbarrier_set_arrayref (MonoArray *arr, void* slot_ptr, MonoObject* value); +typedef struct { + const char *name; + const unsigned char *data; + unsigned int size; +} MonoBundledAssembly; + +void mono_register_bundled_assemblies (const MonoBundledAssembly **assemblies); + static char* m_strdup (const char *str) { @@ -216,6 +224,28 @@ mono_wasm_invoke_js (MonoString *str, int *is_exception) #include "driver-gen.c" #endif +typedef struct WasmAssembly_ WasmAssembly; + +struct WasmAssembly_ { + MonoBundledAssembly assembly; + WasmAssembly *next; +}; + +static WasmAssembly *assemblies; +static int assembly_count; + +EMSCRIPTEN_KEEPALIVE void +mono_wasm_add_assembly (const char *name, const unsigned char *data, unsigned int size) +{ + WasmAssembly *entry = (WasmAssembly *)malloc(sizeof (MonoBundledAssembly)); + entry->assembly.name = m_strdup (name); + entry->assembly.data = data; + entry->assembly.size = size; + entry->next = assemblies; + assemblies = entry; + ++assembly_count; +} + EMSCRIPTEN_KEEPALIVE void mono_wasm_load_runtime (const char *managed_path, int enable_debugging) { @@ -240,6 +270,19 @@ mono_wasm_load_runtime (const char *managed_path, int enable_debugging) #endif mono_icall_table_init (); + if (assembly_count) { + MonoBundledAssembly **bundle_array = (MonoBundledAssembly **)calloc (1, sizeof (MonoBundledAssembly*) * (assembly_count + 1)); + WasmAssembly *cur = assemblies; + bundle_array [assembly_count] = NULL; + int i = 0; + while (cur) { + bundle_array [i] = &cur->assembly; + cur = cur->next; + ++i; + } + mono_register_bundled_assemblies ((const MonoBundledAssembly**)bundle_array); + } + mono_set_assemblies_path (m_strdup (managed_path)); root_domain = mono_jit_init_version ("mono", "v4.0.30319"); diff --git a/sdks/wasm/library_mono.js b/sdks/wasm/library_mono.js index 628cbbfa33f..4ec0dbeeb8f 100644 --- a/sdks/wasm/library_mono.js +++ b/sdks/wasm/library_mono.js @@ -84,6 +84,7 @@ var MonoSupportLib = { var pending = file_list.length; var loaded_files = []; + var mono_wasm_add_assembly = Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']); file_list.forEach (function(file_name) { var fetch_promise = null; if (fetch_file_cb) @@ -98,7 +99,11 @@ var MonoSupportLib = { return response ['arrayBuffer'] (); }).then (function (blob) { var asm = new Uint8Array (blob); - Module.FS_createDataFile (vfs_prefix + "/" + file_name, null, asm, true, true, true); + var memory = Module._malloc(asm.length); + var heapBytes = new Uint8Array(Module.HEAPU8.buffer, memory, asm.length); + heapBytes.set (asm); + mono_wasm_add_assembly (file_name, memory, asm.length); + console.log ("Loaded: " + file_name); --pending; if (pending == 0) { |