Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #48 from stealthrocket/wasi-sock-accept-addr
Browse files Browse the repository at this point in the history
wasi: update signature of SockAccept to access client address
  • Loading branch information
achille-roussel committed Jun 1, 2023
2 parents 04faa6c + 64ba40d commit ece84e5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/google/pprof v0.0.0-20230510103437-eeec1cb781c3
github.com/google/uuid v1.3.0
github.com/klauspost/compress v1.16.5
github.com/stealthrocket/wasi-go v0.2.0
github.com/stealthrocket/wasi-go v0.3.0
github.com/stealthrocket/wazergo v0.19.0
github.com/stealthrocket/wzprof v0.1.5
github.com/tetratelabs/wazero v1.1.1-0.20230522055633-256b7a4bf970
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ github.com/stealthrocket/wasi-go v0.1.1 h1:9Q9zpKWItoObGjNG5kkllzHx1sksiq/MKfuYd
github.com/stealthrocket/wasi-go v0.1.1/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wasi-go v0.2.0 h1:vSIaa2/08os4K7ThE4zpz1DatehcgVHJjiq36sFRNts=
github.com/stealthrocket/wasi-go v0.2.0/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wasi-go v0.2.1-0.20230601091929-e34600730df8 h1:w/V3IQcjLyMfDxFckSK4wgVONZjzOL9VS5hK1u4OlKA=
github.com/stealthrocket/wasi-go v0.2.1-0.20230601091929-e34600730df8/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wasi-go v0.3.0 h1:+L+DfnHkBmOkUmCbsyO9j1KPqsAFu426jD3HH/7BABc=
github.com/stealthrocket/wasi-go v0.3.0/go.mod h1:LBhZHvAroNNQTejkVTMJZ01ssj3jXF+3Lkbru4cTzGQ=
github.com/stealthrocket/wazergo v0.19.0 h1:0ZBya2fBURvV+I2hGl0vcuQ8dgoUvllxQ7aYlZSA5nI=
github.com/stealthrocket/wazergo v0.19.0/go.mod h1:riI0hxw4ndZA5e6z7PesHg2BtTftcZaMxRcoiGGipTs=
github.com/stealthrocket/wzprof v0.1.5 h1:abEwQF9KtqV7UQ0hWk7431vul9/FxOg1eRCqwEKo9/4=
Expand Down
12 changes: 8 additions & 4 deletions internal/timemachine/wasicall/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,14 +842,15 @@ func (c *Codec) DecodeRandomGet(buffer []byte) (result []byte, errno Errno, err
return
}

func (c *Codec) EncodeSockAccept(buffer []byte, fd FD, flags FDFlags, newfd FD, errno Errno) []byte {
func (c *Codec) EncodeSockAccept(buffer []byte, fd FD, flags FDFlags, newfd FD, addr SocketAddress, errno Errno) []byte {
buffer = encodeErrno(buffer, errno)
buffer = encodeFD(buffer, fd)
buffer = encodeFDFlags(buffer, flags)
return encodeFD(buffer, newfd)
buffer = encodeFD(buffer, newfd)
return encodeAddr(buffer, addr)
}

func (c *Codec) DecodeSockAccept(buffer []byte) (fd FD, flags FDFlags, newfd FD, errno Errno, err error) {
func (c *Codec) DecodeSockAccept(buffer []byte) (fd FD, flags FDFlags, newfd FD, addr SocketAddress, errno Errno, err error) {
if errno, buffer, err = decodeErrno(buffer); err != nil {
return
}
Expand All @@ -859,7 +860,10 @@ func (c *Codec) DecodeSockAccept(buffer []byte) (fd FD, flags FDFlags, newfd FD,
if flags, buffer, err = decodeFDFlags(buffer); err != nil {
return
}
newfd, _, err = decodeFD(buffer)
if newfd, buffer, err = decodeFD(buffer); err != nil {
return
}
addr, _, err = decodeAddr(buffer)
return
}

Expand Down
2 changes: 1 addition & 1 deletion internal/timemachine/wasicall/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *exitSystem) RandomGet(ctx context.Context, b []byte) Errno {
panic(s.newExitError())
}

func (s *exitSystem) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno) {
func (s *exitSystem) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, SocketAddress, Errno) {
panic(s.newExitError())
}

Expand Down
6 changes: 3 additions & 3 deletions internal/timemachine/wasicall/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ func (f *FallbackSystem) RandomGet(ctx context.Context, b []byte) Errno {
return errno
}

func (f *FallbackSystem) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno) {
newfd, errno := f.System.SockAccept(ctx, fd, flags)
func (f *FallbackSystem) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, SocketAddress, Errno) {
newfd, addr, errno := f.System.SockAccept(ctx, fd, flags)
if errno == ENOSYS {
return f.secondary.SockAccept(ctx, fd, flags)
}
return newfd, errno
return newfd, addr, errno
}

func (f *FallbackSystem) SockRecv(ctx context.Context, fd FD, iovecs []IOVec, iflags RIFlags) (Size, ROFlags, Errno) {
Expand Down
8 changes: 4 additions & 4 deletions internal/timemachine/wasicall/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ func (o *Observer) RandomGet(ctx context.Context, b []byte) (errno Errno) {
return
}

func (o *Observer) SockAccept(ctx context.Context, fd FD, flags FDFlags) (newfd FD, errno Errno) {
func (o *Observer) SockAccept(ctx context.Context, fd FD, flags FDFlags) (newfd FD, addr SocketAddress, errno Errno) {
if o.before != nil {
o.before(ctx, &SockAcceptSyscall{fd, flags, newfd, errno})
o.before(ctx, &SockAcceptSyscall{fd, flags, newfd, addr, errno})
}
newfd, errno = o.System.SockAccept(ctx, fd, flags)
newfd, addr, errno = o.System.SockAccept(ctx, fd, flags)
if o.after != nil {
o.after(ctx, &SockAcceptSyscall{fd, flags, newfd, errno})
o.after(ctx, &SockAcceptSyscall{fd, flags, newfd, addr, errno})
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions internal/timemachine/wasicall/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,11 @@ func (r *Reader) ReadSyscall() (time.Time, Syscall, error) {
}
syscall = &RandomGetSyscall{b, errno}
case SockAccept:
fd, flags, newfd, errno, err := r.codec.DecodeSockAccept(record.FunctionCall)
fd, flags, newfd, addr, errno, err := r.codec.DecodeSockAccept(record.FunctionCall)
if err != nil {
return time.Time{}, nil, &DecodeError{record, err}
}
syscall = &SockAcceptSyscall{fd, flags, newfd, errno}
syscall = &SockAcceptSyscall{fd, flags, newfd, addr, errno}
case SockShutdown:
fd, flags, errno, err := r.codec.DecodeSockShutdown(record.FunctionCall)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions internal/timemachine/wasicall/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,10 @@ func (r *Recorder) RandomGet(ctx context.Context, b []byte) Errno {
return errno
}

func (r *Recorder) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno) {
newfd, errno := r.system.SockAccept(ctx, fd, flags)
r.record(SockAccept, r.codec.EncodeSockAccept(r.buffer[:0], fd, flags, newfd, errno))
return newfd, errno
func (r *Recorder) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, SocketAddress, Errno) {
newfd, addr, errno := r.system.SockAccept(ctx, fd, flags)
r.record(SockAccept, r.codec.EncodeSockAccept(r.buffer[:0], fd, flags, newfd, addr, errno))
return newfd, addr, errno
}

func (r *Recorder) SockShutdown(ctx context.Context, fd FD, flags SDFlags) Errno {
Expand Down
8 changes: 4 additions & 4 deletions internal/timemachine/wasicall/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,12 @@ func (r *Replay) RandomGet(ctx context.Context, buffer []byte) Errno {
return errno
}

func (r *Replay) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errno) {
func (r *Replay) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, SocketAddress, Errno) {
record, ok := r.readRecord(SockAccept)
if !ok {
return -1, ENOSYS
return -1, nil, ENOSYS
}
recordFD, recordFlags, newfd, errno, err := r.codec.DecodeSockAccept(record.FunctionCall)
recordFD, recordFlags, newfd, addr, errno, err := r.codec.DecodeSockAccept(record.FunctionCall)
if err != nil {
panic(&DecodeError{record, err})
}
Expand All @@ -1054,7 +1054,7 @@ func (r *Replay) SockAccept(ctx context.Context, fd FD, flags FDFlags) (FD, Errn
panic(errors.Join(mismatch...))
}
}
return newfd, errno
return newfd, addr, errno
}

func (r *Replay) SockShutdown(ctx context.Context, fd FD, flags SDFlags) Errno {
Expand Down
3 changes: 2 additions & 1 deletion internal/timemachine/wasicall/syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,12 +570,13 @@ type SockAcceptSyscall struct {
FD FD
Flags FDFlags
NewFD FD
Addr SocketAddress
Errno Errno
}

func (s *SockAcceptSyscall) ID() SyscallID { return SockAccept }
func (s *SockAcceptSyscall) Params() []any { return []any{s.FD, s.Flags} }
func (s *SockAcceptSyscall) Results() []any { return []any{s.NewFD, s.Errno} }
func (s *SockAcceptSyscall) Results() []any { return []any{s.NewFD, s.Addr, s.Errno} }
func (s *SockAcceptSyscall) Error() Errno { return s.Errno }
func (s *SockAcceptSyscall) private() {}

Expand Down

0 comments on commit ece84e5

Please sign in to comment.