]> Cypherpunks repositories - gostls13.git/commitdiff
x/net/route: use libc calls on Darwin
authorKeith Randall <keithr@alum.mit.edu>
Thu, 8 Nov 2018 05:25:42 +0000 (21:25 -0800)
committerKeith Randall <khr@golang.org>
Wed, 14 Nov 2018 22:39:08 +0000 (22:39 +0000)
Starting with 1.12, we must use syscall versions
of sysctl instead of the raw syscall.

An identical CL went into the source copy at golang.org/x/net/route.
This is just a cherry pick of that CL.
(CL: https://go-review.googlesource.com/c/net/+/148597)

Change-Id: I6286ab3e49f82512491afb5bcf349e89ab5645ab
Reviewed-on: https://go-review.googlesource.com/c/149637
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/vendor/golang_org/x/net/route/empty.s [new file with mode: 0644]
src/vendor/golang_org/x/net/route/syscall.go
src/vendor/golang_org/x/net/route/syscall_go1_11_darwin.go [new file with mode: 0644]
src/vendor/golang_org/x/net/route/syscall_go1_12_darwin.go [new file with mode: 0644]

diff --git a/src/vendor/golang_org/x/net/route/empty.s b/src/vendor/golang_org/x/net/route/empty.s
new file mode 100644 (file)
index 0000000..bff0231
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2018 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 darwin,go1.12
+
+// This exists solely so we can linkname in symbols from syscall.
index 5f69ea63d91e1c05907df70de320d54a1cb67493..72431b0341061445ff53a9140739153db25ef4dd 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build darwin dragonfly freebsd netbsd openbsd
+// +build dragonfly freebsd netbsd openbsd
 
 package route
 
diff --git a/src/vendor/golang_org/x/net/route/syscall_go1_11_darwin.go b/src/vendor/golang_org/x/net/route/syscall_go1_11_darwin.go
new file mode 100644 (file)
index 0000000..7228e44
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2018 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 !go1.12
+
+package route
+
+import (
+       "syscall"
+       "unsafe"
+)
+
+var zero uintptr
+
+func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
+       var p unsafe.Pointer
+       if len(mib) > 0 {
+               p = unsafe.Pointer(&mib[0])
+       } else {
+               p = unsafe.Pointer(&zero)
+       }
+       _, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(p), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), newlen)
+       if errno != 0 {
+               return error(errno)
+       }
+       return nil
+}
diff --git a/src/vendor/golang_org/x/net/route/syscall_go1_12_darwin.go b/src/vendor/golang_org/x/net/route/syscall_go1_12_darwin.go
new file mode 100644 (file)
index 0000000..7922a68
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2018 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 go1.12
+
+package route
+
+import _ "unsafe" // for linkname
+
+//go:linkname sysctl syscall.sysctl
+func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error