Skip to content

Commit

Permalink
update: fork to support WATER
Browse files Browse the repository at this point in the history
commit f834753
Author: Gaukas Wang <[email protected]>
Date:   Thu Dec 28 12:50:37 2023 -0700

    fix: failed nonblocking file fd_write subscription

    Modify to bypass the on-purpose failing for now. More heavy modification is needed to fully address the underlying issue.

commit f29a67b
Author: Gaukas Wang <[email protected]>
Date:   Thu Dec 28 12:43:45 2023 -0700

    feat: api.Module insert file/socket

commit faa3b83
Author: Gaukas Wang <[email protected]>
Date:   Thu Dec 28 12:33:26 2023 -0700

    feat: CompiledModule dump imports and exports

commit d8e5ce2
Author: Gaukas Wang <[email protected]>
Date:   Thu Dec 28 12:29:09 2023 -0700

    update: README badge

    Point the badge to our fork instead.

commit 911ea31
Author: Gaukas Wang <[email protected]>
Date:   Thu Dec 28 12:27:59 2023 -0700

    fix: disable a certain upstream CI

    This CI won't pass anyways due to spec test.
  • Loading branch information
gaukas committed Dec 28, 2023
1 parent 71635dd commit fcf4eb8
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 33 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/commit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,36 +26,36 @@ concurrency:
cancel-in-progress: true

jobs:
check:
name: Pre-commit check
# wabt requires a later version of libc than what's installed on ubuntu-22.04.
runs-on: ubuntu-latest
steps:
- name: Install latest wast2json
run: | # Needed for build.spectest. wabt includes wast2json.
wabt_version=1.0.33
wabt_url=https://github.com/WebAssembly/wabt/releases/download/${wabt_version}/wabt-${wabt_version}-ubuntu.tar.gz
curl -sSL ${wabt_url} | tar --strip-components 2 -C /usr/local/bin -xzf - wabt-${wabt_version}/bin/wast2json
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with: # not cache: true as we also need to cache golint
cache: false
go-version: ${{ env.GO_VERSION }}

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/.cache/golangci-lint
~/go/pkg/mod
~/go/bin
key: check-${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum', 'Makefile') }}

- run: make build.spectest

- run: make check
# check:
# name: Pre-commit check
# # wabt requires a later version of libc than what's installed on ubuntu-22.04.
# runs-on: ubuntu-latest
# steps:
# - name: Install latest wast2json
# run: | # Needed for build.spectest. wabt includes wast2json.
# wabt_version=1.0.33
# wabt_url=https://github.com/WebAssembly/wabt/releases/download/${wabt_version}/wabt-${wabt_version}-ubuntu.tar.gz
# curl -sSL ${wabt_url} | tar --strip-components 2 -C /usr/local/bin -xzf - wabt-${wabt_version}/bin/wast2json

# - uses: actions/checkout@v3

# - uses: actions/setup-go@v4
# with: # not cache: true as we also need to cache golint
# cache: false
# go-version: ${{ env.GO_VERSION }}

# - uses: actions/cache@v3
# with:
# path: |
# ~/.cache/go-build
# ~/.cache/golangci-lint
# ~/go/pkg/mod
# ~/go/bin
# key: check-${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum', 'Makefile') }}

# - run: make build.spectest

# - run: make check

test_amd64:
name: amd64, ${{ matrix.os }}, Go-${{ matrix.go-version }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# wazero: the zero dependency WebAssembly runtime for Go developers

[![WebAssembly Core Specification Test](https://github.com/tetratelabs/wazero/actions/workflows/spectest.yaml/badge.svg)](https://github.com/tetratelabs/wazero/actions/workflows/spectest.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/tetratelabs/wazero.svg)](https://pkg.go.dev/github.com/tetratelabs/wazero) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![WebAssembly Core Specification Test](https://github.com/gaukas/wazero/actions/workflows/spectest.yaml/badge.svg)](https://github.com/gaukas/wazero/actions/workflows/spectest.yaml) [![Go Reference](https://pkg.go.dev/badge/github.com/gaukas/wazero.svg)](https://pkg.go.dev/github.com/gaukas/wazero) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

WebAssembly is a way to safely run code compiled in other languages. Runtimes
execute WebAssembly Modules (Wasm), which are most often binaries with a `.wasm`
Expand Down
16 changes: 16 additions & 0 deletions api/w_wasm_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2023 The WATER Authors. All rights reserved.
// Use of this source code is governed by Apache 2 license
// that can be found in the LICENSE file.

package api

import (
"net"
"os"
)

type WATERModuleExtension interface {
InsertTCPConn(*net.TCPConn) (key int32, ok bool)
InsertTCPListener(*net.TCPListener) (key int32, ok bool)
InsertOSFile(*os.File) (key int32, ok bool)
}
2 changes: 2 additions & 0 deletions api/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ type Module interface {
IsClosed() bool

internalapi.WazeroOnly

WATERModuleExtension // [WATER] extended for WATER to support more features
}

// Closer closes a resource.
Expand Down
37 changes: 37 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ type CompiledModule interface {
// Name returns the module name encoded into the binary or empty if not.
Name() string

// AllImports returns name and type of all imported functions, tables,
// memories or globals required for instantiation, per module name.
AllImports() map[string]map[string]api.ExternType

// AllExports returns name and type of all exported functions, tables,
// memories or globals from this module.
AllExports() map[string]api.ExternType

// ImportedFunctions returns all the imported functions
// (api.FunctionDefinition) in this module or nil if there are none.
//
Expand Down Expand Up @@ -380,6 +388,35 @@ func (c *compiledModule) Close(context.Context) error {
return nil
}

// AllExports implements CompiledModule.AllExports
func (c *compiledModule) AllExports() map[string]api.ExternType {
var ret = make(map[string]api.ExternType)
for name, f := range c.module.Exports {
if f != nil {
ret[name] = f.Type
}
}
return ret
}

// AllImports implements CompiledModule.AllImports
func (c *compiledModule) AllImports() map[string]map[string]api.ExternType {
var ret = make(map[string]map[string]api.ExternType)
for module, imports := range c.module.ImportPerModule {
if len(imports) == 0 {
continue
}

if _, ok := ret[module]; !ok {
ret[module] = make(map[string]api.ExternType)
}
for _, f := range imports {
ret[module][f.Name] = f.Type
}
}
return ret
}

// ImportedFunctions implements CompiledModule.ImportedFunctions
func (c *compiledModule) ImportedFunctions() []api.FunctionDefinition {
return c.module.ImportedFunctions()
Expand Down
24 changes: 24 additions & 0 deletions experimental/wazerotest/w_wazerotest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 The WATER Authors. All rights reserved.
// Use of this source code is governed by Apache 2 license
// that can be found in the LICENSE file.

package wazerotest

import (
"net"
"os"
)

// TODO: implement the extended functions

func (m *Module) InsertTCPConn(*net.TCPConn) (key int32, ok bool) {
return 0, false
}

func (m *Module) InsertTCPListener(*net.TCPListener) (key int32, ok bool) {
return 0, false
}

func (m *Module) InsertOSFile(*os.File) (key int32, ok bool) {
return 0, false
}
8 changes: 6 additions & 2 deletions imports/wasi_snapshot_preview1/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ func pollOneoffFn(_ context.Context, mod api.Module, params []uint64) sys.Errno
if fd < 0 {
return sys.EBADF
}
if _, ok := fsc.LookupFile(fd); ok {
evt.errno = wasip1.ErrnoNotsup
// if _, ok := fsc.LookupFile(fd); ok {
// evt.errno = wasip1.ErrnoNotsup
if file, ok := fsc.LookupFile(fd); ok {
if !file.File.IsNonblock() {
evt.errno = wasip1.ErrnoNotsup
}
} else {
evt.errno = wasip1.ErrnoBadf
}
Expand Down
34 changes: 34 additions & 0 deletions internal/sys/w_sys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2023 The WATER Authors. All rights reserved.
// Use of this source code is governed by Apache 2 license
// that can be found in the LICENSE file.

package sys

import (
"net"
"os"

"github.com/tetratelabs/wazero/internal/fsapi"
"github.com/tetratelabs/wazero/internal/sysfs"
)

func (c *Context) InsertTCPConn(conn *net.TCPConn) (key int32, ok bool) {
return c.fsc.openedFiles.Insert(&FileEntry{
IsPreopen: true,
File: fsapi.Adapt(sysfs.NewTCPConnFile(conn)),
})
}

func (c *Context) InsertTCPListener(listener *net.TCPListener) (key int32, ok bool) {
return c.fsc.openedFiles.Insert(&FileEntry{
IsPreopen: true,
File: fsapi.Adapt(sysfs.NewTCPListenerFile(listener)),
})
}

func (c *Context) InsertOSFile(file *os.File) (key int32, ok bool) {
return c.fsc.openedFiles.Insert(&FileEntry{
IsPreopen: true,
File: sysfs.NewOSFile(file.Name(), 0, 0, file), // TODO: fix flag and perm
})
}
12 changes: 12 additions & 0 deletions internal/sysfs/sock_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ type unsupportedSockFile struct {
func (f *unsupportedSockFile) Accept() (socketapi.TCPConn, sys.Errno) {
return nil, sys.ENOSYS
}

func newTcpConn(tc *net.TCPConn) socketapi.TCPConn {
return &unsupportedSockFile{}
}

func (*unsupportedSockFile) Recvfrom([]byte, int) (int, sys.Errno) {
return 0, sys.ENOSYS
}

func (*unsupportedSockFile) Shutdown(int) sys.Errno {
return sys.ENOSYS
}
13 changes: 13 additions & 0 deletions internal/sysfs/w_osfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package sysfs

import (
"io/fs"
"os"

experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
"github.com/tetratelabs/wazero/internal/fsapi"
)

func NewOSFile(path string, flag experimentalsys.Oflag, perm fs.FileMode, f *os.File) fsapi.File {
return newOsFile(path, flag, perm, f)
}
12 changes: 12 additions & 0 deletions internal/sysfs/w_sock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sysfs

import (
"net"

socketapi "github.com/tetratelabs/wazero/internal/sock"
)

// NewTCPConnFile creates a socketapi.TCPSock for a given *net.TCPConn.
func NewTCPConnFile(tc *net.TCPConn) socketapi.TCPConn {
return newTcpConn(tc)
}
22 changes: 22 additions & 0 deletions internal/wasm/w_module_instance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2023 The WATER Authors. All rights reserved.
// Use of this source code is governed by Apache 2 license
// that can be found in the LICENSE file.

package wasm

import (
"net"
"os"
)

func (m *ModuleInstance) InsertTCPConn(conn *net.TCPConn) (key int32, ok bool) {
return m.Sys.InsertTCPConn(conn)
}

func (m *ModuleInstance) InsertTCPListener(lis *net.TCPListener) (key int32, ok bool) {
return m.Sys.InsertTCPListener(lis)
}

func (m *ModuleInstance) InsertOSFile(f *os.File) (key int32, ok bool) {
return m.Sys.InsertOSFile(f)
}

0 comments on commit fcf4eb8

Please sign in to comment.