]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: don't use 32-bit aligned access for cmsgAlignOf on dragonfly after ABI change
authorTobias Klauser <tklauser@distanz.ch>
Fri, 18 Oct 2019 13:52:00 +0000 (15:52 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Sun, 20 Oct 2019 19:33:07 +0000 (19:33 +0000)
Use 32-bit alignment for versions before the September 2019 ABI changes
http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html

Fixes #34958

Change-Id: Iab4b23083a7c9ca7e96a737b03e75cd36d98ee24
Reviewed-on: https://go-review.googlesource.com/c/go/+/201977
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/syscall/sockcmsg_dragonfly.go [new file with mode: 0644]
src/syscall/sockcmsg_unix.go
src/syscall/sockcmsg_unix_other.go [new file with mode: 0644]
src/syscall/syscall_dragonfly.go

diff --git a/src/syscall/sockcmsg_dragonfly.go b/src/syscall/sockcmsg_dragonfly.go
new file mode 100644 (file)
index 0000000..d217d9e
--- /dev/null
@@ -0,0 +1,16 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+// Round the length of a raw sockaddr up to align it properly.
+func cmsgAlignOf(salen int) int {
+       salign := sizeofPtr
+       if sizeofPtr == 8 && !supportsABI(_dragonflyABIChangeVersion) {
+               // 64-bit Dragonfly before the September 2019 ABI changes still requires
+               // 32-bit aligned access to network subsystem.
+               salign = 4
+       }
+       return (salen + salign - 1) & ^(salign - 1)
+}
index 4eb0c0b74872978c7f939ca8600f9f72e664b69e..1ff97a5ae1bd4b6add903cb60c8f0d175c99918e 100644 (file)
@@ -9,35 +9,9 @@
 package syscall
 
 import (
-       "runtime"
        "unsafe"
 )
 
-// Round the length of a raw sockaddr up to align it properly.
-func cmsgAlignOf(salen int) int {
-       salign := sizeofPtr
-
-       switch runtime.GOOS {
-       case "aix":
-               // There is no alignment on AIX.
-               salign = 1
-       case "darwin", "dragonfly", "illumos", "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 "netbsd", "openbsd":
-               // NetBSD and OpenBSD armv7 require 64-bit alignment.
-               if runtime.GOARCH == "arm" {
-                       salign = 8
-               }
-       }
-
-       return (salen + salign - 1) & ^(salign - 1)
-}
-
 // CmsgLen returns the value to store in the Len field of the Cmsghdr
 // structure, taking into account any necessary alignment.
 func CmsgLen(datalen int) int {
diff --git a/src/syscall/sockcmsg_unix_other.go b/src/syscall/sockcmsg_unix_other.go
new file mode 100644 (file)
index 0000000..fbafbf8
--- /dev/null
@@ -0,0 +1,38 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build aix darwin freebsd linux netbsd openbsd solaris
+
+package syscall
+
+import (
+       "runtime"
+)
+
+// Round the length of a raw sockaddr up to align it properly.
+func cmsgAlignOf(salen int) int {
+       salign := sizeofPtr
+
+       // dragonfly needs to check ABI version at runtime, see cmsgAlignOf in
+       // sockcmsg_dragonfly.go
+       switch runtime.GOOS {
+       case "aix":
+               // There is no alignment on AIX.
+               salign = 1
+       case "darwin", "illumos", "solaris":
+               // NOTE: It seems like 64-bit Darwin, Illumos and Solaris
+               // kernels still require 32-bit aligned access to network
+               // subsystem.
+               if sizeofPtr == 8 {
+                       salign = 4
+               }
+       case "netbsd", "openbsd":
+               // NetBSD and OpenBSD armv7 require 64-bit alignment.
+               if runtime.GOARCH == "arm" {
+                       salign = 8
+               }
+       }
+
+       return (salen + salign - 1) & ^(salign - 1)
+}
index 56dd0d76e91989c9083efe46d78e346b96d0a174..0988fe46088a8818b70ac3b82ce7ca987d5248ed 100644 (file)
 
 package syscall
 
-import "unsafe"
+import (
+       "sync"
+       "unsafe"
+)
+
+// See version list in https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/param.h
+var (
+       osreldateOnce sync.Once
+       osreldate     uint32
+)
+
+// First __DragonFly_version after September 2019 ABI changes
+// http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html
+const _dragonflyABIChangeVersion = 500705
+
+func supportsABI(ver uint32) bool {
+       osreldateOnce.Do(func() { osreldate, _ = SysctlUint32("kern.osreldate") })
+       return osreldate >= ver
+}
 
 type SockaddrDatalink struct {
        Len    uint8