openbsd_pledge.go 891 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 openbsd
  5. // +build 386 amd64 arm
  6. package unix
  7. import (
  8. "syscall"
  9. "unsafe"
  10. )
  11. const (
  12. _SYS_PLEDGE = 108
  13. )
  14. // Pledge implements the pledge syscall. For more information see pledge(2).
  15. func Pledge(promises string, paths []string) error {
  16. promisesPtr, err := syscall.BytePtrFromString(promises)
  17. if err != nil {
  18. return err
  19. }
  20. promisesUnsafe, pathsUnsafe := unsafe.Pointer(promisesPtr), unsafe.Pointer(nil)
  21. if paths != nil {
  22. var pathsPtr []*byte
  23. if pathsPtr, err = syscall.SlicePtrFromStrings(paths); err != nil {
  24. return err
  25. }
  26. pathsUnsafe = unsafe.Pointer(&pathsPtr[0])
  27. }
  28. _, _, e := syscall.Syscall(_SYS_PLEDGE, uintptr(promisesUnsafe), uintptr(pathsUnsafe), 0)
  29. if e != 0 {
  30. return e
  31. }
  32. return nil
  33. }