github.com/orangeji11/golang-sys-sw64@v0.0.0-20221228054527-b72799809e00/unix/openbsd_unveil.go (about)

     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  
     5  // +build openbsd
     6  
     7  package unix
     8  
     9  import (
    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.
    18  func 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).
    36  func 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  }