blob: aebc2dc5768f449b6edf39d8d4f6e07557b50cee [file] [log] [blame]
Don Newton98fd8812019-09-23 15:15:02 -04001// 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
Don Newtone0d34a82019-11-14 10:58:06 -05005// +build openbsd
6
Don Newton98fd8812019-09-23 15:15:02 -04007package unix
8
9import (
10 "syscall"
11 "unsafe"
12)
13
14// Unveil implements the unveil syscall.
15// For more information see unveil(2).
16// Note that the special case of blocking further
17// unveil calls is handled by UnveilBlock.
18func Unveil(path string, flags string) error {
19 pathPtr, err := syscall.BytePtrFromString(path)
20 if err != nil {
21 return err
22 }
23 flagsPtr, err := syscall.BytePtrFromString(flags)
24 if err != nil {
25 return err
26 }
27 _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(unsafe.Pointer(pathPtr)), uintptr(unsafe.Pointer(flagsPtr)), 0)
28 if e != 0 {
29 return e
30 }
31 return nil
32}
33
34// UnveilBlock blocks future unveil calls.
35// For more information see unveil(2).
36func UnveilBlock() error {
37 // Both pointers must be nil.
38 var pathUnsafe, flagsUnsafe unsafe.Pointer
39 _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(pathUnsafe), uintptr(flagsUnsafe), 0)
40 if e != 0 {
41 return e
42 }
43 return nil
44}