]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: use correct cmsg alignment for openbsd/arm
authorJoel Sing <joel@sing.id.au>
Wed, 12 Dec 2018 13:38:37 +0000 (00:38 +1100)
committerJoel Sing <joel@sing.id.au>
Thu, 13 Dec 2018 00:47:37 +0000 (00:47 +0000)
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 <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/syscall/sockcmsg_unix.go

index 5020033bad58aff6654a4a37fb8761154c4526a4..954148012fac1c6645a114379ea678c773e42479 100644 (file)
@@ -8,17 +8,30 @@
 
 package syscall
 
-import "unsafe"
+import (
+       "runtime"
+       "unsafe"
+)
 
 // 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
+
+       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 {
+                       salign = 4
+               }
+       case "openbsd":
+               // OpenBSD armv7 requires 64-bit alignment.
+               if runtime.GOARCH == "arm" {
+                       salign = 8
+               }
        }
+
        return (salen + salign - 1) & ^(salign - 1)
 }