openbsd_unveil.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright 2018 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. package unix
  6. import (
  7. "syscall"
  8. "unsafe"
  9. )
  10. // Unveil implements the unveil syscall.
  11. // For more information see unveil(2).
  12. // Note that the special case of blocking further
  13. // unveil calls is handled by UnveilBlock.
  14. func Unveil(path string, flags string) error {
  15. pathPtr, err := syscall.BytePtrFromString(path)
  16. if err != nil {
  17. return err
  18. }
  19. flagsPtr, err := syscall.BytePtrFromString(flags)
  20. if err != nil {
  21. return err
  22. }
  23. _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(unsafe.Pointer(pathPtr)), uintptr(unsafe.Pointer(flagsPtr)), 0)
  24. if e != 0 {
  25. return e
  26. }
  27. return nil
  28. }
  29. // UnveilBlock blocks future unveil calls.
  30. // For more information see unveil(2).
  31. func UnveilBlock() error {
  32. // Both pointers must be nil.
  33. var pathUnsafe, flagsUnsafe unsafe.Pointer
  34. _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(pathUnsafe), uintptr(flagsUnsafe), 0)
  35. if e != 0 {
  36. return e
  37. }
  38. return nil
  39. }