...

Source file src/syscall/sockcmsg_unix_other.go

Documentation: syscall

		 1  // Copyright 2019 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  //go:build aix || darwin || freebsd || linux || netbsd || openbsd || solaris
		 6  // +build aix darwin freebsd linux netbsd openbsd solaris
		 7  
		 8  package syscall
		 9  
		10  import (
		11  	"runtime"
		12  )
		13  
		14  // Round the length of a raw sockaddr up to align it properly.
		15  func cmsgAlignOf(salen int) int {
		16  	salign := sizeofPtr
		17  
		18  	// dragonfly needs to check ABI version at runtime, see cmsgAlignOf in
		19  	// sockcmsg_dragonfly.go
		20  	switch runtime.GOOS {
		21  	case "aix":
		22  		// There is no alignment on AIX.
		23  		salign = 1
		24  	case "darwin", "ios", "illumos", "solaris":
		25  		// NOTE: It seems like 64-bit Darwin, Illumos and Solaris
		26  		// kernels still require 32-bit aligned access to network
		27  		// subsystem.
		28  		if sizeofPtr == 8 {
		29  			salign = 4
		30  		}
		31  	case "netbsd", "openbsd":
		32  		// NetBSD and OpenBSD armv7 require 64-bit alignment.
		33  		if runtime.GOARCH == "arm" {
		34  			salign = 8
		35  		}
		36  		// NetBSD aarch64 requires 128-bit alignment.
		37  		if runtime.GOOS == "netbsd" && runtime.GOARCH == "arm64" {
		38  			salign = 16
		39  		}
		40  	}
		41  
		42  	return (salen + salign - 1) & ^(salign - 1)
		43  }
		44  

View as plain text