syscall_illumos.go 1.8 KB

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