/* Create WASM module. */ auto v8_wasm_module = v8::WasmModuleObject::DeserializeOrCompile(
/* isolate= */ isolate_, /* serialized_module= */ { nullptr, 0 }, /* wire_bytes= */ v8::MemorySpan<const uint8_t>(binary_addr, binary_size) ).ToLocalChecked();
/* Get the WebAssembly instance class prototype. */ auto web_assembly_class = context->Global()->Get(context, V8STR("WebAssembly")).ToLocalChecked().As<v8::Object>();
/* Create a WebAssembly memory object. */ auto wasm_memory_class = web_assembly_class->Get(context, V8STR("Memory")).ToLocalChecked().As<v8::Object>(); auto memory_params_object = v8::Object::New(isolate_); memory_params_object->Set(context, V8STR("initial"), v8::Int32::New(isolate_, 1)); memory_params_object->Set(context, V8STR("maximum"), v8::Int32::New(isolate_, 256)); v8::Local<v8::Value> memory_args[] = { memory_params_object }; auto wasm_memory = wasm_memory_class->CallAsConstructor(context, 1, memory_args).ToLocalChecked().As<v8::Object>();
/* Allocate and initialize host memory. */ auto host_memory = new int32_t[1024]; for (int32_t i = 0; i != 1024; ++i) host_memory[i] = i; auto store = v8::ArrayBuffer::NewBackingStore(host_memory, 1024 * sizeof(int32_t), [](void* data, size_t, void*) { delete[] reinterpret_cast<int32_t*>(data); }, nullptr); auto buffer = v8::ArrayBuffer::New(isolate_, std::move(store));
/* Replace the WebAssembly.Memory's underlying ArrayBuffer. FIXME: Not working as intended! */ wasm_memory->Set(context, V8STR("buffer"), buffer);
/* Create the import object for instantiating the WebAssembly module. */ auto host_object = v8::Object::New(isolate_); host_object->Set(context, V8STR("mem"), wasm_memory); auto import_object = v8::Object::New(isolate_); import_object->Set(context, V8STR("env"), host_object);
/* Create the import object for instantiating the WebAssembly module. */ auto host_object = v8::Object::New(isolate_); host_object->Set(context, V8STR("mem"), wasm_memory); auto import_object = v8::Object::New(isolate_); import_object->Set(context, V8STR("env"), host_object);
/* Get the exports of the created WebAssembly instance. */ auto exports = instance->Get(context, V8STR("exports")).ToLocalChecked().As<v8::Object>();
/* Get exported function `run` from the exports. */ auto run = exports->Get(context, V8STR("run")).ToLocalChecked().As<v8::Function>();
/* Invoke the exported function `run` of the module. */ v8::Local<v8::Value> args[] = { }; auto result = run->Call(context, context->Global(), 0, args).ToLocalChecked().As<v8::Object>();
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/f2ddf715-f8a6-47a8-b872-f77312b0e4c5%40googlegroups.com.
Clemens Backes
Software Engineer
Google Germany GmbH
Erika-Mann-Straße 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.
This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.
Clemens Backes
Software Engineer
Google Germany GmbH
Erika-Mann-Straße 33
80636 München
Geschäftsführer: Paul Manicle, Halimah DeLaine Prado
Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.
This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.
Thanks for your answer. I already had that thought. But copying data is just not an option.
To make my scenario more concrete:
I habe data in main memory, easily tens or hundreds of gigabytes. Programs fly in requiring to access the data. Some programs are short-lived, some will take a long time to compute. Some programs are executed only one, some are executed repeatedly. So I will have to JIT compile many programs to WASM modules. Copying the data into the memory of each module would totally kill performance.
Another idea that comes to my mind is to create a single WASM memory object and implement a designated allocator to allocate memory for host objects in that WASM memory. Then I could import this memory object into the modules... Would that be possible? How would the guard pages affect this approach? (I am thinking of jemalloc on WASM memory.)
I understand that the problem I am proposing is somewhat in contradiction with the WebAssembly idea of sandboxed modules. Anyways, I believe solving this would make WebAssembly make an attractive choice for JIT compiling general purpose languages.
Regards,
Immanuel
Hi Clemens,
Thanks for your answer. I already had that thought. But copying data is just not an option.
To make my scenario more concrete:
I habe data in main memory, easily tens or hundreds of gigabytes. Programs fly in requiring to access the data. Some programs are short-lived, some will take a long time to compute. Some programs are executed only one, some are executed repeatedly. So I will have to JIT compile many programs to WASM modules. Copying the data into the memory of each module would totally kill performance.
Another idea that comes to my mind is to create a single WASM memory object and implement a designated allocator to allocate memory for host objects in that WASM memory. Then I could import this memory object into the modules... Would that be possible? How would the guard pages affect this approach? (I am thinking of jemalloc on WASM memory.)
I understand that the problem I am proposing is somewhat in contradiction with the WebAssembly idea of sandboxed modules. Anyways, I believe solving this would make WebAssembly make an attractive choice for JIT compiling general purpose languages.
Regards,
Immanuel
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/2bfba5a2-91d1-400f-a3e6-89e152a238de%40googlegroups.com.
What I am working on is (a) a research project and (b) the programs are all trust-worthy and harmless.Patching V8 sounds like an option. I would highly appreciate some guidance where to start. I am only superficially familiar with the public API yet.
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/ea1acd82-6dda-4d56-b2c5-5e7ef0288583%40googlegroups.com.
@Clements Regarding point 2, WasmInstanceObject::SetRawMemory() seems to to exactly what I want, right? How can I access this, given a v8::Object of a WebAssembly.Instance ?
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/f723d8b5-d126-4b00-82f0-5ab0176703e3%40googlegroups.com.
diff --git a/include/v8.h b/include/v8.hindex 199fc6ae09..01bc30b031 100644--- a/include/v8.h+++ b/include/v8.h@@ -11776,6 +11776,7 @@ size_t SnapshotCreator::AddData(Local<T> object) { * \example process.cc */ +void SetWasmInstanceRawMemory(Local<Object> wasmInstance, uint8_t *mem_start, size_t mem_size); } // namespace v8 diff --git a/src/api/api.cc b/src/api/api.ccindex ffc89d7dc8..795cc110b8 100644--- a/src/api/api.cc+++ b/src/api/api.cc@@ -340,6 +340,11 @@ class CallDepthScope { } // namespace +void SetWasmInstanceRawMemory(Local<Object> wasmInstance, uint8_t *mem_start, size_t mem_size) {+ i::Handle<i::Object> obj = Utils::OpenHandle(*wasmInstance);+ i::WasmInstanceObject::cast(*obj).SetRawMemory(mem_start, mem_size);+}+ static ScriptOrigin GetScriptOriginForScript(i::Isolate* isolate, i::Handle<i::Script> script) { i::Handle<i::Object> scriptName(script->GetNameOrSourceURL(), isolate);diff --git a/src/flags/flag-definitions.h b/src/flags/flag-definitions.hindex 2b68204af5..e10a583f63 100644--- a/src/flags/flag-definitions.h+++ b/src/flags/flag-definitions.h@@ -746,7 +746,7 @@ DEFINE_BOOL(wasm_no_stack_checks, false, DEFINE_BOOL(wasm_math_intrinsics, true, "intrinsify some Math imports into wasm") -DEFINE_BOOL(wasm_trap_handler, true,+DEFINE_BOOL(wasm_trap_handler, false, "use signal handlers to catch out of bounds memory access in wasm" " (currently Linux x86_64 only)") DEFINE_BOOL(wasm_fuzzer_gen_test, false,
/* Create host memory. */
auto host_memory = new int32_t[1024]; for (int32_t i = 0; i != 1024; ++i) host_memory[i] = i;
v8::SetWasmInstanceRawMemory(instance, reinterpret_cast<uint8_t*>(host_memory), 4096);
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/edc41107-3a61-4e1d-99de-56b95084183c%40googlegroups.com.