Skip to content

Commit

Permalink
unix: add readv/writev for illumos
Browse files Browse the repository at this point in the history
iovec read/writes (readv, writev, preadv, pwritev) are present on
illumos, but they weren't added to the package. This commit adds
those missing features.

Updates golang/go#36201

Change-Id: Iecf2bab7ef846f5ca5d693e833491d819618c15d
GitHub-Last-Rev: 81a479f
GitHub-Pull-Request: #64
Reviewed-on: https://go-review.googlesource.com/c/sys/+/224238
Run-TryBot: Tobias Klauser <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Tobias Klauser <[email protected]>
  • Loading branch information
Araragi Hokuto authored and tklauser committed Mar 21, 2020
1 parent af34d82 commit 328b4cd
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 6 deletions.
11 changes: 11 additions & 0 deletions unix/mkall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ solaris_amd64)
mksysnum=
mktypes="GOARCH=$GOARCH go tool cgo -godefs"
;;
illumos_amd64)
mksyscall="go run mksyscall_solaris.go"
mkerrors=
mksysnum=
mktypes=
;;
*)
echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
exit 1
Expand Down Expand Up @@ -217,6 +223,11 @@ esac
echo "$mksyscall -tags $GOOS,$GOARCH,go1.12 $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
# 1.13 and later, syscalls via libSystem (including syscallPtr)
echo "$mksyscall -tags $GOOS,$GOARCH,go1.13 syscall_darwin.1_13.go |gofmt >zsyscall_$GOOSARCH.1_13.go";
elif [ "$GOOS" == "illumos" ]; then
# illumos code generation requires a --illumos switch
echo "$mksyscall -illumos -tags illumos,$GOARCH syscall_illumos.go |gofmt > zsyscall_illumos_$GOARCH.go";
# illumos implies solaris, so solaris code generation is also required
echo "$mksyscall -tags solaris,$GOARCH syscall_solaris.go syscall_solaris_$GOARCH.go |gofmt >zsyscall_solaris_$GOARCH.go";
else
echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go";
fi
Expand Down
18 changes: 12 additions & 6 deletions unix/mksyscall_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import (
)

var (
b32 = flag.Bool("b32", false, "32bit big-endian")
l32 = flag.Bool("l32", false, "32bit little-endian")
tags = flag.String("tags", "", "build tags")
b32 = flag.Bool("b32", false, "32bit big-endian")
l32 = flag.Bool("l32", false, "32bit little-endian")
tags = flag.String("tags", "", "build tags")
illumos = flag.Bool("illumos", false, "illumos specific code generation")
)

// cmdLine returns this programs's commandline arguments
Expand Down Expand Up @@ -306,11 +307,16 @@ func main() {
imp := ""
if pack != "unix" {
imp = "import \"golang.org/x/sys/unix\"\n"
}

syscallimp := ""
if !*illumos {
syscallimp = "\"syscall\""
}

vardecls := "\t" + strings.Join(vars, ",\n\t")
vardecls += " syscallFunc"
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, imp, dynimports, linknames, vardecls, text)
fmt.Printf(srcTemplate, cmdLine(), buildTags(), pack, syscallimp, imp, dynimports, linknames, vardecls, text)
}

const srcTemplate = `// %s
Expand All @@ -321,8 +327,8 @@ const srcTemplate = `// %s
package %s
import (
"syscall"
"unsafe"
"unsafe"
%s
)
%s
%s
Expand Down
57 changes: 57 additions & 0 deletions unix/syscall_illumos.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// illumos system calls not present on Solaris.

// +build amd64,illumos

package unix

import "unsafe"

func bytes2iovec(bs [][]byte) []Iovec {
iovecs := make([]Iovec, len(bs))
for i, b := range bs {
iovecs[i].SetLen(len(b))
if len(b) > 0 {
// somehow Iovec.Base on illumos is (*int8), not (*byte)
iovecs[i].Base = (*int8)(unsafe.Pointer(&b[0]))
} else {
iovecs[i].Base = (*int8)(unsafe.Pointer(&_zero))
}
}
return iovecs
}

//sys readv(fd int, iovs []Iovec) (n int, err error)

func Readv(fd int, iovs [][]byte) (n int, err error) {
iovecs := bytes2iovec(iovs)
n, err = readv(fd, iovecs)
return n, err
}

//sys preadv(fd int, iovs []Iovec, off int64) (n int, err error)

func Preadv(fd int, iovs [][]byte, off int64) (n int, err error) {
iovecs := bytes2iovec(iovs)
n, err = preadv(fd, iovecs, off)
return n, err
}

//sys writev(fd int, iovs []Iovec) (n int, err error)

func Writev(fd int, iovs [][]byte) (n int, err error) {
iovecs := bytes2iovec(iovs)
n, err = writev(fd, iovecs)
return n, err
}

//sys pwritev(fd int, iovs []Iovec, off int64) (n int, err error)

func Pwritev(fd int, iovs [][]byte, off int64) (n int, err error) {
iovecs := bytes2iovec(iovs)
n, err = pwritev(fd, iovecs, off)
return n, err
}
87 changes: 87 additions & 0 deletions unix/zsyscall_illumos_amd64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 328b4cd

Please sign in to comment.