syscall.go 846 B

123456789101112131415161718192021222324252627282930313233
  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. // +build darwin dragonfly freebsd netbsd openbsd
  5. package route
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  10. // TODO: replace with runtime.KeepAlive when available
  11. //go:noescape
  12. func keepAlive(p unsafe.Pointer)
  13. var zero uintptr
  14. func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
  15. var p unsafe.Pointer
  16. if len(mib) > 0 {
  17. p = unsafe.Pointer(&mib[0])
  18. } else {
  19. p = unsafe.Pointer(&zero)
  20. }
  21. _, _, 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))
  22. keepAlive(p)
  23. if errno != 0 {
  24. return error(errno)
  25. }
  26. return nil
  27. }