1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // +build darwin dragonfly freebsd netbsd openbsd 6 7 package route 8 9 import ( 10 "syscall" 11 "unsafe" 12 ) 13 14 // TODO: replace with runtime.KeepAlive when available 15 //go:noescape 16 func keepAlive(p unsafe.Pointer) 17 18 var zero uintptr 19 20 func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error { 21 var p unsafe.Pointer 22 if len(mib) > 0 { 23 p = unsafe.Pointer(&mib[0]) 24 } else { 25 p = unsafe.Pointer(&zero) 26 } 27 _, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(p), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) 28 keepAlive(p) 29 if errno != 0 { 30 return error(errno) 31 } 32 return nil 33 } 34