sys_solaris.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2017 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. package socket
  5. import (
  6. "runtime"
  7. "syscall"
  8. "unsafe"
  9. )
  10. func probeProtocolStack() int {
  11. switch runtime.GOARCH {
  12. case "amd64":
  13. return 4
  14. default:
  15. var p uintptr
  16. return int(unsafe.Sizeof(p))
  17. }
  18. }
  19. //go:cgo_import_dynamic libc___xnet_getsockopt __xnet_getsockopt "libsocket.so"
  20. //go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
  21. //go:cgo_import_dynamic libc___xnet_recvmsg __xnet_recvmsg "libsocket.so"
  22. //go:cgo_import_dynamic libc___xnet_sendmsg __xnet_sendmsg "libsocket.so"
  23. //go:linkname procGetsockopt libc___xnet_getsockopt
  24. //go:linkname procSetsockopt libc_setsockopt
  25. //go:linkname procRecvmsg libc___xnet_recvmsg
  26. //go:linkname procSendmsg libc___xnet_sendmsg
  27. var (
  28. procGetsockopt uintptr
  29. procSetsockopt uintptr
  30. procRecvmsg uintptr
  31. procSendmsg uintptr
  32. )
  33. func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (uintptr, uintptr, syscall.Errno)
  34. func rawSysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (uintptr, uintptr, syscall.Errno)
  35. func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
  36. l := uint32(len(b))
  37. _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procGetsockopt)), 5, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
  38. return int(l), errnoErr(errno)
  39. }
  40. func setsockopt(s uintptr, level, name int, b []byte) error {
  41. _, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procSetsockopt)), 5, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
  42. return errnoErr(errno)
  43. }
  44. func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
  45. n, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procRecvmsg)), 3, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
  46. return int(n), errnoErr(errno)
  47. }
  48. func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
  49. n, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procSendmsg)), 3, s, uintptr(unsafe.Pointer(h)), uintptr(flags), 0, 0, 0)
  50. return int(n), errnoErr(errno)
  51. }
  52. func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
  53. return 0, errNotImplemented
  54. }
  55. func sendmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
  56. return 0, errNotImplemented
  57. }