sys_solaris.go 2.3 KB

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