It worked! Thanks a million :)

Here is the patch:
diff --git a/include/v8.h b/include/v8.h
index 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.cc
index 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.h
index 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,

Now I can do the following in the host:
    /* 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);

And from within the module I can issue a load and retrieve a value from the 
array. I yet have to experiment with overflows or grows...

As I already said, I want to work with really large allocations, maybe tens 
or hundreds of gigabytes.  Because WebAssembly currently only has 2GiB 
address space, I need some mechanism to feed the host allocations to the 
WASM module in chunks. I think of installing a callback from the WASM 
module to the host, via a WASM module import, that allows the WASM module 
to signal to the host, that the current chunk was processed and the next 
chunk is requested. So roughly every 2GiB of processed data, the WASM 
module issues a callback to the host. When that callback returns, the 
module can assume the next chunk is mapped into the linear memory and 
proceed.
Does this sound like a good approach? Any concerns here (regarding 
correctness or performance)?

-- 
-- 
v8-dev mailing list
[email protected]
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-dev/edc41107-3a61-4e1d-99de-56b95084183c%40googlegroups.com.

Reply via email to