src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

syscall_illumos.go (1805B)


      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 
      9 package unix
     10 
     11 import (
     12 	"unsafe"
     13 )
     14 
     15 func bytes2iovec(bs [][]byte) []Iovec {
     16 	iovecs := make([]Iovec, len(bs))
     17 	for i, b := range bs {
     18 		iovecs[i].SetLen(len(b))
     19 		if len(b) > 0 {
     20 			iovecs[i].Base = &b[0]
     21 		} else {
     22 			iovecs[i].Base = (*byte)(unsafe.Pointer(&_zero))
     23 		}
     24 	}
     25 	return iovecs
     26 }
     27 
     28 //sys	readv(fd int, iovs []Iovec) (n int, err error)
     29 
     30 func Readv(fd int, iovs [][]byte) (n int, err error) {
     31 	iovecs := bytes2iovec(iovs)
     32 	n, err = readv(fd, iovecs)
     33 	return n, err
     34 }
     35 
     36 //sys	preadv(fd int, iovs []Iovec, off int64) (n int, err error)
     37 
     38 func Preadv(fd int, iovs [][]byte, off int64) (n int, err error) {
     39 	iovecs := bytes2iovec(iovs)
     40 	n, err = preadv(fd, iovecs, off)
     41 	return n, err
     42 }
     43 
     44 //sys	writev(fd int, iovs []Iovec) (n int, err error)
     45 
     46 func Writev(fd int, iovs [][]byte) (n int, err error) {
     47 	iovecs := bytes2iovec(iovs)
     48 	n, err = writev(fd, iovecs)
     49 	return n, err
     50 }
     51 
     52 //sys	pwritev(fd int, iovs []Iovec, off int64) (n int, err error)
     53 
     54 func Pwritev(fd int, iovs [][]byte, off int64) (n int, err error) {
     55 	iovecs := bytes2iovec(iovs)
     56 	n, err = pwritev(fd, iovecs, off)
     57 	return n, err
     58 }
     59 
     60 //sys	accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4
     61 
     62 func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
     63 	var rsa RawSockaddrAny
     64 	var len _Socklen = SizeofSockaddrAny
     65 	nfd, err = accept4(fd, &rsa, &len, flags)
     66 	if err != nil {
     67 		return
     68 	}
     69 	if len > SizeofSockaddrAny {
     70 		panic("RawSockaddrAny too small")
     71 	}
     72 	sa, err = anyToSockaddr(fd, &rsa)
     73 	if err != nil {
     74 		Close(nfd)
     75 		nfd = 0
     76 	}
     77 	return
     78 }