Reputation: 51
I'm stuck on this when learing web assembly.
basically I have this index.ts
file written in assembly script
// The entry file of your WebAssembly module.
class Animal {
constructor() {}
name: i32;
age: i32;
}
export function newAnimal(): i32 {
let animal = new Animal();
animal.name = 1;
animal.age = 2;
return 1;
}
I compile with the following command
npx asc assembly/index.ts --target release --use abort=assembly/index/myAbort
However when i check the realease.wat
file it has some weird messages
(memory $0 1)
(data $0 (i32.const 12) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00(\00\00\00A\00l\00l\00o\00c\00a\00t\00i\00o\00n\00 \00t\00o\00o\00 \00l\00a\00r\00g\00e\00\00\00\00\00")
(data $1 (i32.const 76) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00 \00\00\00~\00l\00i\00b\00/\00r\00t\00/\00i\00t\00c\00m\00s\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data $2 (i32.const 144) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data $3 (i32.const 176) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data $4 (i32.const 204) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e\00\00\00\00\00\00\00\00\00")
(data $5 (i32.const 268) ",\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\14\00\00\00~\00l\00i\00b\00/\00r\00t\00.\00t\00s\00\00\00\00\00\00\00\00\00")
(data $6 (i32.const 320) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data $7 (i32.const 348) "<\00\00\00\00\00\00\00\00\00\00\00\02\00\00\00\1e\00\00\00~\00l\00i\00b\00/\00r\00t\00/\00t\00l\00s\00f\00.\00t\00s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00")
(data $8 (i32.const 416) "\06\00\00\00 \00\00\00 \00\00\00 \00\00\00\00\00\00\00 \00\00\00 \00\00\00")
I decode this Unicode message and got this error
<(Allocation too large< ~lib/rt/itcms.ts<$Index out of range,~lib/rt.ts@@<~lib/rt/tlsf.ts
I execute this using go-wasmtime and also got the same error
package main
import (
"encoding/json"
"fmt"
"net/http"
"C"
"github.com/bytecodealliance/wasmtime-go/v9"
)
func main() {
// Load the WebAssembly module from file
// Almost all operations in wasmtime require a contextual `store`
// argument to share, so create that first
engine := wasmtime.NewEngine()
store := wasmtime.NewStore(engine)
linker := wasmtime.NewLinker(engine)
vals := map[int32]int32{}
set := func(k, v int32) {
vals[k] = v
fmt.Printf("set: %d, %d\n", k, v)
}
get := func(k int32) int32 {
fmt.Printf("get: %d\n", k)
return vals[k]
}
linker.DefineFunc(store, "kv", "set", set)
linker.DefineFunc(store, "kv", "get", get)
module, err := wasmtime.NewModuleFromFile(engine, "./release.wasm")
check(err)
// Create the WASI instance
wasiConfig := wasmtime.NewWasiConfig()
store.SetWasi(wasiConfig)
check(err)
instance, err := linker.Instantiate(store, module)
check(err)
mem := instance.GetExport(store, "memory").Memory()
fmt.Printf("mem = %+v\n", mem)
ptr := mem.Data(store)
// Allocate memory
fmt.Printf("Go: wasm sandbox memory info: size %d, data size %d\n",
mem.Size(store),
mem.DataSize(store),
)
buf := mem.UnsafeData(store)
fmt.Printf("Go: wasm sandbox memory content: %s\n", string(buf))
}
func check(e error) {
if e != nil {
panic(e)
}
}
Output
mem = &{val:{store_id:1 index:0}}
Go: wasm sandbox memory info: size 512, data size 33554432
Go: wasm sandbox memory content: <(Allocation too large< ~lib/rt/itcms.ts<$Index out of range,~lib/rt.ts@@<~lib/rt/tlsf.ts
Thank you a lot if any one can give me instruction on how to resolve this issue.
Upvotes: 1
Views: 103