Commit 73d4af5a authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: evaluate cmsg alignment in cmsgAlignOf at compile time

runtime.GOOS and runtime.GOARCH are constants, thus all comparisons are
evaluated at compile time.

Follow-up for CL 153619 to make the code consistent with the syscall
package, cf. CL 153837

Change-Id: I0520d88c1636c6ed2acad69fce85a28042eafe56
Reviewed-on: https://go-review.googlesource.com/c/153937
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: 's avatarJoel Sing <joel@sing.id.au>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b05ddf57
......@@ -13,28 +13,26 @@ import (
"unsafe"
)
var cmsgAlign = SizeofPtr
// Round the length of a raw sockaddr up to align it properly.
func cmsgAlignOf(salen int) int {
salign := 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
salign = 4
}
case "openbsd":
// OpenBSD armv7 requires 64-bit alignment.
if runtime.GOARCH == "arm" {
cmsgAlign = 8
salign = 8
}
}
}
// Round the length of a raw sockaddr up to align it properly.
func cmsgAlignOf(salen int) int {
return (salen + cmsgAlign - 1) & ^(cmsgAlign - 1)
return (salen + salign - 1) & ^(salign - 1)
}
// CmsgLen returns the value to store in the Len field of the Cmsghdr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment