Disallow direct call of host functions (#723)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/tetratelabs/wazero"
|
||||
"github.com/tetratelabs/wazero/api"
|
||||
)
|
||||
|
||||
// addWasm was generated by the following:
|
||||
@@ -34,28 +33,17 @@ func main() {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Add a module to the runtime named "host/math" which exports one function "add", implemented in Go.
|
||||
host, err := r.NewModuleBuilder("host/math").
|
||||
ExportFunction("add", func(v1, v2 uint32) uint32 {
|
||||
return v1 + v2
|
||||
}).Instantiate(ctx, r)
|
||||
// Read two args to add.
|
||||
x, y := readTwoArgs()
|
||||
|
||||
// Call the `add` function in the module and print the results to the console.
|
||||
add := wasm.ExportedFunction("add")
|
||||
results, err := add.Call(ctx, x, y)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Read two args to add.
|
||||
x, y := readTwoArgs()
|
||||
|
||||
// Call the same function in both modules and print the results to the console.
|
||||
for _, mod := range []api.Module{wasm, host} {
|
||||
add := mod.ExportedFunction("add")
|
||||
results, err := add.Call(ctx, x, y)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s: %d + %d = %d\n", mod.Name(), x, y, results[0])
|
||||
}
|
||||
fmt.Printf("%s: %d + %d = %d\n", wasm.Name(), x, y, results[0])
|
||||
}
|
||||
|
||||
func readTwoArgs() (uint64, uint64) {
|
||||
|
||||
Reference in New Issue
Block a user