You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sockcmsg_unix_other.go 1.2KB

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