Commit b05ddf57 authored by Joel Sing's avatar Joel Sing

unix: use correct cmsg alignment for openbsd/arm

The OpenBSD armv7 port requires 64-bit alignment for cmsgs.

Rework the cmsg alignment code to facilitate this.

Change-Id: Ie3eae1d367e2f3ac200fa8b78e97a2eb2eccae6a
Reviewed-on: https://go-review.googlesource.com/c/153619
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 7da8ea5c
...@@ -8,18 +8,33 @@ ...@@ -8,18 +8,33 @@
package unix 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. // Round the length of a raw sockaddr up to align it properly.
func cmsgAlignOf(salen int) int { func cmsgAlignOf(salen int) int {
salign := SizeofPtr return (salen + cmsgAlign - 1) & ^(cmsgAlign - 1)
// 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)
} }
// CmsgLen returns the value to store in the Len field of the Cmsghdr // CmsgLen returns the value to store in the Len field of the Cmsghdr
......
...@@ -8,7 +8,6 @@ package unix ...@@ -8,7 +8,6 @@ package unix
import ( import (
"bytes" "bytes"
"runtime"
"sort" "sort"
"sync" "sync"
"syscall" "syscall"
...@@ -21,13 +20,6 @@ var ( ...@@ -21,13 +20,6 @@ var (
Stderr = 2 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 // Do the interface allocations only once for common
// Errno values. // Errno values.
var ( var (
......
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