提交 3bce782a 编写于 作者: chai2010's avatar chai2010

Revert "升级 wazero-1.0.1, 感谢 @codefromthecrypt 的补丁"

This reverts commit fa5f7bb9.
上级 325bb934
......@@ -5,6 +5,6 @@ module wa-lang.org/wa
go 1.17
require (
github.com/tetratelabs/wazero v1.0.1
github.com/tetratelabs/wazero v1.0.0-pre.4
wa-lang.org/wabt-go v1.2.3
)
......@@ -63,10 +63,10 @@ func ArduinoInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, err
Export("getPinLED").
NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module, ptr, len uint32) {
bytes, _ := m.Memory().Read(ptr, len)
bytes, _ := m.Memory().Read(ctx, ptr, len)
fmt.Printf("arduino.print(%q)\n", string(bytes))
}).
WithParameterNames("ptr", "len").
Export("print").
Instantiate(ctx)
Instantiate(ctx, rt)
}
......@@ -11,5 +11,5 @@ import (
)
func ChromeInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error) {
return rt.NewHostModuleBuilder(config.WaOS_chrome).Instantiate(ctx)
return rt.NewHostModuleBuilder(config.WaOS_chrome).Instantiate(ctx, rt)
}
......@@ -29,7 +29,7 @@ func WasiInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error)
// ----
NewFunctionBuilder().
WithFunc(func(ctx context.Context, m api.Module, pos, len uint32) {
bytes, _ := m.Memory().Read(pos, len)
bytes, _ := m.Memory().Read(ctx, pos, len)
fmt.Print(string(bytes))
}).
WithParameterNames("pos", "len").
......@@ -46,58 +46,44 @@ func WasiInstantiate(ctx context.Context, rt wazero.Runtime) (api.Closer, error)
}).
WithParameterNames("ch").
Export("waPrintRune").
Instantiate(ctx)
Instantiate(ctx, rt)
}
// errno is neither uint16 nor an alias for parity with wasm.ValueType.
type errno = uint32
const (
// ErrnoSuccess No error occurred. System call completed successfully.
errnoSuccess errno = 0
// errnoFault Bad address.
errnoFault errno = 21
// errnoIo I/O error.
errnoIo errno = 29
)
func wasi_fdWriteFn(ctx context.Context, mod api.Module, fd, iovs, iovsCount, resultSize uint32) errno {
func wasi_fdWriteFn(ctx context.Context, mod api.Module, fd, iovs, iovsCount, resultSize uint32) wasi.Errno {
var err error
var nwritten uint32
var writer = os.Stdout
for i := uint32(0); i < iovsCount; i++ {
iov := iovs + i*8
offset, ok := mod.Memory().ReadUint32Le(iov)
offset, ok := mod.Memory().ReadUint32Le(ctx, iov)
if !ok {
return errnoFault
return wasi.ErrnoFault
}
// Note: emscripten has been known to write zero length iovec. However,
// it is not common in other compilers, so we don't optimize for it.
l, ok := mod.Memory().ReadUint32Le(iov + 4)
l, ok := mod.Memory().ReadUint32Le(ctx, iov+4)
if !ok {
return errnoFault
return wasi.ErrnoFault
}
var n int
if writer == io.Discard { // special-case default
n = int(l)
} else {
b, ok := mod.Memory().Read(offset, l)
b, ok := mod.Memory().Read(ctx, offset, l)
if !ok {
return errnoFault
return wasi.ErrnoFault
}
n, err = writer.Write(b)
if err != nil {
return errnoIo
return wasi.ErrnoIo
}
}
nwritten += uint32(n)
}
if !mod.Memory().WriteUint32Le(resultSize, nwritten) {
return errnoFault
if !mod.Memory().WriteUint32Le(ctx, resultSize, nwritten) {
return wasi.ErrnoFault
}
return errnoSuccess
return wasi.ErrnoSuccess
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册