diff --git a/unix/sockcmsg_unix.go b/unix/sockcmsg_unix.go index 9dd2f32f..52b6e225 100644 --- a/unix/sockcmsg_unix.go +++ b/unix/sockcmsg_unix.go @@ -8,18 +8,33 @@ package unix -import "unsafe" +import ( + "runtime" + "unsafe" +) + +var cmsgAlign = SizeofPtr + +func init() { + switch runtime.GOOS { + case "darwin", "dragonfly", "solaris": + // NOTE: It seems like 64-bit Darwin, DragonFly BSD and + // Solaris kernels still require 32-bit aligned access to + // network subsystem. + if SizeofPtr == 8 { + cmsgAlign = 4 + } + case "openbsd": + // OpenBSD armv7 requires 64-bit alignment. + if runtime.GOARCH == "arm" { + cmsgAlign = 8 + } + } +} // Round the length of a raw sockaddr up to align it properly. func cmsgAlignOf(salen int) int { - salign := SizeofPtr - // NOTE: It seems like 64-bit Darwin, DragonFly BSD and - // Solaris kernels still require 32-bit aligned access to - // network subsystem. - if darwin64Bit || dragonfly64Bit || solaris64Bit { - salign = 4 - } - return (salen + salign - 1) & ^(salign - 1) + return (salen + cmsgAlign - 1) & ^(cmsgAlign - 1) } // CmsgLen returns the value to store in the Len field of the Cmsghdr diff --git a/unix/syscall_unix.go b/unix/syscall_unix.go index 64fcda4a..a21486f6 100644 --- a/unix/syscall_unix.go +++ b/unix/syscall_unix.go @@ -8,7 +8,6 @@ package unix import ( "bytes" - "runtime" "sort" "sync" "syscall" @@ -21,13 +20,6 @@ var ( Stderr = 2 ) -const ( - darwin64Bit = runtime.GOOS == "darwin" && SizeofPtr == 8 - dragonfly64Bit = runtime.GOOS == "dragonfly" && SizeofPtr == 8 - netbsd32Bit = runtime.GOOS == "netbsd" && SizeofPtr == 4 - solaris64Bit = runtime.GOOS == "solaris" && SizeofPtr == 8 -) - // Do the interface allocations only once for common // Errno values. var (