github.com/Andyfoo/golang/x/net@v0.0.0-20190901054642-57c1bf301704/internal/socket/sys_solaris.go (about)

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