Skip to content

Commit bbae8d5

Browse files
committed
syscall: 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: I52cf55a8a4cda46c6ef35b0f694862b842028b42 Reviewed-on: https://go-review.googlesource.com/c/153837 Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 09da280 commit bbae8d5

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/syscall/sockcmsg_unix.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@
88

99
package syscall
1010

11-
import "unsafe"
11+
import (
12+
"runtime"
13+
"unsafe"
14+
)
1215

1316
// Round the length of a raw sockaddr up to align it properly.
1417
func cmsgAlignOf(salen int) int {
1518
salign := sizeofPtr
16-
// NOTE: It seems like 64-bit Darwin, DragonFly BSD and
17-
// Solaris kernels still require 32-bit aligned access to
18-
// network subsystem.
19-
if darwin64Bit || dragonfly64Bit || solaris64Bit {
20-
salign = 4
19+
20+
switch runtime.GOOS {
21+
case "darwin", "dragonfly", "solaris":
22+
// NOTE: It seems like 64-bit Darwin, DragonFly BSD and
23+
// Solaris kernels still require 32-bit aligned access to
24+
// network subsystem.
25+
if sizeofPtr == 8 {
26+
salign = 4
27+
}
28+
case "openbsd":
29+
// OpenBSD armv7 requires 64-bit alignment.
30+
if runtime.GOARCH == "arm" {
31+
salign = 8
32+
}
2133
}
34+
2235
return (salen + salign - 1) & ^(salign - 1)
2336
}
2437

0 commit comments

Comments
 (0)