Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/Khan/fastlike

go 1.14

require github.com/bytecodealliance/wasmtime-go v0.26.1
require github.com/bytecodealliance/wasmtime-go v0.29.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
github.com/bytecodealliance/wasmtime-go v0.26.1 h1:xDzNH+Iq5o4N27pmsvB8cY35feN3H4d3bS7RjddBPWQ=
github.com/bytecodealliance/wasmtime-go v0.26.1/go.mod h1:q320gUxqyI8yB+ZqRuaJOEnGkAnHh6WtJjMaT2CW4wI=
github.com/bytecodealliance/wasmtime-go v0.29.0 h1:NEME96y0YKAUjOkTw5/2w1OZ9TLy9FJ+Q7SWW4L/X0o=
github.com/bytecodealliance/wasmtime-go v0.29.0/go.mod h1:q320gUxqyI8yB+ZqRuaJOEnGkAnHh6WtJjMaT2CW4wI=
11 changes: 7 additions & 4 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,16 @@ func (i *Instance) reset() {

func (i *Instance) setup() {
var err error
i.wasm, err = i.wasmctx.linker.Instantiate(i.wasmctx.module)
i.wasm, err = i.wasmctx.linker.Instantiate(i.wasmctx.store, i.wasmctx.module)
check(err)

i.interrupt, err = i.wasmctx.store.InterruptHandle()
check(err)

i.memory = &Memory{&wasmMemory{mem: i.wasm.GetExport("memory").Memory()}}
i.memory = &Memory{&wasmMemory{
store: i.wasmctx.store,
mem: i.wasm.GetExport(i.wasmctx.store, "memory").Memory(),
}}
}

// ServeHTTP serves the supplied request and response pair. This is not safe to call twice.
Expand Down Expand Up @@ -187,8 +190,8 @@ func (i *Instance) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// The entrypoint for a fastly compute program takes no arguments and returns nothing or an
// error. The program itself is responsible for getting a handle on the downstream request
// and sending a response downstream.
entry := i.wasm.GetExport("_start").Func()
_, err := entry.Call()
entry := i.wasm.GetExport(i.wasmctx.store, "_start").Func()
_, err := entry.Call(i.wasmctx.store)
donech <- struct{}{}
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
9 changes: 5 additions & 4 deletions memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (m ByteMemory) Cap() int {

// wasmMemory is a MemorySlice implementation that wraps a wasmtime.Memory
type wasmMemory struct {
store wasmtime.Storelike
mem *wasmtime.Memory
slice []byte
}
Expand All @@ -52,11 +53,11 @@ func (m *wasmMemory) Cap() int {
func (m *wasmMemory) Data() []byte {
// If we have a pre-built slice and that slice capacity is the same as the current data size,
// return it. Otherwise, rebuild the slice.
if m.slice != nil && cap(m.slice) == int(m.mem.DataSize()) {
if m.slice != nil && cap(m.slice) == int(m.mem.DataSize(m.store)) {
return m.slice
}

m.slice = m.mem.UnsafeData()
m.slice = m.mem.UnsafeData(m.store)
return m.slice
}

Expand Down Expand Up @@ -94,13 +95,13 @@ func (m *Memory) PutUint32(v uint32, offset int64) {
}

func (m *Memory) PutInt32(v int32, offset int64) {
var b = new(bytes.Buffer)
b := new(bytes.Buffer)
binary.Write(b, binary.LittleEndian, v)
m.WriteAt(b.Bytes(), offset)
}

func (m *Memory) PutInt64(v int64, offset int64) {
var b = new(bytes.Buffer)
b := new(bytes.Buffer)
binary.Write(b, binary.LittleEndian, v)
m.WriteAt(b.Bytes(), offset)
}
Expand Down
Loading