1// Copyright 2021 The Go Authors. All rights reserved.
 2// Use of this source code is governed by a BSD-style
 3// license that can be found in the LICENSE file.
 4
 5// illumos system calls not present on Solaris.
 6
 7//go:build amd64 && illumos
 8// +build amd64,illumos
 9
10package unix
11
12import (
13	"unsafe"
14)
15
16func bytes2iovec(bs [][]byte) []Iovec {
17	iovecs := make([]Iovec, len(bs))
18	for i, b := range bs {
19		iovecs[i].SetLen(len(b))
20		if len(b) > 0 {
21			iovecs[i].Base = &b[0]
22		} else {
23			iovecs[i].Base = (*byte)(unsafe.Pointer(&_zero))
24		}
25	}
26	return iovecs
27}
28
29//sys	readv(fd int, iovs []Iovec) (n int, err error)
30
31func Readv(fd int, iovs [][]byte) (n int, err error) {
32	iovecs := bytes2iovec(iovs)
33	n, err = readv(fd, iovecs)
34	return n, err
35}
36
37//sys	preadv(fd int, iovs []Iovec, off int64) (n int, err error)
38
39func Preadv(fd int, iovs [][]byte, off int64) (n int, err error) {
40	iovecs := bytes2iovec(iovs)
41	n, err = preadv(fd, iovecs, off)
42	return n, err
43}
44
45//sys	writev(fd int, iovs []Iovec) (n int, err error)
46
47func Writev(fd int, iovs [][]byte) (n int, err error) {
48	iovecs := bytes2iovec(iovs)
49	n, err = writev(fd, iovecs)
50	return n, err
51}
52
53//sys	pwritev(fd int, iovs []Iovec, off int64) (n int, err error)
54
55func Pwritev(fd int, iovs [][]byte, off int64) (n int, err error) {
56	iovecs := bytes2iovec(iovs)
57	n, err = pwritev(fd, iovecs, off)
58	return n, err
59}
60
61//sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4
62
63func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
64	var rsa RawSockaddrAny
65	var len _Socklen = SizeofSockaddrAny
66	nfd, err = accept4(fd, &rsa, &len, flags)
67	if err != nil {
68		return
69	}
70	if len > SizeofSockaddrAny {
71		panic("RawSockaddrAny too small")
72	}
73	sa, err = anyToSockaddr(fd, &rsa)
74	if err != nil {
75		Close(nfd)
76		nfd = 0
77	}
78	return
79}