Removes context parameter from instruction-scoped operations (#923)

We originally had a `context.Context` for anything that might be
traced, but it turned out to be only useful for lifecycle and host functions.

For instruction-scoped aspects like memory updates, a context parameter is too
fine-grained and also invisible in practice. For example, most users will use
the compiler engine, and its memory, global or table access will never use go's
context.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2022-12-14 16:08:07 +09:00
committed by GitHub
parent 0ed4002549
commit 126bd9050d
59 changed files with 526 additions and 578 deletions

View File

@@ -46,7 +46,7 @@ func allocationCall(m Module, _ int) error {
}
// The pointer is a linear memory offset, which is where we write the name.
if err = m.WriteMemory(testCtx, namePtr, []byte(allocationParam)); err != nil {
if err = m.WriteMemory(namePtr, []byte(allocationParam)); err != nil {
return err
}

View File

@@ -40,7 +40,7 @@ type Module interface {
CallI32_V(ctx context.Context, funcName string, param uint32) error
CallV_V(ctx context.Context, funcName string) error
CallI64_I64(ctx context.Context, funcName string, param uint64) (uint64, error)
WriteMemory(ctx context.Context, offset uint32, bytes []byte) error
WriteMemory(offset uint32, bytes []byte) error
Memory() []byte
Close(context.Context) error
}
@@ -79,10 +79,10 @@ func (m *wazeroModule) Memory() []byte {
return m.mod.Memory().(*wasm.MemoryInstance).Buffer
}
func (r *wazeroRuntime) log(ctx context.Context, mod api.Module, stack []uint64) {
func (r *wazeroRuntime) log(_ context.Context, mod api.Module, stack []uint64) {
offset, byteCount := uint32(stack[0]), uint32(stack[1])
buf, ok := mod.Memory().Read(ctx, offset, byteCount)
buf, ok := mod.Memory().Read(offset, byteCount)
if !ok {
panic("out of memory reading log buffer")
}
@@ -197,8 +197,8 @@ func (m *wazeroModule) CallI64_I64(ctx context.Context, funcName string, param u
return 0, nil
}
func (m *wazeroModule) WriteMemory(ctx context.Context, offset uint32, bytes []byte) error {
if !m.mod.Memory().Write(ctx, offset, bytes) {
func (m *wazeroModule) WriteMemory(offset uint32, bytes []byte) error {
if !m.mod.Memory().Write(offset, bytes) {
return errors.New("out of memory writing name")
}
return nil

View File

@@ -173,7 +173,7 @@ func (m *wasmedgeModule) CallI64_I64(_ context.Context, funcName string, param u
}
}
func (m *wasmedgeModule) WriteMemory(_ context.Context, offset uint32, bytes []byte) error {
func (m *wasmedgeModule) WriteMemory(offset uint32, bytes []byte) error {
mod := m.vm.GetActiveModule()
mem := mod.FindMemory("memory")
if unsafeSlice, err := mem.GetData(uint(offset), uint(len(bytes))); err != nil {

View File

@@ -185,7 +185,7 @@ func (m *wasmerModule) CallI64_I64(_ context.Context, funcName string, param uin
}
}
func (m *wasmerModule) WriteMemory(_ context.Context, offset uint32, bytes []byte) error {
func (m *wasmerModule) WriteMemory(offset uint32, bytes []byte) error {
unsafeSlice := m.mem.Data()
copy(unsafeSlice[offset:], bytes)
return nil

View File

@@ -187,7 +187,7 @@ func (m *wasmtimeModule) CallI64_I64(_ context.Context, funcName string, param u
}
}
func (m *wasmtimeModule) WriteMemory(_ context.Context, offset uint32, bytes []byte) error {
func (m *wasmtimeModule) WriteMemory(offset uint32, bytes []byte) error {
unsafeSlice := m.mem.UnsafeData(m.store)
copy(unsafeSlice[offset:], bytes)
return nil