Nahum Shalman | c94f622 | 2021-03-16 16:49:22 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Go Authors. All rights reserved. |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 | |
Russ Cox | 9a76102 | 2021-02-19 22:57:36 -0500 | [diff] [blame] | 7 | //go:build amd64 && illumos |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 8 | |
| 9 | package unix |
| 10 | |
Nahum Shalman | 635bc2c | 2021-03-16 16:47:47 +0000 | [diff] [blame] | 11 | import ( |
| 12 | "unsafe" |
| 13 | ) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 { |
Ian Lance Taylor | 175b2fd | 2022-06-15 17:01:07 -0700 | [diff] [blame] | 20 | iovecs[i].Base = &b[0] |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 21 | } else { |
Ian Lance Taylor | 175b2fd | 2022-06-15 17:01:07 -0700 | [diff] [blame] | 22 | iovecs[i].Base = (*byte)(unsafe.Pointer(&_zero)) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 23 | } |
| 24 | } |
| 25 | return iovecs |
| 26 | } |
| 27 | |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 28 | //sys readv(fd int, iovs []Iovec) (n int, err error) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 | |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 36 | //sys preadv(fd int, iovs []Iovec, off int64) (n int, err error) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 | |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 44 | //sys writev(fd int, iovs []Iovec) (n int, err error) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 | |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 52 | //sys pwritev(fd int, iovs []Iovec, off int64) (n int, err error) |
Araragi Hokuto | 328b4cd | 2020-03-21 13:33:22 +0000 | [diff] [blame] | 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 | } |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 59 | |
Tobias Klauser | e10f822 | 2020-09-21 15:04:15 +0200 | [diff] [blame] | 60 | //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) = libsocket.accept4 |
Tobias Klauser | 6d893a6 | 2020-09-14 15:46:41 +0200 | [diff] [blame] | 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 | } |