wasmerio / wasmer-go

🐹🕸️ WebAssembly runtime for Go
https://pkg.go.dev/github.com/wasmerio/wasmer-go
MIT License
2.84k stars 161 forks source link

Access non-exported memory from guest module #361

Closed MlennGarien closed 2 years ago

MlennGarien commented 2 years ago

Summary

Let's say we have a module with the following definition:

(module (import "env" "require_auth" (func $env.require_auth (type $t1))) (import "env" "eosio_assert" (func $env.eosio_assert (type $t2))) (import "env" "db_find_i64" (func $env.db_find_i64 (type $t3))) (import "env" "current_receiver" (func $env.current_receiver (type $t4))) (import "env" "abort" (func $env.abort (type $t0))) (import "env" "memset" (func $env.memset (type $t5))) (import "env" "db_update_i64" (func $env.db_update_i64 (type $t6))) (import "env" "memcpy" (func $env.memcpy (type $t5))) (import "env" "db_store_i64" (func $env.db_store_i64 (type $t7))) (import "env" "is_account" (func $env.is_account (type $t8))) (import "env" "require_recipient" (func $env.require_recipient (type $t1))) (import "env" "has_auth" (func $env.has_auth (type $t8))) (import "env" "db_next_i64" (func $env.db_next_i64 (type $t9))) (import "env" "action_data_size" (func $env.action_data_size (type $t10))) (import "env" "read_action_data" (func $env.read_action_data (type $t9))) (import "env" "memmove" (func $env.memmove (type $t5))) ... omitted (table $T0 1 1 funcref) (memory $M0 1) (global $g0 (mut i32) (i32.const 8192)) (global $g1 i32 (i32.const 9610)) (global $g2 i32 (i32.const 9610)) (data $d0 (i32.const 8220) "failed to allocate pages\00invalid symbol name\00") (data $d1 (i32.const 8265) "invalid supply\00") (data $d2 (i32.const 8280) "token with symbol already exists\00")

As seen in the example above the memory isn't exported making it impossible to use instance.Exports.GetMemory as far as I could tell. How would I get access to the memory of this module to handle memory specific operations? I'm trying to provide the memcpy and memmove imported functions but would need access to the guest's memory to perform these operations.

There used to be a instance.Memory field but that's been removed?